mmdgp: Generate longitudinal hierarchical data

View source: R/all_custom_functions.R

mmdgpR Documentation

Generate longitudinal hierarchical data

Description

A function to generate longitudinal hierarchical data. The data represents measurements from people, nested in classes. Each person is measured once per day for a number of days. There is an age, a gender, a day and a within-subject variable effect. The random effects are random intercepts for people and class, and a random slope for the within-subject predictor. This function can for example be used to test some analysis or some plotting procedure.

Usage

mmdgp(n = 200, nC = 5, sd_S = 3, sd_C = 5, sd_e = 2,
b0 = 50, tb = c(0,4,10,4,0), genb = 10, ageb = 1, xwithnb=2, sd_xwithn=1)

Arguments

n

Number of people

nC

Number of classes

sd_S

Standard deviation of people (random intercept)

sd_C

Standard deviation of classes (random intercept)

sd_e

Standard deviation of errors

b0

Intercept

tb

A vector containing the effects of each day. Length can be chosen depending on how many days should be included in the data set.

genb

Gender effect

ageb

Age effect

xwithnb

Main effect of the within-subject predictor

sd_xwithn

Standard deviation of the random slope effect of the within-subject predictor

Value

A data frame with the predictor variables and the target variable.

Examples

dat <- mmdgp()
# Lmer fit:
# lmerTest::lmer(y ~ gen + age + day + xwithn + (xwithn|id) + (1|class), dat)

ryannick28/CustomFunctionsYrotha documentation built on June 1, 2025, 4:02 p.m.