GLM error, surely a simple fix

I am a very new user trying to wade through data analysis for a class that requires R yet has taught us very little about how to use it. With that said, I'm perplexed and am sure this is a simple fix. I am trying to use binomial regression to examine Pref by Disability and Senior in order to find the p -value of the Disability × Senior interaction. I know that I need a binary y to run the GLM but how do I run a GLM in that case? The assignment specifically says we have to run GLM. Screenshot of partial data attached. Thank you so much in advance for any advice.

deviceprefsSr = read.csv("deviceprefsSr.csv")
deviceprefsSr$Subject = factor(deviceprefsSr$Subject) # convert to nominal factor
deviceprefsSr$Senior = factor(deviceprefsSr$Senior) # Rv4
deviceprefsSr$Disability = factor(deviceprefsSr$Disability) # Rv4

library(car) # for Anova
contrasts(deviceprefsSr$Senior) <- "contr.sum"
contrasts(deviceprefsSr$Disability) <- "contr.sum"
m = glm(Pref ~ Disability * Senior, data=deviceprefsSr, family=binomial)
Anova(m, type=3)

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

A binary Y variable should be 0 or 1. Create a trackball variable which is 1 if the preference is for a trackball and 0 if the preference is not a trackball = it is for a touchpad. The pref variable as a factor is probably 1 for one of the options and 2 for the other option.

Thanks! I am just not sure how to turn that variable into binary, unfortunately.

To create a new binary Y variable:

deviceprefsSr$Trackball <- ifelse(deviceprefsSr$Pref == "trackball", 1, 0)

This changed my variable to binary, thank you. I still can't solve the problem for some reason but I am sure it is an issue with the earlier code. Thanks for your help.

This topic was automatically closed 7 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.