sim.data.single {macc} | R Documentation |
Generate single-level simulation data
Description
This function generates a single-level dataset with given parameters.
Usage
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
###################################################
# 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)
###################################################
[Package macc version 1.0.1 Index]