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

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

Open
vincentarelbundock opened this issue Jul 31, 2023 · 4 comments

Comments

@vincentarelbundock
Copy link

In case you had not seen this StackOverflow error report from 2020:

https://stackoverflow.com/questions/64056125/how-to-fix-erreur-subscript-amr1-orig-is-a-matrix-the-data-x-imp-possib

I just ran into the same problem. The solution is simple. Just add this to convert x to data frame if it is a tibble:

if (inherits(x, "tbl_df")) {
  x <- as.data.frame(x)
}
@vincentarelbundock
Copy link
Author

FWIW, I ran into this issue with a complex dataset today. Hard to create a minimal reproducible example, but the SO question and answer have a lot of likes and comments, so I think the bug should be treated as "replicated on several machines."

@mecoskun
Copy link

Ran into this problem recently, and spent an hour trying to understand what was wrong. Fortunately, the SO post helped me resolve it. A bug fix would be helpful.

@raffaem
Copy link

raffaem commented Dec 23, 2024

Here is the most minimal reproducible example I can come up with:

#!/usr/bin/env R

# Load CHES
rm(list = ls())
library(tidyverse)
library(magrittr)
library(Amelia)

infp <- "ches.csv"
stopifnot(file.exists(infp))
ches <- readr::read_csv(infp, show_col_types = FALSE)

year_range <- ches %>%
  pull(year) %>%
  range()
years <- seq(year_range[1], year_range[2])

ches %<>% select(party_id, year, environment)
ches %<>% complete(party_id, year = years)
ches %<>% arrange(party_id, year)
#ches2 %<>% as.data.frame()
a.out <- amelia(ches, 
                m = 5, 
                ts = "year",
                cs = "party_id",
                polytime = 3)

ches.csv

Although the error message is slightly different:

Error in [<-:
! Subscript AMr1.orig is a matrix, the data x.imp[AMr1.orig] must have size 1.
Run rlang::last_trace() to see where the error occurred.

@IQSS any idea how to fix it?

@raffaem
Copy link

raffaem commented Dec 29, 2024

Maybe @mattblackwell ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants