Type: | Package |
Title: | Educational Platform Trials Simulator |
Version: | 1.2.2 |
Description: | Simulating multi-arm cluster-randomized, multi-site, and simple randomized trials. Includes functions for conducting multilevel analyses using both Bayesian and Frequentist methods. Supports futility and superiority analyses through Bayesian approaches, along with visualization tools to aid interpretation and presentation of results. |
License: | AGPL (≥ 3) |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.2 |
LazyData: | true |
Suggests: | knitr, rmarkdown, testthat (≥ 3.0.0) |
Depends: | R (≥ 4.3.0) |
Imports: | eefAnalytics, lme4, ggplot2, ggpubr, methods, graphics, stats, mvtnorm, coda, MCMCvis, dplyr, magrittr, shiny |
NeedsCompilation: | no |
Author: | Mohammad Sayari [aut, cre], Akansha Singh [aut], Germaine Uwimpuhwe [aut], Jochen Einbeck [aut] |
Maintainer: | Mohammad Sayari <md.sayari13@gmail.com> |
Config/testthat/edition: | 3 |
Packaged: | 2025-05-13 16:16:50 UTC; mdsay |
Repository: | CRAN |
Date/Publication: | 2025-05-20 08:00:02 UTC |
Simulated 4-Arm Cluster Randomized Trial (CRT) Data
Description
A simulated cluster randomised trial dataset containing 10 schools and 1,000 pupils. This is a 4-arm trial design with one control group and three intervention groups.
Usage
crt4armSimData
Format
A data frame with 1,000 rows and 7 variables:
- pupils
Identifier for each pupil
- schools
Identifier for each school
- interventions
Treatment assignment coded as 0 for control and 1–3 for intervention groups
- pretest
Pre-test scores
- gender
Binary gender
- ethnicity
A categorical variable with 3 categories
- posttest
Post-test scores
Source
Simulated
Add a New Intervention Group to Clustered Randomized Trial (CRT)
Description
This function adds a new intervention group to an existing CRT dataset. It models post-test outcomes using fixed and random effects estimated from the original data and incorporates user-specified effect size and attrition for the new intervention.
Usage
crtAddIntervention(
originalData,
ns,
np,
es,
attritionrate,
outcome,
interventions,
schoolsID,
pupilsID,
continuous_covariates,
categorical_covariates
)
Arguments
originalData |
A data frame containing the variables including outcome, predictors, the clustering variable, and the intervention for CRT design. |
ns |
The number of schools to assign to the new intervention group. |
np |
The number of pupils per new school. |
es |
The standardized effect size for the new intervention group. |
attritionrate |
The proportion of pupils in the new group to drop due to attrition. |
outcome |
A string specifying the name of the column containing outcome variable (e.g., post-test scores). |
interventions |
A string specifying the name of the intervention assignment column. |
schoolsID |
A string specifying the name of the school ID column. |
pupilsID |
A string specifying the name of the pupil ID column. |
continuous_covariates |
A character vector specifying the names of continuous covariates in the model. |
categorical_covariates |
A character vector specifying the names of categorical covariates in the model (converted to factors). |
Details
The function performs the following:
Fits a linear mixed-effects model (
lmer
) to the original dataset using provided covariates.Applies the specified effect size (
es
) and generates new post-test scores.Simulates attrition by removing post-test scores at random.
Value
A data.frame
combining the original and new intervention group, including post-test outcomes
simulated for the new intervention based on the estimated mixed model.
See Also
lmer
from the lme4 package
Examples
data(crt4armSimData)
new_crt5armData <- crtAddIntervention(originalData = crt4armSimData, ns = 2,
np = 100, es = 0.3, attritionrate = 0.1, outcome = "posttest", interventions = "interventions",
schoolsID = "schools", pupilsID = "pupils",
continuous_covariates = c("pretest"), categorical_covariates = c("gender", "ethnicity"))
head(new_crt5armData)
Simulate Clustered Randomized Trial (CRT) Data
Description
This function simulates a multiple intervention arms CRT data. The model includes intervention and pre-test scores as covariates.
Usage
crtDataSimulation(
ni,
nstreated,
np,
ns,
sigma,
ICC,
B0,
es,
seed,
attritionrates,
covariates
)
Arguments
ni |
The number of intervention groups excluding the control group. |
nstreated |
The number of schools in each group, including the control group. It should be specified as an integer vector of length ni + 1. |
np |
The number of pupils per school. |
ns |
The total number of schools. |
sigma |
The standard deviation of the individual-level error. |
ICC |
The intra-class correlation coefficient. |
B0 |
The intercept of the model. |
es |
The standardized effect sizes for each intervention group. It should be specified as a numeric vector. |
seed |
The random seed for reproducibility. |
attritionrates |
The proportion of attrition for each group, including the control group. It should be specified as a numeric vector of length ni + 1. |
covariates |
List of covariate specifications. Each element should be a list with the following fields:
|
Value
A data.frame
containing:
- pupils
Unique pupil ID
- schools
School ID
- interventions
Intervention group (0 = control, 1 to
ni
for interventions)- covariates
Simulated covariates
- posttest
Simulated posttest scores (NA if attrited)
Examples
covariates <- list(
list(name = "pretest", type = "continuous", sd = 1, coefficient = 1.7),
list(name = "gender", type = "categorical", levels = c("Male", "Female"),
probs = c(0.3, 0.7), reference = "Male", coefficients = list(B = -0.5)),
list(name = "ethnicity", type = "categorical", levels = c("White", "Black", "Asian"),
probs = c(0.3, 0.3, 0.4), reference = "White", coefficients = list(B = 1.02, C = 1.3))
)
crtdata <- crtDataSimulation(ni = 3, ns = 10, np = 100, nstreated = c(2, 3, 2, 3),
sigma = 1, ICC = 0.1, B0 = 1.45, es = c(0.1, 0.2, 0.5),
seed = 1234, attritionrates = c(0, 0.1, 0.2, 0.1), covariates = covariates)
head(crtdata)
Internal plotting function for comparison plots
Description
Internal plotting function for comparison plots
Usage
forestPlotMultiArms(
eefAnalyticsList,
group,
Conditional = TRUE,
ES_Total = TRUE,
modelNames,
intlabels = NULL,
intcolors = NULL,
maintitle = NULL,
xlabel = NULL,
ylabel = NULL,
vlinecolor = "black"
)
Futility Analysis Across Interventions for CRT, MST, or SRT Designs
Description
This function performs a Bayesian futility analysis for each intervention group compared to control, across cluster randomized trials (CRT), multisite trials (MST) or simple randomized trials (SRT).
Usage
futilityAnalysis(
method = c("crt", "mst", "srt"),
data,
outcome = "posttest",
interventions = "interventions",
Random = "schools",
Nsim = 10000,
Threshold = 0.05,
FutThreshold = 0.8,
continuous_covariates = NULL,
categorical_covariates = NULL
)
Arguments
method |
The trial design type: "crt", "mst", or "srt". |
data |
A data frame containing the variables including outcome, predictors, the clustering variable, and the intervention. |
outcome |
The name of the outcome (post-test) variable. |
interventions |
A string specifying the intervention variable. |
Random |
The name of the clustering variable (e.g., schools or sites) for CRT and MST designs. |
Nsim |
Number of MCMC iterations to be performed. A minimum of 10,000 is recommended to ensure convergence. |
Threshold |
The effect size threshold for posterior computation (default = 0.05). |
FutThreshold |
The minimum posterior probability threshold for non-futility (default = 0.8). |
continuous_covariates |
A character vector specifying the names of continuous covariates. |
categorical_covariates |
A character vector specifying the names of categorical covariates (converted to factors). |
Details
The function loops over each intervention, fits the appropriate Bayesian model (crtBayes
, mstBayes
, srtBayes
),
extracts the posterior probability, and determines futility based on the specified probability threshold.
Value
A data.frame
with columns:
-
Intervention
: Intervention group identifier. -
Futility
: 1 if considered futile (posterior probability < FutThreshold), 0 otherwise. -
ProbES
: Bayesian posterior probabilities that the observed effect size is greater than or equal to a pre-specified threshold
See Also
crtBayes
, mstBayes
, srtBayes
functions from the eefAnalytics package
Examples
###Futility analysis of cluster randomized trial###
data(crt4armSimData)
futilityAnalysis(method = "crt", data = crt4armSimData, outcome = "posttest",
interventions = "interventions", Random = "schools", Nsim = 10000,
Threshold = 0.05, FutThreshold = 0.8,continuous_covariates = c("pretest"),
categorical_covariates = c("gender", "ethnicity"))
###Futility analysis of multisite trial###
data(mst4armSimData)
futilityAnalysis(method = "mst", data = mst4armSimData, outcome = "posttest",
interventions = "interventions", Random = "schools", Nsim = 10000,
Threshold = 0.05, FutThreshold = 0.8,continuous_covariates = c("pretest"),
categorical_covariates = c("gender", "ethnicity"))
###Futility analysis of simple randomized trial###
data(srt4armSimData)
futilityAnalysis(method = "srt", data = srt4armSimData, outcome = "posttest",
interventions = "interventions", Nsim = 10000, Threshold = 0.05, FutThreshold = 0.8,
continuous_covariates = c("pretest"), categorical_covariates = c("gender", "ethnicity"))
Simulated 4-Arm Multisite Trial (MST) Data
Description
A simulated multisite trial dataset containing 10 schools and 1,000 pupils. This is a 4-arm trial design with one control group and three intervention groups.
Usage
mst4armSimData
Format
A data frame with 1,000 rows and 7 variables:
- pupils
Identifier for each pupil
- schools
Identifier for each school
- interventions
Treatment assignment coded as 0 for control and 1–3 for intervention groups
- pretest
Pre-test scores
- gender
Binary gender
- ethnicity
A categorical variable with 3 categories
- posttest
Post-test scores
Source
Simulated
Add a New Intervention Group to Multisite Trial (MST)
Description
This function adds a new intervention group to an existing Multisite Trial (MST) dataset. It fits a linear mixed-effects model to the original data, then uses its estimates to generate post-test outcomes for the new group, incorporating random intercepts, slopes, and user-defined effect size.
Usage
mstAddIntervention(
originalData,
ns,
np,
es,
attritionrate,
intper,
outcome,
interventions,
schoolsID,
pupilsID,
continuous_covariates,
categorical_covariates
)
Arguments
originalData |
A data frame containing the variables including outcome, predictors, the clustering variable, and the intervention for MST design. |
ns |
The number of schools to assign to the new intervention group. |
np |
The number of pupils per new school. |
es |
The standardized effect size for the new intervention group. |
attritionrate |
The proportion of pupils in the new group to drop due to attrition. |
intper |
Proportion of pupils per new school assigned to the Intervention group. |
outcome |
A string specifying the name of the column containing outcome variable (e.g., post-test scores). |
interventions |
A string specifying the name of the intervention assignment column. |
schoolsID |
A string specifying the name of the school ID column. |
pupilsID |
A string specifying the name of the pupil ID column. |
continuous_covariates |
A character vector specifying the names of continuous covariates. |
categorical_covariates |
A character vector specifying the names of categorical covariates (converted to factors). |
Details
The function:
Fits a linear mixed-effects model (
lmer
) with random slopes and intercepts using existing MST data.Simulates new schools and pupils, assigning intervention randomly by specified percentage.
Simulates attrition by removing post-test scores at random.
Value
A data.frame
containing the combined dataset with the newly added intervention group and simulated outcomes.
See Also
lmer
from the lme4 package
Examples
data(mst4armSimData)
new_mst5armData <- mstAddIntervention(originalData = mst4armSimData, ns = 2, np = 100, es = 0.3,
intper = 0.5, attritionrate = 0.1, outcome = "posttest", interventions = "interventions",
schoolsID = "schools", pupilsID = "pupils",
continuous_covariates = c("pretest"), categorical_covariates = c("gender", "ethnicity"))
head(new_mst5armData)
Simulate Multisite Trial (MST) Data
Description
This function simulates a multiple intervention arms Multisite Trial (MST) data. The model includes intervention and pre-test scores as covariates.
Usage
mstDataSimulation(
ni,
tpi,
np,
ns,
sigma,
sigmab0,
sigmab1,
B0,
es,
seed,
attritionrates,
covariates
)
Arguments
ni |
The number of intervention groups excluding the control group. |
tpi |
The proportions (in percent) of total participants assigned to each group, with the first value for the control group. It should be specified as a numeric vector of length ni + 1. |
np |
The number of pupils per school. |
ns |
The number of schools. |
sigma |
The standard deviation of the individual-level error. |
sigmab0 |
The standard deviation of random intercepts at the school level. |
sigmab1 |
The standard deviation of random slopes for the intervention effect. |
B0 |
The intercept of the model. |
es |
The standardized effect sizes for each intervention group. It should be specified as a numeric vector. |
seed |
The random seed for reproducibility. |
attritionrates |
The attrition proportions for each group, including the control group. It should be specified as a numeric vector of length ni + 1. |
covariates |
List of covariate specifications. Each element should be a list with the following fields:
|
Value
A data.frame
containing:
- pupils
Pupil ID
- schools
School ID
- interventions
Intervention group assignment (0 = control, 1 to
ni
= intervention groups)- covariates
Simulated covariates
- posttest
Posttest score (NA if attrited)
Examples
covariates <- list(
list(name = "pretest", type = "continuous", sd = 1, coefficient = 1.7),
list(name = "gender", type = "categorical", levels = c("Male", "Female"),
probs = c(0.3, 0.7), reference = "Male", coefficients = list(B = -0.5)),
list(name = "ethnicity", type = "categorical", levels = c("White", "Black", "Asian"),
probs = c(0.3, 0.3, 0.4), reference = "White", coefficients = list(B = 1.02, C = 1.3))
)
mstdata <- mstDataSimulation(ni = 3, ns = 10, np = 100, tpi = c(30, 30, 20, 20),
sigma = 1, sigmab0 = 0.5, sigmab1 = 0.5, B0 = 1.45,
es = c(0.2, 0.3, 0.1), seed = 1234, attritionrates = c(0.1, 0.1, 0.1, 0), covariates = covariates)
head(mstdata)
Bayesian or Frequentist Analysis with Forest Plot Comparison for Multi-Arm Trial Designs
Description
This function fits Bayesian or frequentist and producing a forest plot across multiple intervention groups for cluster randomized trials (CRT), multisite trials (MST) or simple randomized trials (SRT).
Usage
multiArmAnalysis(
method = "crtBayes",
data,
outcome = "posttest",
interventions = "interventions",
Random = "schools",
Nsim = 10000,
Threshold = 0.05,
FREQoption = "Default",
nPerm = NULL,
nBoot = NULL,
bootType = NULL,
continuous_covariates = NULL,
categorical_covariates = NULL,
maintitle = NULL,
xlabel = NULL,
ylabel = NULL,
vlinecolor = "black",
intlabels = NULL,
intcolors = NULL
)
Arguments
method |
The model fitting method. Should be specified as a character string. Choices are:
|
data |
A data frame containing the variables including outcome, predictors, the clustering variable, and the intervention. |
outcome |
The name of the outcome (post-test) variable. |
interventions |
A string specifying the intervention variable. |
Random |
The name of the clustering variable (e.g., schools or sites) for CRT and MST designs. |
Nsim |
Number of MCMC iterations to be performed for Bayesian analysis. A minimum of 10,000 is recommended to ensure convergence. |
Threshold |
The effect size threshold for posterior computation for Bayesian analysis (default = 0.05). |
FREQoption |
The option for frequentist methods. Choices are "Default", "Permutation", or "Bootstrap". |
nPerm |
The number of permutations required to generate a permutated p-value. |
nBoot |
The number of bootstraps required to generate bootstrap confidence intervals. |
bootType |
method of bootstrapping including case re-sampling at student level "case(1)",case re-sampling at school level "case(2)", case re-sampling at both levels "case(1,2)" and residual bootstrapping using "residual". If not provided, default will be case re-sampling at student level. |
continuous_covariates |
A character vector specifying the names of continuous covariates. |
categorical_covariates |
A character vector specifying the names of categorical covariates (converted to factors). |
maintitle |
main title for the plot. |
xlabel |
Label for the x-axis. |
ylabel |
Label for the y-axis. |
vlinecolor |
Color of the vertical reference line (default = "black"). |
intlabels |
Optional custom intervention labels for the plot. |
intcolors |
Optional intervention colors for the plot. |
Details
This function loops through each intervention, fits the requested statistical model, stores the results, and forest plot visualization for easy comparison. It allows flexible customization for plotting aesthetics.
Value
A ggplot
object showing intervention effect sizes and their confidence intervals.
See Also
Functions from the eefAnalytics package:
crtBayes
, crtFREQ
, mstBayes
, mstFREQ
, srtBayes
, srtFREQ
Examples
### Bayesian analysis of cluster randomised trials ###
data(crt4armSimData)
multiArmAnalysis(method = "crtBayes", data = crt4armSimData, outcome = "posttest",
interventions = "interventions", Random = "schools", Nsim = 10000, Threshold = 0.05,
continuous_covariates = c("pretest"), categorical_covariates = c("gender", "ethnicity"),
intlabels = c("Intervention A", "Intervention B", "Intervention C"),
maintitle = "Forest plot of comparison of effect sizes", xlabel = "Hedges'g",
ylabel = "Interventions", vlinecolor = "black")
###MLM analysis of multisite trials with residual bootstrap confidence intervals ###
data(mst4armSimData)
multiArmAnalysis(method = "mstFREQ", data = mst4armSimData, outcome = "posttest",
interventions = "interventions", Random = "schools", nBoot = 1000, bootType="residual",
continuous_covariates = c("pretest"), categorical_covariates = c("gender", "ethnicity"),
intlabels = c("Intervention A", "Intervention B", "Intervention C"),
intcolors = c("Intervention A" = "blue", "Intervention B" = "green", "Intervention C" = "red"),
maintitle = "Forest plot of comparison of effect sizes ", xlabel = "Hedges'g",
ylabel = "Interventions", vlinecolor = "black")
###MLM analysis of multisite trials with permutation p-value###
data(mst4armSimData)
multiArmAnalysis(method = "mstFREQ", data = mst4armSimData, outcome = "posttest",
interventions = "interventions", Random = "schools", nPerm = 1000,
continuous_covariates = c("pretest"), categorical_covariates = c("gender", "ethnicity"),
intlabels = c("Intervention A", "Intervention B", "Intervention C"),
intcolors = c("Intervention A" = "blue", "Intervention B" = "green", "Intervention C" = "red"),
maintitle = "Forest plot of comparison of effect sizes ",
xlabel = "Hedges'g", ylabel = "Interventions", vlinecolor = "black")
###Bayesian analysis of simple randomised trials###
data(srt4armSimData)
multiArmAnalysis(method = "srtBayes", data = srt4armSimData, outcome = "posttest",
interventions = "interventions", Random = "schools", Nsim = 10000, Threshold = 0.05,
continuous_covariates = c("pretest"), categorical_covariates = c("gender", "ethnicity"),
intlabels = c("Int A", "Int B", "Int C"),
intcolors = c("Int A" = "#1F77B4", "Int B" = "#2CA02C", "Int C" = "#D62728"),
maintitle = "Forest plot of comparison of effect sizes ", xlabel = "Hedges'g",
ylabel = "Interventions", vlinecolor = "black")
Plot Posterior Probabilities Across Thresholds for CRT, MST, or SRT Designs
Description
This function generates a Bayesian posterior probability plot across multiple thresholds for each intervention group in a clustered randomized trial (CRT), multisite trial (MST), or simple randomized trial (SRT).
Usage
plotPosteriorProbs(
method = c("crt", "mst", "srt"),
data,
outcome = "posttest",
interventions = "interventions",
Random = "schools",
Nsim = 10000,
continuous_covariates = NULL,
categorical_covariates = NULL,
VerticalLine = NULL,
VerticalLineColor = "#0000FF",
HorizontalLine = NULL,
HorizontalLineColor = "#FF0000",
threshold_range = c(0, 1),
maintitle = "Posterior Probabilities Across Thresholds",
xlabel = "Threshold",
ylabel = "Posterior Probability",
intcolors = NULL,
intlabels = NULL,
xbreaks = NULL,
ybreaks = seq(0, 1, by = 0.1)
)
Arguments
method |
The trial design type: "crt", "mst", or "srt". |
data |
A data frame containing the variables including outcome, predictors, the clustering variable, and the intervention. |
outcome |
The name of the outcome (post-test) variable. |
interventions |
A string specifying the intervention variable. |
Random |
The name of the clustering variable (e.g., schools or sites) for CRT and MST designs. |
Nsim |
Number of MCMC iterations to be performed. A minimum of 10,000 is recommended to ensure convergence. |
continuous_covariates |
A character vector specifying the names of continuous covariates. |
categorical_covariates |
A character vector specifying the names of categorical covariates (converted to factors). |
VerticalLine |
Optional vertical reference line added at a threshold value. It should be specified as a numeric value. |
VerticalLineColor |
The color of the vertical reference line. It should be specified as a character string (default = "#0000FF"). |
HorizontalLine |
Optional posterior probability cutoff for adding a horizontal reference line. It should be specified as a numeric value. |
HorizontalLineColor |
The color of the horizontal reference line. It should be specified as a character string (default = "#FF0000"). |
threshold_range |
The range of thresholds to evaluate. It should be specified as a numeric vector of length 2 (default = c(0, 1.0)). |
maintitle |
The main title of the plot. |
xlabel |
The label for the x-axis. |
ylabel |
The label for the y-axis. |
intcolors |
Optional intervention colors specified manually. It should be provided as a named character vector. |
intlabels |
Optional intervention labels to use instead of default names. It should be specified as a character vector. |
xbreaks |
Tick marks for the x-axis. Must be a numeric vector with values within the specified threshold_range (default = 0.1). |
ybreaks |
Tick marks for the y-axis. It should be specified as a numeric vector (default = seq(0, 1, by = 0.1)). |
Details
The function uses crtBayes()
, mstBayes()
, or srtBayes()
from eefAnalytics package depending on the method
.
Value
A ggplot
object that displays posterior probabilities across thresholds for each intervention.
See Also
crtBayes
, mstBayes
, srtBayes
functions from the eefAnalytics package
Examples
###Plot Posterior Probabilities of cluster randomized trial###
data(crt4armSimData)
plotPosteriorProbs(method = "crt",data = crt4armSimData, outcome = "posttest",
interventions = "interventions", Random = "schools", Nsim = 10000,
continuous_covariates = c("pretest"), categorical_covariates = c("gender", "ethnicity"),
threshold_range = c(0, 0.1), VerticalLine = 0.05, HorizontalLine = 0.8,
VerticalLineColor= "purple", HorizontalLineColor= "black",
intlabels = c("Intervention A", "Intervention B", "Intervention C"),
intcolors = c("Intervention A" = "blue", "Intervention B" = "red",
"Intervention C" = "green"), maintitle= "Posterior probability plot",
xlabel= "Threshold", ylabel= "Posterior probability",
xbreaks= 0.1, ybreaks= seq(0, 1, by = 0.1))
###Plot Posterior Probabilities of multisite trial###
data(mst4armSimData)
plotPosteriorProbs(method = "ms",data = mst4armSimData, outcome = "posttest",
interventions = "interventions", Random = "schools", Nsim = 10000,
continuous_covariates = c("pretest"), categorical_covariates = c("gender", "ethnicity"),
threshold_range = c(0, 0.1), VerticalLine = 0.05, HorizontalLine = 0.8,
VerticalLineColor= "purple", HorizontalLineColor= "black",
intlabels = c("Intervention A", "Intervention B", "Intervention C"),
intcolors = c("Intervention A" = "blue", "Intervention B" = "red",
"Intervention C" = "green"), maintitle= "Posterior probability plot",
xlabel= "Threshold", ylabel= "Posterior probability",
xbreaks= 0.1, ybreaks= seq(0, 1, by = 0.1))
###Futility analysis of simple randomized trial###
data(srt4armSimData)
plotPosteriorProbs(method = "srt",data = srt4armSimData, outcome = "posttest",
interventions = "interventions", Nsim = 10000, threshold_range = c(0, 0.2),
continuous_covariates = c("pretest"), categorical_covariates = c("gender", "ethnicity"),
VerticalLine = 0.05, HorizontalLine = 0.8, VerticalLineColor= "purple",
HorizontalLineColor= "black", intlabels = c("Intervention A", "Intervention B",
"Intervention C"), intcolors = c("Intervention A" = "#1F77B4",
"Intervention B" = "#D62728", "Intervention C" = "#2CA02C"),
maintitle= "Posterior probability plot", xlabel= "Threshold",
ylabel= "Posterior probability", xbreaks= 0.1, ybreaks= seq(0, 1, by = 0.1))
Run the EPTS Shiny Application
Description
Launches a Shiny application that provides an interactive user interface to run the functions provided by the epts package.
Usage
runEPTS()
Examples
if (interactive()) {
runEPTS()
}
Simulated 4-Arm Simple Randomized Trial (SRT) Data
Description
A simulated simple randomized trial dataset containing 1,000 individuals. This is a 4-arm trial design with one control group and three intervention groups.
Usage
srt4armSimData
Format
A data frame with 1,000 rows and 6 variables:
- ID
Identifier for participants ID
- interventions
Treatment assignment coded as 0 for control and 1–3 for intervention groups
- pretest
Pre-test scores
- gender
Binary gender
- ethnicity
A categorical variable with 3 categories
- posttest
Post-test scores
Source
Simulated
Add a New Intervention Group to Simple Randomized Trial (SRT) Data
Description
This function adds a new intervention group to an existing SRT dataset by generating new participant-level data.
Usage
srtAddIntervention(
existing_data,
np,
es,
attritionrate,
outcome,
interventions,
id,
continuous_covariates,
categorical_covariates
)
Arguments
existing_data |
A data frame containing the variables including outcome, predictors, the clustering variable, and the intervention for CRT design. |
np |
The number of new participants to generate for the new intervention group. |
es |
The standardized effect size for the new intervention group. |
attritionrate |
The proportion of pupils in the new group to drop due to attrition. |
outcome |
A string specifying the name of the column containing outcome variable (post-test scores). |
interventions |
A string specifying the name of the intervention assignment column. |
id |
A string specifying the name of the participant ID column. |
continuous_covariates |
A character vector specifying the names of continuous covariates. |
categorical_covariates |
A character vector specifying the names of categorical covariates (converted to factors). |
Value
A data.frame
combining the original dataset with the newly simulated intervention group.
Examples
data(srt4armSimData)
new_srt5armData <- srtAddIntervention(existing_data = srt4armSimData, np = 100,
es = 0.3, attritionrate = 0.1, outcome = "posttest", interventions = "interventions",
id = "ID", continuous_covariates = c("pretest"), categorical_covariates = c("gender", "ethnicity"))
head(new_srt5armData)
Simulate Simple Randomized Trial (SRT) Data
Description
This function simulates a Simple Randomized Trial (SRT), with multiple intervention arms, pre-test and post-test scores, and individual-level attrition. No clustering or hierarchical structure is assumed.
Usage
srtDataSimulation(ni, tpi, np, sigma, B0, es, seed, attritionrates, covariates)
Arguments
ni |
The number of intervention groups excluding the control group. |
tpi |
The proportions (in percent) assigned to each group, with the first value for the control group followed by the intervention groups. Must sum to 100. It should be specified as a numeric vector of length ni + 1. |
np |
The total number of participants. |
sigma |
The standard deviation of individual-level error for the post-test score. |
B0 |
The intercept term in the model. |
es |
The standardized effect sizes for each intervention group. It should be specified as a numeric vector. |
seed |
The random seed for reproducibility. |
attritionrates |
The attrition rates for each group, including the control group. It should be specified as a numeric vector of length ni + 1. |
covariates |
List of covariate specifications. Each element should be a list with the following fields:
|
Value
A data.frame
containing:
- ID
Participant ID
- interventions
Intervention assignment (0 = control, 1 to
ni
= intervention groups)- covariates
Simulated covariates
- posttest
Posttest score (NA if participant attrited)
Examples
covariates <- list(
list(name = "pretest", type = "continuous", sd = 1, coefficient = 1.7),
list(name = "gender", type = "categorical", levels = c("Male", "Female"),
probs = c(0.3, 0.7), reference = "Male", coefficients = list(B = -0.5)),
list(name = "ethnicity", type = "categorical", levels = c("White", "Black", "Asian"),
probs = c(0.3, 0.3, 0.4), reference = "White", coefficients = list(B = 1.02, C = 1.3))
)
srtdata <- srtDataSimulation(ni = 3, np = 1000, tpi = c(30, 30, 20, 20),
sigma = 1, B0 = 1.45, es = c(0.2, 0.3, 0.1), seed = 1234,
attritionrates = c(0.1, 0.1, 0.1, 0), covariates = covariates)
head(srtdata)
Superiority Analysis Across Interventions for CRT, MST, or SRT Designs
Description
This function performs a Bayesian superiority analysis, comparing each intervention against a reference intervention, across cluster randomized trials (CRT), multisite trials (MST) or simple randomized trials (SRT).
Usage
superiorityAnalysis(
method = c("crt", "mst", "srt"),
data,
outcome = "posttest",
interventions = "interventions",
Random = "schools",
Nsim = 10000,
Threshold = 0.05,
refintervention = 1,
SupThreshold = 0.8,
continuous_covariates = NULL,
categorical_covariates = NULL
)
Arguments
method |
The trial design type: "crt", "mst", or "srt". |
data |
A data frame containing the variables including outcome, predictors, the clustering variable, and the intervention. |
outcome |
The name of the outcome (post-test) variable. |
interventions |
A string specifying the intervention variable. |
Random |
The name of the clustering variable (e.g., schools or sites) for CRT and MST designs. |
Nsim |
Number of MCMC iterations to be performed. A minimum of 10,000 is recommended to ensure convergence. |
Threshold |
The effect size threshold for posterior computation (default = 0.05). |
refintervention |
The value of the intervention used as the reference group (default = 1). |
SupThreshold |
The minimum posterior probability threshold to declare superiority (default = 0.8). |
continuous_covariates |
A character vector specifying the names of continuous covariates. |
categorical_covariates |
A character vector specifying the names of categorical covariates (converted to factors). |
Details
The effect size is estimated against a reference intervention, which by default is intervention 1 but can be reassigned to any other intervention, including the control (refintervention = 0).
Value
A data.frame
with columns:
-
Intervention
: Intervention group identifier. -
ProbES
: Posterior probability of superiority over the reference intervention. -
Superiority
: Label indicating"Superior"
,"Not Superior"
, or"Reference"
.
See Also
crtBayes
, mstBayes
, srtBayes
functions from the eefAnalytics package
Examples
###Superiority analysis of cluster randomized trial###
data(crt4armSimData)
superiorityAnalysis(method = "crt", data = crt4armSimData, outcome = "posttest",
interventions = "interventions", Random = "schools", Nsim = 10000, refintervention = 2,
Threshold = 0.05, SupThreshold = 0.8,continuous_covariates = c("pretest"),
categorical_covariates = c("gender", "ethnicity"))
###Superiority analysis of multisite trial###
data(mst4armSimData)
superiorityAnalysis(method = "mst", data = mst4armSimData, outcome = "posttest",
interventions = "interventions", Random = "schools", Nsim = 10000, refintervention = 2,
Threshold = 0.05, SupThreshold = 0.8,continuous_covariates = c("pretest"),
categorical_covariates = c("gender", "ethnicity"))
###Superiority analysis of simple randomized trial###
data(srt4armSimData)
superiorityAnalysis(method = "srt", data = srt4armSimData, outcome = "posttest",
interventions = "interventions", Nsim = 10000, refintervention = 2,
Threshold = 0.05, SupThreshold = 0.8,continuous_covariates = c("pretest"),
categorical_covariates = c("gender", "ethnicity"))