########################################## #This is the file appeared in Appendix D # # of Yuan, Cheng and Maxwell (2012) # ########################################## setwd("d:/moderation") #change working directory; source("NML.R") #load the package; yxu=matrix(scan("simudata.dat"),ncol=6,byrow=T) #read data; n=nrow(yxu); #identify the sample size; y=yxu[,1]; #the dependent variable; x1=yxu[,2]; #first predictor; x2=yxu[,3]; #second predictor; u1=yxu[,4]; #first moderator; u2=yxu[,5]; #second moderator; u3=yxu[,6]; #third moderator; x0=matrix(1,n,1); colnames(x0)="x0"; #level-1 intercept label; u0=matrix(1,n,1); colnames(u0)="u0"; #level-2 intercept label; ########################################################## # specification of the model for regression coefficients # ########################################################## L1=cbind(x0,x1,x2);#level-1 predictors; L20=cbind(u0,u1,u2);#level-2 predictors for beta_i0; L21=cbind(u0,u2,u3);#level-2 predictors for beta_i1; L22=cbind(u0,u1,u2,u3);#level-2 predictors for beta_i2; L2=list(L20,L21,L22); #all level-2 predictors; ########################################################### # specification of the H matrix for variance parameters # ########################################################### H_mat=cbind(x1*x1, x2*x2, 2*x1*x2,2*x1, 2*x2, 1); H_name=c("x1x1", "x2x2", "x1x2", "x0x1", "x0x2", "x0e"); colnames(H_mat)=H_name; #label for variance parameters; gamma.sig=NMLreg(L1,L2,H_mat,y) #call the NMLreg function