View source: R/data-generation.R
gendata_crt | R Documentation |
gendata_crt
generates a dataset from a generalized linear mixed model
gendata_crt(family = gaussian, nclus, size, theta = 0, sigma, Sigma,
mu, rho = 0, sd = 1, redist = "normal")
family |
a description of the error distribution and link function to
be used in the data generation model. This can be a character string
naming a family function, a family function or the result of a call to a
family function. (See |
nclus |
vector of length 2 specifying the number of clusters in treatment group (trt == 1) and control group (trt == 0), respectively |
size |
vector of length 2 specifying range of cluster sizes that will be drawn from a uniform distribution |
theta |
treatment effect |
sigma |
SD of random cluster effect; ignored if |
Sigma |
optional user-specified covariance matrix for multivariate normal random cluster effects |
mu |
intercept in GLMM |
rho |
between-cluster correlation (assuming exchangeable covariance); if non-zero, then there is corrrelation between clusters. |
sd |
SD of residual error (only applies if family = gaussian) |
redist |
assumed distribution for random effects (currently supports 'normal' and 'lognormal') |
This function generates data from a generalized linear mixed model, a GLMM, with a fixed intercept, fixed treatment effect, and random cluster intercept. The data will be sorted increasing by cluster then subject. The GLMM is
g(E[Y_{ki}]) = \mu + \alpha_k + \theta * X_k
where X_k
is the treatment indicator for the k
th cluster and
\alpha ~ N(0, Sigma)
. If only sigma
is specified, then
Sigma
is exchangeable with sigma^2
on the diagonals and
rho * sigma^2
on the off-diagonals. If redist = 'lognormal', then
\alpha ~ logN(meanlog = 0, sdlog = sigma)
.
# generate data from GLMM with bernoulli outcome,
# treatment odds ratio of 1.5, baseline odds in
# control group of 0.3, 10 clusters (5 in each group)
# with sizes ranging from 100 to 200.
set.seed(444)
ds <- gendata_crt(family = binomial, nclus = c(5, 5), size = c(100, 200),
theta = log(1.5), sigma = 0.5, mu = log(0.3))
head(ds)
# unique.id clusid id trt y
# 1 1.1 1 1 1 0
# 2 1.2 1 2 1 1
# 3 1.3 1 3 1 0
# 4 1.4 1 4 1 0
# 5 1.5 1 5 1 0
# 6 1.6 1 6 1 0
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.