Error in a bivariate logistic model in R

不羁岁月 提交于 2019-12-24 08:04:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!