r-mice

R - how to pass formula to a with(df, glm(y ~ x)) construction inside a function

穿精又带淫゛_ 提交于 2019-12-12 02:23:18
问题 I'm using the mice package in R to multiply-impute some missing data. I need to be able to specify a formula that is passed to a with(df, glm(y ~ x)) construction inside of a function. This with() construction is the format used by the mice package to fit the regression model separately within each of the imputed datasets. However, I cannot figure out the scoping problems preventing me from successfully passing the formula as an argument. Here is a reproducible example: library(mice) data

Multiple Imputed datasets - pooling results

一世执手 提交于 2019-12-11 18:44:32
问题 I have a dataset containing missing values. I have imputed this dataset, as follows: library(mice) id <- c(1,2,3,4,5,6,7,8,9,10) group <- c(0,1,1,0,1,1,0,1,0,1) measure_1 <- c(60,80,90,54,60,61,77,67,88,90) measure_2 <- c(55,NA,88,55,70,62,78,66,65,92) measure_3 <- c(58,88,85,56,68,62,89,62,70,99) measure_4 <- c(64,80,78,92,NA,NA,87,65,67,96) measure_5 <- c(64,85,80,65,74,69,90,65,70,99) measure_6 <- c(70,NA,80,55,73,64,91,65,91,89) dat <- data.frame(id, group, measure_1, measure_2, measure_3

Run glm.mids on a subset of imputed data from mice (R)

拈花ヽ惹草 提交于 2019-12-11 11:35:49
问题 I get an error when I try to run glm.mids on a subset of a mids imputation object: library(mice) imp2 = mice(nhanes) glm.mids( (hyp==2)~bmi+chl, data=imp2, subset=(age==1) ) gives the cryptic error message "Error in eval(expr, envir, enclos) : ..1 used in an incorrect context, no ... to look in" even though the syntax works with regular glm on the original dataset: glm( (hyp==2)~bmi+chl, data=nhanes, subset=(age==1) ) The documentation ?glm.mids doesn't specifically address subset but says

Leftover NAs after imputing using mice

前提是你 提交于 2019-12-11 08:45:46
问题 What is going on in the following? #create some data library(data.table) library(mice) myData = data.table(invisible.covariate=rnorm(10), visible.covariate=rnorm(10), category=factor(sample(1:3,10, replace=TRUE)), treatment=sample(0:1,10, replace=TRUE)) myData[,outcome:=invisible.covariate+visible.covariate+treatment*as.integer(category)] myData[,invisible.covariate:=NULL] myData[treatment == 0,untreated.outcome:=outcome] myData[treatment == 1,treated.outcome:=outcome] #impute missing values

recode mice mids object

扶醉桌前 提交于 2019-12-11 01:41:32
问题 I have a mids object created from mice . I would like to recode some imputed variables and retain the mids object. I know that I could convert the mids object to "long" with complete() , but I want to keep the mids object since it has some additional uses. Here's an example using the nhanes dataset. Running mice() creates 5 imputed datasets for the variables in nhanes . I'm focusing on hyp . library(mice) names(nhanes) nhanes$hyp #[1] NA 1 1 NA 1 NA 1 1 1 NA NA NA 1 2 1 NA 2 2 1 2 NA 1 1 1

Stripplot in MICE

我与影子孤独终老i 提交于 2019-12-11 00:56:23
问题 I´m using the package MICE in R to do multiple imputations. I´ve done several imputations with only numerical variables, the imputation method is predictive mean matching, and when I use the command stripplot(name of imputed dataset) I get to see the observed and imputed values of all the variables. The problem occurs when I try to do imputation on a combination of categorical and numerical variables. The imputation method then is PMM for the numerical variables, and logistical regression for

Can MICE pool complete GLM output binary logistic regression?

本小妞迷上赌 提交于 2019-12-09 07:57:01
问题 I am running a logistic regression with a binary outcome variable on data that has been multiply imputed using MICE. It seems straightforward to pool the coefficients of the glm model: imp=mice(nhanes2, print=F) imp$meth fit0=with(data=imp, glm(hyp~age, family = binomial)) fit1=with(data=imp, glm(hyp~age+chl, family = binomial)) summary(pool(fit1)) However, I can't figure out a way to pool other output generated by the glm. For instance, the glm function produces AIC, Null deviance and

Error with svydesign using imputed data sets

ぃ、小莉子 提交于 2019-12-08 09:56:39
问题 I am analyzing an imputed dataset using svydesign but I am getting an error. Below is the code: library(mitools) library(survey) data(nhanes) nhanes$hyp <- as.factor(nhanes$hyp) imp <- mice(nhanes,method=c("polyreg","pmm","logreg","pmm"), seed = 23109) des<-svydesign(id=~1, strat=~age, data=imputationList(imp)) Error in as.data.frame.default(data, optional = TRUE) : cannot coerce class ""call"" to a data.frame I am following the tutorial from this page: http://r-survey.r-forge.r-project.org

Automatically compare nested models from mice's glm.mids

▼魔方 西西 提交于 2019-12-08 00:40:49
问题 I have a multiply-imputed model from R's mice package in which there are lots of factor variables. For example: library(mice) library(Hmisc) # turn all the variables into factors fake = nhanes fake$age = as.factor(nhanes$age) fake$bmi = cut2(nhanes$bmi, g=3) fake$chl = cut2(nhanes$chl, g=3) head(fake) age bmi hyp chl 1 1 <NA> NA <NA> 2 2 [20.4,25.5) 1 [187,206) 3 1 <NA> 1 [187,206) 4 3 <NA> NA <NA> 5 1 [20.4,25.5) 1 [113,187) 6 3 <NA> NA [113,187) imput = mice(nhanes) # big model fit1 = glm

Automatically compare nested models from mice's glm.mids

你说的曾经没有我的故事 提交于 2019-12-06 11:07:30
I have a multiply-imputed model from R's mice package in which there are lots of factor variables. For example: library(mice) library(Hmisc) # turn all the variables into factors fake = nhanes fake$age = as.factor(nhanes$age) fake$bmi = cut2(nhanes$bmi, g=3) fake$chl = cut2(nhanes$chl, g=3) head(fake) age bmi hyp chl 1 1 <NA> NA <NA> 2 2 [20.4,25.5) 1 [187,206) 3 1 <NA> 1 [187,206) 4 3 <NA> NA <NA> 5 1 [20.4,25.5) 1 [113,187) 6 3 <NA> NA [113,187) imput = mice(nhanes) # big model fit1 = glm.mids((hyp==2) ~ age + bmi + chl, data=imput, family = binomial) I want to test the significance of each