问题
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:
or
beta <- c(24.5,3.6,2.87,7.32)
So I want to use
model <- glm(y~x_1+x_2+x_3+x_4, family=binomial(link="logit"), data=dt)
and in some way incorporate the known betas, so the glm function only fits the alpha. How can I do that?
回答1:
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)
来源:https://stackoverflow.com/questions/31571299/fit-glm-with-known-coefficients-and-unknown-intercept