R中的双变量逻辑模型中的错误 [英] Error in a bivariate logistic model in R

查看:109
本文介绍了R中的双变量逻辑模型中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的研究中有一个意外错误.让我向您展示我研究中的几个代码块.希望你能帮助我.

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)

我尝试使用zeligverse软件包分析模型

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

eval(process.binomial2.data.VGAM)中的错误:必须响应 只能包含0和1

Error in eval(process.binomial2.data.VGAM) : response must contains 0's and 1's only

由于cbind中的变量是二项式的,所以我无法获得它.

I couldn't get it as variables in cbind are binominal.

推荐答案

最好了解您要适应的内容以及数据的外观. 此处,这里有一些准则可以问一些好问题.

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.

我假设您正在尝试运行(二进制)logit.如果是这样,glm()可以估算出这样的模型

I assume you are trying to run a (binary) logit. If so glm() can estimate such a model

例如:

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))

如果结果变量中有两个以上类别,则将它们排序. ordinal软件包中的clm()可以是一个选项:

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")

我希望对您有帮助

这篇关于R中的双变量逻辑模型中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆