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


#1

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!


#2

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


#3

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:


#4

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