www.crosshyou.info

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

OECD Trust in government data analysis 6 - Multiple(one numerical, one categorical variable) Linear Regression with R. I am very confident that per capita GDP is related to Trust in government

Generated by Bing Image Creator: Phot of beautiful nature scene, that includes blue sky, while clouds, yellow flowers, green fields.

www.crosshyou.info

This post is following of the above post.
In this post I use l_pc_gdp and country for explanatory variable.

Let's start.

The observed slope for l_pc_gdp is 11.3.

Next, let's generate bootstrap distribuution.

# generate bootstrap distribution
set.seed(260) boot_dist_mult2 <- df %>% specify(trust ~ l_pc_gdp + country) %>% generate(reps = 10000, type = "bootstrap") %>% fit()
boot_dist_mult2

Since I am interested in l_pc_gdp only, I only visualize for it.

# visualize l_pc_gdp only
boot_dist_mult2 %>% filter(term == "l_pc_gdp") %>% ggplot(aes(x = estimate)) + geom_histogram(color = "white") + labs(title = "Bootstrap Distribution for l_pc_gdp slope")

Bootstrap Distribution for l_pc_gdp slope

Above histogram does not include 0.

Next, let's calculate 95% confidence intervals.

# 95% confidence interval
multi_ci2 <- get_confidence_interval(boot_dist_mult2, level = 0.95, type = "percentile", point_estimate = obs_slope2)
multi_ci2 %>% filter(term == "l_pc_gdp")

95% confidence interval for l_pc_gdp is between 6.92 and 15.7, which does not include 0.

Let's add confidence interval and observed slope into above histogram.

# adding ci and observed slope
boot_dist_mult2 %>% filter(term == "l_pc_gdp") %>% ggplot(aes(x = estimate)) + geom_histogram(bins = 30, color = "white") + geom_vline(xintercept = 6.92, color = "green", linewidth = 2) + geom_vline(xintercept = 15.7, color = "green", linewidth = 2) + geom_vline(xintercept = 11.3, color = "red", linewidth = 2) + labs(title = "Boostrap l_pc_gdp distribution and CI and observed slope")

So far,

I tries regression analysis to see whether trust in government is related to per capita GDP.

 

All four confidence interval don't include 0. So, I am very confident that per capita GDP is related to trust in government.
That's it! Thank you!

 

To read the first post,

 

www.crosshyou.info