Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential bug for mice.impute.polr #684

Open
andrewd4vis opened this issue Jan 6, 2025 · 0 comments
Open

Potential bug for mice.impute.polr #684

andrewd4vis opened this issue Jan 6, 2025 · 0 comments
Labels

Comments

@andrewd4vis
Copy link

Hello,

I have been working on a simulation study and have been using mice for multiple imputation. I think I have found a bug in mice.impute.polr.

Describe the bug
In some cases I get the following error: Error in apply(draws, 2, sum) : dim(X) must have a positive length

I was able to narrow down this issue and found it only occurred when there was a single missing data point that needs to be imputed for the variable and the proportional log odds model fails and the function resorts to running a multinomial regression as a back up.

I think the error is caused by line 27 converting the post object to a matrix:
if (sum(wy) == 1) {
post <- matrix(post, nrow = 1, ncol = length(post))
}

and then later in the if statement starting on line 32 (which I think is meant to catch cases where just one piece of data is imputed so converts a vector into a matrix):
if (is.vector(post)) {
post <- matrix(c(1 - post, post), ncol = 2)
}

Therefore this leaves the post matrix in incorrect format to then apply the following code, which results in the error:
draws <- un > apply(post, 1, cumsum)
idx <- 1 + apply(draws, 2, sum)

Please let me know if you have any feedback on this issue.

@andrewd4vis andrewd4vis added the bug label Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant