创建和绘制二项式GLM
我正在尝试使用Logistic链接创建一个二项式GLM来对我的数据进行建模。变量 为:年龄(年龄组; 25-29、30-39或40-49),教育(教育水平;高或低),想要更多的孩子(可能需要更多的孩子;是或否),使用(妇女数量)使用避孕)和非避孕(不使用避孕的女性数量)。
我正在尝试预测使用教育,年龄和想要的变量使用避孕的女性数量。
我已经设置了我的模型,如下所示,但是由于错误消息,我无法使其工作,也显示了下面。有人知道我在设置模型时出错了吗?
我的模型
my_model = glm(cbind(notUsing, using-notUsing) ~ age + education + wantsMore,
data = contraceptive2,
family = binomial(link = "logit"))
错误消息
Error in family$linkfun(mustart) : Value 7.64286 out of range (0, 1)
假设这链接到我的解释变量,但不确定如何更改它
我的数据框
head(contraceptive2)
age education wantsMore notUsing using
1 <25 low yes 53 6
2 <25 low no 10 4
3 <25 high yes 200 52
4 <25 high no 50 10
5 25-29 low yes 60 14
6 25-29 low no 19 10
I am trying to create a Binomial GLM with a logistic link to model my data. The variables
are: age (age group; 25-29, 30-39 or 40-49), education (educational level; high or low), wantsMore (may want more children in longer term; yes or no), using (number of women using contraception) and notUsing (number of women not using contraception).
I am trying to predict the number of numbers of women not using contraception using the education, age and wantsMore variables.
I have set up my model as seen below but I cant get it to work due to error messages, also shown below. Does anyone know where I have gone wrong in setting up the model?
my model
my_model = glm(cbind(notUsing, using-notUsing) ~ age + education + wantsMore,
data = contraceptive2,
family = binomial(link = "logit"))
error message
Error in family$linkfun(mustart) : Value 7.64286 out of range (0, 1)
Assume this is linked to my explanatory variables but unsure how to change it
My dataframe
head(contraceptive2)
age education wantsMore notUsing using
1 <25 low yes 53 6
2 <25 low no 10 4
3 <25 high yes 200 52
4 <25 high no 50 10
5 25-29 low yes 60 14
6 25-29 low no 19 10
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
公式左侧的两个列矩阵应包含“成功”和“失败”,即在这种情况下“ notuse”和“使用”(或vice-vices-vices-vice-vice-vice-vice-vice-vice-vice-vice-vice-vice-vice-vice-vice-vices)。您不想从失败中减去成功。除了任何内容,这些数据都会有负数的故障!尝试:
The two column matrix in the left hand side of the formula should contain "successes" and "failures", i.e. in this case "notUsing" and "using" (or vice-versa). You don't want to subtract the successes from the failures. Apart from anything this data would have a negative number of failures! Try: