Title: | A Wrapper of 'simdata' Package |
---|---|
Description: | Simulating data according to marginal distributions and pairwise correlation. This is a wrapper for the 'simdata' package to make it easier to use. |
Authors: | person) [aut] ("aut", "cre"), Han Zhang [cre] |
Maintainer: | Han Zhang <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0 |
Built: | 2025-02-14 04:56:36 UTC |
Source: | https://github.com/cran/easySimData |
Calls come from ... in simulateTrialData
. For individual level data,
empirical quantile will be generated using simdata::quantile_functions_from_data
.
For calls specifying common distribution families and their parameters in plain text,
quantile functions will be generated by quantile functions in stats
, e.g.,
qnorm, qunif, etc. For calls of user-customized quantile functions, it returns
those directly.
configureTrial(..., var_prefix)
configureTrial(..., var_prefix)
... |
calls describing the marginal distributions of endpoints. See |
var_prefix |
prefix to name variables that users do not give to those. |
a list of quantile functions.
simdata
packageA data frame containing the variables as follows:
data(df)
data(df)
A data frame with 4709 rows and 7 variables:
Gender
Age
Race
Weight
BMI
BPsys
BPdia
simdata R package.
data(df) df
data(df) df
easySimData
package.Plot data generated by the easySimData
package.
## S3 method for class 'easySimData' plot(x, ...)
## S3 method for class 'easySimData' plot(x, ...)
x |
an object of class |
... |
ignored. |
an object returned by gridExtra::grid.arrange
, a grid of plots
comparing the simulated marginal distribution with the ones specified by
users.
Parameters of marginal distribution of endpoints and their target correlation are specified. This function returns endpoint data of one arm. To generate data of multiple arms, one need to call this function for each of the arms.
simulateTrialData( ..., cor_matrix, trial_size = 100, arm_label = NULL, var_prefix = "easySimData" )
simulateTrialData( ..., cor_matrix, trial_size = 100, arm_label = NULL, var_prefix = "easySimData" )
... |
calls describing the marginal distributions of endpoints. They
can be data frames, e.g., |
cor_matrix |
a target correlation matrix. See the |
trial_size |
size of an arm. |
arm_label |
a character to name the arm. When specified, a column |
var_prefix |
a character as the prefix of endpoints specified by common distributions. |
A data frame of endpoints.
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' )
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' )