搜索
人大经济论坛 附件下载

附件下载

所在主题:
文件名:  supp app.pdf
资料下载链接地址: https://bbs.pinggu.org/a-1387169.html
附件大小:
31.61 KB   举报本内容
各位网友:
我在读一篇论文(附件1),但是在如何产生文中的Figure 1是遇到了难题。我按照文中第2部分的产生数据的方法产生了所需数据,但是利用附件2 给出的R代码并不能产生图1, 所以请求各位指点迷津。
产生数据代码:
##set the seed to make the result is reproducible;
set.seed(100);
##specify the number of the subjects in the trial;
n<-100
##specify the number of visits planned;
v<-5
##sample the measures as the complete data;
x<-matrix(rlnorm(n*v,0,1), nrow=n);#sample the complete data; n subjects v visits planned

##rename the complete data so that it can be handled later;
y<-x;
##specify the drop out timepoints for each subject independently (sample should with replacement);
drop<-sample(1:v, n, replace=T)
#rename the drop timepoints;
d<-drop;
#change the data to make the data meet the drop meaning;
for(subj in 1:n){
while(d[subj]<v){
y[subj, d[subj]+1]=NA
d[subj]=d[subj]+1 }
}
##disply the final result;
y

#calculate the mean measurement by drop out time and meansureable timepoint;
m<-matrix(NA, nrow=v, ncol=v);
#redefine the matrix of the data Xit*I(Di=d)
ind<-matrix(, nrow=1,ncol=v)
#Get the final data as Table 1;

for (dr in 1:v){
for(tr in 1:v){
if (length(which(drop==dr))>0){ind<-which(drop==dr)
m[v-dr+1,tr]<-mean(y[ind,tr])}
}
}
##Get the final data to be used Plot;
m
附件中的产生图1的代码:
require(plotrix)
first.na=function(x){
if (sum(is.na(x))==0) return(length(x)+1)
else return(min(which(is.na(x))))
}
last.non.na=function(x){
return(which.max(!is.na(x)==T))
}
triPlot=function(dsn,incl.leg=F,legloc=rep(0,4),cex=1,maintitle=""){
tt=ncol(dsn)
mm=apply(dsn,1,last.non.na)
timemeans=matrix(NA,nrow=tt,ncol=tt)
for(j in 1:tt){
timemeans[j,]=apply(dsn[which(mm==j),],2,mean,na.rm=T)
}
grcolor=grey(90:1 / 100)

par(mar=c(4,4,6,2)+0.1,mgp=c(3,0.5,0))
image(t(timemeans),x=1:tt,y=1:tt,col=grcolor,xaxt="n",yaxt="n",bty="n",
xlab="",ylab="Dropout Time",main=maintitle)
abline(v=(1:tt)+0.5,col="white")
abline(h=(1:tt)+0.5,col="white")
axis(2,lwd=0)
axis(3,lwd=0)
mtext("Measurement Time",side=1,line=1)
if(incl.leg)
color.legend(legloc[1],legloc[2],legloc[3],legloc[4],
legend=pretty(timemeans,n=2,min.n=1),
rect.col=grcolor,gradient="x",cex=cex)
}

运行 triPlot(m) 只能产生最后的 图, 请指导。谢谢。








    熟悉论坛请点击新手指南
下载说明
1、论坛支持迅雷和网际快车等p2p多线程软件下载,请在上面选择下载通道单击右健下载即可。
2、论坛会定期自动批量更新下载地址,所以请不要浪费时间盗链论坛资源,盗链地址会很快失效。
3、本站为非盈利性质的学术交流网站,鼓励和保护原创作品,拒绝未经版权人许可的上传行为。本站如接到版权人发出的合格侵权通知,将积极的采取必要措施;同时,本站也将在技术手段和能力范围内,履行版权保护的注意义务。
(如有侵权,欢迎举报)
二维码

扫码加我 拉你入群

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

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

GMT+8, 2026-1-17 17:21