NErler / JointAI

Joint Analysis and Imputation of generalized linear models and linear mixed models with missing values
https://nerler.github.io/JointAI
28 stars 4 forks source link

Error when passing tibble #12

Open johnsonra opened 1 year ago

johnsonra commented 1 year ago

I'm getting the following error when passing a tibble. I'm guessing this is the same problem that was reported in Issue #8.

Example

library(dplyr)
library(JointAI)

set.seed(284397)
lm_imp(y ~ x,
       data = tibble(y = rnorm(100),
                     x = c(rnorm(99), NA)))

## Error in is.nan(data[, k]) : 
##  default method not implemented for type 'list'

Work around

Convert tibbles to data.frames:

lm_imp(y ~ x,
       data = tibble(y = rnorm(100),
                     x = c(rnorm(99), NA)) %>%
         as.data.frame())

## Note: No MCMC sample will be created when n.iter is set to 0.
## 
## Call:
## lm_imp(formula = y ~ x, data = tibble(y = rnorm(100), x = c(rnorm(99), 
##     NA)) %>% as.data.frame())
## 
## (The object does not contain an MCMC sample.)
johnsonra commented 1 year ago

I think the issue stems from line 191 of helpfunctions_checks.R - probably because indexing a tibble in this way returns a tibble with one variable, rather than a vector.

Modifying line 191 as follows seems to resolve the error:

data[is.nan(unlist(data[, k])), k]

npadhye commented 9 months ago

Thanks, @johnsonra - converting tibble to data.frame helped to avoid this error.