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

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

OECD Household disposable income data analysis 7 - Bootstrap using R

f:id:cross_hyou:20210821072418j:plain

 Photo by Toni Lluch on Unsplash  

www.crosshyou.info

This post is following of above post.
In this post I will do Bootstrap and make confidence inerval of regression.

First, let's check coefficients for static regression model again.

f:id:cross_hyou:20210821073234p:plain

Intercept is 4.1635, avg_gr_us is -0.8626.

Then, I make a custom function to get intercept.

f:id:cross_hyou:20210821074124p:plain

Next, I replicate 10,000 times to get intercept.

f:id:cross_hyou:20210821074615p:plain


Let's see a histogram of intercept_samples.

f:id:cross_hyou:20210821075025p:plain

f:id:cross_hyou:20210821075035p:plain

Now, we can get 95% confidence interval and mean.

f:id:cross_hyou:20210821075955p:plain

Our regression model's intercept is 4.1635. So, bootstrap gets very close intercept value.


We can do the same procedure about slope.

f:id:cross_hyou:20210821075758p:plain

I replicate 10,000 times for get_slope().

f:id:cross_hyou:20210821080209p:plain

Let's see a histogram.

f:id:cross_hyou:20210821080343p:plain

f:id:cross_hyou:20210821080357p:plain

Now, I can get 95% confidence interval and mean value.

f:id:cross_hyou:20210821080605p:plain

Our regression model's slope is -0.8626. So, bootstrap slope is very close to it.

That's it. Thank you!

To read the fist post,

 

www.crosshyou.info