Giter VIP home page Giter VIP logo

Comments (9)

stephematician avatar stephematician commented on June 3, 2024

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.

squalo78 avatar squalo78 commented on June 3, 2024

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.

squalo78 avatar squalo78 commented on June 3, 2024

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.

stephematician avatar stephematician commented on June 3, 2024

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.

squalo78 avatar squalo78 commented on June 3, 2024

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.

stephematician avatar stephematician commented on June 3, 2024

Using is.na(y) in assignment to where will work in both cases you describe, without error.

from mice.

stefvanbuuren avatar stefvanbuuren commented on June 3, 2024

Thanks. Just pushed a fix for this.

from mice.

stephematician avatar stephematician commented on June 3, 2024

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.

stefvanbuuren avatar stefvanbuuren commented on June 3, 2024

Thanks. Great simplification.

from mice.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.