gpt4 book ai didi

r - 如何设置回归中的系数值;电阻

转载 作者:行者123 更新时间:2023-12-04 23:28:47 30 4
gpt4 key购买 nike

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

我知道这会给我一个较低的 R^2 值,但我知道模型的预测能力会更大。

glm 的权重组件看起来很有希望,但我还没有弄清楚。

任何帮助将不胜感激。

最佳答案

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

glm(y ~ x1, offset = x2,...)

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

要扩展,这里是 ?glmoffset争论:

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() 在模型公式本身中添加偏移量功能,也。这是一个说明其用法的简单示例:
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

请注意,最后两个具有相同的系数。

关于r - 如何设置回归中的系数值;电阻,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8234972/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com