# \donttest{
#binary x and categorical moderator
#linear model
data("weight_behavior")
pred=weight_behavior[,3]
x=weight_behavior[,c(2,4:14)]
inter=form.interaction(x,pred,inter.cov=c("race"),predref="M")
x=cbind(x,inter)
y=weight_behavior[,15]
head(x)
data.bin<-data.org(x,y,pred=pred,contmed=c(7:9,11:12),binmed=c(6,10),
binref=c(1,1),catmed=5,catref=1,predref="M",alpha=0.4,alpha2=0.4)
temp1<-boot.med(data=data.bin,n=2,n2=4,all.model=TRUE)
temp1.mode=boot.mod(temp1,vari="race",continuous.resolution=10)
plot2.mma(temp1.mode,vari="exercises",moderator="race")
plot2.mma(temp1.mode,vari="sports",moderator="race")
#nonlinear model
x=weight_behavior[,c(2,4:14)]
pred=weight_behavior[,3]
y=weight_behavior[,15]
data.bin<-data.org(x,y,pred=pred,contmed=c(7:9,11:12),binmed=c(6,10),binref=c(1,1),
catmed=5,catref=1,predref="M",alpha=0.4,alpha2=0.4)
temp2<-boot.med(data=data.bin,n=2,n2=4,nu=0.05,nonlinear=TRUE,all.model=TRUE)
temp2.mode=boot.mod(temp2,vari="race",continuous.resolution=10)
plot2.mma(temp2.mode,vari="exercises",moderator="race")
plot2.mma(temp2.mode,vari="sports",moderator="race")
#binary x and continuou moderator
x=weight_behavior[,c(2,4:14)]
pred=weight_behavior[,3]
y=weight_behavior[,1]
inter=form.interaction(x,pred,inter.cov=c("age"),predref="M")
x=cbind(x,inter)
head(x)
data.cont<-data.org(x,y,pred=pred,contmed=c(7:9,11:12),binmed=c(6,10),
binref=c(1,1),catmed=5,catref=1,predref="M",alpha=0.4,alpha2=0.4)
temp3<-boot.med(data=data.cont,n=2,n2=4,all.model=TRUE)
temp3.mode=boot.mod(temp3,vari="age",continuous.resolution=2)
summary(temp3.mode)
plot2.mma(temp3.mode,vari="exercises",moderator="age")
plot2.mma(temp3.mode,vari="sports",moderator="age")
x=weight_behavior[,c(2,4:14)]
pred=weight_behavior[,3]
y=weight_behavior[,1]
data.cont<-data.org(x,y,pred=pred,mediator=5:12,jointm=list(n=1,j1=7:9),
predref="M",alpha=0.4,alpha2=0.4)
temp4<-boot.med(data=data.cont,n=2,n2=4,nu=0.05, nonlinear=TRUE,all.model=TRUE)
temp4.mode=boot.mod(temp4,vari="age",continuous.resolution=2,n=20)
summary(temp4.mode)
summary(temp4.mode,bymed=TRUE)
# }
Run the code above in your browser using DataLab