gendata_crt: Generate data from GLMM

View source: R/data-generation.R

gendata_crtR Documentation

Generate data from GLMM

Description

gendata_crt generates a dataset from a generalized linear mixed model

Usage

gendata_crt(family = gaussian, nclus, size, theta = 0, sigma, Sigma,
  mu, rho = 0, sd = 1, redist = "normal")

Arguments

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 family for details.) Currently gendata_crt supports gaussian, binomial, and poisson.

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 is specified

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')

Details

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 kth 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).

Examples

# 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

djrabideau/permuter documentation built on Jan. 9, 2025, 11:45 p.m.