mypath<-matrix(NA,3,4)
mypath[1,]<-c(1.000000,-0.066678, 0.420036,0.764638)
mypath[2,]<-c(-0.066678,1.000000,-0.559718,0.496831)
mypath[3,]<-c(0.420036,-0.559718,1.000000,0.414346)
colnames(mypath)<-c("ldl","hdl","tg","path")
mypath<-DataFrame(mypath)
#mypath
#DataFrame with 3 rows and 4 columns
# ldl hdl tg path
# <numeric> <numeric> <numeric> <numeric>
#1 1.000000 -0.066678 0.420036 0.764638
#2 -0.066678 1.000000 -0.559718 0.496831
#3 0.420036 -0.559718 1.000000 0.414346
#In this pathdiagram, the outcome is TC
pathD<-matrix(NA,4,5)
pathD[1,]<-c(1, -0.070161,0.399038,0.907127,1.210474)
pathD[2,]<-c(-0.070161, 1,-0.552106,0.212201,0.147933)
pathD[3,]<-c(0.399038,-0.552106,1,0.44100,0.64229)
pathD[4,]<-c(0.907127 ,0.212201,0.441007,1,-1.035677)
colnames(pathD)<-c("ldl","hdl","tg","tc","path")
#pathD
# LDL HDL TG TC path
#1 1.000000 -0.070161 0.399038 0.907127 1.210474
#2 -0.070161 1.000000 -0.552106 0.212201 0.147933
#3 0.399038 -0.552106 1.000000 0.441000 0.642290
#4 0.907127 0.212201 0.441007 1.000000 -1.035677
pathD<-as.data.frame(pathD)
## tc is outcome in my path
pathdiagram2(pathD=pathD,pathO=mypath,rangeD=c(1:4),rangeO=c(1:3),disease="CAD",
R2D=0.536535,R2O=0.988243)
Run the code above in your browser using DataLab