加权最小二乘法 [英] Weighted Least Square

查看:63
本文介绍了加权最小二乘法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对 y~x(只有 1 个因变量和 1 个自变量)进行回归,但我有异方差性.y 的可变性随着 x 的增加而增加.为了解决这个问题,我想通过 R 中的 "gls()" 函数使用加权最小二乘法.

I want to do a regression of y~x (just 1 dependent and 1 independent variable) but I have heteroskedasticity. The variability of y increases as x increases. To deal with it, I would like to use weighted least squares through the "gls()" function in R.

但是我不得不承认我不明白如何使用它.我必须将方差函数应用于 gls 函数的权重"参数.但我不知道选择哪一个以及如何使用它.

But I have to admit that I don't understand how to use it. I have to apply a variance function to the "weights" argument of the gls function. But I don't which one to choose and how to use it.

推荐答案

这是一个处理泊松计数之类的数据的示例,其中的变化将与均值成正比(这听起来像是你有的).

Here's an example of taking care of poisson count like data where the variation will be proportional to the mean (which it sounds like you have).

fit = lm (y ~ x, data=dat,weights=(1/dat$x^2))

您使用倒数作为权重,因为您将乘以这些值.您将其平方以处理泊松计数数据,因为方差的单位是平方.您可以执行以下操作:

You use the recipricol as the weight since you will be multiplying the values. You square it for taking care of Poisson count data because the variance has units squared. You can do something like:

fit = lm (y ~ x, data=dat,weights=(1/dat$x))

简单地按 x 值缩放它,看看哪个效果更好.

To simply scale it by the x value and see what works better.

这篇关于加权最小二乘法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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