将一个或多个系数设置为特定整数 [英] Set one or more of coefficients to a specific integer

查看:77
本文介绍了将一个或多个系数设置为特定整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是标准lm模型,并希望将我的一个或多个变量的系数设置为特定整数.

I am using a standard lm model and would like to set the coefficients of one or more of my variables to a specific integer.

例如,我希望我的天气和价格变量的系数分别为647和15.

For example, I would like the coefficient of my weather and price variables to be 647 and 15 respectively.

我正在使用带有标准公式的lm函数.

I am using the lm function with a standard formula.

到目前为止,我发现最接近的东西是glm中的offset函数,或systemfit中的strict.rhs.

The closest things I've found so far are the offset function within glm, or restrict.rhs within systemfit.

我还研究了从设置了系数的变量中减去总贡献,但这不是很可扩展.

I've also looked at subtracting the total contribution from these variables with their coefficients set, but this is not very scalable.

我知道设置系数的所有问题,但只是出于探索的考虑.

I'm aware of all the issues setting a coefficient has, but would like to do so just from an exploratory point of view.

推荐答案

您可以在公式中使用偏移项,并在其中包括所需的系数和变量:

You can use the offset term in the formula and include the desired coefficient and variable therein:

df<-data.frame(aa=1:6,bb=2:7,cc=c(4,2,7,5,8,3))

lm(cc ~ aa + offset(647*bb), data = df)

因此,这是对aa上的cc加上固定项bb * 647进行回归.对于一个以上给定的系数,请添加适当的其他offset()项.

So this is regressing cc on aa plus the fixed term bb * 647. For more than one given coefficient, add the appropriate additional offset() terms.

这篇关于将一个或多个系数设置为特定整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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