if (FALSE) { # interactive()
library(dplyr)
data(df)
head(df)
cmat <- matrix(.5, 10, 10)
diag(cmat) <- 1.
## the first argument should always be x if a user-defined quantile function
## is supplied. This is required by the `simdata` package.
user_qfun <- function(x, shape1 = .6, shape2 = 1.2){
qbeta(x, shape1 = shape1, shape2 = shape2)
}
data <- simulateTrialData(
df[, c('Gender', 'Age')] %>% dplyr::filter(Age < 50), # an expression with
# its value a data frame
df %>% dplyr::select(-c(Gender, Age, Race)), # same as above
norm(mean = 0.2,sd = 1.2), # distribution name. Note that it is not a valid
# R function but a symbol.
binom(prob =.4, size=1 ), # spaces are ignore, order does not matter
norm(mean =-0.4, sd=0.9), # same distribution with different parameters
user_qfun, # user-defined quantile
cor_matrix = cmat,
trial_size = 1000,
arm_label = 'placebo'
)
## for diagnosis
plot(data)
cor(data %>% dplyr::select(-matches('arm')))
## Note that user_qfun is simply the quantile function of a beta distribution,
## so a preferred way to use easySimData is as follow
data <- simulateTrialData(
df[, c('Gender', 'Age')] %>% dplyr::filter(Age < 50), # an expression with
# its value a data frame
df %>% dplyr::select(-c(Gender, Age, Race)), # same as above
norm(mean = 0.2,sd = 1.2), # distribution name. Note that it is not a valid
# R function but a symbol.
binom(prob =.4, size=1 ), # spaces are ignored, order does not matter
norm(mean =-0.4, sd=0.9), # same distribution with different parameters
beta(shape1 = .5, shape2 = 1.2), # distribution name
cor_matrix = cmat,
trial_size = 1000,
arm_label = 'placebo'
)
}
Run the code above in your browser using DataLab