==== normal data ====
R<-1000
pc<-0
pmu1<-0
pmu2<-0
pS1<-1
pS2<-1
pSX<-1
rho<-.5
sm<-1.1521
sy<-1.175234
set.seed(20100402)
dir.create('compdata')
for (r in 1:R){
for (ab in c(0, .14, .39, .59)){
pa<-ab
pb<-ab
## Generate complete data
X<-rnorm(500)
M<-pmu1+pa*X+rnorm(500)
Y<-pmu2+pb*M+pc*X+rnorm(500)
rho<-.5
## auxiliary data
by<-sqrt(rho^2/(1-rho^2)/sy)
bm<-sqrt(rho^2/(1-rho^2)/sm)
V<-bm*M+rnorm(500)
W<-by*Y+rnorm(500)
## all data together
dset<-cbind(X, M, Y, V, W)
write.table(dset, paste('compdata/500-','ab-',ab,'-r',r,'.txt', sep=''), row.names=F, col.names=F)
## select data with a fixed sample size
for (N in c(50,100,200)){
## MCAR data
rate<-c(0.1,0.2,0.4)
X<-dset[1:N,1]
for (i in 1:3){
M<-dset[1:N,2]
Y<-dset[1:N,3]
M[sample(1:N, N*rate[i])]<-NA
Y[sample(1:N, N*rate[i])]<-NA
## create a folder
folder.name<-paste('ab',ab,'N',N,'MCAR','M',rate[i],sep='')
if (!file.exists(folder.name)) dir.create(folder.name)
## no auxiliary variables
out.name<-paste(folder.name,'/data-noav-',r,'.txt',sep='')
write.table(cbind(X,M,Y), out.name, row.names=F, col.names=F, na='99999')
## with auxiliary variables
out.name<-paste(folder.name,'/data-av-',r,'.txt',sep='')
write.table(cbind(X,M,Y,dset[1:N,4:5]), out.name, row.names=F, col.names=F, na='99999')
}
##End of MCAR data
## Start of MAR data
rate<-c(9,4,1.5)
mrate<- -log(rate)
X<-dset[1:N,1]
for (i in 1:3){
M<-dset[1:N,2]
Y<-dset[1:N,3]
rate.m<-exp(mrate[i]+X)/(1+exp(mrate[i]+X))
rate.y<-exp(mrate[i]+X)/(1+exp(mrate[i]+X))
M[runif(N)par), na.rm=T)*100
power<-mean((temp[,5]>0) | (temp[,9]<0), na.rm=T)*100
c(bias, cvg, power)
}
for (ab in c(0, .14, .39, .59)){
for (N in c(50,100,200)){
for (miss in c('MCAR','MNAR1', 'MNAR2')){
for (rate in c(.1,.2,.4) ){
for (av in c('av','noav')){
res.name<-paste('ab',ab,'N',N,miss,'M',rate,av,'-em-results.txt',sep='')
if (file.exists(res.name)){
cat(ab, N, miss, rate, av, runone(res.name, ab),'\n') }
}
}
}
for (miss in 'MAR'){
for (rate in c(1.5, 4, 9) ){
for (av in c('av','noav')){
res.name<-paste('ab',ab,'N',N,miss,'M',rate,av,'-em-results.txt',sep='')
if (file.exists(res.name)){
cat(ab, N, miss, rate, av, runone(res.name, ab),'\n') }
}
}
}
}
}
==== Lognormal data ====
R<-200
pc<-0
pmu1<-0
pmu2<-0
pS1<-1
pS2<-1
pSX<-1
rho<-.5
sm<-1.1521
sy<-1.175234
set.seed(20100402)
dir.create('compdata')
for (r in 1001:1100){
for (ab in c(0, .14, .39, .59)){
pa<-ab
pb<-ab
## Generate complete data
X<-rlnorm(500)
M<-pmu1+pa*X+rlnorm(500)
Y<-pmu2+pb*M+pc*X+rlnorm(500)
rho<-.5
## auxiliary data
by<-sqrt(rho^2/(1-rho^2)/sy)
bm<-sqrt(rho^2/(1-rho^2)/sm)
V<-bm*M+rlnorm(500)
W<-by*Y+rlnorm(500)
## all data together
dset<-cbind(X, M, Y, V, W)
write.table(dset, paste('compdata/500-','ab-',ab,'-r',r,'.txt', sep=''), row.names=F, col.names=F)
## select data with a fixed sample size
for (N in c(50,100,200)){
## MCAR data
rate<-c(0.1,0.2,0.4)
X<-dset[1:N,1]
for (i in 1:3){
M<-dset[1:N,2]
Y<-dset[1:N,3]
M[sample(1:N, N*rate[i])]<-NA
Y[sample(1:N, N*rate[i])]<-NA
## create a folder
folder.name<-paste('ab',ab,'N',N,'MCAR','M',rate[i],sep='')
if (!file.exists(folder.name)) dir.create(folder.name)
## no auxiliary variables
out.name<-paste(folder.name,'/data-noav-',r,'.txt',sep='')
write.table(cbind(X,M,Y), out.name, row.names=F, col.names=F, na='99999')
## with auxiliary variables
out.name<-paste(folder.name,'/data-av-',r,'.txt',sep='')
write.table(cbind(X,M,Y,dset[1:N,4:5]), out.name, row.names=F, col.names=F, na='99999')
}
##End of MCAR data
## Start of MAR data
rate<-c(9,4,1.5)
mrate<- -log(rate)
X<-dset[1:N,1]
for (i in 1:3){
M<-dset[1:N,2]
Y<-dset[1:N,3]
rate.m<-exp(mrate[i]+X)/(1+exp(mrate[i]+X))
rate.y<-exp(mrate[i]+X)/(1+exp(mrate[i]+X))
M[runif(N)