### Launch the medRCT Shiny application Source: https://t0ngchen.github.io/medRCT/articles/intro.html Use this command to start the interactive Shiny interface for assessing fitted models before proceeding with analysis. ```R medRCT_shiny(data = data) ``` -------------------------------- ### Install medRCT Package from GitHub Source: https://t0ngchen.github.io/medRCT/index.html Use this command to install the latest stable version of the medRCT package directly from its GitHub repository. Ensure you have the 'remotes' package installed. ```r remotes::install_github("T0ngChen/medRCT") ``` -------------------------------- ### Launch medRCT Shiny Application Source: https://t0ngchen.github.io/medRCT/reference/medRCT_shiny.html Initializes the interactive Shiny interface for model assessment using a provided dataset. ```R medRCT_shiny(data, ...) ``` ```R if (interactive()) { medRCT_shiny(data=LSACdata) } ``` -------------------------------- ### Launch Interactive Shiny App Source: https://t0ngchen.github.io/medRCT/reference/medRCT_shiny.html Launches a Shiny application to provide model summaries and facilitate adjustments of interaction terms for model assessment. ```APIDOC ## GET medRCT_shiny ### Description Launches a Shiny application to provide model summaries of all models fitted by the algorithm. The app provides a user-friendly interface for model assessment and facilitates adjustments of interaction terms to improve model fit. ### Method Function Call ### Endpoint medRCT_shiny(data, ...) ### Parameters #### Arguments - **data** (data.frame) - Required - A dataset containing variables for the exposure, outcome, mediators, confounders, and exposure-induced mediator-outcome confounders. - **...** (dots) - Optional - Additional arguments for shiny. ### Request Example medRCT_shiny(data=LSACdata) ### Response #### Success Response - **Shiny App** (Interface) - Launches an interactive browser-based interface for model assessment. ``` -------------------------------- ### Initialize medRCT Analysis Source: https://t0ngchen.github.io/medRCT/index.html Load the package, set a seed for reproducibility, and define the confounder vector for the analysis. ```R # Load the medRCT package library(medRCT) # Set a seed for reproducibility set.seed(2025) # Display the first few rows of the dataset head(LSACdata) #> child_sex child_atsi mat_cob mat_engl mat_age sep fam_stress parent_mh #> 1 0 1 0 0 1 0 0 0 #> 2 NA 0 0 0 NA 0 NA NA #> 3 NA 0 0 0 NA 0 NA NA #> 4 NA 0 0 0 NA 0 NA NA #> 5 1 0 0 0 1 1 0 0 #> 6 1 0 0 0 1 0 1 1 #> preschool_att child_mh child_SDQscore #> 1 1 0 8.924660 #> 2 0 0 7.349826 #> 3 0 1 12.824643 #> 4 0 0 6.611369 #> 5 0 1 10.329341 #> 6 0 1 13.552515 # Define confounders for the analysis confounders <- c("child_sex", "child_atsi", "mat_cob", "mat_engl", "mat_age") ``` -------------------------------- ### Mediation Analysis Configuration Source: https://t0ngchen.github.io/medRCT/reference/medRCT.html This section details the arguments available for configuring mediation analysis, including data input, variable specification, interaction terms, and simulation parameters. ```APIDOC ## Arguments for Mediation Analysis ### Data Input - **dat** (data.frame) - Required - A data frame containing the dataset for analysis. It should include variables for the exposure, outcome, mediators, (baseline) confounders, and intermediate (exposure-induced) mediator-outcome confounders. ### Variable Specification - **exposure** (character) - Required - The name of the exposure variable. Must be categorical with '0' denoting the unexposed group. - **outcome** (character) - Required - The name of the outcome variable. Can be binary or continuous. - **mediators** (character vector) - Required - Names of the mediator variables. Can be binary or continuous. Order matters for `shift_k_order`. - **intermediate_confs** (character vector) - Optional - Names of intermediate confounder variables. Can be binary or continuous. Defaults to NULL. - **confounders** (character vector) - Required - Names of baseline confounder variables. ### Interaction Terms - **interactions_XC** (character) - Optional - Specifies two-way interactions between exposure and baseline confounders. Options: 'all' (default), 'none'. - **use_interactions_XM** (logical) - Optional - Include exposure–mediator and exposure–intermediate confounder interactions. Defaults to TRUE. ### Effect Measurement and Intervention Type - **intervention_type** (character) - Optional - Type of interventional effect to estimate. Options: 'all' (default), 'shift_all', 'shift_k', 'shift_k_order'. - **effect_measure** (character) - Optional - Effect measure to calculate. For continuous outcome: 'Diff'. For binary outcome: 'RD' or 'RR'. Defaults based on outcome type. ### Simulation and Bootstrapping - **mcsim** (integer) - Optional - Number of Monte Carlo simulations. Defaults to 200. Recommended minimum is 200. - **bootstrap** (logical) - Optional - Whether to perform bootstrapping. Defaults to TRUE. - **boot_args** (list) - Optional - Arguments for bootstrapping (e.g., R, stype, ci.type). Defaults to R=200, stype='i', ci.type='norm'. - **...** - Optional - Additional arguments passed to the `boot` function. ``` -------------------------------- ### Estimate interventional effects with medRCT Source: https://t0ngchen.github.io/medRCT/articles/intro.html This snippet demonstrates loading the package, inspecting the dataset, and running the medRCT function to estimate interventional indirect effects. ```R library(medRCT) #> medRCT: Causal mediation analysis estimating interventional effects mapped to a target trial #> Note: When setting intervention_type = 'shift_k_order', the order of the mediators as specified #> in the 'mediators' argument is important. # Set a seed for reproducibility set.seed(2025) # Display the first few rows of the dataset head(LSACdata) #> child_sex child_atsi mat_cob mat_engl mat_age sep fam_stress parent_mh #> 1 0 1 0 0 1 0 0 0 #> 2 NA 0 0 0 NA 0 NA NA #> 3 NA 0 0 0 NA 0 NA NA #> 4 NA 0 0 0 NA 0 NA NA #> 5 1 0 0 0 1 1 0 0 #> 6 1 0 0 0 1 0 1 1 #> preschool_att child_mh child_SDQscore #> 1 1 0 8.924660 #> 2 0 0 7.349826 #> 3 0 1 12.824643 #> 4 0 0 6.611369 #> 5 0 1 10.329341 #> 6 0 1 13.552515 # Define confounders for the analysis confounders <- c("child_sex", "child_atsi", "mat_cob", "mat_engl", "mat_age") # Define intermediate confounders intermediate_confs <- "fam_stress" # Estimate interventional indirect effects med_res <- medRCT( dat = LSACdata, exposure = "sep", outcome = "child_mh", mediators = c("parent_mh", "preschool_att"), intermediate_confs = intermediate_confs, confounders = confounders, interactions_XC = "all", intervention_type = "all", bootstrap = TRUE, boot_args = list(R = 100, stype = "i", ci.type = "norm"), mcsim = 200 ) #> Assumed causal order for estimating effect of type 'shift_k_order': parent_mh, preschool_att #> Conducting complete case analysis, 2499 observations were excluded due to missing data. ``` -------------------------------- ### Estimate and Summarize Interventional Effects Source: https://t0ngchen.github.io/medRCT/index.html Run the medRCT analysis using shift_k intervention type and summarize the resulting interventional effects. Note that incomplete records are automatically removed, and at least 200 Monte Carlo simulations are recommended for production. ```R # Estimate interventional effects for a hypothetical intervention # that shifts the distribution of each mediator individually med_res <- medRCT( dat = LSACdata, exposure = "sep", outcome = "child_mh", mediators = c("parent_mh", "preschool_att"), intermediate_confs = "fam_stress", # intermediate confounders confounders = confounders, bootstrap = TRUE, intervention_type = "shift_k", mcsim = 50 ) #> Conducting complete case analysis, 2499 observations were excluded due to missing data. #> Note: It is recommended to run analysis with no fewer than 200 Monte Carlo simulations. # Summarise the results summary(med_res) #> #> Estimated interventional indirect effect: #> #> Estimate Std. Error CI Lower CI Upper p-value #> IIE_1 (p_trt - p_1) 0.011155 0.004181 0.002814 0.019203 0.0076 #> IIE_2 (p_trt - p_2) -0.000763 0.002501 -0.005443 0.004362 0.7604 #> TCE (p_trt - p_ctr) 0.128669 0.024554 0.082420 0.178668 1.6e-07 #> #> Estimated interventional direct effect: #> #> Estimate Std. Error CI Lower CI Upper p-value #> IDE_1 (p_1 - p_ctr) 0.1175 0.0247 0.0712 0.1679 1.9e-06 #> IDE_2 (p_2 - p_ctr) 0.1294 0.0244 0.0833 0.1789 1.1e-07 #> #> Estimated expected outcome in each trial arm: #> #> Estimate Std. Error CI Lower CI Upper p-value #> p_1 0.3302 0.0225 0.2872 0.3755 <2e-16 #> p_2 0.3421 0.0221 0.2995 0.3862 <2e-16 #> p_ctr 0.2127 0.0100 0.1922 0.2315 <2e-16 #> p_trt 0.3413 0.0223 0.2987 0.3860 <2e-16 #> #> Sample Size: 2608 #> #> Simulations: 50 #> #> Effect Measure: Risk Difference #> Results are based on all 100 bootstrap samples. ``` -------------------------------- ### Summarise medRCT object Source: https://t0ngchen.github.io/medRCT/reference/summary.medRCT.html Use this method to generate a summary for an object of class medRCT. ```R # S3 method for class 'medRCT' summary(object, ...) ``` -------------------------------- ### Accessing the LSACdata dataset Source: https://t0ngchen.github.io/medRCT/reference/LSACdata.html Use this identifier to load or reference the simulated LSAC dataset in R. ```R LSACdata ``` -------------------------------- ### Summarize medRCT results Source: https://t0ngchen.github.io/medRCT/articles/intro.html Displays the estimated interventional indirect effects, direct effects, and expected outcomes for a medRCT object. ```R summary(med_res) ``` -------------------------------- ### Specify interaction terms in medRCT Source: https://t0ngchen.github.io/medRCT/articles/intro.html Configures two-way interactions between exposure and baseline confounders using the interactions_XC argument. ```R interactions_XC = "all" ``` ```R interactions_XC = "none" ``` ```R interactions_XC = "exposure:confounder1 + exposure:confounder2" ``` -------------------------------- ### Perform mediation analysis without intermediate confounders Source: https://t0ngchen.github.io/medRCT/articles/intro.html Set the intermediate_confs argument to NULL when no intermediate confounders are present in the analysis. ```R med_res <- medRCT( dat = LSACdata, exposure = "sep", outcome = "child_mh", mediators = c("parent_mh", "preschool_att"), intermediate_confs = intermediate_confs, confounders = confounders, interactions_XC = "all", intervention_type = "all", intermediate_confs = NULL, bootstrap = TRUE, boot_args = list(R = 100, stype = "i", ci.type = "norm"), mcsim = 200 ) ``` -------------------------------- ### medRCT Function Reference Source: https://t0ngchen.github.io/medRCT/reference/medRCT.html Reference for the main medRCT function, detailing its parameters for causal mediation analysis. ```APIDOC ## medRCT Function ### Description Estimates interventional effects that map to a target trial evaluating hypothetical mediator interventions of interest. It can handle any number of potentially correlated mediators, including mediators that are not of primary interest but that are intermediate (exposure-induced) mediator-outcome confounders. ### Usage ```R medRCT( dat, exposure, outcome, mediators, intermediate_confs, confounders, interactions_XC = "all", use_interactions_XM = TRUE, intervention_type = c("all", "shift_all", "shift_k", "shift_k_order"), effect_measure = NULL, mcsim = 200, bootstrap = TRUE, boot_args = list(R = 200, stype = "i", ci.type = "norm"), ... ) ``` ### Parameters #### Data and Variable Specification - **dat** (data.frame) - The dataset containing the variables. - **exposure** (character) - The name of the exposure variable. - **outcome** (character) - The name of the outcome variable. - **mediators** (character) - Names of the mediator variables. - **intermediate_confs** (character) - Names of intermediate confounders. - **confounders** (character) - Names of confounders. #### Model Specification - **interactions_XC** (character or list) - Specifies interactions between exposure and confounders. Defaults to "all". - **use_interactions_XM** (logical) - Whether to use interactions between exposure and mediators. Defaults to TRUE. #### Intervention and Effect Measurement - **intervention_type** (character) - Type of intervention to consider. Options include "all", "shift_all", "shift_k", "shift_k_order". - **effect_measure** (NULL or character) - The effect measure to compute. If NULL, defaults are used. #### Simulation and Bootstrapping - **mcsim** (integer) - Number of Monte Carlo simulations for estimation. Defaults to 200. - **bootstrap** (logical) - Whether to perform bootstrapping for confidence intervals. Defaults to TRUE. - **boot_args** (list) - Arguments for the bootstrapping function. Defaults to `list(R = 200, stype = "i", ci.type = "norm")`. #### Other - **...** - Additional arguments to be passed to other functions. ``` -------------------------------- ### summary.medRCT.Rd Source: https://t0ngchen.github.io/medRCT/reference/summary.medRCT.html Provides a summary of the results obtained from a mediation analysis conducted using the medRCT function. ```APIDOC ## summary.medRCT.Rd ### Description Provides a summary of the results obtained from a mediation analysis conducted using the `medRCT` function. ### Usage ```R # S3 method for class 'medRCT' summary(object, ...) ``` ### Arguments * `object` (medRCT) - An object of class `medRCT`. * `...` - Additional arguments to customise the summary output. ``` -------------------------------- ### Estimate Interventional Indirect Effects Source: https://t0ngchen.github.io/medRCT/reference/medRCT.html Use this function to estimate interventional indirect effects for various hypothetical interventions. Ensure confounders and mediators are correctly defined. The function accepts binary mediators and intermediate confounders coded as 0/1, TRUE/FALSE, or any two unique values. ```R if (FALSE) { # \dontrun{ # Define confounders for the analysis confounders <- c("child_sex", "child_atsi", "mat_cob", "mat_engl", "mat_age") # Define intermediate confounders intermediate_confs <- "fam_stress" # Estimate interventional indirect effects for various # hypothetical interventions med_res <- medRCT( dat = LSACdata, exposure = "sep", outcome = "child_mh", mediators = c("parent_mh", "preschool_att"), intermediate_confs = intermediate_confs, confounders = confounders, interactions_XC = "all", intervention_type = "all", effect_measure = "RD", bootstrap = TRUE, boot_args = list(R = 200, stype = "i", ci.type = "norm"), mcsim = 200 ) # Summarise the results summary(med_res) } # } ``` -------------------------------- ### medRCT Function Signature Source: https://t0ngchen.github.io/medRCT/reference/medRCT.html This is the main function for causal mediation analysis. It requires data, exposure, outcome, mediators, intermediate confounders, and general confounders as input. Optional arguments control interaction terms, intervention types, effect measures, and simulation/bootstrap settings. ```R medRCT( dat, exposure, outcome, mediators, intermediate_confs, confounders, interactions_XC = "all", use_interactions_XM = TRUE, intervention_type = c("all", "shift_all", "shift_k", "shift_k_order"), effect_measure = NULL, mcsim = 200, bootstrap = TRUE, boot_args = list(R = 200, stype = "i", ci.type = "norm"), ... ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.