simglmm {rsq}R Documentation

Simulate Data from Generalized Linear Mixed Models

Description

Simulate data from linear and generalized linear mixed models. The coefficients of the two covariate are specified by beta.

Usage

simglmm(family=c("binomial","gaussian","poisson","negative.binomial"),
beta=c(2,0),tau=1,n=200,m=10,balance=TRUE)

Arguments

family

the family of the distribution.

beta

regression coefficients (excluding the intercept which is set as zero).

tau

the variance of the random intercept.

n

the sample size.

m

the number of groups.

balance

simulate balanced data if TRUE, unbalanced data otherwise.

Details

The first covariate takes 1 in half of the observations, and 0 or -1 in the other half. When beta gets larger, it is supposed to easier to predict the response variable.

Value

Returned values include yx, beta, and u.

yx

a data frame including the response y and covariates x1, x2, and so on.

beta

true values of the regression coefficients.

u

the random intercepts.

Author(s)

Dabao Zhang, Department of Statistics, Purdue University

References

Zhang, D. (2020). Coefficients of determination for generalized linear mixed models. Technical Report, 20-01, Department of Statistics, Purdue University.

See Also

rsq, rsq.lmm, rsq.glmm, simglm,

Examples

require(lme4)

# Linear mixed models
gdata <- simglmm(family="gaussian")
lmm1 <- lmer(y~x1+x2+(1|subject),data=gdata$yx)
rsq(lmm1)

# Generalized linear mixed models
bdata <- simglmm(family="binomial",n=400,m=20)
glmm1 <- glmer(y~x1+x2+(1|subject),family="binomial",data=bdata$yx)
rsq(glmm1)

[Package rsq version 2.6 Index]