获得平均系数和调整使用lapply来自多个合并回归的R ^ 2 [英] obtaining average coefficients and adj. R^2 from multiple pooled regressions using lapply

查看:121
本文介绍了获得平均系数和调整使用lapply来自多个合并回归的R ^ 2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用循环功能执行了多个Pooled回归,并将回归输出存储在列表中(myregression).我现在想做的是有效地执行lmtest程序包中的coeftest函数,以调整我的所有回归(即myregression列表),以调整标准误差和t统计量.最后,我想获得系数,标准误差和t值的平均值.

I have performed multiple Pooled regressions with a loop function and stored the regression output in a list (myregression). What i would like to do now is to efficiently perform the coeftest function in the lmtest package over all my regressions (i.e. myregression list) to adjust standard errors and t-statistics. Finally i would like to obtain the mean of the coefficients, standard errors and t-values.

这是我到目前为止提出的内容:

Here is what i came up so far:

library(plm)
data("Grunfeld", package="plm")

# Store each subset regression in myregression
myregression <- list()

count <- 1

# Regression on six-year subsets of Grunfeld
for(t in 1940:1950){

  myregression[[count]] <- plm(inv ~ value + capital, 
                              subset(Grunfeld, year<=t & year>=t-5),
                              index=c("firm","year"))

# Name each regression based on the year range included in the data subset
names(myregression)[[count]] = paste0("Year_",t)
count <- count+1
}

这是我遇到的问题所在:尽管我能够对列表的单个组件执行coeftest函数,但是我无法相应地对lapply函数进行编码.

Here is where my problems kick in: Although i'm able to perform the coeftest function to invidiual components of the list, I'm unable to code the lapply function accordingly.

## Apply coeftest function to all plm-objects
library(lmtest)

coeftest(myregression$Year_1940, vcov=function(x) vcovSCC(x, type="HC3", maxlag=4))
coeftest(myregression$Year_1941, vcov=function(x) vcovSCC(x, type="HC3", maxlag=4))

COEFTEST<-lapply(myregression, coeftest(x, vcov=function(x) vcovSCC(x, type="HC3", maxlag=4)))

## obtaining average coefficients, se's,and t values over all regressions
lapply(COEFTEST, mean)

我希望只有一个小错误,我看不到. 我进一步注意到,plm回归输出小于常规lm输出,还有另一种获取均值调整的方法. R ^ 2?

I hope there is only a minor mistake that I'm unable to see. I further noticed that the plm regression output is smaller than regular lm output is there another way to obtain mean adj. R^2?

推荐答案

尝试

 COEFTEST<-lapply(myregression, function(x) coeftest(x, vcov=vcovSCC(x, type="HC3", maxlag=4)))

Thsi将为您提供每次回归的coeftest输出列表,然后您可以按任何需要的方式使用它.

Thsi will give you a list of coeftest-outputs for each regression, which you can then use in whatever way you want.

作为旁注,请确保您对该输出所做的任何事情都有意义.用coeftest输出的平均值对我来说并不明智.如果要获得所有系数的平均值,请尝试类似

As a sidenote, make sure that whatever you do with this output makes sense. Taking the mean of an coeftest-output is not obvously sensible to me. If you want to have the average over all coefficients, try something like

 mean(sapply(COEFTEST, function(x)  x["capital", "Estimate"]))

在这里,sapplyCOEFTEST输出中检索变量capital的所有估计值,并将它们放入向量中.

Here, sapply retrieves all estimates for the variable capital from the COEFTEST outputs and puts them into a vector.

要访问其他元素,使用str()查看对象的结构将很有帮助.例如,str(summary(myregression[[1]]))显示r平方以名称r.squared保存.您可以使用例如summary(myregression[[1]])$r.squared用于第一个回归输出.自动执行此操作,您可以再次使用上述结构,例如

To access other elements, it is helpful to look at the structure of the objects using str(). For instance, str(summary(myregression[[1]])) reveals that the r-squares are saved under the name r.squared. These you can access using e.g. summary(myregression[[1]])$r.squared for the first regression output. Automating this, you can again use a construct as above, e.g.

 sapply(myregression, function(x) summary(x)$r.squared)

这篇关于获得平均系数和调整使用lapply来自多个合并回归的R ^ 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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