从缩放和居中数据缩减 R 中的线性回归系数 [英] Scale back linear regression coefficients in R from scaled and centered data

查看:79
本文介绍了从缩放和居中数据缩减 R 中的线性回归系数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 OLS 拟合线性模型,并使用 R 中的函数 scale 缩放我的回归量,因为变量之间的度量单位不同.然后,我使用 lm 命令拟合模型并获得拟合模型的系数.据我所知,拟合模型的系数与原始回归变量的单位不同,因此在解释它们之前必须按比例缩小.我一直在寻找一种直接的方法来做到这一点,但找不到任何东西.有人知道怎么做吗?

I'm fitting a linear model using OLS and have scaled my regressors with the function scale in R because of the different units of measure between variables. Then, I fit the model using the lm command and get the coefficients of the fitted model. As far as I know the coefficients of the fitted model are not in the same units of the original regressors variables and therefore must be scaled back before they can be interpreted. I have been searching for a direct way to do it by couldn't find anything. Does anyone know how to do that?

请看一下代码,你能帮我实现你的建议吗?

Please have a look to the code, could you please help me implementing what you proposed?

library(zoo)
filename="DataReg4.csv"
filepath=paste("C:/Reg/",filename, sep="")
separator=";"
readfile=read.zoo(filepath, sep=separator, header=T, format = "%m/%d/%Y", dec=".")
readfile=as.data.frame(readfile)
str(readfile)
DF=readfile
DF=as.data.frame(scale(DF)) 
fm=lm(USD_EUR~diff_int+GDP_US+Net.exports.Eur,data=DF)
summary(fm)
plot(fm)

对不起,这是数据.

http://www.mediafire.com/?hmcp7urt0ag8187

推荐答案

如果我理解您的描述(不幸的是目前没有代码),您将获得 Y ~ As + Bs*Xs 的标准化回归系数,其中所有那些s"项是缩放变量.然后,系数是 Y 的标准偏差尺度上的预测变化,与 X 的一个标准偏差的 X 变化相关联.scale 函数将记录 hte 缩放的属性的均值和标准偏差目的.如果没有,那么您将在控制台日志中的某处获得这些估计值.X 中变化 dX 的 dY 估计变化应为:dY*(1/sdY) = Bs*dX*(1/sdX).预测应该是这样的:

If I understand your description (that is unfortunately at the moment code-free), you are getting standardized regression coefficients for Y ~ As + Bs*Xs where all those "s" items are scaled variables. The coefficients then are the predicted change on a std deviation scale of Y associated with a change in X of one standard deviation of X. The scale function would have recorded the means and standard deviations in attributes for hte scaled object. If not, then you will have those estimates somewhere in your console log. The estimated change in dY for a change dX in X should be: dY*(1/sdY) = Bs*dX*(1/sdX). Predictions should be something along these lines:

Yest = As*(sdX) + Xmn + Bs*(Xs)*(sdX)

您可能不需要标准化 Y 值,我希望您不需要,因为它可以更轻松地处理 X 均值的调整.如果您想要实现和检查答案,请放入一些代码和示例数据.我认为@DanielGerlance 说乘以而不是除以 SD 是正确的.

You probably should not have needed to standardize the Y values, and I'm hoping that you didn't because it makes dealing with the adjustment for the means of the X's easier. Put some code and example data in if you want implemented and checked answers. I think @DanielGerlance is correct in saying to multiply rather than divide by the SD's.

这篇关于从缩放和居中数据缩减 R 中的线性回归系数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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