问题
I have an unexpected error in my research. Let me show you several code chunks from my research. Hope, you'll help me.
I have two binary variables: alco and smoke that were generated like this:
smoke<- factor(with(df, ifelse((q34<2),1,0)))
alco<-factor(with(df, ifelse((q47==1), 1,0)))
df<- cbind(df, smoke, alco, educ_3, smoke_14)
I tried to analyse a model using zeligverse package
m3<-zelig(cbind(smoke,alco) ~ fem+age+age2+smoke_14+ninc, model = "blogit", data = df)
that lead to the mistake
Error in eval(process.binomial2.data.VGAM) : response must contains 0's and 1's only
I couldn't get it as variables in cbind are binominal.
回答1:
It would be good to know what you are trying to fit and how your data look like. Here there are some guidelines to ask good questions.
I assume you are trying to run a (binary) logit. If so glm()
can estimate such a model
For example:
df = data.frame(x = factor(sample(0:1, 25, replace = TRUE)),
y = factor(sample(1:4, 25, replace = TRUE)),
z = sample(18:65, 25, replace = TRUE))
summary(glm(x ~ y + z, family = binomial(link = "logit"),
data = df))
If you have more than two categories in your outcome variable and they are ordered. clm()
from ordinal
package can be an option:
library(ordinal)
summary(clm(y ~ x + z, data = df, link = "logit")
I hope it helps
来源:https://stackoverflow.com/questions/50778016/error-in-a-bivariate-logistic-model-in-r