Comments (9)
I think revising the assignment to where in rbind.mids above to:
where <- rbind(x$where, is.na(y))
would suffice to fix this issue
from mice.
I had a similar issue.
I think the issue is that:
print(dim(D_rbind$data))
[1] 10 2
print(dim(D_rbind$where))
[1] 5 2
But I disagree with the solution you are proposing. I would instead suggest something like
where <- rbind(x$where, matrix(FALSE, ncol=ncol(y), nrow=nrow(y)) )
The reason being that when we use rbind.mids, I think the object 'y' should be left untouched (also the missing in y)
from mice.
What I wanted to say is that the dimensions of D_rbind$data and D_rbind$where are not consistent. I think this is what is causing issues then with the mice:::complete() function.
from mice.
I don't mind either way, I assumed that the where
variable was supposed to indicate where missing data is located in the dataset, hence my proposal. Note that the assignment to imp
in the rbind.mids
function already ensures that no imputation is performed on the y
dataset regardless of the value of where
.
And yep, I agree regarding your reasoning for the misbehaviour in complete()
.
from mice.
I think the the 'where' determine how 'complete' will fills the missing.
If you run the code below, then the issue you describe is solved.
x <- rnorm(10)
D <- data.frame(x=x, y=2*x+rnorm(10))
D[2:4, 1] <- NA
D_mids <- mice(D[1:5,])
y <- D[6:10,]
D_rbind <- mice:::rbind.mids(x=D_mids, y=y)
D_rbind$where <- rbind(D_rbind$where, matrix(FALSE, ncol=ncol(y), nrow=nrow(y)) )
mice:::complete(D_rbind, 1, include=T)
print(D)
One issue which I still have is that if I introduce some NAs in the 'y' data, it fails:
x <- rnorm(10)
D <- data.frame(x=x, y=2*x+rnorm(10))
D[2:4, 1] <- NA
D_mids <- mice(D[1:5,])
y <- D[6:10,]
y[4:5,1] <- NA
D_rbind <- mice:::rbind.mids(x=D_mids, y=y)
D_rbind$where <- rbind(D_rbind$where, matrix(FALSE, ncol=ncol(y), nrow=nrow(y)) )
mice:::complete(D_rbind, 1, include=T)
with the error below:
Error in [<-.data.frame
(*tmp*
, where[, j], j, value = c(0.700183624923754, :
replacement has 5 rows, data has 3
from mice.
Using is.na(y)
in assignment to where
will work in both cases you describe, without error.
from mice.
Thanks. Just pushed a fix for this.
from mice.
All good, I get why where=F
assignment is the correct approach. Just FYI - this means that in rbind.mids()
the following code
# The original data of y will be copied into the multiple imputed dataset, including the missing values of y.
r <- !wy
imp <- vector("list", ncol(y))
for (j in visitSequence) {
imp[[j]] <-
rbind(x$imp[[j]],
as.data.frame(matrix(NA, nrow = sum(!r[, j]), ncol = x$m,
dimnames = list(row.names(y)[r[, j] == FALSE], 1:m))))
}
names(imp) <- varnames
can be replaced with
imp <- x$imp
from mice.
Thanks. Great simplification.
from mice.
Related Issues (20)
- [Question] Is there a way to use mice with nlme::gls() or mmrm:mmrm() and use pooled results with emmeans?
- error with futuremice when n.core is not specified and exceeds m HOT 4
- Missing Data for Imputed Variables Post-Imputation HOT 3
- Mids object returns NA for imputed variables HOT 2
- mice multilevel imputation for a longitudinal dataset HOT 3
- [Question] Is there a way to obtain marginal effects from glm after mice? HOT 2
- question imputation joint model HOT 3
- [Question] How to set up methods and predictors matrix for this longitudinal example? HOT 2
- mice() Different results depending on column order HOT 1
- WISH: Avoid parallel::detectCores() HOT 2
- Can't access additional packages in futuremice HOT 3
- [Question] Is there any way to pool Kaplan-Meier curves (including surv. probability and getting their CIs)?
- the plot of standard deviation (SD) of variables in the iteration cruve after multiple imputation are blank/empty HOT 2
- Conditional imputation (ifdo) related issue HOT 8
- Imputation of Longitudinal data HOT 1
- Futuremice with future.plan='cluster' HOT 4
- Warning when imputing level 2 factor variables with 2lonly.pmm HOT 2
- On futuremice() and reproducibility HOT 3
- Behaviour of `mice.impute.norm` HOT 7
- Create a `mice` cheat sheet HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mice.