sim.data.single: Generate single-level simulation data

Description Usage Arguments Details Value Author(s) References Examples

Description

This function generates a single-level dataset with given parameters.

Usage

1
sim.data.single(Z, Theta, Sigma)

Arguments

Z

a vector of treatment/exposure assignment.

Theta

a 2 by 2 matrix, containing the model coefficients.

Sigma

a 2 by 2 matrix, is the covariance matrix of the model errors.

Details

The single level mediation model is

M=ZA+E_1,

R=ZC+MB+E_2.

Theta[1,1] = A, Theta[1,2] = C and Theta[2,2] = B; Sigma is the covariance matrix of (E_1,E_2).

Value

The function returns a dataframe with variables Z, M and R.

Author(s)

Yi Zhao, Brown University, yi_zhao@brown.edu; Xi Luo, Brown University, xi.rossi.luo@gmail.com

References

Zhao, Y., & Luo, X. (2014). Estimating Mediation Effects under Correlated Errors with an Application to fMRI. arXiv preprint arXiv:1410.7217.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  ###################################################
  # Generate a single-level dataset

  # covariance matrix of errors
  delta<-0.5
  Sigma<-matrix(c(1,2*delta,2*delta,4),2,2)

  # model coefficients
  A0<-0.5
  B0<--1
  C0<-0.5

  Theta<-matrix(c(A0,0,C0,B0),2,2)

  # number of trials
  n<-100

  # generate a treatment assignment vector
  set.seed(100)
  Z<-matrix(rbinom(n,size=1,0.5),n,1)

  # Data
  set.seed(5000)
  data.single<-sim.data.single(Z,Theta,Sigma)
  ###################################################

macc documentation built on May 2, 2019, 12:23 p.m.