문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top