本文介绍了用已知系数和未知截距拟合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
发布评论