hd_mi: Generate multiple imputated datasets using MICE.

Description Usage Arguments Value Examples

View source: R/hd_mi.R

Description

Generate multiple imputated datasets using MICE.

Usage

1
2
3
hd_mi(hddat, hd.method = c("voxelwise", "pca"), mice.method = "pmm",
  m = 4, seed = 1, mice.maxit = 5, mc.cores = 4,
  pca.threshold = 0.8)

Arguments

hddat

Data list has to follow the following format (e.g. list(cov=age, img=list(bl, fu))) n (number of subjects) x ( p (number of variables) x timepoint + covariates) matrix. In current implementation, cov should be complete.

hd.method

(default='voxelwise') For voxelwise multiple imputation, hd.method='voxelwise', for principal component analysis based method hd.method='pca'

mice.method

(default='pmm') mice method for multiple impuation

Value

complete (a list of imputed dataset)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
m.dim=c(6,6,10)
npergroup=30
y.base=y.fu=array(0,c(m.dim,npergroup*2))
eff.d=1 ## effect size
perturb=1
set.seed(1234)
for (j in 1:(npergroup*2)){
y.base[,,,j]<-array(rnorm(m.dim[1]*m.dim[2]*m.dim[3]),dim=m.dim)
tmp2<-perturb*array(rnorm(m.dim[1]*m.dim[2]*m.dim[3]),dim=m.dim)
if (j<=npergroup){tmp2[3:4,3:4,5:6]<-tmp2[3:4,3:4,5:6]+eff.d}
y.fu[,,,j]<-tmp2
}
## impose missing
attrition=0.2
missing.indx=sort(sample(1:(2*npergroup),attrition*npergroup*2))
y.fu[,,,missing.indx]<-NA
## In the function, for the missing image, we impose missing values
y.base.mat=array(y.base,dim=c(m.dim[1]*m.dim[2]*m.dim[3],npergroup*2))
dim(y.base.mat)
y.fu.mat=array(y.fu,dim=c(m.dim[1]*m.dim[2]*m.dim[3],npergroup*2))
dim(y.fu.mat)
group=rep(c('txt','con'),each=npergroup)
age=floor(runif(2*npergroup)*20)+20
hd.dat=list(cov=age, img=list(y.base.mat, y.fu.mat))
system.time(voxel.mi<-hd_mi(hd.dat, hd.method='voxelwise', mice.method='pmm'))
system.time(pca.mi<-hd_mi(hd.dat, hd.method='pca', mice.method='pmm'))

seonjoo/neurorct documentation built on May 7, 2020, 3:18 a.m.