Subsetting to country
switzerland_data <- ess %>%
filter(cntry == "CH")
df <- switzerland_data
Creating/cleaning main outcome variable.
Create our tables
## Warning: The histogram argument is only supported for (a) output types "default",
## "html", "kableExtra", or "gt"; (b) writing to file paths with extensions
## ".html", ".jpg", or ".png"; and (c) Rmarkdown, knitr or Quarto documents
## compiled to PDF (via kableExtra) or HTML (via kableExtra or gt). Use
## `histogram=FALSE` to silence this warning.
| Unique (#) | Missing (%) | Mean | SD | Min | Median | Max |
|---|---|---|---|---|---|---|---|
happy | 11 | 0 | 69.0 | 1.4 | 67.0 | 69.0 | 76.0 |
health | 5 | 0 | 5.1 | 0.8 | 2.0 | 5.0 | 6.0 |
stflife | 11 | 0 | 8.0 | 1.7 | 0.0 | 8.0 | 10.0 |
trstprl | 11 | 0 | 5.7 | 2.0 | 0.0 | 6.0 | 10.0 |
edulvla | 5 | 0 | 3.3 | 1.2 | 1.0 | 3.0 | 5.0 |
## Warning: The histogram argument is only supported for (a) output types "default",
## "html", "kableExtra", or "gt"; (b) writing to file paths with extensions
## ".html", ".jpg", or ".png"; and (c) Rmarkdown, knitr or Quarto documents
## compiled to PDF (via kableExtra) or HTML (via kableExtra or gt). Use
## `histogram=FALSE` to silence this warning.
| Unique (#) | Missing (%) | Mean | SD | Min | Median | Max |
|---|---|---|---|---|---|---|---|
How happy are you | 11 | 0 | 69.0 | 1.4 | 67.0 | 69.0 | 76.0 |
Subjective general health | 5 | 0 | 5.1 | 0.8 | 2.0 | 5.0 | 6.0 |
How satisfied with life as a whole | 11 | 0 | 8.0 | 1.7 | 0.0 | 8.0 | 10.0 |
Trust in country's parliament | 11 | 0 | 5.7 | 2.0 | 0.0 | 6.0 | 10.0 |
Highest level of education | 5 | 0 | 3.3 | 1.2 | 1.0 | 3.0 | 5.0 |
Finding
df <- df %>%
mutate(
edulvla = edulvla %>%
na_if(55) %>%
na_if(88),
edulvlb = edulvlb %>%
na_if(5555) %>%
na_if(7777) %>%
na_if(8888),
educ.ba = case_when(
essround < 5 & edulvla == 5 ~ 1,
essround >= 5 & edulvlb > 600 ~ 1,
TRUE ~ 0))
table(df$edulvla)
##
## 1 2 3 4 5
## 292 1324 3616 134 1967
df <- df %>% filter(!is.na(educ.ba))
d <- df %>%
# Convert factors/characters to numeric
mutate(
educ_ba_num = as.numeric(educ.ba),
)
table2 <- datasummary_skim(d %>% dplyr::select(educ_ba_num, life_expectancy), output = "flextable")
## Warning: The histogram argument is only supported for (a) output types "default",
## "html", "kableExtra", or "gt"; (b) writing to file paths with extensions
## ".html", ".jpg", or ".png"; and (c) Rmarkdown, knitr or Quarto documents
## compiled to PDF (via kableExtra) or HTML (via kableExtra or gt). Use
## `histogram=FALSE` to silence this warning.
table2
| Unique (#) | Missing (%) | Mean | SD | Min | Median | Max |
|---|---|---|---|---|---|---|---|
educ_ba_num | 2 | 0 | 0.3 | 0.4 | 0.0 | 0.0 | 1.0 |
life_expectancy | 34 | 0 | 30.9 | 10.7 | 0.0 | 30.6 | 100.0 |
Hypothesis testing with infer
## Message: The independence null hypothesis does not inform calculation of the
## observed statistic (a correlation) and will be ignored.
## Response: life_expectancy (numeric)
## Explanatory: educ.ba (numeric)
## Null Hypothesis: independence
## # A tibble: 1,000 × 2
## replicate stat
## <int> <dbl>
## 1 1 -0.00818
## 2 2 0.0161
## 3 3 0.0192
## 4 4 -0.00308
## 5 5 0.0000254
## 6 6 -0.0118
## 7 7 -0.00938
## 8 8 -0.0205
## 9 9 0.00823
## 10 10 -0.0164
## # ℹ 990 more rows
## # A tibble: 1 × 1
## p_value
## <dbl>
## 1 1
| Â (1) | Â Â (2) | Â Â (3) | |
|---|---|---|---|
| educ.ba | −7.8 (0.3)*** | −7.3 (0.2)*** | −7.5 (0.2)*** |
| stflife | −4.5 (0.0)*** | ||
| health | 13.8 (3.9)*** | ||
| happy | 6.2 (0.3)*** | ||
| health × happy | −0.2 (0.1)** | ||
| Num.Obs. | 7333 | 7333 | 7333 |
| R2 | 0.102 | 0.611 | 0.600 |
| R2 Adj. | 0.102 | 0.611 | 0.600 |
| AIC | 55435.8 | 49299.2 | 49509.4 |
| BIC | 55456.5 | 49326.8 | 49550.8 |
| Log.Lik. | −27714.917 | −24645.575 | −24748.715 |
| RMSE | 10.16 | 6.68 | 6.76 |
Visual
##
## health*happy effect
## happy
## health 67 70 72 74 77
## 2 14.32593 31.71640 43.31005 54.90370 72.29418
## 3 16.26902 33.12872 44.36852 55.60832 72.46801
## 4 18.21212 34.54104 45.42698 56.31293 72.64185
## 5 20.15521 35.95335 46.48545 57.01754 72.81568
## 6 22.09831 37.36567 47.54391 57.72216 72.98952
| Model 1 | Â Model 2 | Â Model 3 | |
|---|---|---|---|
| (Intercept) | 32.719 | 69.172 | −399.651 |
| (0.136) | (0.383) | (19.869) | |
| educ.ba | −7.828 | −7.297 | −7.471 |
| (0.272) | (0.179) | (0.182) | |
| stflife | −4.543 | ||
| (0.046) | |||
| health | 13.797 | ||
| (3.926) | |||
| happy | 6.151 | ||
| (0.286) | |||
| health × happy | −0.177 | ||
| (0.057) | |||
| Num.Obs. | 7333 | 7333 | 7333 |
| R2 | 0.102 | 0.611 | 0.600 |
| R2 Adj. | 0.102 | 0.611 | 0.600 |
| AIC | 55435.8 | 49299.2 | 49509.4 |
| BIC | 55456.5 | 49326.8 | 49550.8 |
| Log.Lik. | −27714.917 | −24645.575 | −24748.715 |
| RMSE | 10.16 | 6.68 | 6.76 |
| Model 1 | Â Model 2 | Â Model 3 | |
|---|---|---|---|
| (Intercept) | 32.719 | 69.172 | −399.651 |
| (0.157) | (0.555) | (28.812) | |
| educ.ba | −7.828 | −7.297 | −7.471 |
| (0.273) | (0.181) | (0.183) | |
| stflife | −4.543 | ||
| (0.067) | |||
| health | 13.797 | ||
| (5.932) | |||
| happy | 6.151 | ||
| (0.416) | |||
| health × happy | −0.177 | ||
| (0.086) | |||
| Num.Obs. | 7333 | 7333 | 7333 |
| R2 | 0.102 | 0.611 | 0.600 |
| R2 Adj. | 0.102 | 0.611 | 0.600 |
| AIC | 55435.8 | 49299.2 | 49509.4 |
| BIC | 55456.5 | 49326.8 | 49550.8 |
| Log.Lik. | −27714.917 | −24645.575 | −24748.715 |
| RMSE | 10.16 | 6.68 | 6.76 |
| Std.Errors | HC3 | HC3 | HC3 |
| Model 1 | Â Model 2 | Â Model 3 | |
|---|---|---|---|
| (Intercept) | 32.7 (0.1)*** | 69.2 (0.4)*** | −399.7 (19.9)*** |
| educ.ba | −7.8 (0.3)*** | −7.3 (0.2)*** | −7.5 (0.2)*** |
| stflife | −4.5 (0.0)*** | ||
| health | 13.8 (3.9)*** | ||
| happy | 6.2 (0.3)*** | ||
| health × happy | −0.2 (0.1)** | ||
| Num.Obs. | 7333 | 7333 | 7333 |
| R2 | 0.102 | 0.611 | 0.600 |
| R2 Adj. | 0.102 | 0.611 | 0.600 |
| AIC | 55435.8 | 49299.2 | 49509.4 |
| BIC | 55456.5 | 49326.8 | 49550.8 |
| Log.Lik. | −27714.917 | −24645.575 | −24748.715 |
| RMSE | 10.16 | 6.68 | 6.76 |