#packages
library(pacman)
p_load(kirkegaard, readr, dplyr)
#data
fin = read_csv("data/finland.csv") %>%
mutate(
ISO = pu_translate(Country)
)
## Parsed with column specification:
## cols(
## Country = col_character(),
## fin_net_fiscal_contribution = col_integer()
## )
mega = read_csv("data/Megadataset_v2.0p.csv") %>%
rename(
ISO = X1
)
## Parsed with column specification:
## cols(
## .default = col_double(),
## X1 = col_character(),
## EthnicHeterogenityVanhanen2012 = col_integer(),
## EthnicConflictVanhanen2012 = col_integer(),
## SlowTimePrefWangetal2011 = col_integer(),
## Math00Mean = col_integer(),
## Math00SD = col_integer(),
## Read00Mean = col_integer(),
## Read00SD = col_integer(),
## Sci00Mean = col_integer(),
## Sci00SD = col_integer(),
## Math03Mean = col_integer(),
## Math03SD = col_integer(),
## Read03Mean = col_integer(),
## Read03SD = col_integer(),
## Sci03Mean = col_integer(),
## Sci03SD = col_integer(),
## PS03Mean = col_integer(),
## PS03SD = col_integer(),
## Read09.Native = col_integer(),
## Read09.1g = col_integer()
## # ... with 102 more columns
## )
## See spec(...) for full column specifications.
dnk = read_csv("data/denmark.csv")
## Parsed with column specification:
## cols(
## ISO = col_character(),
## dnk_net_fiscal_contribution = col_double()
## )
#merge data
d = dplyr::full_join(mega, fin[-1], by = "ISO") %>% full_join(dnk, by = "ISO")
#add some synnonyms/extra
d %<>% mutate(
name = pu_translate(ISO, reverse = T),
dk_fiscal = dnk_net_fiscal_contribution*1000/7.44,
fi_fiscal = fin_net_fiscal_contribution,
dk_S = S.factor.in.Denmark.Kirkegaard2014,
Muslim_pct = Muslim*100
)
## No match: Africa
## No match: Asia
## No match: ASM
## No match: BELFL
## No match: BELFR
## No match: BIF
## No match: CHA
## No match: Eastern-Europe
## No match: MCA
## No match: MIC
## No match: MIR
## No match: North America and Oceania
## No match: PRI
## No match: SAS
## No match: South and Middle America
## No match: SRP
## No match: VGB
## No match: VIR
## No match: Western-Europe
Plot the main analyses of interest.
#compare DK FI
GG_scatter(d, "dk_fiscal", "fi_fiscal", case_names = "name", check_overlap = F) +
scale_x_continuous("Denmark: Net fiscal contribution\n(euro/year)", limits = c(NA, 10000), breaks = seq(-20000, 10000, by = 5000)) +
scale_y_continuous("Finland: Net fiscal contribution\n(euro/year)", breaks = seq(-15000, 2500, 2500), limits = c(-15000, 2500))
GG_save("figures/dk_fi.png")
## FINLAND
#IQ
GG_scatter(d, "IQ", "fi_fiscal", case_names = "name", check_overlap = F) +
scale_x_continuous("Origin country IQ", breaks = seq(70, 110, by = 5)) +
scale_y_continuous("Finland: Net fiscal contribution\n(euro/year)", breaks = seq(-15000, 2500, 2500))
GG_save("figures/finland_IQ_fiscal.png")
#Islam
GG_scatter(d, "Muslim", "fi_fiscal", case_names = "name", check_overlap = F) +
scale_x_continuous("Origin country Muslim%", labels = scales::percent) +
scale_y_continuous("Finland: Net fiscal contribution\n(euro/year)", breaks = seq(-15000, 2500, 2500))
GG_save("figures/finland_Muslim_fiscal.png")
##DENMARK
#IQ
GG_scatter(d, "IQ", "dk_fiscal", case_names = "name", check_overlap = T) +
scale_x_continuous("Origin country IQ", breaks = seq(70, 110, by = 5)) +
scale_y_continuous("Denmark: Net fiscal contribution\n(euro/year)") +
GG_save("figures/denmark_IQ_fiscal.png")
#Islam
GG_scatter(d, "Muslim", "dk_fiscal", case_names = "name", check_overlap = T) +
scale_x_continuous("Origin country Muslim%", labels = scales::percent) +
scale_y_continuous("Denmark: Net fiscal contribution\n(euro/year)") +
GG_save("figures/denmark_Muslim_fiscal.png")
#map to S
GG_scatter(d, "S.factor.in.Denmark.Kirkegaard2014", "dk_fiscal", case_names = "name", check_overlap = T) +
scale_x_continuous("S factor (general socioeconomic factor)") +
scale_y_continuous("Denmark: Net fiscal contribution\n(euro/year)") +
GG_save("figures/denmark_S_fiscal.png")
#without Syria
d %>%
filter(ISO != "SYR") %>%
.[c("S.factor.in.Denmark.Kirkegaard2014", "dk_fiscal")] %>%
cor_matrix(CI = .95)
## S.factor.in.Denmark.Kirkegaard2014
## S.factor.in.Denmark.Kirkegaard2014 "1"
## dk_fiscal "0.90 [0.80 0.95]"
## dk_fiscal
## S.factor.in.Denmark.Kirkegaard2014 "0.90 [0.80 0.95]"
## dk_fiscal "1"
Here we calculate the coefficients, so we can say exactly how much 1 IQ/1% more Muslims is/are worth.
#we do these so we can can mention the specific costs per Muslim% and IQ point
#finland
lm(fi_fiscal ~ IQ, data = d) %>% MOD_summary(standardize = F, kfold = F)
##
## ---- Model summary ----
## Model coefficients
## Beta SE CI_lower CI_upper
## IQ 470.0969 100.7806 242.1153 698.0785
##
##
## Model meta-data
## outcome N df R2 R2-adj. R2-cv
## 1 fi_fiscal 11 9 0.707394 0.6748822 NA
##
##
## Etas from analysis of variance
## Eta Eta_partial
## IQ 0.8410672 0.8410672
lm(fi_fiscal ~ Muslim_pct, data = d) %>% MOD_summary(standardize = F, kfold = F)
##
## ---- Model summary ----
## Model coefficients
## Beta SE CI_lower CI_upper
## Muslim_pct -86.0832 25.44487 -143.6435 -28.5229
##
##
## Model meta-data
## outcome N df R2 R2-adj. R2-cv
## 1 fi_fiscal 11 9 0.5598062 0.5108958 NA
##
##
## Etas from analysis of variance
## Eta Eta_partial
## Muslim_pct 0.748202 0.748202
#denmark
lm(dk_fiscal ~ IQ, data = d) %>% MOD_summary(standardize = F, kfold = F)
##
## ---- Model summary ----
## Model coefficients
## Beta SE CI_lower CI_upper
## IQ 917.2366 176.6732 556.4217 1278.051
##
##
## Model meta-data
## outcome N df R2 R2-adj. R2-cv
## 1 dk_fiscal 32 30 0.473258 0.4557 NA
##
##
## Etas from analysis of variance
## Eta Eta_partial
## IQ 0.6879375 0.6879375
lm(dk_fiscal ~ Muslim_pct, data = d) %>% MOD_summary(standardize = F, kfold = F)
##
## ---- Model summary ----
## Model coefficients
## Beta SE CI_lower CI_upper
## Muslim_pct -187.5798 32.1122 -253.1616 -121.9979
##
##
## Model meta-data
## outcome N df R2 R2-adj. R2-cv
## 1 dk_fiscal 32 30 0.5321403 0.516545 NA
##
##
## Etas from analysis of variance
## Eta Eta_partial
## Muslim_pct 0.7294795 0.7294795
#dispersion
d$dk_fiscal %>% describe
## vars n mean sd median trimmed mad min max
## X1 1 32 -2471.02 10603.73 -1129.03 -1395.78 7771.69 -39717.74 11827.96
## range skew kurtosis se
## X1 51545.7 -1.35 2.63 1874.49
d$fi_fiscal %>% describe
## vars n mean sd median trimmed mad min max range skew
## X1 1 11 -4625.45 5083.34 -3900 -4320 3409.98 -14000 2000 16000 -0.7
## kurtosis se
## X1 -0.81 1532.68