I'm looking for a way to specify the value of a predictor variable. When I run a glm with my current data, the coefficient for one of my variables is close to one. I'd like to set it at .8.
I know this will give me a lower R^2 value, but I know a priori that the predictive power of the model will be greater.
The weights component of glm looks promising, but I haven't figured it out yet.
Any help would be greatly appreciated.
The mathematical formula of the linear regression can be written as y = b0 + b1*x + e , where: b0 and b1 are known as the regression beta coefficients or parameters: b0 is the intercept of the regression line; that is the predicted value when x = 0 . b1 is the slope of the regression line.
The parameter β (the regression coefficient) signifies the amount by which change in x must be multiplied to give the corresponding average change in y, or the amount y changes for a unit increase in x. In this way it represents the degree to which the line slopes upwards or downwards.
R2= 1- SSres / SStot Always remember, Higher the R square value, better is the predicted model!
I believe you are looking for the offset
argument in glm
. So for example, you might do something like this:
glm(y ~ x1, offset = x2,...)
where in this case the coefficient of x2
would be set at 1. In your case, you may perhaps want to multiply that column by 0.8?
To expand, here is what ?glm
says about the offset
argument:
this can be used to specify an a priori known component to be included in the linear predictor during fitting. This should be NULL or a numeric vector of length equal to the number of cases. One or more offset terms can be included in the formula instead or as well, and if more than one is specified their sum is used. See model.offset.
So you can add offsets in the model formula itself using the offset()
function, as well. Here is a simple example illustrating its use:
set.seed(123)
d <- data.frame(y = factor(sample(0:1,size = 100,replace = TRUE)),x1 = runif(100),x2 = runif(100))
glm1 <- glm(y~x1+x2,data = d,family = binomial)
coef(glm1)
(Intercept) x1 x2
0.4307718 -0.4128541 -0.6994810
glm2 <- glm(y~x1,data = d,offset = x2,family = binomial)
coef(glm2)
(Intercept) x1
-0.4963699 -0.2185571
glm3 <- glm(y~x1+offset(x2),data = d,family = binomial)
coef(glm3)
(Intercept) x1
-0.4963699 -0.2185571
Note that the last two have the same coefficients.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With