Last chance! 50% off unlimited learning
Sale ends in
jomo1rancon(Y, X=matrix(1,nrow(Y),1), Z=matrix(1,nrow(Y),1), clus,
beta.start=matrix(0,ncol(X),ncol(Y)),u.start=NULL,
l1cov.start=diag(1,ncol(Y)),l2cov.start=NULL,
l1cov.prior=diag(1,ncol(Y)), l2cov.prior=NULL,
nburn=100, nbetween=100, nimp=5, output=1, out.iter=10)
#First of all we load and attach the data:
data(mldata)
attach(mldata)
#Then we define all the inputs:
Y<-data.frame(measure,age)
X<-data.frame(rep(1,1000),sex)
Z<-data.frame(rep(1,1000))
clus<-data.frame(city)
beta.start<-matrix(0,2,2)
u.start<-matrix(0,10,2)
l1cov.start<-diag(1,2)
l2cov.start<-diag(1,2)
l1cov.prior=diag(1,2);
nburn=as.integer(200);
nbetween=as.integer(200);
nimp=as.integer(5);
l2cov.prior=diag(1,5);
#And finally we run the imputation function:
imp<-jomo1rancon(Y,X,Z,clus,beta.start,u.start,l1cov.start, l2cov.start,l1cov.prior,
l2cov.prior,nburn,nbetween,nimp)
cat("Original value was missing(",imp[4,1],"), imputed value:", imp[1004,1])
#Then we run the model on the imputed datsets:
estimates<-rep(0,5)
ses<-rep(0,5)
estimates2<-rep(0,5)
ses2<-rep(0,5)
for (i in 1:5) {
dat<-imp[imp$Imputation==i,]
fit<-lm(measure~age+sex+factor(clus),data=dat)
estimates[i]<-coef(summary(fit))[2,1]
ses[i]<-coef(summary(fit))[2,2]
estimates2[i]<-coef(summary(fit))[3,1]
ses2[i]<-coef(summary(fit))[3,2]
}
#And finally we aggregate results through RUbin's rules with package BaBooN.
#library("BaBooN")
#MI.inference(estimates, ses^2)
#MI.inference(estimates2, ses2^2)
Run the code above in your browser using DataLab