How to fix the problem of Error in xj[i] : invalid subscript type 'list'

Hi everyone, I am using Binary Logistics Regression and I tried to split the data into training data and test data. But I somehow got an error "Error in xj[i] : invalid subscript type 'list'"

#Splitting the data into training and test sets
library(dplyr)
mtcars$id <- 1:nrow(mtcars)
train <- mtcars %>% dplyr::sample_frac(.75)
test  <- dplyr::anti_join(mtcars, train, by = 'id')

#Fit the logistic regression using only the train data
glm.fit <- glm(formula = am ~ cyl + hp + wt, data = input, family = binomial, subset = train)

Error in xj[i] : invalid subscript type 'list'

I tried many ways suggested in StackoverFlow, but that solutions don't work. How can I solve this problem? Please give me advice!
Thank you so much!

I would replace your data = input to data = train and remove the subset part.

Hi Kentm,

If replacing data = input to data = train, and remove the subset part, there are 2 warning messages:
Warning messages:
1: glm.fit: algorithm did not converge
2: glm.fit: fitted probabilities numerically 0 or 1 occurred

:disappointed_relieved:

Those warnings are specific to the model you are creating. Basically, there is perfect separation of your outcome variable and predictor variables.

1 Like

I think you forgot quotation marks around your file name.

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.