r-mice

Imputation using mice with clustered data

 ̄綄美尐妖づ 提交于 2020-01-12 08:28:08
问题 So I am using the mice package to impute missing data. I'm new to imputation so I've got to a point but have run into a steep learning curve. To give a toy example: library(mice) # Using nhanes dataset as example df1 <- mice(nhanes, m=10) So as you can see I imputed df1 10 times using mostly default settings - and I am comfortable using this result in regression models, pooling results etc. However in my real life data, I have survey data from different countries. And so levels of missings

Parallel computation of multiple imputation by using mice R package

人走茶凉 提交于 2019-12-31 08:13:10
问题 I want to run 150 multiple imputations by using mice in R . However, in order to save some computing time, I would lie to subdivide the process in parallel streams (as suggested by Stef van Buuren in "Flexible Imputation for Missing Data"). My question is: how to do that? I can imagine 2 options: opt.1: imp1<-mice(data, m=1, pred=quicktry, maxit=15, seed=1) imp2<-mice(data, m=1, pred=quicktry, maxit=15, seed=1) imp...<-mice(data, m=1, pred=quicktry, maxit=15, seed=1) imp150<-mice(data, m=1,

How to use constructed formula with glm.mids

故事扮演 提交于 2019-12-24 17:15:49
问题 Working with a large number of variables and addressing them with constructed formula (via paste0() ) using variables passed to functions. I have stumbled across a problem/bug I cannot figure out. Easiest explained with a toy example: library(mice) imp2 = mice(nhanes) # So both these models run fine: mod1 <- glm(bmi ~ hyp + age, data=nhanes) mod1.im <- with(imp2, glm(bmi ~ hyp + age)) # However if I try to pass a formula to glm() in the with() I get an error formula = bmi ~ hyp + age mod2 <-

multinominal regression with imputed data

耗尽温柔 提交于 2019-12-24 06:21:32
问题 I need to impute missing data and then coduct multinomial regression with the generated datasets. I have tried using mice for the imputing and then multinom function from nnet for the multnomial regression. But this gives me unreadable output. Here is an example using the nhanes2 dataset available with the mice package: library(mice) library(nnet) test <- mice(nhanes2, meth=c('sample','pmm','logreg','norm')) #age is categorical, bmi is continuous m <- with(test, multinom(age ~ bmi, model = T)

How to find out which seed the MICE R-package chose for multiple imputation when using seed=NA?

空扰寡人 提交于 2019-12-13 19:17:54
问题 I´m doing a multiple imputation for a dataframe named "mydata" with this code: library(mice) imp<-mice(mydata,pred=pred,method="pmm", m=10) Because the default argument for this is function is "seed=NA", the seed-number is chosen randomly. I would like to keep it like this, because i don´t know which number i should choose as a seed. But for replication i would like to know which seed this function chose for me. Is there a possibility to inspect the mids-object "imp" for the seed-value? Or

Time lag analysis on list of imputed datasets

别来无恙 提交于 2019-12-13 16:42:23
问题 My question and data is similar to the post in: Loop Through Data with Sequential Time Lags output Linear Regression Coefficients set.seed(242) df<- data.frame(month=order(seq(1,248,1),decreasing=TRUE), psit=c(79,1, NA, 69, 66, 77, 76, 93, NA, 65 ,NA ,3, 45, 64, 88, 88 ,76, NA, NA, 85,sample(1:10,228, replace=TRUE)),var=sample(1:10,248, replace=TRUE)) However, the structure of my dataset differs because I have imputed missing values for psit . Now psit , month and var are now nested within a

R: Clustered robust standard errors using miceadds lm.cluster - error with subset and weights

空扰寡人 提交于 2019-12-12 18:14:02
问题 I am trying to use the lm.cluster function in the package miceadds to get robust clustered standard errors for a multiply imputed dataset. I am able to get the standard version of it to run but I get the following error when I try to add a subset or weights: Error in eval(substitute(subset), data, env) : ..1 used in an incorrect context, no ... to look in Example that works without subset or weights: require("mice") require("miceadds") data(data.ma01) # imputation of the dataset: use six

R MICE imputation failing

笑着哭i 提交于 2019-12-12 11:13:15
问题 I am really baffled about why my imputation is failing in R's Mice 2.22 package. I am attempting a very simple operation with the following data frame: > dfn a b c d 1 0 1 0 1 2 1 0 0 0 3 0 0 0 0 4 NA 0 0 0 5 0 0 0 NA I then use mice in the following way to perform a simple mean imputation: imp <- mice(dfn, method = "mean", m = 1, maxit =1) filled <- complete(imp) However, my completed data looks like this: > fill a b c d 1 0.00 1 0 1 2 1.00 0 0 0 3 0.00 0 0 0 4 0.25 0 0 0 5 0.00 0 0 NA Why

How to set MaxNWts value in R

被刻印的时光 ゝ 提交于 2019-12-12 06:48:14
问题 I am trying to impute categorical data through the mice package. {qualiD = mice(quali,1, seed=123)} And I get the following error: {Error in nnet.default(X, Y, w, mask = mask, size = 0, skip = TRUE, softmax = TRUE, : too many (2184) weights} I tried increasing the number of weights by including the MaxNWts param. {qualiD = mice(quali,1, seed=123, MaxNWts = 3000)} But then again i get this error: {Error in nnet.default(X, Y, w, mask = mask, size = 0, skip = TRUE, softmax = TRUE, : formal

Simple restrictions/constraint for multiple imputation (MICE) in R

∥☆過路亽.° 提交于 2019-12-12 03:27:38
问题 This question was migrated from Cross Validated because it can be answered on Stack Overflow. Migrated 3 years ago . I want to perform multiple imputation for a set of variables using the MICE package in R. # Example data data <- data.frame( gcs = c(3, 10, NA, NA, NA, 15, 14, 15, 15, 14, 15, NA, 13, 15, 15), hf = c(50, 66, 78, 99, NA, NA, 56, 55, NA, 76, 98, 105, NA, NA, 65), ... ) The minimum for gcs is 3 and the maximum is 15 , and it may not be a fractional number, how can I set these