# List of packages
packages <- c("tidyverse", "modelsummary", "forcats", "RColorBrewer",
"fst", "viridis", "knitr", "rmarkdown", "ggridges", "viridis", "questionr", "flextable", "infer","effects", "survey", "MASS", "dplyr", "htmltools")
# Install packages if they aren't installed already
new_packages <- packages[!(packages %in% installed.packages()[,"Package"])]
if(length(new_packages)) install.packages(new_packages)
# Load the packages
lapply(packages, library, character.only = TRUE)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.3 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.3 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
## Loading required package: viridisLite
##
##
## Attaching package: 'flextable'
##
##
## The following object is masked from 'package:purrr':
##
## compose
##
##
## Loading required package: carData
##
## lattice theme set by effectsTheme()
## See ?effectsTheme for details.
##
## Loading required package: grid
##
## Loading required package: Matrix
##
##
## Attaching package: 'Matrix'
##
##
## The following objects are masked from 'package:tidyr':
##
## expand, pack, unpack
##
##
## Loading required package: survival
##
##
## Attaching package: 'survey'
##
##
## The following object is masked from 'package:graphics':
##
## dotchart
##
##
##
## Attaching package: 'MASS'
##
##
## The following object is masked from 'package:dplyr':
##
## select
## [[1]]
## [1] "lubridate" "forcats" "stringr" "dplyr" "purrr" "readr"
## [7] "tidyr" "tibble" "ggplot2" "tidyverse" "stats" "graphics"
## [13] "grDevices" "utils" "datasets" "methods" "base"
##
## [[2]]
## [1] "modelsummary" "lubridate" "forcats" "stringr" "dplyr"
## [6] "purrr" "readr" "tidyr" "tibble" "ggplot2"
## [11] "tidyverse" "stats" "graphics" "grDevices" "utils"
## [16] "datasets" "methods" "base"
##
## [[3]]
## [1] "modelsummary" "lubridate" "forcats" "stringr" "dplyr"
## [6] "purrr" "readr" "tidyr" "tibble" "ggplot2"
## [11] "tidyverse" "stats" "graphics" "grDevices" "utils"
## [16] "datasets" "methods" "base"
##
## [[4]]
## [1] "RColorBrewer" "modelsummary" "lubridate" "forcats" "stringr"
## [6] "dplyr" "purrr" "readr" "tidyr" "tibble"
## [11] "ggplot2" "tidyverse" "stats" "graphics" "grDevices"
## [16] "utils" "datasets" "methods" "base"
##
## [[5]]
## [1] "fst" "RColorBrewer" "modelsummary" "lubridate" "forcats"
## [6] "stringr" "dplyr" "purrr" "readr" "tidyr"
## [11] "tibble" "ggplot2" "tidyverse" "stats" "graphics"
## [16] "grDevices" "utils" "datasets" "methods" "base"
##
## [[6]]
## [1] "viridis" "viridisLite" "fst" "RColorBrewer" "modelsummary"
## [6] "lubridate" "forcats" "stringr" "dplyr" "purrr"
## [11] "readr" "tidyr" "tibble" "ggplot2" "tidyverse"
## [16] "stats" "graphics" "grDevices" "utils" "datasets"
## [21] "methods" "base"
##
## [[7]]
## [1] "knitr" "viridis" "viridisLite" "fst" "RColorBrewer"
## [6] "modelsummary" "lubridate" "forcats" "stringr" "dplyr"
## [11] "purrr" "readr" "tidyr" "tibble" "ggplot2"
## [16] "tidyverse" "stats" "graphics" "grDevices" "utils"
## [21] "datasets" "methods" "base"
##
## [[8]]
## [1] "rmarkdown" "knitr" "viridis" "viridisLite" "fst"
## [6] "RColorBrewer" "modelsummary" "lubridate" "forcats" "stringr"
## [11] "dplyr" "purrr" "readr" "tidyr" "tibble"
## [16] "ggplot2" "tidyverse" "stats" "graphics" "grDevices"
## [21] "utils" "datasets" "methods" "base"
##
## [[9]]
## [1] "ggridges" "rmarkdown" "knitr" "viridis" "viridisLite"
## [6] "fst" "RColorBrewer" "modelsummary" "lubridate" "forcats"
## [11] "stringr" "dplyr" "purrr" "readr" "tidyr"
## [16] "tibble" "ggplot2" "tidyverse" "stats" "graphics"
## [21] "grDevices" "utils" "datasets" "methods" "base"
##
## [[10]]
## [1] "ggridges" "rmarkdown" "knitr" "viridis" "viridisLite"
## [6] "fst" "RColorBrewer" "modelsummary" "lubridate" "forcats"
## [11] "stringr" "dplyr" "purrr" "readr" "tidyr"
## [16] "tibble" "ggplot2" "tidyverse" "stats" "graphics"
## [21] "grDevices" "utils" "datasets" "methods" "base"
##
## [[11]]
## [1] "questionr" "ggridges" "rmarkdown" "knitr" "viridis"
## [6] "viridisLite" "fst" "RColorBrewer" "modelsummary" "lubridate"
## [11] "forcats" "stringr" "dplyr" "purrr" "readr"
## [16] "tidyr" "tibble" "ggplot2" "tidyverse" "stats"
## [21] "graphics" "grDevices" "utils" "datasets" "methods"
## [26] "base"
##
## [[12]]
## [1] "flextable" "questionr" "ggridges" "rmarkdown" "knitr"
## [6] "viridis" "viridisLite" "fst" "RColorBrewer" "modelsummary"
## [11] "lubridate" "forcats" "stringr" "dplyr" "purrr"
## [16] "readr" "tidyr" "tibble" "ggplot2" "tidyverse"
## [21] "stats" "graphics" "grDevices" "utils" "datasets"
## [26] "methods" "base"
##
## [[13]]
## [1] "infer" "flextable" "questionr" "ggridges" "rmarkdown"
## [6] "knitr" "viridis" "viridisLite" "fst" "RColorBrewer"
## [11] "modelsummary" "lubridate" "forcats" "stringr" "dplyr"
## [16] "purrr" "readr" "tidyr" "tibble" "ggplot2"
## [21] "tidyverse" "stats" "graphics" "grDevices" "utils"
## [26] "datasets" "methods" "base"
##
## [[14]]
## [1] "effects" "carData" "infer" "flextable" "questionr"
## [6] "ggridges" "rmarkdown" "knitr" "viridis" "viridisLite"
## [11] "fst" "RColorBrewer" "modelsummary" "lubridate" "forcats"
## [16] "stringr" "dplyr" "purrr" "readr" "tidyr"
## [21] "tibble" "ggplot2" "tidyverse" "stats" "graphics"
## [26] "grDevices" "utils" "datasets" "methods" "base"
##
## [[15]]
## [1] "survey" "survival" "Matrix" "grid" "effects"
## [6] "carData" "infer" "flextable" "questionr" "ggridges"
## [11] "rmarkdown" "knitr" "viridis" "viridisLite" "fst"
## [16] "RColorBrewer" "modelsummary" "lubridate" "forcats" "stringr"
## [21] "dplyr" "purrr" "readr" "tidyr" "tibble"
## [26] "ggplot2" "tidyverse" "stats" "graphics" "grDevices"
## [31] "utils" "datasets" "methods" "base"
##
## [[16]]
## [1] "MASS" "survey" "survival" "Matrix" "grid"
## [6] "effects" "carData" "infer" "flextable" "questionr"
## [11] "ggridges" "rmarkdown" "knitr" "viridis" "viridisLite"
## [16] "fst" "RColorBrewer" "modelsummary" "lubridate" "forcats"
## [21] "stringr" "dplyr" "purrr" "readr" "tidyr"
## [26] "tibble" "ggplot2" "tidyverse" "stats" "graphics"
## [31] "grDevices" "utils" "datasets" "methods" "base"
##
## [[17]]
## [1] "MASS" "survey" "survival" "Matrix" "grid"
## [6] "effects" "carData" "infer" "flextable" "questionr"
## [11] "ggridges" "rmarkdown" "knitr" "viridis" "viridisLite"
## [16] "fst" "RColorBrewer" "modelsummary" "lubridate" "forcats"
## [21] "stringr" "dplyr" "purrr" "readr" "tidyr"
## [26] "tibble" "ggplot2" "tidyverse" "stats" "graphics"
## [31] "grDevices" "utils" "datasets" "methods" "base"
##
## [[18]]
## [1] "htmltools" "MASS" "survey" "survival" "Matrix"
## [6] "grid" "effects" "carData" "infer" "flextable"
## [11] "questionr" "ggridges" "rmarkdown" "knitr" "viridis"
## [16] "viridisLite" "fst" "RColorBrewer" "modelsummary" "lubridate"
## [21] "forcats" "stringr" "dplyr" "purrr" "readr"
## [26] "tidyr" "tibble" "ggplot2" "tidyverse" "stats"
## [31] "graphics" "grDevices" "utils" "datasets" "methods"
## [36] "base"
ess <- read_fst("All-ESS-Data.fst")
library(fst)
# Creating Israel's dataset
israel_dataset <- ess[ess$cntry == "IL", ]
# Cleaning Israel's dataset
israel_clean <- israel_dataset %>%
dplyr::select(eduail1, hinctnta, happy, rlgdgr, essround, yrbrn, rlgdnm, imprich, inprdsc) %>%
filter(!yrbrn %in% c(7777, 8888)) %>%
mutate(
happy = ifelse(happy %in% c(77, 88, 99), NA, happy),
rlgdgr = ifelse(rlgdgr %in% c(77, 88, 99), NA, rlgdgr),
eduail1 = ifelse(eduail1 %in% c(4444, 5555, 7777, 8888, 9999), NA, eduail1),
hinctnta = ifelse(hinctnta %in% c(77, 88, 99), NA, hinctnta),
rlgdnm = ifelse(rlgdnm %in% c(77,99), NA, rlgdnm),
imprich = ifelse(imprich %in% c(7, 8, 9), NA, imprich),
inprdsc = ifelse(inprdsc %in% c(77, 88, 99), NA, inprdsc),
year = case_when(essround == 1 ~ 2002,
essround == 2 ~ 2004,
essround == 3 ~ 2006,
essround == 4 ~ 2008,
essround == 5 ~ 2010,
essround == 6 ~ 2012,
essround == 7 ~ 2014,
essround == 8 ~ 2016,
essround == 9 ~ 2018,
essround == 10 ~ 2020),
) %>%
filter(!is.na(happy) & !is.na(rlgdgr) & !is.na(eduail1) & !is.na(hinctnta) & !is.na(rlgdnm) & !is.na(imprich) & !is.na(inprdsc))
# Recoding Variables
israel_clean <- israel_clean %>%
mutate(
eduail1 = factor(
case_when(
eduail1 == 1 ~ "Not completed Primary Education",
eduail1 == 2 ~ "Primary School",
eduail1 == 3 ~ "Junior High School",
eduail1 %in% 4:9 ~ "Secondary School",
eduail1 %in% 10:11 ~ "Post-Secondary School (Non-Tetiary)",
eduail1 %in% 12:13 ~ "Bachelor's Degree",
eduail1 %in% 14:16 ~ "Master's Degree",
eduail1 == 17 ~ "Doctorate Degree",
TRUE ~ as.character(eduail1) # Convert to character for consistency
),
levels = c("Not completed Primary Education", "Primary School", "Junior High School",
"Secondary School", "Post-Secondary School (Non-Tetiary)",
"Bachelor's Degree", "Master's Degree", "Doctorate Degree")
)
) %>%
mutate(
inprdsc = factor(
case_when(
inprdsc == 0 ~ "None",
inprdsc == 1 ~ "1",
inprdsc == 2 ~ "2",
inprdsc == 3 ~ "3",
inprdsc == 4 ~ "4-6",
inprdsc == 5 ~ "7-9",
inprdsc == 6 ~ "10 or more",
TRUE ~ as.character(inprdsc) # Convert to character for consistency
),
levels = c("None", "1", "2", "3", "4-6", "7-9", "10 or more")
)
)
levels(israel_clean$eduail1)
## [1] "Not completed Primary Education" "Primary School"
## [3] "Junior High School" "Secondary School"
## [5] "Post-Secondary School (Non-Tetiary)" "Bachelor's Degree"
## [7] "Master's Degree" "Doctorate Degree"
levels(israel_clean$inprdsc)
## [1] "None" "1" "2" "3" "4-6"
## [6] "7-9" "10 or more"
test_stat <- israel_clean %>%
specify(explanatory = eduail1,
response = happy) %>%
hypothesize(null = "independence") %>%
calculate(stat = "F")
print(test_stat$stat)
## [1] 9.288192
null_distribution <- israel_clean %>%
specify(explanatory = eduail1,
response = happy) %>%
hypothesize(null = "independence") %>%
generate(reps = 1000, type = "permute") %>%
calculate(stat = "f")
p_val <- null_distribution %>%
get_pvalue(obs_stat = test_stat, direction = "greater")
## Warning: Please be cautious in reporting a p-value of 0. This result is an
## approximation based on the number of `reps` chosen in the `generate()` step.
## See `?get_p_value()` for more information.
p_val
## # A tibble: 1 × 1
## p_value
## <dbl>
## 1 0
null_distribution %>%
visualize() +
shade_p_value(obs_stat = test_stat, direction = "greater")
## Warning in min(diff(unique_loc)): no non-missing arguments to min; returning
## Inf
friend_stat <- israel_clean %>%
specify(explanatory = inprdsc,
response = happy) %>%
hypothesize(null = "independence") %>%
calculate(stat = "F")
print(friend_stat$stat)
## [1] 18.358
null_friend <- israel_clean %>%
specify(explanatory = inprdsc,
response = happy) %>%
hypothesize(null = "independence") %>%
generate(reps = 1000, type = "permute") %>%
calculate(stat = "F")
p_friend <- null_friend %>%
get_pvalue(obs_stat = friend_stat, direction = "greater")
## Warning: Please be cautious in reporting a p-value of 0. This result is an
## approximation based on the number of `reps` chosen in the `generate()` step.
## See `?get_p_value()` for more information.
p_friend
## # A tibble: 1 × 1
## p_value
## <dbl>
## 1 0
null_friend %>%
visualize() +
shade_p_value(obs_stat = friend_stat, direction = "greater")
## Warning in min(diff(unique_loc)): no non-missing arguments to min; returning
## Inf
model1 <- lm(happy ~ eduail1, data = israel_clean)
model2 <- lm(happy ~ eduail1 + inprdsc, data = israel_clean)
model3 <- lm(happy ~ eduail1 + inprdsc + eduail1*inprdsc, data = israel_clean)
modelsummary(
list(model1, model2, model3))
| (1) | (2) | (3) |
|---|---|---|---|
(Intercept) | 7.165 | 6.292 | 6.400 |
(0.193) | (0.221) | (0.592) | |
eduail1Primary School | -0.139 | -0.008 | -0.576 |
(0.231) | (0.228) | (0.648) | |
eduail1Junior High School | -0.028 | -0.012 | 0.165 |
(0.233) | (0.230) | (0.709) | |
eduail1Secondary School | 0.434 | 0.414 | 0.482 |
(0.201) | (0.198) | (0.616) | |
eduail1Post-Secondary School (Non-Tetiary) | 0.590 | 0.528 | -0.030 |
(0.213) | (0.211) | (0.693) | |
eduail1Bachelor's Degree | 0.751 | 0.639 | 1.418 |
(0.209) | (0.207) | (0.714) | |
eduail1Master's Degree | 0.729 | 0.590 | -1.400 |
(0.225) | (0.223) | (0.967) | |
eduail1Doctorate Degree | 0.867 | 0.759 | 0.100 |
(0.392) | (0.388) | (1.450) | |
inprdsc1 | 0.824 | 0.081 | |
(0.138) | (0.693) | ||
inprdsc2 | 0.846 | 0.933 | |
(0.141) | (0.738) | ||
inprdsc3 | 1.144 | 1.100 | |
(0.141) | (0.714) | ||
inprdsc4-6 | 1.065 | 1.667 | |
(0.142) | (0.764) | ||
inprdsc7-9 | 1.349 | 3.600 | |
(0.209) | (1.964) | ||
inprdsc10 or more | 1.168 | 0.600 | |
(0.184) | (1.108) | ||
eduail1Primary School × inprdsc1 | 1.065 | ||
(0.776) | |||
eduail1Junior High School × inprdsc1 | 0.169 | ||
(0.829) | |||
eduail1Secondary School × inprdsc1 | 0.642 | ||
(0.722) | |||
eduail1Post-Secondary School (Non-Tetiary) × inprdsc1 | 1.236 | ||
(0.805) | |||
eduail1Bachelor's Degree × inprdsc1 | -0.070 | ||
(0.824) | |||
eduail1Master's Degree × inprdsc1 | 2.725 | ||
(1.085) | |||
eduail1Doctorate Degree × inprdsc1 | 2.419 | ||
(1.634) | |||
eduail1Primary School × inprdsc2 | 0.537 | ||
(0.847) | |||
eduail1Junior High School × inprdsc2 | -0.107 | ||
(0.880) | |||
eduail1Secondary School × inprdsc2 | -0.478 | ||
(0.768) | |||
eduail1Post-Secondary School (Non-Tetiary) × inprdsc2 | 0.332 | ||
(0.844) | |||
eduail1Bachelor's Degree × inprdsc2 | -0.718 | ||
(0.857) | |||
eduail1Master's Degree × inprdsc2 | 1.881 | ||
(1.093) | |||
eduail1Doctorate Degree × inprdsc2 | -0.433 | ||
(2.409) | |||
eduail1Primary School × inprdsc3 | 0.639 | ||
(0.830) | |||
eduail1Junior High School × inprdsc3 | -0.046 | ||
(0.864) | |||
eduail1Secondary School × inprdsc3 | -0.057 | ||
(0.745) | |||
eduail1Post-Secondary School (Non-Tetiary) × inprdsc3 | 0.461 | ||
(0.824) | |||
eduail1Bachelor's Degree × inprdsc3 | -0.979 | ||
(0.832) | |||
eduail1Master's Degree × inprdsc3 | 1.857 | ||
(1.070) | |||
eduail1Doctorate Degree × inprdsc3 | 0.000 | ||
(1.722) | |||
eduail1Primary School × inprdsc4-6 | 0.096 | ||
(0.880) | |||
eduail1Junior High School × inprdsc4-6 | -1.188 | ||
(0.943) | |||
eduail1Secondary School × inprdsc4-6 | -0.857 | ||
(0.793) | |||
eduail1Post-Secondary School (Non-Tetiary) × inprdsc4-6 | -0.099 | ||
(0.866) | |||
eduail1Bachelor's Degree × inprdsc4-6 | -1.513 | ||
(0.877) | |||
eduail1Master's Degree × inprdsc4-6 | 1.383 | ||
(1.101) | |||
eduail1Doctorate Degree × inprdsc4-6 | -0.417 | ||
(1.666) | |||
eduail1Primary School × inprdsc7-9 | -1.424 | ||
(2.383) | |||
eduail1Junior High School × inprdsc7-9 | -1.451 | ||
(2.123) | |||
eduail1Secondary School × inprdsc7-9 | -2.424 | ||
(1.988) | |||
eduail1Post-Secondary School (Non-Tetiary) × inprdsc7-9 | -1.345 | ||
(2.051) | |||
eduail1Bachelor's Degree × inprdsc7-9 | -3.487 | ||
(2.034) | |||
eduail1Master's Degree × inprdsc7-9 | -0.850 | ||
(2.175) | |||
eduail1Doctorate Degree × inprdsc7-9 | -2.433 | ||
(2.603) | |||
eduail1Primary School × inprdsc10 or more | 2.192 | ||
(1.251) | |||
eduail1Junior High School × inprdsc10 or more | -1.165 | ||
(1.401) | |||
eduail1Secondary School × inprdsc10 or more | 0.532 | ||
(1.144) | |||
eduail1Post-Secondary School (Non-Tetiary) × inprdsc10 or more | 1.065 | ||
(1.217) | |||
eduail1Bachelor's Degree × inprdsc10 or more | -0.946 | ||
(1.218) | |||
eduail1Master's Degree × inprdsc10 or more | 2.733 | ||
(1.406) | |||
eduail1Doctorate Degree × inprdsc10 or more | 1.400 | ||
(1.964) | |||
Num.Obs. | 3092 | 3092 | 3092 |
R2 | 0.021 | 0.046 | 0.065 |
R2 Adj. | 0.018 | 0.042 | 0.048 |
AIC | 12758.6 | 12688.0 | 12710.5 |
BIC | 12812.9 | 12778.6 | 13054.6 |
Log.Lik. | -6370.290 | -6329.011 | -6298.242 |
RMSE | 1.90 | 1.87 | 1.86 |
modelsummary(
list(model1, model2, model3),
fmt = 1,
estimate = c( "{estimate} ({std.error}){stars}",
"{estimate} ({std.error}){stars}",
"{estimate} ({std.error}){stars}"),
statistic = NULL,
coef_omit = "Intercept")
| (1) | (2) | (3) |
|---|---|---|---|
eduail1Primary School | -0.1 (0.2) | 0.0 (0.2) | -0.6 (0.6) |
eduail1Junior High School | 0.0 (0.2) | 0.0 (0.2) | 0.2 (0.7) |
eduail1Secondary School | 0.4 (0.2)* | 0.4 (0.2)* | 0.5 (0.6) |
eduail1Post-Secondary School (Non-Tetiary) | 0.6 (0.2)** | 0.5 (0.2)* | 0.0 (0.7) |
eduail1Bachelor's Degree | 0.8 (0.2)*** | 0.6 (0.2)** | 1.4 (0.7)* |
eduail1Master's Degree | 0.7 (0.2)** | 0.6 (0.2)** | -1.4 (1.0) |
eduail1Doctorate Degree | 0.9 (0.4)* | 0.8 (0.4)+ | 0.1 (1.5) |
inprdsc1 | 0.8 (0.1)*** | 0.1 (0.7) | |
inprdsc2 | 0.8 (0.1)*** | 0.9 (0.7) | |
inprdsc3 | 1.1 (0.1)*** | 1.1 (0.7) | |
inprdsc4-6 | 1.1 (0.1)*** | 1.7 (0.8)* | |
inprdsc7-9 | 1.3 (0.2)*** | 3.6 (2.0)+ | |
inprdsc10 or more | 1.2 (0.2)*** | 0.6 (1.1) | |
eduail1Primary School × inprdsc1 | 1.1 (0.8) | ||
eduail1Junior High School × inprdsc1 | 0.2 (0.8) | ||
eduail1Secondary School × inprdsc1 | 0.6 (0.7) | ||
eduail1Post-Secondary School (Non-Tetiary) × inprdsc1 | 1.2 (0.8) | ||
eduail1Bachelor's Degree × inprdsc1 | -0.1 (0.8) | ||
eduail1Master's Degree × inprdsc1 | 2.7 (1.1)* | ||
eduail1Doctorate Degree × inprdsc1 | 2.4 (1.6) | ||
eduail1Primary School × inprdsc2 | 0.5 (0.8) | ||
eduail1Junior High School × inprdsc2 | -0.1 (0.9) | ||
eduail1Secondary School × inprdsc2 | -0.5 (0.8) | ||
eduail1Post-Secondary School (Non-Tetiary) × inprdsc2 | 0.3 (0.8) | ||
eduail1Bachelor's Degree × inprdsc2 | -0.7 (0.9) | ||
eduail1Master's Degree × inprdsc2 | 1.9 (1.1)+ | ||
eduail1Doctorate Degree × inprdsc2 | -0.4 (2.4) | ||
eduail1Primary School × inprdsc3 | 0.6 (0.8) | ||
eduail1Junior High School × inprdsc3 | 0.0 (0.9) | ||
eduail1Secondary School × inprdsc3 | -0.1 (0.7) | ||
eduail1Post-Secondary School (Non-Tetiary) × inprdsc3 | 0.5 (0.8) | ||
eduail1Bachelor's Degree × inprdsc3 | -1.0 (0.8) | ||
eduail1Master's Degree × inprdsc3 | 1.9 (1.1)+ | ||
eduail1Doctorate Degree × inprdsc3 | 0.0 (1.7) | ||
eduail1Primary School × inprdsc4-6 | 0.1 (0.9) | ||
eduail1Junior High School × inprdsc4-6 | -1.2 (0.9) | ||
eduail1Secondary School × inprdsc4-6 | -0.9 (0.8) | ||
eduail1Post-Secondary School (Non-Tetiary) × inprdsc4-6 | -0.1 (0.9) | ||
eduail1Bachelor's Degree × inprdsc4-6 | -1.5 (0.9)+ | ||
eduail1Master's Degree × inprdsc4-6 | 1.4 (1.1) | ||
eduail1Doctorate Degree × inprdsc4-6 | -0.4 (1.7) | ||
eduail1Primary School × inprdsc7-9 | -1.4 (2.4) | ||
eduail1Junior High School × inprdsc7-9 | -1.5 (2.1) | ||
eduail1Secondary School × inprdsc7-9 | -2.4 (2.0) | ||
eduail1Post-Secondary School (Non-Tetiary) × inprdsc7-9 | -1.3 (2.1) | ||
eduail1Bachelor's Degree × inprdsc7-9 | -3.5 (2.0)+ | ||
eduail1Master's Degree × inprdsc7-9 | -0.9 (2.2) | ||
eduail1Doctorate Degree × inprdsc7-9 | -2.4 (2.6) | ||
eduail1Primary School × inprdsc10 or more | 2.2 (1.3)+ | ||
eduail1Junior High School × inprdsc10 or more | -1.2 (1.4) | ||
eduail1Secondary School × inprdsc10 or more | 0.5 (1.1) | ||
eduail1Post-Secondary School (Non-Tetiary) × inprdsc10 or more | 1.1 (1.2) | ||
eduail1Bachelor's Degree × inprdsc10 or more | -0.9 (1.2) | ||
eduail1Master's Degree × inprdsc10 or more | 2.7 (1.4)+ | ||
eduail1Doctorate Degree × inprdsc10 or more | 1.4 (2.0) | ||
Num.Obs. | 3092 | 3092 | 3092 |
R2 | 0.021 | 0.046 | 0.065 |
R2 Adj. | 0.018 | 0.042 | 0.048 |
AIC | 12758.6 | 12688.0 | 12710.5 |
BIC | 12812.9 | 12778.6 | 13054.6 |
Log.Lik. | -6370.290 | -6329.011 | -6298.242 |
RMSE | 1.90 | 1.87 | 1.86 |
model21 <- lm(happy ~ hinctnta, data = israel_clean)
model22 <- lm(happy ~ hinctnta + imprich, data = israel_clean)
model23 <- lm(happy ~ hinctnta + imprich + hinctnta*imprich, data = israel_clean)
modelsummary(
list(model21, model22, model23))
| (1) | (2) | (3) |
|---|---|---|---|
(Intercept) | 6.857 | 6.584 | 6.670 |
(0.074) | (0.106) | (0.189) | |
hinctnta | 0.151 | 0.147 | 0.130 |
(0.013) | (0.013) | (0.034) | |
imprich | 0.083 | 0.058 | |
(0.023) | (0.051) | ||
hinctnta × imprich | 0.005 | ||
(0.009) | |||
Num.Obs. | 3092 | 3092 | 3092 |
R2 | 0.042 | 0.046 | 0.046 |
R2 Adj. | 0.041 | 0.045 | 0.045 |
AIC | 12679.6 | 12668.4 | 12670.1 |
BIC | 12697.7 | 12692.6 | 12700.3 |
Log.Lik. | -6336.786 | -6330.214 | -6330.060 |
RMSE | 1.88 | 1.87 | 1.87 |
modelsummary(
list(model21, model22, model23),
fmt = 1,
estimate = c( "{estimate} ({std.error}){stars}",
"{estimate} ({std.error}){stars}",
"{estimate} ({std.error}){stars}"),
statistic = NULL,
coef_omit = "Intercept")
| (1) | (2) | (3) |
|---|---|---|---|
hinctnta | 0.2 (0.0)*** | 0.1 (0.0)*** | 0.1 (0.0)*** |
imprich | 0.1 (0.0)*** | 0.1 (0.1) | |
hinctnta × imprich | 0.0 (0.0) | ||
Num.Obs. | 3092 | 3092 | 3092 |
R2 | 0.042 | 0.046 | 0.046 |
R2 Adj. | 0.041 | 0.045 | 0.045 |
AIC | 12679.6 | 12668.4 | 12670.1 |
BIC | 12697.7 | 12692.6 | 12700.3 |
Log.Lik. | -6336.786 | -6330.214 | -6330.060 |
RMSE | 1.88 | 1.87 | 1.87 |
##Interaction plot arrange
interaction_plot <- effect("hinctnta*imprich", model23, na.rm=TRUE)
plot(interaction_plot,
main="Interaction effect",
xlab="Income level with Importance of being rich",
ylab="Perceived happiness level")
interaction_plot
##
## hinctnta*imprich effect
## imprich
## hinctnta 1 2 4 5 6
## 1 6.863168 6.926153 7.052123 7.115108 7.178093
## 3 7.132830 7.205654 7.351303 7.424128 7.496952
## 6 7.537323 7.624907 7.800074 7.887658 7.975242
## 8 7.806985 7.904408 8.099255 8.196678 8.294101
## 10 8.076647 8.183910 8.398435 8.505698 8.612961
interaction_plot <- effect("eduail1*inprdsc", model3, na.rm=TRUE)
plot(interaction_plot,
main="Interaction effect Education Level x Number of Intimate Friends",
xlab="Education Level",
ylab="Happiness Levels")
# Installing package
remotes::install_github("datalorax/equatiomatic", force = TRUE)
## Downloading GitHub repo datalorax/equatiomatic@HEAD
## xfun (0.40 -> 0.41 ) [CRAN]
## rlang (1.1.1 -> 1.1.2 ) [CRAN]
## cli (3.6.1 -> 3.6.2 ) [CRAN]
## sass (0.4.7 -> 0.4.8 ) [CRAN]
## lifecycle (1.0.3 -> 1.0.4 ) [CRAN]
## jsonlite (1.8.7 -> 1.8.8 ) [CRAN]
## htmltools (0.5.6 -> 0.5.7 ) [CRAN]
## later (1.3.1 -> 1.3.2 ) [CRAN]
## vctrs (0.6.3 -> 0.6.5 ) [CRAN]
## utf8 (1.2.3 -> 1.2.4 ) [CRAN]
## withr (2.5.0 -> 2.5.2 ) [CRAN]
## fansi (1.0.4 -> 1.0.6 ) [CRAN]
## stringi (1.7.12 -> 1.8.3 ) [CRAN]
## cpp11 (0.4.6 -> 0.4.7 ) [CRAN]
## stringr (1.5.0 -> 1.5.1 ) [CRAN]
## dplyr (1.1.3 -> 1.1.4 ) [CRAN]
## yaml (2.3.7 -> 2.3.8 ) [CRAN]
## evaluate (0.21 -> 0.23 ) [CRAN]
## bslib (0.5.1 -> 0.6.1 ) [CRAN]
## httpuv (1.6.11 -> 1.6.13) [CRAN]
## knitr (1.43 -> 1.45 ) [CRAN]
## shiny (1.7.5 -> 1.8.0 ) [CRAN]
## Installing 22 packages: xfun, rlang, cli, sass, lifecycle, jsonlite, htmltools, later, vctrs, utf8, withr, fansi, stringi, cpp11, stringr, dplyr, yaml, evaluate, bslib, httpuv, knitr, shiny
##
## The downloaded binary packages are in
## /var/folders/b5/h52zt6f97kxdhyyj25772_c80000gn/T//RtmpeMAis8/downloaded_packages
## ── R CMD build ─────────────────────────────────────────────────────────────────
##
checking for file ‘/private/var/folders/b5/h52zt6f97kxdhyyj25772_c80000gn/T/RtmpeMAis8/remotes22f2192b86cf/datalorax-equatiomatic-39e8c3e/DESCRIPTION’ ...
✔ checking for file ‘/private/var/folders/b5/h52zt6f97kxdhyyj25772_c80000gn/T/RtmpeMAis8/remotes22f2192b86cf/datalorax-equatiomatic-39e8c3e/DESCRIPTION’
##
─ preparing ‘equatiomatic’:
## checking DESCRIPTION meta-information ...
✔ checking DESCRIPTION meta-information
##
─ checking for LF line-endings in source and make files and shell scripts
##
─ checking for empty or unneeded directories
##
─ building ‘equatiomatic_0.3.1.tar.gz’
##
##
# Getting the equation
equatiomatic::extract_eq(model2, use_coefs = TRUE)
\[ \operatorname{\widehat{happy}} = 6.29 - 0.01(\operatorname{eduail1}_{\operatorname{Primary\ School}}) - 0.01(\operatorname{eduail1}_{\operatorname{Junior\ High\ School}}) + 0.41(\operatorname{eduail1}_{\operatorname{Secondary\ School}}) + 0.53(\operatorname{eduail1}_{\operatorname{Post-Secondary\ School\ (Non-Tetiary)}}) + 0.64(\operatorname{eduail1}_{\operatorname{Bachelor's\ Degree}}) + 0.59(\operatorname{eduail1}_{\operatorname{Master's\ Degree}}) + 0.76(\operatorname{eduail1}_{\operatorname{Doctorate\ Degree}}) + 0.82(\operatorname{inprdsc}_{\operatorname{1}}) + 0.85(\operatorname{inprdsc}_{\operatorname{2}}) + 1.14(\operatorname{inprdsc}_{\operatorname{3}}) + 1.06(\operatorname{inprdsc}_{\operatorname{4-6}}) + 1.35(\operatorname{inprdsc}_{\operatorname{7-9}}) + 1.17(\operatorname{inprdsc}_{\operatorname{10\ or\ more}}) \]