全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
2304 1
2014-11-29
R软件 做交互作用分析 代码是从文献上弄的,可是运行到最后没有提示错误,可是结果在哪呢 没有结果 还是没输出出来....结果应该是交互作用的三个指标吧??

菜鸟一个 就会复制粘贴,代码如下 求高手


test<-read.table (file="C:/test2.dat",header=T,fill=TRUE)
name(test)
confounders<-cbind(test$dummyag1,test$dummyag2,test$dummyag3)
test$A<-test$ASE
test$B<-test$APTPN22
test$case<-test$KIND

interaction<-function(inter,case,A,B,confounders){
inter$A0B0[inter$A==0 & inter$B==0&#93;<-1
inter$A0B0[inter$A==1 & inter$B==0 | inter$A==0 & inter$B==1 | inter$A==1 & inter$B==1&#93;<-0
inter$A1B0[inter$A==1 & inter$B==0&#93;<-1
inter$A1B0[inter$A==0 & inter$B==0 | inter$A==0 & inter$B==1 | inter$A==1 & inter$B==1&#93;<-0
inter$A0B1[inter$A==0 & inter$B==1&#93;<-1
inter$A0B1[inter$A==1 & inter$B==0 | inter$A==0 & inter$B==0 | inter$A==1 & inter$B==1&#93;<-0
inter$A1B1[inter$A==1 & inter$B==1&#93;<-1
inter$A1B1[inter$A==1 & inter$B==0 | inter$A==0 & inter$B==1 | inter$A==0 & inter$B==0&#93;<-0
glmdata<-cbind("A1B1"=inter$A1B1,"A1B0"=inter$A1B0,"A0B1"=inter$A0B1,"A0B0"=inter$A0B0,
as.data.frame(confounders,row.names=NULL,optional=TRUE))

interaction.Iglm<-glm(case~.,family=binomial(link="logit"),
data=glmdata)
mod<-summary(interaction.Iglm)

cor<-vcor(interaction.Iglm)
A1B1var<-cor[2,2]
A1B0var<-cor[3,3]
A0B1var<-cor[4,4]
cov23<-cor[4,3]
cov13<-cor[4,2]
cov12<-cor[3,2]

x<-summary(interaction.Iglm)$coefficients
OR<-round(exp(c(x[,1])),digits=3)
OR.LowLi<-round(exp(c(x[,1]-1.96*x[,2])),digits=3)
OR.UppLi<-round(exp(c(x[,1]+1.96*x[,2])),digits=3)
outf<-data.frame(OR,OR.LowLi,OR.UppLi)
out<-data.matrix(outf)
ORii<-out[2,1]
ORio<-out[3,1]
ORoi<-out[4,1]
ORoo<-1.0
ORg<-c(ORoo,ORio,ORoi,ORii)
ORn<-c("OR_A0B0","OR_A1B0","OR_A0B1","OR_A1B1")

RERI<-round(out[2,1]-out[4,1]-out[3,1]+1,digit=3)
hr1<-(-out[3,1])
hr2<-(-out[4,1])
hr3<--out[2,1]
SeRERI<-sqrt(hr1**2*A1B0var+hr2**2*A0B1var+hr3**2*A1B1var+2*hr1*hr2*cov23+2*hr1*hr3*cov12+2*hr3*hr2*cov12)
RERI.95Low<-round(RERI-1.96*SeRERI,digits=3)
RERI.95High<-round(RERI+1.96*SeRERI,digits=3)

ha1<-(-(ORio/ORii))
ha2<-(-(ORoi/ORii))
ha3<-(out[3,1]+out[4,1]-1)/out[2,1]
SeAP<-sqrt(ha1**2*A1B0var+ha2**2*A0B1var+ha3**2*A1B1var+2*ha1*ha2*cov23+2*ha1*ha3*cov12+2*ha3*ha2*cov12)
AP<-round(RERI/ORii,digits=3)
AP.95Low<-round(AP-1.96*SeAP,digits=3)
AP.95High<-round(AP+1.96*SeAP,digits=3)

SI<-round((out[2,1]-1)/(out[4,1]+out[3,1]-2),digits=3)
hs1<-(-out[3,1]/(out[3,1]+out[4,1]-2))
hs2<-(-out[4,1]/(out[3,1]+out[4,1]-2))
hs3<-(-out[2,1]/(out[2,1]-1))
SeSI<-sqrt(hs1**2*A1B0var+hs2**2*A0B1var+hs3**2*A1B1var+2*hs1*hs2*cov23+2*hs1*hs3*cov12+2*hs3*hs2*cov12)
SI.95Low<-round(SI-1.96*SeSI,digits=3)
SI.95High<-round(SI+1.96*SeSI,digits=3)

IM<-data.frame(RERI,RERI.95Low,RERI.95High,AP,AP.95Low,AP.95High)
SyI<-data.frame(SI,SI.95Low,SI.95.High)
ILST<-list(barplot((ORg),names.arg=(ORn)),mod,out,SyI,IM)
return(ILST)
}
附件列表

R 交互作用.txt

大小:2.64 KB

 马上下载

相关代码

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2014-11-30 10:58:17
怎么就没人给看看呢   版主尼  高手在哪里
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群