I've been trying to apply the mifa analysis on my data with ordinal variables, using polr method on mice. I ran into some challenges on mifa, and I thought it was easier to run the MI using mice separately - which worked out well. Now, I meant to follow the path took for mifa https://github.com/vahidnassiri/mifa/blob/master/R/mifa.cov.R, adapting the combination of the MIs into a single averaged correlation matrix (instead of covariance) - getting errors.
I can't seem to troubleshoot the issues by myself (I am new in R), any insights are highly appreciated - The R code is below (the blue text is a note about it). Any thoughts?
Thanks,
Kika
####### MULTIPLE IMPUTATION
#reading my dataset
icmbio=read_csv("icmbio5-R.csv") %>%
mutate_all(as.factor)%>%
select(3:75)
#Specifying the mice method per column
icmbio_init = mice(icmbio, maxit=0)
meth=icmbio_init$method
meth[c(1:67)]="polr" #Proportional odds model for ordered variables (Likert scale items)
meth[c(1:67)]="logreg" #Logistic regression for binary variables (sex and education)
meth[c(70:73)]="lda" # unordered categorical variables - Linear discriminant analysis (Wu et al 2015)
#imputing (mice)
icmbio1= mice(icmbio, method=meth, m=5, remove_collinear = FALSE) # skip removal of collinear variables
# checking if everything is imputed
colSums(is.na(complete(icmbio1,1)))
# extracting imputed datasets (worked)
comp.mice=NULL
mi.na=rep(0,5)
for (i in 1:5){
comp.mice[[i]]=complete(icmbio1,i)
mi.na[i]=sum(is.na(comp.mice[[i]]))
}
### End: Implementing the imputation
### CORRELATION
# Now estimating correlation matrix based on imputed values,
cor.mice.imp=NULL
prop.exp=rep(0,5)
for (i in 1:5){
cor.tmp=polychoric(comp.mice[[i]]) # polychoric correlations considering the categorical nature of the data
cor.mice.imp[[i]]=cor.tmp
}
##### ERRORS
I managed to do these steps above, extract and save the complete and each imputed dataset. I tried using your code for extracting the datasets and estimating the correlation matrixes (instead of covariances - adapting it to a correlation function), but was not able to extract separate matrix, although was able to run the code and calculate it using polychoric(imp.icmbio1)$rho.
## Combining the estimated correlation from different imputations (DID NOT WORK)
cor.combined=Reduce('+',cor.mice.imp)/5
Error in f(init, x[[i]]) : non-numeric argument to binary operator
##I also tried the micombine.cor function of mice
cor.comb= miceadds::micombine.cor(mi.res=icmbio1)
Error in stats::cor(dat_ii, dat_jj, method = method, use = "pairwise.complete.obs") :
'x' must be numeric
I've been trying to apply the mifa analysis on my data with ordinal variables, using polr method on mice. I ran into some challenges on mifa, and I thought it was easier to run the MI using mice separately - which worked out well. Now, I meant to follow the path took for mifa https://github.com/vahidnassiri/mifa/blob/master/R/mifa.cov.R, adapting the combination of the MIs into a single averaged correlation matrix (instead of covariance) - getting errors.
I can't seem to troubleshoot the issues by myself (I am new in R), any insights are highly appreciated - The R code is below (the blue text is a note about it). Any thoughts?
Thanks,
Kika
I managed to do these steps above, extract and save the complete and each imputed dataset. I tried using your code for extracting the datasets and estimating the correlation matrixes (instead of covariances - adapting it to a correlation function), but was not able to extract separate matrix, although was able to run the code and calculate it using
polychoric(imp.icmbio1)$rho.