Skip to contents

Simulates a data.frame with n rows and 12 columns:

  • X1, ..., X10, random standard normal vectors.

  • g, a factor with ngroup levels, assigned at random.

  • Y, the response, generated as a additive combination of

    1. a linear effect in X1 with (randomly generated) intercepts and slopes varying between groups of g,

    2. linear effects X1, X2 and X3.

    3. non-linear effects in X6 and X7.

    4. a non-linear three-way interaction of X3, X4 and X5 and

    5. residuals from a normal or t distributions with df degrees of freedom (df=Inf is normal).

    See examples and code for details.

Usage

simuldat(n = 500, ngroup = 20, df = Inf, b = 1, weights = NULL)

Arguments

n

Number of observations

ngroup

Number of groups in g.

df

Number of degrees of freedom of t distribution for simulation of residuals. Default Inf generates normal residuals.

b

Numeric vector of length 4 (shorter will be expanded to length 4): multiplicators of the 4 effects,

weights

NULL or vector of n non-negative values: If not NULL, simulated residuals will be divided by 1/sqrt(weights).

Value

simuldat() returns a data.frame.

Examples

# Simluate data
d <- simuldat()

# Fit the "true" model
if (require(lme4)){
  form <- Y ~ (X1|g) + X2 + X3 + abs(X3+X4+X5) + I(exp(2*X6)/(1+exp(2*X6))) + dnorm(X7, sd = 0.5)
  (truemodel <- lmer(form, d))
  confint(truemodel)
}
#> Loading required package: lme4
#> Loading required package: Matrix
#> Error in initializePtr(): function 'cholmod_factor_ldetA' not provided by package 'Matrix'

# Data set with a purely random response
str(simuldat(b = 0))
#> 'data.frame':	500 obs. of  12 variables:
#>  $ X1 : num  0.692 -0.114 0.237 -0.295 0.911 ...
#>  $ X2 : num  -1.017 -0.41 -2.356 -0.528 1.047 ...
#>  $ X3 : num  0.8512 -0.7571 0.9302 -0.0572 -0.2885 ...
#>  $ X4 : num  -0.4212 -2.2553 0.3703 0.0236 0.5044 ...
#>  $ X5 : num  0.51629 0.1971 -1.78122 -0.00583 -0.6424 ...
#>  $ X6 : num  -0.0671 -2.3904 0.6285 1.2853 0.5334 ...
#>  $ X7 : num  -0.54 0.393 0.47 0.278 -0.29 ...
#>  $ X8 : num  -1.621 -0.156 1.683 0.35 0.953 ...
#>  $ X9 : num  -0.4778 -0.6577 -1.3883 -0.0141 -0.0733 ...
#>  $ X10: num  -0.7658 0.0554 -0.541 2.0413 1.1976 ...
#>  $ g  : Factor w/ 20 levels "g1","g10","g11",..: 19 13 17 8 11 19 5 1 1 20 ...
#>  $ Y  : num  -0.0552 0.204 -2.2725 -1.345 0.6766 ...