【问题标题】:lm.beta produces different results with standardized coefficients calculated by myselflm.beta 用我自己计算的标准化系数产生不同的结果
【发布时间】:2017-11-05 16:24:50
【问题描述】:

我试图使用以下代码来计算标准化系数:

rm(list=ls())
#install.packages("AER")
library(AER)
data("CASchools",package="AER")
CASchools$score=with(CASchools,(math+read)/2)
attach(CASchools)
#regular regressopm
lm1<-lm(score~income)
#standardized regression
stdscore<-(score-mean(score)/sd(score))
stdincome<-(income-mean(income))/sd(income)
lm1e<-lm(stdscore~stdincome)

#standardized regression provided by different package
#install.packages("QuantPsyc")
library(QuantPsyc)
lm.beta(lm1)

#but lm.beta is different from the coefficients I calculated with standardized regression
lm1e$coef

但是,QuantPsyc 包的输出似乎与我自己标准化回归量和因变量获得的结果不同。

两个输出是:

> lm.beta(lm1)
   income 
0.7124308 

> lm1e$coef
(Intercept)   stdincome 
  619.82365    13.57419 

如您所见,其中一个结果是 0.7124308,另一个是 13.57419。根据我的理解,它们应该是等价的。

知道为什么吗?

【问题讨论】:

    标签: r statistics regression


    【解决方案1】:

    您在缩放变量时犯了一个错误。 lm.beta 将非标准化系数事后转换为标准化系数,因此公式不同。但是,对变量进行正确的回归前标准化会产生相同的结果。

    您的错误:(score-mean(score)/sd(score)) 应该是(score-mean(score))/sd(score)。操作顺序很重要!

    检查一下:

    > (score[1]-mean(score))/sd(score)
    [1] 1.923202 #Clearly standardized
    > (score[1]-mean(score)/sd(score))
    [1] 656.4671 #Clearly NOT standardized!
    

    所以:

    stdscore<-(score-mean(score))/sd(score)
    stdincome<-(income-mean(income))/sd(income)
    lm1e<-lm(stdscore~stdincome)
    
    lm.beta(lm1)
     income 
    0.7124308 
    
    lm1e$coef[2]
    stdincome 
    0.7124308 
    
    round(lm.beta(lm1),5) == round(lm1e$coef[2],5)
    income 
      TRUE 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-04-24
      • 2018-11-01
      • 2018-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-11
      相关资源
      最近更新 更多