创建一个函数(x),包括glm(... 〜x,...)时x = parameter1 * parameter2。 GLM()的摘要仅显示截距和X(不是参数)
在那里,您可以看到我的代码和输出R给出。我的问题是:在GLM()摘要中,如何将R打印为函数的参数为分离值。因此,拦截,性别_m0,age_cented and gender_m0 * age_cented而不是拦截和y?我希望有人可以帮助我解决我的小问题。谢谢。
test_reg <- function(parameters){
glm_model2 <- glm(healing ~ parameters, family = "binomial", data = psa_data)
summary(glm_model2)}
test_reg(psa_data$gender_m0 * age_centered)
Call:
glm(formula = healing ~ parameters, family = "binomial", data = psa_data)
Deviance Residuals:
Min 1Q Median 3Q Max
-2.2323 0.4486 0.4486 0.4486 0.6800
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 2.24590 0.13844 16.223 <2e-16 ***
parameters -0.02505 0.01369 -1.829 0.0674 .
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 426.99 on 649 degrees of freedom
Residual deviance: 423.79 on 648 degrees of freedom
(78 Beobachtungen als fehlend gelöscht)
AIC: 427.79
Number of Fisher Scoring iterations: 5
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
内部公式的术语永远不会被替换而是从字面上替代,因此
glm
正在您的数据框架中寻找一个称为“参数”的列,这当然不存在。您需要从呼叫中捕获参数,去除它们并构建公式,如果您想以这种方式调用您的功能:显然,我没有您的数据,但是如果我创建了带有相同名称的少量示例数据框架,我们可以看到这项工作如预期的:
由
The terms inside formulas are never substituted but taken literally, so
glm
is looking for a column called "parameters" in your data frame, which of course doesn't exist. You will need to capture the parameters from your call, deparse them and construct the formula if you want to call your function this way:Obviously, I don't have your data, but if I create a little sample data frame with the same names, we can see this works as expected:
Created on 2022-06-29 by the reprex package (v2.0.1)