estSeqSim | R Documentation |
Simulate Comparisons For Use in Sequential Clinical Trial Simulations
estSeqSim(parameter, looks, gendat, fitter, nsim = 1, progress = FALSE)
parameter |
vector of true parameter (effects; group differences) values |
looks |
integer vector of observation numbers at which posterior probabilities are computed |
gendat |
a function of three arguments: true parameter value (scalar), sample size for first group, sample size for second group |
fitter |
a function of two arguments: 0/1 group indicator vector and the dependent variable vector |
nsim |
number of simulations (default is 1) |
progress |
set to |
Simulates sequential clinical trials. Looks are done sequentially at observation numbers given in the vector looks
with the earliest possible look being at observation 2. For each true effect parameter value, simulation, and at each look, runs a function to compute the estimate of the parameter of interest along with its variance. For each simulation, data are first simulated for the last look, and these data are sequentially revealed for earlier looks. The user provides a function gendat
that given a true effect of parameter
and the two sample sizes (for treatment groups 1 and 2) returns a list with vectors y1
and y2
containing simulated data. The user also provides a function fitter
with arguments x
(group indicator 0/1) and y
(response variable) that returns a 2-vector containing the effect estimate and its variance. parameter
is usually on the scale of a regression coefficient, e.g., a log odds ratio.
a data frame with number of rows equal to the product of nsim
, the length of looks
, and the length of parameter
.
Frank Harrell
gbayesSeqSim()
, simMarkovOrd()
, estSeqMarkovOrd()
if (requireNamespace("rms", quietly = TRUE)) {
# Run 100 simulations, 5 looks, 2 true parameter values
# Total simulation time: 2s
lfit <- function(x, y) {
f <- rms::lrm.fit(x, y)
k <- length(coef(f))
c(coef(f)[k], vcov(f)[k, k])
}
gdat <- function(beta, n1, n2) {
# Cell probabilities for a 7-category ordinal outcome for the control group
p <- c(2, 1, 2, 7, 8, 38, 42) / 100
# Compute cell probabilities for the treated group
p2 <- pomodm(p=p, odds.ratio=exp(beta))
y1 <- sample(1 : 7, n1, p, replace=TRUE)
y2 <- sample(1 : 7, n2, p2, replace=TRUE)
list(y1=y1, y2=y2)
}
set.seed(1)
est <- estSeqSim(c(0, log(0.7)), looks=c(50, 75, 95, 100, 200),
gendat=gdat,
fitter=lfit, nsim=100)
head(est)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.