Error when using the mice package

Hello,

I'm encountering an error while working on my R code, and I'm hoping to get some guidance on how to resolve it. The error message I'm receiving is:

"Error in class(ff) <- "formula" : attempt to set an attribute on NULL"

I have read an excel sheet using the "readxl" package, stored it in an object named "data.pre", converted it from a tibble dataframe to a traditional dataframe to avoid errors and checked for missing data and null values using: "sum(is.na(data.pre))" and "sum(is.null(data.pre))", which have returned 60 and 0, respectively.

I am very new to R and any guidance on how I can identify and overcome this problem would help a lot.

Best regards,
Matheus

The current code is:

install.packages("readxl")
library(readxl)

data.pre = read_excel("C:/Users/josia/Documents/pre.xlsx", sheet = "Pre", range = "A1:U28", na = "NA")
sum(is.na(data.pre))

data.pre = as.data.frame(data.pre)

install.packages("mice")
library(mice)

imp_model = mice(data.pre, method = "logreg", m = 5)

Thanks in advance.

Please post the output of

dput(data.pre)

Place a line with three back ticks just before and after the pasted output, like this:
```
pasted output goes here
```

I actually managed to go past that error by deleting the identifiers of all observations, it seems there were some characters that were considered NULL values. However I can't seem to proceed with multiple imputations because I get the message there is significant co-linearity. I have already excluded the data from variables that did not vary, but the error is still there.

This is the output of "dput(new.data.pos)" (I changed the object name):

> dput(new.data.pos)
structure(list(F = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 1), G = c(1, 1, 1, 0, NA, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
NA, 1, NA, 1), I = c(1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, 
0, 0, 0, NA, 0), K = c(1, NA, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, NA, 
NA, NA, 0, NA, 0), L = c(1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 
0, NA, NA, 0, NA, 0), M = c(1, NA, 0, 0, 0, 0, 0, 1, 1, 1, 0, 
1, 1, NA, 1, NA, NA, 1), N = c(1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1), O = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
1, 0, 0, 0, 0, 0, 0, 1), P = c(1, NA, 1, 0, 1, 0, 1, 1, 1, 0, 
0, 1, NA, 1, 1, NA, 1, 0)), row.names = c(NA, -18L), class = c("tbl_df", 
"tbl", "data.frame"))

Your help is very much appreciated,
Matheus

The colinearity is a different problem that probably should have a separate thread. I can't help with a solution because I have never used the mice package. I will observe that a few of your columns are nearly identical. F, I, and O are almost all zeros and G and N are almost all ones. I don't know how much of that the mice algorithm can handle or what tools it has to alleviate the problem.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.