How to fix Erreur : Subscript `AMr1.orig` is a matrix, the data `x.imp[, -possibleFactors][AMr1.orig]` must have size 1

Viewed 1308

I'm trying to run Amelia to impute some missing data on several variables with the following code:

set.seed(1) zz[,c("id", "sex", "team", "minsSocial", "satisTravail", "performance")] <- Amelia::amelia(zz[,c("id", "sex", "team", "minsSocial", "satisTravail", "performance")], m=1, idvars="id", noms=c("sex","team"))$imputations$imp1

Unfortunately, I get this error message :

Erreur : Subscript AMr1.orig is a matrix, the data x.imp[, -possibleFactors][AMr1.orig] must have size 1.

Any toughts on where is the problem and how I could fix it? Is it because my data contains values <1?

Thank you!

1 Answers

I think this might be due to some recent changes to error handling in tibbles. If you cast your data as a data.frame instead (assuming that zz is a tibble), the error should go away (this worked for me).

zz <- as.data.frame(zz)

Not sure about the reason behind the error message though. I get a similar error message from rlang::last_error(), and the code worked with earlier versions of the packages.

<error/tibble_error_subset_matrix_must_be_scalar>
Subscript `AMr1.orig` is a matrix, the data `x.imp[AMr1.orig]` must have size 1.
Backtrace:
 1. Amelia::amelia(...)
 2. Amelia::amelia.default(...)
 3. base::lapply(seq_len(m), do.amelia)
 4. Amelia:::FUN(X[[i]], ...)
 5. Amelia:::impfill(...)
 7. tibble:::`[<-.tbl_df`(...)
 8. tibble:::tbl_subassign_matrix(x, j, value, j_arg, substitute(value))
Related