sim_2x2: Simulate 2x2 data with autocorrelated errors

Description Usage Arguments Details Value

View source: R/simulation.R

Description

Simulate 2x2 data with autocorrelated errors

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
sim_2x2(
  n_subj = 48,
  n_obs = 48,
  int = 0,
  A = 0,
  B = 0,
  AB = 0,
  rint = 0.5,
  rslp = 0.5,
  rcorr = 0.5,
  version = 0L,
  rand_fn = "shuffle",
  verbose = FALSE,
  extra_args = NULL
)

Arguments

n_subj

Number of subjects to simulate. Must be a positive integer that is a multiple of 2.

n_obs

Number of observations per subject. Must be a positive even integer.

int

Intercept.

A

Main effect of A (within-subject factor).

B

Main effect of B (between-subject factor).

AB

AB interaction effect.

rint

Random intercept variance.

rslp

Random slope variance (for factor A).

rcorr

Random correlation.

version

How to generate residuals: either an integer representing the Scenario number (see errsim) or the name of a user-defined function.

rand_fn

Name of the function to randomize trial order (defaults to shuffle). This can be a user-supplied function; see shuffle for details on how this function should be constructed.

verbose

Whether the data frame should include GLM components.

extra_args

A list of extra arguments to be passed to a user-defined function to generate residuals.

Details

When used with a user-defined function to generate residuals, the residuals for each subject will be standardized (i.e., converted to z-scores) before they are combined with other model components.

Value

A data frame with n_subj * n_obs rows and either 9 or 12 columns depending on whether verbose is TRUE or FALSE respectively.

subj_id
A

Level of within-subject factor A.

B

Level of between-subject factor B.

A_c

Deviation-coded predictor for A.

B_c

Deviation-coded predictor for B.

tnum_r

Trial number for the fully randomized version.

tnum_b

Trial number for the blocked version.

Y_r

Response variable for the fully randomized version.

Y_b

Response variable for the fully blocked version.

rint

Random intercept effect (verbose mode only.)

rslp

Random slope effect (verbose mode only).

Y_fit

Fitted value (all effects except residual.)


dalejbarr/autocorr documentation built on March 27, 2021, 3:03 a.m.