sampleRem: Sample Longuitudinal Data

View source: R/sampleRem.R

sampleRemR Documentation

Sample Longuitudinal Data

Description

Sample longuitudinal data with covariates

Usage

sampleRem(
  n,
  n.times,
  mu = 1:n.times,
  sigma = rep(1, n.times),
  lambda = rep(1, n.times),
  beta = c(2, 1, 0, 0, 0, 1, 1, 0, 0, 0),
  gamma = matrix(0, nrow = n.times, ncol = 10),
  format = "wide",
  latent = FALSE
)

Arguments

n

[integer,>0] sample size

n.times

[integer,>0] number of visits (i.e. measurements per individual).

mu

[numeric vector] expected measurement value at each visit (when all covariates are fixed to 0). Must have length n.times.

sigma

[numeric vector,>0] standard error of the measurements at each visit (when all covariates are fixed to 0). Must have length n.times.

lambda

[numeric vector] covariance between the measurement at each visit and the individual latent variable. Must have length n.times.

beta

[numeric vector of length 10] regression coefficient between the covariates and the latent variable.

gamma

[numeric matrix with n.times rows and 10 columns] regression coefficient specific to each timepoint (i.e. interaction with time).

format

[character] Return the data in the wide format ("wide") or long format ("long"). Can also be "wide+" or "long+" to export as attributes the function arguments and the latent variable model used to generate the data.

latent

[logical] Should the latent variable be output?

Details

The generative model is a latent variable model where each outcome (Y_j) load on the latent variable (\eta) with a coefficient lambda:

Y_j = \mu_j + \lambda_j*\eta + \sigma_j\epsilon_j

The latent variable is related to the covariates (X_1,\ldots,X_(10)):

\eta = \alpha + \beta_1 X_1 + ... + \beta_{10} X_{10} + \xi

\epsilon_j and \xi are independent random variables with standard normal distribution.

Value

a data.frame

Examples

set.seed(10)
dW <- sampleRem(100, n.times = 3, format = "wide")
set.seed(10)
dL <- sampleRem(100, n.times = 3, format = "long")

LMMstar documentation built on Nov. 9, 2023, 1:06 a.m.