Main set
#SPI ~ LV + Falk
list(
ols(SPI_g ~ IQlv, data = std_sub, weights = std_sub$popsqrt),
ols(SPI_g ~ IQlv, data = std_sub_falk, weights = std_sub_falk$popsqrt),
ols(SPI_g ~ time_pref_falk, data = std_sub_falk, weights = std_sub_falk$popsqrt),
ols(SPI_g ~ IQlv + time_pref_falk, data = std_sub_falk, weights = std_sub_falk$popsqrt),
ols(SPI_g ~ IQlv + time_pref_falk + UN_macroregion, data = std_sub_falk, weights = std_sub_falk$popsqrt),
#other measures
ols(SPI_g ~ IQlv + time_pref_falk + risktaking + posrecip + negrecip + altruism + trust, data = std_sub_falk, weights = std_sub_falk$popsqrt),
ols(SPI_g ~ IQlv + time_pref_falk + risktaking + posrecip + negrecip + altruism + trust + UN_macroregion, data = std_sub_falk, weights = std_sub_falk$popsqrt),
ols(SPI_g ~ SPI_g_lag + IQlv + time_pref_falk + risktaking + posrecip + negrecip + altruism + trust, data = std_sub_falk, weights = std_sub_falk$popsqrt)
) ->
model_set_P
#SPI ~ LV + Wang
list(
ols(SPI_g ~ IQlv, data = std_sub, weights = std_sub$popsqrt),
ols(SPI_g ~ IQlv, data = std_sub_wang, weights = std_sub_wang$popsqrt),
ols(SPI_g ~ time_pref_wang, data = std_sub_wang, weights = std_sub_wang$popsqrt),
ols(SPI_g ~ IQlv + time_pref_wang, data = std_sub_wang, weights = std_sub_wang$popsqrt),
ols(SPI_g ~ IQlv + time_pref_wang + UN_macroregion, data = std_sub_wang, weights = std_sub_wang$popsqrt),
ols(SPI_g ~ SPI_g_lag + IQlv + time_pref_wang, data = std_sub_wang, weights = std_sub_wang$popsqrt)
) ->
model_set_S1
#SPI ~ LV + Rieger10
list(
ols(SPI_g ~ IQlv, data = std_sub, weights = std_sub$popsqrt),
ols(SPI_g ~ IQlv, data = std_sub_rieger10, weights = std_sub_rieger10$popsqrt),
ols(SPI_g ~ time_pref_rieger10, data = std_sub_rieger10, weights = std_sub_rieger10$popsqrt),
ols(SPI_g ~ IQlv + time_pref_rieger10, data = std_sub_rieger10, weights = std_sub_rieger10$popsqrt),
ols(SPI_g ~ IQlv + time_pref_rieger10 + UN_macroregion, data = std_sub_rieger10, weights = std_sub_rieger10$popsqrt),
ols(SPI_g ~ SPI_g_lag + IQlv + time_pref_rieger10, data = std_sub_rieger10, weights = std_sub_rieger10$popsqrt)
) ->
model_set_S2
#HDI ~ LV + Falk
list(
ols(HDI2018 ~ IQlv, data = std_sub, weights = std_sub$popsqrt),
ols(HDI2018 ~ IQlv, data = std_sub_falk, weights = std_sub_falk$popsqrt),
ols(HDI2018 ~ time_pref_falk, data = std_sub_falk, weights = std_sub_falk$popsqrt),
ols(HDI2018 ~ IQlv + time_pref_falk, data = std_sub_falk, weights = std_sub_falk$popsqrt),
ols(HDI2018 ~ IQlv + time_pref_falk + UN_macroregion, data = std_sub_falk, weights = std_sub_falk$popsqrt),
ols(HDI2018 ~ HDI2018_lag + IQlv + time_pref_falk + risktaking + posrecip + negrecip + altruism + trust, data = std_sub_falk, weights = std_sub_falk$popsqrt)
) ->
model_set_S3
#SPI ~ Rindermann + Falk
list(
ols(SPI_g ~ IQr, data = std_sub, weights = std_sub$popsqrt),
ols(SPI_g ~ IQr, data = std_sub_falk_r, weights = std_sub_falk_r$popsqrt),
ols(SPI_g ~ time_pref_falk, data = std_sub_falk_r, weights = std_sub_falk_r$popsqrt),
ols(SPI_g ~ IQr + time_pref_falk, data = std_sub_falk_r, weights = std_sub_falk_r$popsqrt),
ols(SPI_g ~ IQr + time_pref_falk + UN_macroregion, data = std_sub_falk_r, weights = std_sub_falk_r$popsqrt),
#other measures
ols(SPI_g ~ IQr + time_pref_falk + risktaking + posrecip + negrecip + altruism + trust, data = std_sub_falk_r, weights = std_sub_falk_r$popsqrt),
ols(SPI_g ~ IQr + time_pref_falk + risktaking + posrecip + negrecip + altruism + trust + UN_macroregion, data = std_sub_falk_r, weights = std_sub_falk_r$popsqrt),
ols(SPI_g ~ SPI_g_lag + IQr + time_pref_falk + risktaking + posrecip + negrecip + altruism + trust, data = std_sub_falk_r, weights = std_sub_falk_r$popsqrt)
) ->
model_set_S4
#SPI ~ Becker + Falk
list(
ols(SPI_g ~ IQb, data = std_sub, weights = std_sub$popsqrt),
ols(SPI_g ~ IQb, data = std_sub_falk_b, weights = std_sub_falk_b$popsqrt),
ols(SPI_g ~ time_pref_falk, data = std_sub_falk_b, weights = std_sub_falk_b$popsqrt),
ols(SPI_g ~ IQb + time_pref_falk, data = std_sub_falk_b, weights = std_sub_falk_b$popsqrt),
ols(SPI_g ~ IQb + time_pref_falk + UN_macroregion, data = std_sub_falk_b, weights = std_sub_falk_b$popsqrt),
#other measures
ols(SPI_g ~ IQb + time_pref_falk + risktaking + posrecip + negrecip + altruism + trust, data = std_sub_falk_b, weights = std_sub_falk_b$popsqrt),
ols(SPI_g ~ IQb + time_pref_falk + risktaking + posrecip + negrecip + altruism + trust + UN_macroregion, data = std_sub_falk_b, weights = std_sub_falk_b$popsqrt),
ols(SPI_g ~ SPI_g_lag + IQb + time_pref_falk + risktaking + posrecip + negrecip + altruism + trust, data = std_sub_falk_b, weights = std_sub_falk_b$popsqrt)
) ->
model_set_S5
#SPI ~ LV + Falk / NO weights
list(
ols(SPI_g ~ IQlv, data = std_sub),
ols(SPI_g ~ IQlv, data = std_sub_falk),
ols(SPI_g ~ time_pref_falk, data = std_sub_falk),
ols(SPI_g ~ IQlv + time_pref_falk, data = std_sub_falk),
ols(SPI_g ~ IQlv + time_pref_falk + UN_macroregion, data = std_sub_falk),
#other measures
ols(SPI_g ~ IQlv + time_pref_falk + risktaking + posrecip + negrecip + altruism + trust, data = std_sub_falk),
ols(SPI_g ~ IQlv + time_pref_falk + risktaking + posrecip + negrecip + altruism + trust + UN_macroregion, data = std_sub_falk),
ols(SPI_g ~ SPI_g_lag + IQlv + time_pref_falk + risktaking + posrecip + negrecip + altruism + trust, data = std_sub_falk)
) ->
model_set_S6
#SPI ~ LV + Falk, robust
#this function is picky with factors
#not included in the main results because added later and requires too much hacking to get to work
#nonetheless shows about the same results
list(
MASS::rlm(SPI_g ~ IQlv, data = std_sub, weights = std_sub$popsqrt, maxit = 999),
MASS::rlm(SPI_g ~ IQlv, data = std_sub_falk, weights = std_sub_falk$popsqrt, maxit = 999),
MASS::rlm(SPI_g ~ time_pref_falk, data = std_sub_falk, weights = std_sub_falk$popsqrt, maxit = 999),
MASS::rlm(SPI_g ~ IQlv + time_pref_falk, data = std_sub_falk, weights = std_sub_falk$popsqrt, maxit = 999),
MASS::rlm(SPI_g ~ IQlv + time_pref_falk + UN_macroregion, data = std_sub_falk %>% mutate(UN_macroregion = as.character(UN_macroregion)), weights = std_sub_falk$popsqrt, maxit = 999),
#other measures
MASS::rlm(SPI_g ~ IQlv + time_pref_falk + risktaking + posrecip + negrecip + altruism + trust, data = std_sub_falk, weights = std_sub_falk$popsqrt, maxit = 999),
MASS::rlm(SPI_g ~ IQlv + time_pref_falk + risktaking + posrecip + negrecip + altruism + trust + UN_macroregion, data = std_sub_falk %>% mutate(UN_macroregion = as.character(UN_macroregion)), weights = std_sub_falk$popsqrt, maxit = 999),
MASS::rlm(SPI_g ~ SPI_g_lag + IQlv + time_pref_falk + risktaking + posrecip + negrecip + altruism + trust, data = std_sub_falk, weights = std_sub_falk$popsqrt, maxit = 999)
) ->
model_set_S7
#quantitative summary across models
extract_func = function(x) {
# browser()
#last model
xlast = x %>% last() %>% .[[1]]
#model summary
tibble(
lag = coef(xlast)[2],
IQ = coef(xlast)[3],
time_pref = coef(xlast)[4],
risktaking = coef(xlast)["risktaking"],
posrecip = coef(xlast)["posrecip"],
negrecip = coef(xlast)["negrecip"],
altruism = coef(xlast)["altruism"],
trust = coef(xlast)["trust"],
N = xlast$stats[1],
R2adj = xlast %>% summary.lm() %>% .$adj.r.squared
)
}
#list of list of models
ll_models = list(
#primary set
model_set_P,
#supplemental
model_set_S1,
model_set_S2,
model_set_S3,
model_set_S4,
model_set_S5,
model_set_S6
)
#quantitative summary
map_df(ll_models, extract_func) ->
param_sum
param_sum
param_sum %>% colMeans(na.rm = T)
## lag IQ time_pref risktaking posrecip negrecip altruism
## 0.39397 0.41161 0.13547 0.08797 -0.00898 -0.04918 0.00924
## trust N R2adj
## -0.16289 77.42857 0.70340
param_sum %>% describe()
#model accuracy of models
map2_df(ll_models, seq_along(ll_models), function(x, i) {
#subset to to wanted models
#note that the lists do not have the same number of models, so we need to use negative indexing
#models 1-2, are pure national IQ
#model 3 is pure time pref
#model 4 is combined national IQ + time pref
#next to last model is full model with regional dummies
#last model is full model with spatial lag
xx = x[c(2, 3, 4, length(x)-1, length(x))]
#model adj. R2s
tibble(
model_set = i,
model = c("1. National IQ", "2. Time pref.", "3. National IQ + time pref.", "4. Full model with dummies", "5. Full model with spatial lag"),
R2adj = map_dbl(xx, ~summary.lm(.) %>% .$adj.r.squared)
)
}) %>%
ggplot(aes(model, R2adj, color = factor(model_set), group = factor(model_set))) +
geom_line() +
scale_x_discrete(guide = guide_axis(angle = -7)) +
scale_y_continuous("Adjusted R²", labels = scales::percent) +
scale_color_discrete("Model set", labels = c("SPI ~ LV + Falk", "SPI ~ LV + Wang", "SPI ~ LV + Rieger10", "HDI ~ LV + Falk", "SPI ~ R + Falk", "SPI ~ B + Falk", "SPI ~ LV + Falk\nno weights"))

GG_save("figs/model_r2s.png")
#test addition of time pref
map_dbl(ll_models, function(x) {
#test model 2 vs. 4
# browser()
lrtest(x[[2]], x[[4]])$stats[3]
})
## [1] 0.06064 0.01550 0.00619 0.03750 0.14099 0.03452 0.00768
#print model summaries
model_set_P %>% summarize_models(asterisks_only = F)
model_set_S1 %>% summarize_models(asterisks_only = F)
model_set_S2 %>% summarize_models(asterisks_only = F)
model_set_S3 %>% summarize_models(asterisks_only = F)
model_set_S4 %>% summarize_models(asterisks_only = F)
model_set_S5 %>% summarize_models(asterisks_only = F)
model_set_S6 %>% summarize_models(asterisks_only = F)
SPI indicators
Fit specific models for every SPI indicator to assess robustness of result.
#fit function
fit_models = function(y) {
#prep local subset of data because of bug in rms, we need to drop unused factor levels
# browser()
y_sym = as.symbol(y)
local_subset = std_sub %>% filter(!is.na(!!y_sym)) %>% df_drop_fct_levels()
local_subset_falk = std_sub %>% filter(!is.na(!!y_sym), !is.na(time_pref_falk)) %>% df_drop_fct_levels()
#fit
#but with changed formula
list(
ols(str_glue("{y} ~ IQlv") %>% as.formula(), data = local_subset, weights = local_subset$popsqrt),
ols(str_glue("{y} ~ IQlv") %>% as.formula(), data = local_subset_falk, weights = local_subset_falk$popsqrt),
ols(str_glue("{y} ~ time_pref_falk") %>% as.formula(), data = local_subset_falk, weights = local_subset_falk$popsqrt),
ols(str_glue("{y} ~ IQlv + time_pref_falk") %>% as.formula(), data = local_subset_falk, weights = local_subset_falk$popsqrt),
ols(str_glue("{y} ~ IQlv + time_pref_falk + UN_macroregion") %>% as.formula(), data = local_subset_falk, weights = local_subset_falk$popsqrt),
#other measures
ols(str_glue("{y} ~ IQlv + time_pref_falk + risktaking + posrecip + negrecip + altruism + trust") %>% as.formula(), data = local_subset_falk, weights = local_subset_falk$popsqrt),
ols(str_glue("{y} ~ IQlv + time_pref_falk + risktaking + posrecip + negrecip + altruism + trust + UN_macroregion") %>% as.formula(), data = local_subset_falk, weights = local_subset_falk$popsqrt),
ols(str_glue("{y} ~ {y}_lag + IQlv + time_pref_falk + risktaking + posrecip + negrecip + altruism + trust") %>% as.formula(), data = local_subset_falk, weights = local_subset_falk$popsqrt)
)
}
#loop and fit for each SPI indicator
SPI_indicator_fits = map(SPI_indicators, fit_models)
#extract summary to long form
SPI_indicator_fits_long = map_df(SPI_indicator_fits, function(x) {
# browser()
#summarize
x %>%
summarize_models(beta_digits = 5) %>%
#just numbers
{
#convert to just betas
cbind(.[1], map_df(.[-1], function(xx) {
str_match(xx, "[\\d\\.]+") %>% as.numeric()
}))
} %>%
mutate(
outcome = x[[1]] %>% terms() %>% .[[2]] %>% as.character()
)
})
#print for inspection
SPI_indicator_fits_long
#fix up a bit
SPI_indicator_fits_long2 = SPI_indicator_fits_long %>%
{
colnames(.)[1:9] = c("predictor", "model_" + 1:8)
.
} %>%
filter(predictor %in% c("IQlv", "time_pref_falk"))
#model 4
#plot simple comparison
SPI_indicator_fits_long2 %>%
GG_denhist("model_4", "predictor", vline = median) +
scale_x_continuous("Standardized beta")
## Scale for 'x' is already present. Adding another scale for 'x', which will
## replace the existing scale.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

GG_save("figs/SPI_indicators_beta_dist.png")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#numbers
describeBy(SPI_indicator_fits_long2$model_4, SPI_indicator_fits_long2$predictor)
##
## Descriptive statistics by group
## group: IQlv
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 51 0.37 0.21 0.4 0.37 0.26 0.01 0.71 0.7 -0.11 -1.23 0.03
## ------------------------------------------------------------
## group: time_pref_falk
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 51 0.19 0.19 0.14 0.16 0.12 0 1.14 1.14 2.65 9.86 0.03
#relationship
SPI_indicator_fits_long2 %>%
select(predictor, model_4, outcome) %>%
spread(key = predictor, value = model_4) %>%
mutate(
ratio = IQlv / time_pref_falk
) %>%
{
describe(.$ratio) %>% print()
.[-26, ]
} %>%
GG_scatter("IQlv", "time_pref_falk", case_names = "outcome")
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 51 14.4 53.1 2.99 3.96 3.46 0.0448 373 373 6.08 38 7.44
## `geom_smooth()` using formula 'y ~ x'

#within model comparison
SPI_indicator_fits_long2 %>%
#fix factor level
mutate(
outcome = factor(outcome %>% str_clean(), levels = SPI_indicators %>% str_clean()) %>% fct_reorder(model_4)
) %>%
ggplot(aes(model_4, outcome)) +
geom_point(aes(color = predictor)) +
# scale_color_discrete(guide = F) +
scale_x_continuous("Standardized beta", breaks = seq(0, 2, .2))

GG_save("figs/SPI_indicators_beta_by_side.png")
#model 7
#plot simple comparison
SPI_indicator_fits_long2 %>%
GG_denhist("model_7", "predictor", vline = median) +
scale_x_continuous("Standardized beta")
## Scale for 'x' is already present. Adding another scale for 'x', which will
## replace the existing scale.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

GG_save("figs/SPI_indicators_beta_dist_full.png")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#numbers
describeBy(SPI_indicator_fits_long2$model_7, SPI_indicator_fits_long2$predictor)
##
## Descriptive statistics by group
## group: IQlv
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 51 0.4 0.21 0.39 0.4 0.23 0.01 0.85 0.84 0.16 -0.78 0.03
## ------------------------------------------------------------
## group: time_pref_falk
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 51 0.14 0.12 0.11 0.13 0.1 0 0.66 0.66 1.83 4.91 0.02
#relationship
SPI_indicator_fits_long2 %>%
select(predictor, model_7, outcome) %>%
spread(key = predictor, value = model_7) %>%
mutate(
ratio = IQlv / time_pref_falk
) %>%
{
describe(.$ratio) %>% print()
.[-26, ]
} %>%
GG_scatter("IQlv", "time_pref_falk", case_names = "outcome")
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 51 11.2 38.8 3.47 4.21 2.43 0.0717 275 275 6.22 39.2 5.43
## `geom_smooth()` using formula 'y ~ x'

#within model comparison
SPI_indicator_fits_long2 %>%
#fix factor level
mutate(
outcome = factor(outcome %>% str_clean(), levels = SPI_indicators %>% str_clean()) %>% fct_reorder(model_7)
) %>%
ggplot(aes(model_7, outcome)) +
geom_point(aes(color = predictor)) +
scale_color_discrete(labels = c("IQlv", "Time pref.")) +
scale_x_continuous("Standardized beta", breaks = seq(0, 2, .2))

GG_save("figs/SPI_indicators_beta_by_side_full.png")
Economic outcomes
Since SPI does not include these.
#correlations with other variables
d %>% select(IQlv, SPI_g, !!econ_outcomes) %>% wtd.cors(weight = d$popsqrt)
## IQlv SPI_g median_income median_income_hh GNI_2019
## IQlv 1.000 0.7717 0.78641 0.7344 0.8113
## SPI_g 0.772 1.0000 0.89925 0.8709 0.9337
## median_income 0.786 0.8992 1.00000 0.9689 0.9185
## median_income_hh 0.734 0.8709 0.96886 1.0000 0.9043
## GNI_2019 0.811 0.9337 0.91855 0.9043 1.0000
## GNI_growth 0.380 0.0258 -0.04735 -0.0909 0.0745
## GDP_2019 0.804 0.9327 0.91695 0.9016 0.9991
## GDP_growth 0.384 0.0656 -0.00336 -0.0450 0.0967
## GNI_growth GDP_2019 GDP_growth
## IQlv 0.3803 0.8042 0.38404
## SPI_g 0.0258 0.9327 0.06557
## median_income -0.0473 0.9169 -0.00336
## median_income_hh -0.0909 0.9016 -0.04500
## GNI_2019 0.0745 0.9991 0.09675
## GNI_growth 1.0000 0.0766 0.99638
## GDP_2019 0.0766 1.0000 0.10009
## GDP_growth 0.9964 0.1001 1.00000
d %>% select(IQlv, SPI_g, !!econ_outcomes) %>% wtd.cors()
## IQlv SPI_g median_income median_income_hh GNI_2019 GNI_growth
## IQlv 1.000 0.800 0.8410 0.7908 0.780 0.2613
## SPI_g 0.800 1.000 0.9009 0.8639 0.916 0.1533
## median_income 0.841 0.901 1.0000 0.9659 0.923 0.0928
## median_income_hh 0.791 0.864 0.9659 1.0000 0.915 0.0798
## GNI_2019 0.780 0.916 0.9229 0.9146 1.000 0.1769
## GNI_growth 0.261 0.153 0.0928 0.0798 0.177 1.0000
## GDP_2019 0.767 0.913 0.9206 0.9109 0.996 0.1819
## GDP_growth 0.244 0.161 0.1462 0.1361 0.177 0.9820
## GDP_2019 GDP_growth
## IQlv 0.767 0.244
## SPI_g 0.913 0.161
## median_income 0.921 0.146
## median_income_hh 0.911 0.136
## GNI_2019 0.996 0.177
## GNI_growth 0.182 0.982
## GDP_2019 1.000 0.199
## GDP_growth 0.199 1.000
d %>% select(IQlv, SPI_g, !!econ_outcomes) %>% pairwiseCount()
## IQlv SPI_g median_income median_income_hh GNI_2019 GNI_growth
## IQlv 196 174 131 131 170 141
## SPI_g 174 176 130 130 163 133
## median_income 131 130 131 131 124 101
## median_income_hh 131 130 131 131 124 101
## GNI_2019 170 163 124 124 174 142
## GNI_growth 141 133 101 101 142 142
## GDP_2019 172 165 126 126 174 142
## GDP_growth 152 144 109 109 154 142
## GDP_2019 GDP_growth
## IQlv 172 152
## SPI_g 165 144
## median_income 126 109
## median_income_hh 126 109
## GNI_2019 174 154
## GNI_growth 142 142
## GDP_2019 177 155
## GDP_growth 155 155
#pairwise plots
d %>% select(IQlv, SPI_g, !!econ_outcomes) %>% GGally::ggpairs()
## Registered S3 method overwritten by 'GGally':
## method from
## +.gg ggplot2
## Warning: Removed 65 rows containing non-finite values (stat_density).
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 87 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 130 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 130 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 91 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 120 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 89 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 109 rows containing missing values
## Warning: Removed 87 rows containing missing values (geom_point).
## Warning: Removed 85 rows containing non-finite values (stat_density).
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 131 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 131 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 98 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 128 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 96 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 117 rows containing missing values
## Warning: Removed 130 rows containing missing values (geom_point).
## Warning: Removed 131 rows containing missing values (geom_point).
## Warning: Removed 130 rows containing non-finite values (stat_density).
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 130 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 137 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 160 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 135 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 152 rows containing missing values
## Warning: Removed 130 rows containing missing values (geom_point).
## Warning: Removed 131 rows containing missing values (geom_point).
## Warning: Removed 130 rows containing missing values (geom_point).
## Warning: Removed 130 rows containing non-finite values (stat_density).
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 137 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 160 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 135 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 152 rows containing missing values
## Warning: Removed 91 rows containing missing values (geom_point).
## Warning: Removed 98 rows containing missing values (geom_point).
## Warning: Removed 137 rows containing missing values (geom_point).
## Warning: Removed 137 rows containing missing values (geom_point).
## Warning: Removed 87 rows containing non-finite values (stat_density).
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 119 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 87 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 107 rows containing missing values
## Warning: Removed 120 rows containing missing values (geom_point).
## Warning: Removed 128 rows containing missing values (geom_point).
## Warning: Removed 160 rows containing missing values (geom_point).
## Warning: Removed 160 rows containing missing values (geom_point).
## Warning: Removed 119 rows containing missing values (geom_point).
## Warning: Removed 119 rows containing non-finite values (stat_density).
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 119 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 119 rows containing missing values
## Warning: Removed 89 rows containing missing values (geom_point).
## Warning: Removed 96 rows containing missing values (geom_point).
## Warning: Removed 135 rows containing missing values (geom_point).
## Warning: Removed 135 rows containing missing values (geom_point).
## Warning: Removed 87 rows containing missing values (geom_point).
## Warning: Removed 119 rows containing missing values (geom_point).
## Warning: Removed 84 rows containing non-finite values (stat_density).
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 106 rows containing missing values
## Warning: Removed 109 rows containing missing values (geom_point).
## Warning: Removed 117 rows containing missing values (geom_point).
## Warning: Removed 152 rows containing missing values (geom_point).
## Warning: Removed 152 rows containing missing values (geom_point).
## Warning: Removed 107 rows containing missing values (geom_point).
## Warning: Removed 119 rows containing missing values (geom_point).
## Warning: Removed 106 rows containing missing values (geom_point).
## Warning: Removed 106 rows containing non-finite values (stat_density).

GG_save("figs/economic_pairwise.png")
## Warning: Removed 65 rows containing non-finite values (stat_density).
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 87 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 130 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 130 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 91 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 120 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 89 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 109 rows containing missing values
## Warning: Removed 87 rows containing missing values (geom_point).
## Warning: Removed 85 rows containing non-finite values (stat_density).
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 131 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 131 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 98 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 128 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 96 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 117 rows containing missing values
## Warning: Removed 130 rows containing missing values (geom_point).
## Warning: Removed 131 rows containing missing values (geom_point).
## Warning: Removed 130 rows containing non-finite values (stat_density).
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 130 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 137 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 160 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 135 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 152 rows containing missing values
## Warning: Removed 130 rows containing missing values (geom_point).
## Warning: Removed 131 rows containing missing values (geom_point).
## Warning: Removed 130 rows containing missing values (geom_point).
## Warning: Removed 130 rows containing non-finite values (stat_density).
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 137 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 160 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 135 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 152 rows containing missing values
## Warning: Removed 91 rows containing missing values (geom_point).
## Warning: Removed 98 rows containing missing values (geom_point).
## Warning: Removed 137 rows containing missing values (geom_point).
## Warning: Removed 137 rows containing missing values (geom_point).
## Warning: Removed 87 rows containing non-finite values (stat_density).
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 119 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 87 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 107 rows containing missing values
## Warning: Removed 120 rows containing missing values (geom_point).
## Warning: Removed 128 rows containing missing values (geom_point).
## Warning: Removed 160 rows containing missing values (geom_point).
## Warning: Removed 160 rows containing missing values (geom_point).
## Warning: Removed 119 rows containing missing values (geom_point).
## Warning: Removed 119 rows containing non-finite values (stat_density).
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 119 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 119 rows containing missing values
## Warning: Removed 89 rows containing missing values (geom_point).
## Warning: Removed 96 rows containing missing values (geom_point).
## Warning: Removed 135 rows containing missing values (geom_point).
## Warning: Removed 135 rows containing missing values (geom_point).
## Warning: Removed 87 rows containing missing values (geom_point).
## Warning: Removed 119 rows containing missing values (geom_point).
## Warning: Removed 84 rows containing non-finite values (stat_density).
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 106 rows containing missing values
## Warning: Removed 109 rows containing missing values (geom_point).
## Warning: Removed 117 rows containing missing values (geom_point).
## Warning: Removed 152 rows containing missing values (geom_point).
## Warning: Removed 152 rows containing missing values (geom_point).
## Warning: Removed 107 rows containing missing values (geom_point).
## Warning: Removed 119 rows containing missing values (geom_point).
## Warning: Removed 106 rows containing missing values (geom_point).
## Warning: Removed 106 rows containing non-finite values (stat_density).
#spearman
d %>% select(IQlv, SPI_g, !!econ_outcomes) %>% cor(use = "pairwise", method = "spearman")
## IQlv SPI_g median_income median_income_hh GNI_2019 GNI_growth
## IQlv 1.000 0.814 0.848 0.800 0.788 0.302
## SPI_g 0.814 1.000 0.929 0.887 0.921 0.215
## median_income 0.848 0.929 1.000 0.979 0.952 0.102
## median_income_hh 0.800 0.887 0.979 1.000 0.933 0.062
## GNI_2019 0.788 0.921 0.952 0.933 1.000 0.197
## GNI_growth 0.302 0.215 0.102 0.062 0.197 1.000
## GDP_2019 0.775 0.918 0.950 0.930 0.997 0.196
## GDP_growth 0.287 0.229 0.164 0.131 0.213 0.963
## GDP_2019 GDP_growth
## IQlv 0.775 0.287
## SPI_g 0.918 0.229
## median_income 0.950 0.164
## median_income_hh 0.930 0.131
## GNI_2019 0.997 0.213
## GNI_growth 0.196 0.963
## GDP_2019 1.000 0.226
## GDP_growth 0.226 1.000
#refit main models with economic outcomes
econ_models_fit = map(econ_outcomes, fit_models)
#extract summary to long form
econ_fits_long = map_df(econ_models_fit, function(x) {
# browser()
#summarize
x %>%
summarize_models(beta_digits = 5) %>%
#just numbers
{
#convert to just betas
cbind(.[1], map_df(.[-1], function(xx) {
str_match(xx, "[\\d\\.]+") %>% as.numeric()
}))
} %>%
mutate(
outcome = x[[1]] %>% terms() %>% .[[2]] %>% as.character()
)
})
#print for inspection
econ_fits_long
#fix up a bit
econ_fits_long2 = econ_fits_long %>%
{
colnames(.)[1:9] = c("predictor", "model_" + 1:8)
.
} %>%
filter(predictor %in% c("IQlv", "time_pref_falk"))
#numbers
describeBy(econ_fits_long2$model_4, econ_fits_long2$predictor)
##
## Descriptive statistics by group
## group: IQlv
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 6 0.54 0.04 0.54 0.54 0.03 0.46 0.58 0.11 -0.81 -0.86 0.02
## ------------------------------------------------------------
## group: time_pref_falk
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 6 0.21 0.08 0.19 0.21 0.08 0.13 0.34 0.21 0.53 -1.53 0.03
describeBy(econ_fits_long2$model_7, econ_fits_long2$predictor)
##
## Descriptive statistics by group
## group: IQlv
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 6 0.47 0.18 0.52 0.47 0.19 0.25 0.64 0.4 -0.18 -2.11 0.07
## ------------------------------------------------------------
## group: time_pref_falk
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 6 0.2 0.17 0.15 0.2 0.16 0.01 0.44 0.42 0.34 -1.89 0.07
#relationship
econ_fits_long2 %>%
select(predictor, model_7, outcome) %>%
spread(key = predictor, value = model_7) %>%
mutate(
ratio = IQlv / time_pref_falk
) %>%
{
describe(.$ratio) %>% print()
.[-26, ]
} %>%
GG_scatter("IQlv", "time_pref_falk", case_names = "outcome")
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 6 7.74 11.7 1.84 7.74 0.485 1.47 30.9 29.5 1.2 -0.389 4.78
## `geom_smooth()` using formula 'y ~ x'

#within model comparison
econ_fits_long2 %>%
#fix factor level
mutate(
outcome = factor(outcome %>% str_clean(), levels = econ_outcomes %>% str_clean())
) %>%
ggplot(aes(model_7, outcome)) +
geom_point(aes(color = predictor), size = 3) +
scale_color_discrete(labels = c("IQlv", "Time pref.")) +
scale_x_continuous("Standardized beta", breaks = seq(0, 2, .1))

GG_save("figs/econ_beta_by_side_full.png")
#direct comparison, model 4
econ_fits_long2 %>%
#fix factor level
mutate(
outcome = factor(outcome %>% str_clean(), levels = econ_outcomes %>% str_clean()) %>% fct_reorder(model_4)
) %>%
ggplot(aes(model_4, outcome)) +
geom_point(aes(color = predictor)) +
scale_color_discrete(labels = c("IQlv", "Time pref.")) +
scale_x_continuous("Standardized beta", breaks = seq(0, 2, .1))

GG_save("figs/econ_beta_by_side_direct.png")