Search code examples
rglm

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


I have a dataset that looks like this:

    Act Day        Sin
1   1   Monday     3
2   0   Tuesday    0
3   0   Wednesday  1    

I'm trying to do linear regression on the Act column. I read about dummy variables, so I'm adding columns for each of the days like this:

data$Mon = ifelse(data$Day=="Monday", 1, 0)
... and so on for the other days

Which gives me data like this

    Act Day        Sin  Mon Tue Wed Thu Fri Sat
1   1   Monday     3    1   0   0   0   0   0
2   0   Tuesday    0    0   1   0   0   0   0
3   0   Wednesday  1    0   0   1   0   0   0
... and so on

Then when I try and create my model like this:

glm.fit <- glm(Activity ~ Mon, data = data, family = binomial)

I'm getting the following error:

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

I've looked at a lot of other posts about this error and they all suggest making the y values 1's and 0's. But my 'Mon' column is already values of 0 and 1. What am I doing wrong?


Solution

  • I wrapped my dependent variable into a as.factor and that worked:

    glm.fit <- glm(as.factor(Activity) ~ Mon, data = data, family = binomial)