Rで何かをしたり、読書をするブログ

政府統計の総合窓口のデータや、OECDやUCIやのデータを使って、Rの練習をしています。ときどき、読書記録も載せています。

OECD NEET Data Analysis 6- Heteroskedasticity-Robust Inference using R

f:id:cross_hyou:20211003094813j:plain

Photo by Gabriel Garcia Marengo on Unsplash 

www.crosshyou.info

This post is following of the above post.

Hello. In this post, I will do Heteroskedasiticity test usung R.

In te previous post, I meade regression model using R.

Let's plot fitted value vs. residual value

f:id:cross_hyou:20211003095325p:plain

f:id:cross_hyou:20211003095340p:plain

Above plot is men_15_29 ~ log(usd) + capi.

f:id:cross_hyou:20211003095533p:plain

f:id:cross_hyou:20211003095550p:plain

Above plot is for women_15_29 ~ log(usd) + capi.

Let's test if those models have heteroskedasticity.
FIrstly, I use Breush-Pegan test manually.

f:id:cross_hyou:20211003100040p:plain

p-value is 0.04711, which is smaller than 0.05. So, lm_men model has heteroskedasticity.

Next, let's use lmtest package and bptest() function.

f:id:cross_hyou:20211003100314p:plain

p-value is 0.04729, it is close to manual calculation.

Then, let's check for lm_women. I use manual Special Case of White Test.

f:id:cross_hyou:20211003100945p:plain

P-value is almost 0. So, lm_women model has heteroskedasticiy.

SInce the both model, lm_men and lm_women have heteroskedasticity, let's see heteroskedasticiry-robust standard error.

I use car package and lmtest package, then use coeftest() function.

f:id:cross_hyou:20211003101337p:plain

On Heteroskedasticity-robust standard error, log(usd) and capi are statistically significant.

f:id:cross_hyou:20211003101639p:plain

log(usd) and capi are statistically significant on lm_women model under heteroskedasticity robust inference.

Thant's it. Thank you!

Next post is,

 

www.crosshyou.info

 



To read from the 1st post,

 

www.crosshyou.info