### Install graphicalMCP development version from GitHub Source: https://openpharma.github.io/graphicalMCP/index.html Install the current development version of graphicalMCP from GitHub using the pak package. The first line is commented out and should be run once if pak is not already installed. ```R # install.packages("pak") pak::pak("openpharma/graphicalMCP") ``` -------------------------------- ### Example of graphical group sequential test report Source: https://openpharma.github.io/graphicalMCP/reference/print.gsd_graph_report.html This example demonstrates creating a graph and running a shortcut test, which returns a gsd_graph_report object that is then printed to the console. ```R hypotheses <- c(0.5, 0.5) transitions <- rbind(c(0, 1), c(1, 0)) g <- graph_create(hypotheses, transitions) p <- rbind( H1 = c(0.024, 0.01), H2 = c(0.015, 0.005) ) graph_test_shortcut_gsd( graph = g, p = p, alpha = 0.025, info_frac = c(0.5, 1), spending_fn = spending_of ) #> #> Test parameters ($inputs) ------------------------------------------------------ #> Initial graph #> #> --- Hypothesis weights --- #> H1: 0.5 #> H2: 0.5 #> #> --- Transition weights --- #> H1 H2 #> H1 0 1 #> H2 1 0 #> #> Alpha = 0.025 #> #> Information fractions #> Analysis_1 Analysis_2 #> H1 0.5 1 #> H2 0.5 1 #> #> P-values #> Analysis_1 Analysis_2 #> H1 0.024000 0.010000 #> H2 0.015000 0.005000 #> #> Spending functions #> H1: O'Brien-Fleming #> H2: O'Brien-Fleming #> #> Look back = FALSE #> #> Test summary ($outputs) -------------------------------------------------------- #> Hypothesis Adj.p* Reject Tested.at First.Rej.at Last.Rej.at Look.back #> H1 0.010094 TRUE 2 2 2 FALSE #> H2 0.010051 TRUE 2 2 2 FALSE #> (*) Adjusted p-values account for both the group sequential design and the #> graphical multiple comparison procedure. Based on repeated p-values when #> look_back = FALSE, and sequential p-values when look_back = TRUE. #> #> Rejection sequence: H2 -> H1 #> #> Final updated graph after removing rejected hypotheses #> #> --- Hypothesis weights --- #> H1: NA #> H2: NA #> #> --- Transition weights --- #> H1 H2 #> H1 NA NA #> H2 NA NA #> ``` -------------------------------- ### Calculate power for a graphical multiple comparison procedure Source: https://openpharma.github.io/graphicalMCP/reference/print.power_report.html An example demonstrating the setup of a graphical multiple comparison procedure and the calculation of power, which generates a power_report object. ```R # A graphical multiple comparison procedure with two primary hypotheses (H1 # and H2) and two secondary hypotheses (H3 and H4) # See Figure 4 in Bretz et al. (2011). alpha <- 0.025 hypotheses <- c(0.5, 0.5, 0, 0) delta <- 0.5 transitions <- rbind( c(0, delta, 1 - delta, 0), c(delta, 0, 0, 1 - delta), c(0, 1, 0, 0), c(1, 0, 0, 0) ) g <- graph_create(hypotheses, transitions) marginal_power <- c(0.8, 0.8, 0.7, 0.9) corr1 <- matrix(0.5, nrow = 2, ncol = 2) diag(corr1) <- 1 corr <- rbind( cbind(corr1, 0.5 * corr1), cbind(0.5 * corr1, corr1) ) success_fns <- list( # Probability to reject both H1 and H2 `H1andH2` = function(x) x[1] & x[2], # Probability to reject both (H1 and H3) or (H2 and H4) `(H1andH3)or(H2andH4)` = function(x) (x[1] & x[3]) | (x[2] & x[4]) ) set.seed(1234) # Bonferroni tests # Reduce the number of simulations to save time for package compilation power_output <- graph_calculate_power( g, alpha, sim_corr = corr, sim_n = 1e2, power_marginal = marginal_power, sim_success = success_fns ) ``` -------------------------------- ### Examples of printing updated_graph objects Source: https://openpharma.github.io/graphicalMCP/reference/print.updated_graph.html This example demonstrates creating a graph and printing the results of hypothesis deletion in both unordered and ordered modes. ```R # A graphical multiple comparison procedure with two primary hypotheses (H1 # and H2) and two secondary hypotheses (H3 and H4) # See Figure 1 in Bretz et al. (2011). hypotheses <- c(0.5, 0.5, 0, 0) transitions <- rbind( c(0, 0, 1, 0), c(0, 0, 0, 1), c(0, 1, 0, 0), c(1, 0, 0, 0) ) g <- graph_create(hypotheses, transitions) # Delete the second and third hypotheses in the "unordered mode" graph_update(g, delete = c(FALSE, TRUE, TRUE, FALSE)) #> Initial and final graphs ------------------------------------------------------- #> #> Initial graph #> #> --- Hypothesis weights --- #> H1: 0.5 #> H2: 0.5 #> H3: 0.0 #> H4: 0.0 #> #> --- Transition weights --- #> H1 H2 H3 H4 #> H1 0 0 1 0 #> H2 0 0 0 1 #> H3 0 1 0 0 #> H4 1 0 0 0 #> #> Updated graph after deleting hypotheses 2, 3 #> #> --- Hypothesis weights --- #> H1: 0.5 #> H2: NA #> H3: NA #> H4: 0.5 #> #> --- Transition weights --- #> H1 H2 H3 H4 #> H1 0 NA NA 1 #> H2 NA NA NA NA #> H3 NA NA NA NA #> H4 1 NA NA 0 # Equivalent way in the "ordered mode" to obtain the updated graph after # deleting the second and third hypotheses # Additional intermediate updated graphs are also provided graph_update(g, delete = 2:3) #> Initial and final graphs ------------------------------------------------------- #> #> Initial graph #> #> --- Hypothesis weights --- #> H1: 0.5 #> H2: 0.5 #> H3: 0.0 #> H4: 0.0 #> #> --- Transition weights --- #> H1 H2 H3 H4 #> H1 0 0 1 0 #> H2 0 0 0 1 #> H3 0 1 0 0 #> H4 1 0 0 0 #> #> Updated graph after deleting hypotheses 2, 3 #> #> --- Hypothesis weights --- #> H1: 0.5 #> H2: NA #> H3: NA #> H4: 0.5 #> #> --- Transition weights --- #> H1 H2 H3 H4 #> H1 0 NA NA 1 #> H2 NA NA NA NA #> H3 NA NA NA NA #> H4 1 NA NA 0 #> #> Deletion sequence ($intermediate_graphs) --------------------------------------- #> #> Initial graph #> #> --- Hypothesis weights --- #> H1: 0.5 #> H2: 0.5 #> H3: 0.0 #> H4: 0.0 #> #> --- Transition weights --- #> H1 H2 H3 H4 #> H1 0 0 1 0 #> H2 0 0 0 1 #> H3 0 1 0 0 #> H4 1 0 0 0 #> #> Step 1: Updated graph after removing hypothesis 2 #> #> --- Hypothesis weights --- #> H1: 0.5 #> H2: NA #> H3: 0.0 #> H4: 0.5 #> #> --- Transition weights --- #> H1 H2 H3 H4 #> H1 0 NA 1 0 #> H2 NA NA NA NA #> H3 0 NA 0 1 #> H4 1 NA 0 0 #> #> Step 2: Updated graph after removing hypotheses 2, 3 #> #> --- Hypothesis weights --- #> H1: 0.5 #> H2: NA #> H3: NA #> H4: 0.5 #> #> --- Transition weights --- #> H1 H2 H3 H4 #> H1 0 NA NA 1 #> H2 NA NA NA NA #> H3 NA NA NA NA #> H4 1 NA NA 0 #> #> Final updated graph after removing deleted hypotheses #> #> --- Hypothesis weights --- #> H1: 0.5 #> H2: NA #> H3: NA #> H4: 0.5 #> #> --- Transition weights --- #> H1 H2 H3 H4 #> H1 0 NA NA 1 #> H2 NA NA NA NA #> H3 NA NA NA NA #> H4 1 NA NA 0 ``` -------------------------------- ### Usage of example graph functions Source: https://openpharma.github.io/graphicalMCP/reference/example_graphs.html Lists the function signatures for generating example graphs. Each function creates an S3 object via graph_create(). ```R bonferroni(num_hyps, hyp_names = NULL) bonferroni_weighted(hypotheses, hyp_names = NULL) bonferroni_holm(num_hyps, hyp_names = NULL) bonferroni_holm_weighted(hypotheses, hyp_names = NULL) dunnett_single_step(num_hyps, hyp_names = NULL) dunnett_single_step_weighted(hypotheses, hyp_names = NULL) dunnett_closure_weighted(hypotheses, hyp_names = NULL) hochberg(num_hyps, hyp_names = NULL) hommel(num_hyps, hyp_names = NULL) huque_etal(hyp_names = NULL) fallback(hypotheses, hyp_names = NULL) fallback_improved_1(hypotheses, hyp_names = NULL) fallback_improved_2(hypotheses, epsilon = 1e-04, hyp_names = NULL) fixed_sequence(num_hyps, hyp_names = NULL) sidak(num_hyps, hyp_names = NULL) simple_successive_1(hyp_names = NULL) simple_successive_2(hyp_names = NULL) two_doses_two_primary_two_secondary(hyp_names = NULL) three_doses_two_primary_two_secondary(hyp_names = NULL) random_graph(num_hyps, hyp_names = NULL) ``` -------------------------------- ### Install graphicalMCP from CRAN Source: https://openpharma.github.io/graphicalMCP/index.html Install the current release version of graphicalMCP from CRAN. ```R install.packages("graphicalMCP") ``` -------------------------------- ### R: Fallback graph test with graph_test_shortcut Source: https://openpharma.github.io/graphicalMCP/articles/graph-examples.html Creates a fallback graph and runs a shortcut test with multiple p-values. The example uses runif with seed 1234 and alpha 0.025, and shows typically one hypothesis is rejected under this setup. ```R test_results$outputs$rejected #> H1 H2 H3 H4 #> TRUE FALSE FALSE FALSE ``` -------------------------------- ### Output of graph_test_shortcut() for the example graph Source: https://openpharma.github.io/graphicalMCP/reference/print.graph_report.html Output produced by graph_test_shortcut() in the example. It shows the test parameters, hypothesis and transition weights, alpha, unadjusted p-values, test types, and the test summary with adjusted p-values and rejection decisions. The final updated graph after removing rejected hypotheses is also displayed. ```r #> #> Test parameters ($inputs) ------------------------------------------------------ #> Initial graph #> #> --- Hypothesis weights --- #> H1: 0.5 #> H2: 0.5 #> H3: 0.0 #> H4: 0.0 #> #> --- Transition weights --- #> H1 H2 H3 H4 #> H1 0 0 1 0 #> H2 0 0 0 1 #> H3 0 1 0 0 #> H4 1 0 0 0 #> #> Alpha = 0.025 #> #> H1 H2 H3 H4 #> Unadjusted p-values: 0.018 0.010 0.105 0.006 #> #> Test types #> bonferroni: (H1, H2, H3, H4) #> #> Test summary ($outputs) -------------------------------------------------------- #> Hypothesis Adj.p Reject #> H1 0.020 TRUE #> H2 0.020 TRUE #> H3 0.105 FALSE #> H4 0.020 TRUE #> #> Final updated graph after removing rejected hypotheses #> #> --- Hypothesis weights --- #> H1: NA #> H2: NA #> H3: 1 #> H4: NA #> #> --- Transition weights --- #> H1 H2 H3 H4 #> H1 NA NA NA NA #> H2 NA NA NA NA #> H3 NA NA 0 NA #> H4 NA NA NA NA #> ``` -------------------------------- ### Load graphicalMCP and gt libraries Source: https://openpharma.github.io/graphicalMCP/articles/shortcut-testing.html Initial setup required to use the graphicalMCP package and the gt library for table formatting. ```R library(gt) library(graphicalMCP) ``` -------------------------------- ### Examples of gs_corr Source: https://openpharma.github.io/graphicalMCP/reference/gs_corr.html Examples demonstrating the calculation of correlation matrices for three equally spaced analyses and two analyses at 50% and 100% information fractions. ```R # Three equally spaced analyses gs_corr(c(1 / 3, 2 / 3, 1)) #> [,1] [,2] [,3] #> [1,] 1.0000000 0.7071068 0.5773503 #> [2,] 0.7071068 1.0000000 0.8164966 #> [3,] 0.5773503 0.8164966 1.0000000 # Two analyses at 50% and 100% gs_corr(c(0.5, 1)) #> [,1] [,2] #> [1,] 1.0000000 0.7071068 #> [2,] 0.7071068 1.0000000 ``` -------------------------------- ### Repeated p-values at each analysis Source: https://openpharma.github.io/graphicalMCP/reference/repeated_p.html Examples showing how to compute repeated p-values at each analysis separately. The first example computes at analysis 1 with p=0.05 and info_frac=0.3, output 0.2830392. The second computes at analysis 2 with p=c(0.05,0.02) and info_frac=c(0.3,0.7), output 0.05185878. ```r # Repeated p-values at each analysis # Analysis 1 repeated_p( p = 0.05, info_frac = 0.3, spending_fn = spending_of ) #> [1] 0.2830392 ``` ```r # Analysis 2 repeated_p( p = c(0.05, 0.02), info_frac = c(0.3, 0.7), spending_fn = spending_of ) #> [1] 0.05185878 ``` -------------------------------- ### Load graphicalMCP package Source: https://openpharma.github.io/graphicalMCP/articles/internal-validation.html Loads the graphicalMCP package before running power simulations and internal validation examples. ```r library(graphicalMCP) ``` -------------------------------- ### Simulate power output structure Source: https://openpharma.github.io/graphicalMCP/articles/shortcut-testing.html Example of the power output object structure containing local power, expected rejections, and success measures. ```R power_output$power #> $power_local #> H1 H2 H3 H4 #> 0.76396 0.75887 0.56767 0.69133 #> #> $rejection_expected #> [1] 2.78183 #> #> $power_at_least_1 #> [1] 0.85557 #> #> $power_all #> [1] 0.51205 #> #> $power_success #> H1 Expected no. of rejections #> 0.76396 2.78183 #> AtLeast1 All #> 0.85557 0.51205 #> H1andH2 (H1andH3)or(H2andH4) #> 0.66726 0.74695 ``` -------------------------------- ### Convert graphicalMCP graph to gMCP and igraph and back Source: https://openpharma.github.io/graphicalMCP/reference/as_graph.html Example converting a `graphicalMCP` initial graph to `gMCP` and `igraph` classes, then back. Requires the `gMCP` and `igraph` packages; the `all.equal()` checks return `TRUE` for both conversions. ```r g_graphicalMCP <- random_graph(5) if (requireNamespace("gMCP", quietly = TRUE)) { g_gMCP <- as_graphMCP(g_graphicalMCP) all.equal(g_graphicalMCP, as_initial_graph(g_gMCP)) } #> [1] TRUE if (requireNamespace("igraph", quietly = TRUE)) { g_igraph <- as_igraph(g_graphicalMCP) all.equal(g_graphicalMCP, as_initial_graph(g_igraph)) } #> [1] TRUE ``` -------------------------------- ### Execute graph_test_closure with parametric and Simes tests Source: https://openpharma.github.io/graphicalMCP/reference/graph_test_closure.html This example demonstrates how to run a closed graphical multiple comparison procedure by defining test groups and their corresponding test types. ```R set.seed(1234) graph_test_closure( graph = g, p = p, alpha = alpha, test_groups = list(group1 = 1:2, group2 = 3:4), test_types = c(group1 = "parametric", group2 = "simes"), test_corr = corr_list ) #> #> Test parameters ($inputs) ------------------------------------------------------ #> Initial graph #> #> --- Hypothesis weights --- #> H1: 0.5 #> H2: 0.5 #> H3: 0.0 #> H4: 0.0 #> #> --- Transition weights --- #> H1 H2 H3 H4 #> H1 0.0 0.5 0.5 0.0 #> H2 0.5 0.0 0.0 0.5 #> H3 0.0 1.0 0.0 0.0 #> H4 1.0 0.0 0.0 0.0 #> #> Alpha = 0.025 #> #> H1 H2 H3 H4 #> Unadjusted p-values: 0.018 0.010 0.105 0.006 #> #> Correlation matrix: H1 H2 #> H1 1.0 0.5 #> H2 0.5 1.0 #> #> Test types #> parametric: (H1, H2) #> simes: (H3, H4) #> #> Test summary ($outputs) -------------------------------------------------------- #> Hypothesis Adj.p Reject #> H1 0.02400 TRUE #> H2 0.01871 TRUE #> H3 0.10500 FALSE #> H4 0.02400 TRUE #> #> Final updated graph after removing rejected hypotheses #> #> --- Hypothesis weights --- #> H1: NA #> H2: NA #> H3: 1 #> H4: NA #> #> --- Transition weights --- #> H1 H2 H3 H4 #> H1 NA NA NA NA #> H2 NA NA NA NA #> H3 NA NA 0 NA #> H4 NA NA NA NA ``` -------------------------------- ### Perform group sequential testing with graph_test_shortcut_gsd Source: https://openpharma.github.io/graphicalMCP/reference/graph_test_shortcut_gsd.html Executes a group sequential test using a graphical MCP. The example includes the function call and the resulting test parameters and summary output. ```R graph_test_shortcut_gsd( graph = g, p = p, alpha = 0.025, info_frac = rbind(c(0.5, 1), c(0.6, 1)), spending_fn = spending_of ) #> #> Test parameters ($inputs) ------------------------------------------------------ #> Initial graph #> #> --- Hypothesis weights --- #> H1: 0.5 #> H2: 0.5 #> #> --- Transition weights --- #> H1 H2 #> H1 0 1 #> H2 1 0 #> #> Alpha = 0.025 #> #> Information fractions #> Analysis_1 Analysis_2 #> H1 0.5 1 #> H2 0.6 1 #> #> P-values #> Analysis_1 Analysis_2 #> H1 0.024000 0.010000 #> H2 0.015000 0.005000 #> #> Spending functions #> H1: O'Brien-Fleming #> H2: O'Brien-Fleming #> #> Look back = FALSE #> #> Test summary ($outputs) -------------------------------------------------------- #> Hypothesis Adj.p* Reject Tested.at First.Rej.at Last.Rej.at Look.back #> H1 0.010202 TRUE 2 2 2 FALSE #> H2 0.010202 TRUE 2 2 2 FALSE #> (*) Adjusted p-values account for both the group sequential design and the #> graphical multiple comparison procedure. Based on repeated p-values when #> look_back = FALSE, and sequential p-values when look_back = TRUE. #> #> Rejection sequence: H2 -> H1 #> #> Final updated graph after removing rejected hypotheses #> #> --- Hypothesis weights --- #> H1: NA #> H2: NA #> #> --- Transition weights --- #> H1 H2 #> H1 NA NA #> H2 NA NA ``` -------------------------------- ### Implement parametric tests for primary hypotheses Source: https://openpharma.github.io/graphicalMCP/articles/closed-testing.html This example demonstrates using graph_test_closure with specified test groups, types, and a correlation matrix to perform a mixed-test procedure. It shows the resulting adjusted p-values and rejection decisions. ```R corr_12 <- matrix(0.5, nrow = 2, ncol = 2) diag(corr_12) <- 1 test_results_parametric <- graph_test_closure( g, p = p_values, alpha = 0.025, test_groups = list(c(1, 2), 3:6), test_types = c("parametric", "bonferroni"), test_corr = list(corr_12, NA), test_values = TRUE ) test_results_parametric$outputs$adjusted_p #> H1 H2 H3 H4 H5 H6 #> 0.02413846 0.02413846 0.02800000 0.02800000 0.10000000 0.02800000 test_results_parametric$outputs$rejected #> H1 H2 H3 H4 H5 H6 #> TRUE TRUE FALSE FALSE FALSE FALSE ``` -------------------------------- ### Create graph and run shortcut testing with graph_test_shortcut() Source: https://openpharma.github.io/graphicalMCP/reference/graph_rejection_orderings.html Defines hypotheses, transitions, and alpha, then creates the graph and runs shortcut testing. The output shows rejected hypotheses (H1, H2, H4) and the default rejection order (H2, H1, H4). ```R # A graphical multiple comparison procedure with two primary hypotheses (H1 # and H2) and two secondary hypotheses (H3 and H4) # See Figure 4 in Bretz et al. (2011). hypotheses <- c(0.5, 0.5, 0, 0) delta <- 0.5 transitions <- rbind( c(0, delta, 1 - delta, 0), c(delta, 0, 0, 1 - delta), c(0, 1, 0, 0), c(1, 0, 0, 0) ) g <- graph_create(hypotheses, transitions) p <- c(0.018, 0.01, 0.105, 0.006) alpha <- 0.025 shortcut_testing <- graph_test_shortcut(g, p, alpha, verbose = TRUE) # Reject H1, H2, and H4 shortcut_testing$outputs$rejected #> H1 H2 H3 H4 #> TRUE TRUE FALSE TRUE # Default order of rejections: H2, H1, H4 shortcut_testing$details$del_seq #> [1] "H2" "H1" "H4" ``` -------------------------------- ### Create an initial graph with graph_create() Source: https://openpharma.github.io/graphicalMCP/articles/graphicalMCP.html Creates an initial_graph object with hypothesis weights and transition weights. The example defines four hypotheses (H1-H4) with two primary and two secondary hypotheses. The output shows the graph structure with hypothesis and transition weights. ```R library(graphicalMCP) # A graph of two primary hypotheses (H1 and H2) and two secondary hypotheses (H3 # and H4) hypotheses <- c(0.5, 0.5, 0, 0) transitions <- rbind( c(0, 0, 1, 0), c(0, 0, 0, 1), c(0, 1, 0, 0), c(1, 0, 0, 0) ) hyp_names <- c("H1", "H2", "H3", "H4") example_graph <- graph_create(hypotheses, transitions, hyp_names) example_graph #> Initial graph #> #> --- Hypothesis weights --- #> H1: 0.5 #> H2: 0.5 #> H3: 0.0 #> H4: 0.0 #> #> --- Transition weights --- #> H1 H2 H3 H4 #> H1 0 0 1 0 #> H2 0 0 0 1 #> H3 0 1 0 0 #> H4 1 0 0 0 ``` -------------------------------- ### Example: Create and print an initial graph Source: https://openpharma.github.io/graphicalMCP/reference/print.initial_graph.html Creates a graphical multiple comparison procedure with two primary and two secondary hypotheses, then prints it. The output shows the initial graph header, hypothesis weights, and transition weights. ```r # A graphical multiple comparison procedure with two primary hypotheses (H1 # and H2) and two secondary hypotheses (H3 and H4) # See Figure 1 in Bretz et al. (2011). hypotheses <- c(0.5, 0.5, 0, 0) transitions <- rbind( c(0, 0, 1, 0), c(0, 0, 0, 1), c(0, 1, 0, 0), c(1, 0, 0, 0) ) hyp_names <- c("H11", "H12", "H21", "H22") g <- graph_create(hypotheses, transitions, hyp_names) g #> Initial graph #> #> --- Hypothesis weights --- #> H11: 0.5 #> H12: 0.5 #> H21: 0.0 #> H22: 0.0 #> #> --- Transition weights --- #> H11 H12 H21 H22 #> H11 0 0 1 0 #> H12 0 0 0 1 #> H21 0 1 0 0 #> H22 1 0 0 0 ``` -------------------------------- ### Create and test a graph with graph_create() and graph_test_shortcut() Source: https://openpharma.github.io/graphicalMCP/reference/print.graph_report.html Example from the print.graph_report documentation: creates a graphical multiple comparison procedure with two primary (H1, H2) and two secondary (H3, H4) hypotheses, then runs graph_test_shortcut() with p-values and alpha = 0.025. The printed output shows test parameters, hypothesis weights, transition weights, adjusted p-values, and rejection decisions. ```r # A graphical multiple comparison procedure with two primary hypotheses (H1 # and H2) and two secondary hypotheses (H3 and H4) # See Figure 1 in Bretz et al. (2011). hypotheses <- c(0.5, 0.5, 0, 0) transitions <- rbind( c(0, 0, 1, 0), c(0, 0, 0, 1), c(0, 1, 0, 0), c(1, 0, 0, 0) ) g <- graph_create(hypotheses, transitions) p <- c(0.018, 0.01, 0.105, 0.006) alpha <- 0.025 graph_test_shortcut(g, p, alpha) ``` -------------------------------- ### Example: Generate Weighting Strategy for 4 Hypotheses with Output Source: https://openpharma.github.io/graphicalMCP/reference/graph_generate_weights.html Create a graph with two primary and two secondary hypotheses, then compute the weighting strategy. The printed matrix shows intersection hypotheses and weights for all 15 combinations. ```R # A graphical multiple comparison procedure with two primary hypotheses (H1 # and H2) and two secondary hypotheses (H3 and H4) # See Figure 1 in Bretz et al. (2011). hypotheses <- c(0.5, 0.5, 0, 0) transitions <- rbind( c(0, 0, 1, 0), c(0, 0, 0, 1), c(0, 1, 0, 0), c(1, 0, 0, 0) ) g <- graph_create(hypotheses, transitions) graph_generate_weights(g) ``` ```output #> H1 H2 H3 H4 H1 H2 H3 H4 #> 1 1 1 1 1 0.5 0.5 0.0 0.0 #> 2 1 1 1 0 0.5 0.5 0.0 0.0 #> 3 1 1 0 1 0.5 0.5 0.0 0.0 #> 4 1 1 0 0 0.5 0.5 0.0 0.0 #> 5 1 0 1 1 0.5 0.0 0.0 0.5 #> 6 1 0 1 0 1.0 0.0 0.0 0.0 #> 7 1 0 0 1 0.5 0.0 0.0 0.5 #> 8 1 0 0 0 1.0 0.0 0.0 0.0 #> 9 0 1 1 1 0.0 0.5 0.5 0.0 #> 10 0 1 1 0 0.0 0.5 0.5 0.0 #> 11 0 1 0 1 0.0 1.0 0.0 0.0 #> 12 0 1 0 0 0.0 1.0 0.0 0.0 #> 13 0 0 1 1 0.0 0.0 0.5 0.5 #> 14 0 0 1 0 0.0 0.0 1.0 0.0 #> 15 0 0 0 1 0.0 0.0 0.0 1.0 ``` -------------------------------- ### Example for adjust_weights_parametric() Source: https://openpharma.github.io/graphicalMCP/reference/adjust_weights.html Runs adjust_weights_parametric() on a 4-hypothesis Bonferroni-Holm graph with two test groups and a diagonal correlation matrix. Returns a 15-row matrix of adjusted weights. The example uses a random seed (1234) and alpha = 0.025. ```R alpha <- 0.025 num_hyps <- 4 g <- bonferroni_holm(num_hyps) weighting_strategy <- graph_generate_weights(g) matrix_intersections <- weighting_strategy[, seq_len(num_hyps)] matrix_weights <- weighting_strategy[, -seq_len(num_hyps)] set.seed(1234) adjust_weights_parametric( matrix_weights = matrix_weights, matrix_intersections = matrix_intersections, test_corr = list(diag(2), diag(2)), alpha = alpha, test_groups = list(1:2, 3:4) ) ``` ```R #> H1 H2 H3 H4 #> 1 0.2507911 0.2507911 0.2507911 0.2507911 #> 2 0.3347254 0.3347254 0.3333333 0.0000000 #> 3 0.3347254 0.3347254 0.0000000 0.3333333 #> 4 0.5031647 0.5031647 0.0000000 0.0000000 #> 5 0.3333333 0.0000000 0.3347254 0.3347254 #> 6 0.5000000 0.0000000 0.5000000 0.0000000 #> 7 0.5000000 0.0000000 0.0000000 0.5000000 #> 8 1.0000000 0.0000000 0.0000000 0.0000000 #> 9 0.0000000 0.3333333 0.3347254 0.3347254 #> 10 0.0000000 0.5000000 0.5000000 0.0000000 #> 11 0.0000000 0.5000000 0.0000000 0.5000000 #> 12 0.0000000 1.0000000 0.0000000 0.0000000 #> 13 0.0000000 0.0000000 0.5031647 0.5031647 #> 14 0.0000000 0.0000000 1.0000000 0.0000000 #> 15 0.0000000 0.0000000 0.0000000 1.0000000 ``` -------------------------------- ### Plot the initial graph with plot() Source: https://openpharma.github.io/graphicalMCP/articles/graphicalMCP.html Plots the initial graph created with graph_create(). The vertex.size parameter controls the size of the nodes in the plot. ```R plot(example_graph, vertex.size = 60) ``` -------------------------------- ### Example: adjust_p_hochberg Source: https://openpharma.github.io/graphicalMCP/reference/adjust_p.html Computes an adjusted p-value using Hochberg tests with four hypotheses and p-values. The output is 0.05. ```r hypotheses <- c(H1 = .25, H2 = .25, H3 = 0.25, H4 = 0.25) p <- c(0.019, 0.025, 0.05, .05) adjust_p_hochberg(p, hypotheses) #> [1] 0.05 ``` -------------------------------- ### Example: adjust_p_simes Source: https://openpharma.github.io/graphicalMCP/reference/adjust_p.html Computes an adjusted p-value using Simes tests with three hypotheses and p-values. The output is 0.03333333. ```r hypotheses <- c(H1 = 0.5, H2 = 0.25, H3 = 0.25) p <- c(0.019, 0.025, 0.05) adjust_p_simes(p, hypotheses) #> [1] 0.03333333 ``` -------------------------------- ### R: Run graph_test_closure() on a graphical MCP with Bonferroni tests Source: https://openpharma.github.io/graphicalMCP/reference/graph_test_closure.html This R example creates a graphical multiple comparison procedure with two primary (H1, H2) and two secondary (H3, H4) hypotheses, as in Figure 4 of Bretz et al. (2011). It defines the graph with graph_create(), then applies the closed testing procedure using graph_test_closure() with Bonferroni tests. The output shows the test parameters, adjusted p-values, and the final updated graph after removing rejected hypotheses. The results are the same as those from graph_test_shortcut(). ```r # A graphical multiple comparison procedure with two primary hypotheses # (H1 and H2) and two secondary hypotheses (H3 and H4) # See Figure 4 in Bretz et al. (2011). hypotheses <- c(0.5, 0.5, 0, 0) delta <- 0.5 transitions <- rbind( c(0, delta, 1 - delta, 0), c(delta, 0, 0, 1 - delta), c(0, 1, 0, 0), c(1, 0, 0, 0) ) g <- graph_create(hypotheses, transitions) p <- c(0.018, 0.01, 0.105, 0.006) alpha <- 0.025 # Closed graphical multiple comparison procedure using Bonferroni tests # Same results as `graph_test_shortcut(g, p, alpha)` graph_test_closure(g, p, alpha) #> #> Test parameters ($inputs) ------------------------------------------------------ #> Initial graph #> #> --- Hypothesis weights --- #> H1: 0.5 #> H2: 0.5 #> H3: 0.0 #> H4: 0.0 #> #> --- Transition weights --- #> H1 H2 H3 H4 #> H1 0.0 0.5 0.5 0.0 #> H2 0.5 0.0 0.0 0.5 #> H3 0.0 1.0 0.0 0.0 #> H4 1.0 0.0 0.0 0.0 #> #> Alpha = 0.025 #> #> H1 H2 H3 H4 #> Unadjusted p-values: 0.018 0.010 0.105 0.006 #> #> Test types #> bonferroni: (H1, H2, H3, H4) #> #> Test summary ($outputs) -------------------------------------------------------- #> Hypothesis Adj.p Reject #> H1 0.024 TRUE #> H2 0.020 TRUE #> H3 0.105 FALSE #> H4 0.024 TRUE #> #> Final updated graph after removing rejected hypotheses #> #> --- Hypothesis weights --- #> H1: NA #> H2: NA #> H3: 1 #> H4: NA #> #> --- Transition weights --- #> H1 H2 H3 H4 #> H1 NA NA NA NA #> H2 NA NA NA NA #> H3 NA NA 0 NA #> H4 NA NA NA NA #> ``` -------------------------------- ### Example: adjust_p_bonferroni Source: https://openpharma.github.io/graphicalMCP/reference/adjust_p.html Computes an adjusted p-value using Bonferroni tests with three hypotheses and p-values. The output is 0.038. ```r hypotheses <- c(H1 = 0.5, H2 = 0.25, H3 = 0.25) p <- c(0.019, 0.025, 0.05) adjust_p_bonferroni(p, hypotheses) #> [1] 0.038 ```