简体   繁体   中英

Logistic regression with categorical variable as a response variable

I am trying to put a categorical variable as a response variable to glm function. So I initially did this:

logreg_ <- glm(Genre ~ price, data = train)
msummary(logreg_)

However, it just have given this as a result and I don't know how to fix this.

Error in y - mu : non-numeric argument to binary operator

The glimpse() of these columns are like this:

$ Genre            <chr> "Strategy", "Strategy", "Early Access", "Early Access",~
$ price            <dbl> 0.00, 0.79, 3.99, 11.39, 5.59, 0.79, 10.99, 5.79, 1.69,~

What should I do?

As said by @Brian, for logistic regression, you need to specify glm(...,family="binomial) , second the outcome must be a factor . A toy example:

set.seed(4)
df <- data.frame(y =sample(letters[1:4],100,replace = T),x=runif(100),stringAsFactor=T)
str(df)
logreg<- glm(y ~ x, data = df,family = "binomial")
summary(logreg)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM