crosshyou

主にクロス表(分割表)分析をしようかなと思いはじめましたが、あまりクロス表の分析はできず。R言語の練習ブログになっています。

OECD Material productivity data analysis 3 - Using R for multiple linear regression. OLS(ordinary least squares) and WLS(weighted least squares)

f:id:cross_hyou:20220220094614j:plain

Photo by Wolfgang Hasselmann on Unsplash 

www.crosshyou.info

This post is following of above post.

From the previous post, NONNRGMAT has correlated to r_capi: squared rooted per capita gdp. Let's do regression analysys using R.

f:id:cross_hyou:20220220095542p:plain

p-value for r_capi is almost 0. For TIME variables are not significant. Let's check if there are jointly significant. I use car::linearHypothesis() function.

f:id:cross_hyou:20220220095958p:plain

f:id:cross_hyou:20220220100600p:plain

I used matchCoef() function to make my Null Hypothesis. Then, I use linearHypothesis() function. The result shows p-value is 0.9628. So, TIME is not jointly significant.

Then, let's check if residuals is Homoskedasticiy or Heteroskedasticiy.
I use bptest() finction in lmtest package.

 

f:id:cross_hyou:20220220101249p:plain

p-value is almost 0. So, this regression model has Heteroskedasticiy. Let's confirm lm() function and resid() function.

f:id:cross_hyou:20220220101714p:plain

p-value is 2.689e-06, it is almost 0. So, we reject Null Hypothesis: residual is Homoskedasticity. 

So, I compute Heteroskedasticity robust standard error with lmtest::coeftest( , cvov = hccm) function.

f:id:cross_hyou:20220220102559p:plain

The conclusion does not change. l_gdp is significant at 5% level, r_capi is is significant at 0.11% level or below.

 Next, let's do Weighted Least Square estimation. I use "weight = 1/r_capi" in lm() function.

f:id:cross_hyou:20220220104014p:plain

Let's compare OLS estimation(lm_1) and WLS estimation(lm_wls) with statgazer package.

f:id:cross_hyou:20220220104316p:plain

f:id:cross_hyou:20220220104438p:plain

(1) is OLS and (2) is WLS. There is not significant change between OLS and WLS for r_capi coefficient.

That's it. Thank you!

Next post it

 

www.crosshyou.info

 



To read from the 1st post,

 

www.crosshyou.info