用已知系数和未知截距拟合glm

编程入门 行业动态 更新时间:2024-10-22 07:19:13
本文介绍了用已知系数和未知截距拟合glm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用glm拟合逻辑回归模型,在该模型中我仅对截距感兴趣-但我仍然希望该模型适合已知系数. 示例:

I am trying to fit a logistic regression model using glm, where I am only interested in the intercept - but I still want the model to be fitted with known coefficients. Example:

beta <- c(24.5,3.6,2.87,7.32)

所以我想使用

model <- glm(y~x_1+x_2+x_3+x_4, family=binomial(link="logit"), data=dt)

并以某种方式合并了已知的beta,因此glm函数仅适合alpha.我怎样才能做到这一点?

and in some way incorporate the known betas, so the glm function only fits the alpha. How can I do that?

推荐答案

具有偏移量,可以向GLM的线性预测变量(公式的RHS,对数刻度)添加一个已知项.

With offsets, which add a known term to the linear predictor (RHS of the formula, on the logit scale) of a GLM.

beta <- c(24.5, 3.6, 2.87, 7.32) dt <- transform(dt, pred=beta[1]*x_1+beta[2]*x_2+beta[3]*x_3+beta[4]*x_4) model <- glm(y~1+offset(pred), family=binomial(link="logit"), data=dt)

更多推荐

用已知系数和未知截距拟合glm

本文发布于:2023-07-27 23:06:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1225165.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:系数   glm

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!