Error in eval(predvars, data, env) : object 'Juice_practice' not found when running binary logistic regression in r

18 Views Asked by At

I am trying to run a binary logistic regression, here is my code:

dataTest <- read.csv("location.csv")
dataTest
dataTest<- as.factor(dataTest$Juice_practice)

str(dataTest)
head(dataTest)
summary(dataTest)

logit_model <- glm(Juice_practice ~ Age + Gender + Education,
                   family = binomial, data = dataTest)`
Error in eval(predvars, data, env) : 
  object 'Juice_practice' not found

Initially I was getting this error message

Error in eval(family$initialize) : y values must be 0 <= y <= 1

Then I did this:

dataTest<- as.factor(dataTest$Juice_practice)

When I check str(dataTest), it shows this Factor w/ 2 levels "No","Yes": 2 2 1 2 2 2 1 2 1 1 ...

When I check head(dataTest) it shows this; [1] Yes Yes No Yes Yes Yes Levels: No Yes

I don't know what happened to the columns after setting Juice_practice as a factor. I do not know how to address this data structure problem.

0

There are 0 best solutions below