I'm trying to fit a multiple linear regression model. It has 10 variables, 2 of which are specified (e.g. $\beta_4 = 0.5$, $\beta_7 = 0.77$).
How do I go about fitting this in R? I need to find the intercept (estimate) of the model as well.
I'm trying to fit a multiple linear regression model. It has 10 variables, 2 of which are specified (e.g. $\beta_4 = 0.5$, $\beta_7 = 0.77$).
How do I go about fitting this in R? I need to find the intercept (estimate) of the model as well.
The answer by @t.f is the principled one, but can only be used as is for linear models: For glm's (generalized linear models, and other non-linear models needing iterative fitting methods) it cannot be used. So, the concept of an offset was invented: It is a variable in a regression model with a known coefficient (of one.)
Building on that R example, the code would be
lm(y ~ offset(beta1*x1) + x2)
You could just subtract them from the your $y$. For our example we have 2 explanatory variables $\beta_1 = 0.5$ for the sake of the example.
$$ y = \beta_0 + X_1\beta_1 + X_1 \beta_2 + \epsilon, \epsilon ~ N(0, \sigma^2)$$
then
$$ y - 0.5 * X_1 = \beta_0 + X_1 \beta_2 + \epsilon$$
So that is the model you fit. It should be noted that it assumes that the $\beta$s that are known are the correct $\beta$s.
Our example in R:
x1 <- rnorm(100, 0.5, 1)
x2 <- rnorm(100, 2, 1.5)
beta1 <- 1
beta2 <- 2
y <- 3 + beta1 * x1 + beta2 * x2 + rnorm(100)
lm(y ~ x1 + x2)
lm(y - x1 * beta1 ~ x2)