I have a design matrix with predictor columns A, B, C and a binary response D
However, I want predictor to have a given coefficient of 1, and only want to determine the weights for B and C. Instead of a0+a1*x1+a2*x2+a3*x3~y I want a0+x1+a2*x2+a3*x3~y
How could I do that with glm?
I first thought about manipulating the formula for logistic regression - remove the A predictor and substract it from the response, but
This is done with offset
:
> ?offset
An offset is a term to be added to a linear predictor, such as in
a generalised linear model, with known coefficient 1 rather than
an estimated coefficient.
Example:
> dat <- iris[iris$Species!="setosa",]
> fit <- glm(Species ~ Sepal.Length + Sepal.Width + Petal.Length + offset(Petal.Width), dat, family=binomial)
The same is achieved with the offset
parameter in glm:
fit2 <- glm(Species ~ Sepal.Length + Sepal.Width + Petal.Length, offset=Petal.Width, data=dat, family=binomial)
The coeffcients in fit
and fit2
are identical.