如何设置回归系数值; [R [英] How to set the Coefficient Value in Regression; R

查看:99
本文介绍了如何设置回归系数值; [R的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种指定预测变量值的方法.当我用当前数据运行glm时,我的变量之一的系数接近于1.我想将其设置为.8.

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.

我知道这会给我一个较低的R ^ 2值,但是我先验地知道该模型的预测能力会更大.

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.

glm的权重部分看起来很有希望,但我还没有弄清楚.

The weights component of glm looks promising, but I haven't figured it out yet.

任何帮助将不胜感激.

推荐答案

我相信您正在glm中寻找offset参数.因此,例如,您可能会执行以下操作:

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,...)

在这种情况下,x2的系数将设置为1.在您的情况下,您可能想将该列乘以0.8?

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?

为了扩展,这是?glm关于offset参数的内容:

To expand, here is what ?glm says about the offset argument:

这可以用来指定要包括的先验已知组件 在拟合期间在线性预测器中.这应该为NULL或 长度等于个案数的数值向量.一个或多个 补偿条款可以替代地也可以包括在公式中,如果 指定了一个以上的总和.参见model.offset.

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.

因此,您也可以使用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.

这篇关于如何设置回归系数值; [R的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆