── 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
Code
Group7 <-read_csv("Desktop/Group7.csv")
Rows: 996 Columns: 28
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (28): gender, age, ethnic_1, ethnic_2, ethnic_3, ethnic_4, ethnic_5, eth...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Code
Group7 <- Group7 %>%filter(ideo !=8)
Code chunk for standardizing our religiosity variables and creating our religiosity index:
Code chunk for our regression model, in which we predicted happiness levels based on political orientation, religiosity, age, sex, educational level, and the interaction between political orientation and religiosity.
Code
#writing the code for our regression model#first, we ensure r views all of our variables as numeric for the sake of the regression outputGroup7$ideo <-as.numeric(as.character(Group7$ideo)) Group7$religiosity <-as.numeric(as.character(Group7$religiosity))Group7$age <-as.numeric(Group7$age) Group7$educ <-as.numeric(as.character(Group7$educ))#regression coderegressionmodel =lm(formula = happy ~ ideo + religiosity + age + gender + educ + ideo:religiosity, data=Group7)summary(regressionmodel)
Call:
lm(formula = happy ~ ideo + religiosity + age + gender + educ +
ideo:religiosity, data = Group7)
Residuals:
Min 1Q Median 3Q Max
-4.1579 -0.9683 0.3935 1.1730 2.6549
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 4.06826 0.43039 9.452 < 2e-16 ***
ideo -0.05849 0.05150 -1.136 0.25696
religiosity 0.61809 0.31555 1.959 0.05107 .
age 0.11031 0.05573 1.979 0.04869 *
gender -0.01539 0.15841 -0.097 0.92265
educ 0.14587 0.05113 2.853 0.00464 **
ideo:religiosity -0.01232 0.07290 -0.169 0.86587
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 1.578 on 297 degrees of freedom
(608 observations deleted due to missingness)
Multiple R-squared: 0.09275, Adjusted R-squared: 0.07442
F-statistic: 5.06 on 6 and 297 DF, p-value: 5.823e-05
Code
#some code for making our regression results more well-formatted (showing intercepts and p-values in parentheses)options(repos =c(CRAN ="https://cloud.r-project.org/"))install.packages("modelsummary")
Installing package into '/Users/claireheyne/Library/R/arm64/4.3/library'
(as 'lib' is unspecified)
The downloaded binary packages are in
/var/folders/4v/p0llgt5n3_l5x55x1g2swx_h0000gn/T//RtmpkErFkS/downloaded_packages
Code
library(modelsummary)
Warning: package 'modelsummary' was built under R version 4.3.3
Code
modelsummary(list("Regression Results"= regressionmodel),output ="kableExtra", # Can also use "gt", "html", "latex"stars =TRUE, statistic ="p.value",title ="Linear Regression Results")
Linear Regression Results
Regression Results
(Intercept)
4.068***
(<0.001)
ideo
−0.058
(0.257)
religiosity
0.618+
(0.051)
age
0.110*
(0.049)
gender
−0.015
(0.923)
educ
0.146**
(0.005)
ideo × religiosity
−0.012
(0.866)
Num.Obs.
304
R2
0.093
R2 Adj.
0.074
AIC
1148.8
BIC
1178.6
Log.Lik.
−566.410
RMSE
1.56
+ p < 0.1, * p < 0.05, ** p < 0.01, *** p < 0.001
So, to summarize, we found that religiosity, age, and education were significant predictors of happiness, such that higher levels of religiosity predict higher levels of happiness, greater age predicts higher levels of happiness, and higher educational levels predict higher happiness.
Our finding about religiosity is consistent with Bixter’s findings. However, contrary to what Bixter found, neither political orientation nor the interaction between political orientation and religiosity significantly predicted happiness in our model. In Bixter’s study, being more conservative was associated with greater happiness, and it was found that religiosity has a greater effect on happiness for more conservative individuals compared to those who are more politically liberal.
Our adjusted r-squared value of 0.074 indicates that this only 7.4% of the variance in happiness levels is explained by the variance in political orientation, religiosity, age, sex, educational level, and the interaction between political orientation and religiosity. This is actually slightly better than the R-squared values obtained by Bixter (0.04 and 0.02!).
Code chunk for a data visualization of mean happiness of different political orientations by religiosity level
Code
#data visualization for mean happiness of different political orientations by religiosity level#first, let's make political orientation a categorical variableGroup7 <- Group7 %>%mutate(political_orientation_categorical =case_when( ideo %in%c(1, 2) ~"Liberal", ideo %in%c(3, 4, 5) ~"Moderate", ideo %in%c(6, 7) ~"Conservative",TRUE~NA_character_ ))#and we will do the same for religiosityGroup7$religiosity <-as.numeric(as.character(Group7$religiosity))#let's determine the 33rd and 67th percentiles so we can split the data into low, moderate, and high religiosityquantile(Group7$religiosity, probs =c(0.33, 0.67), na.rm =TRUE)
So, to summarize what we can see in the visual (this does NOT mean these observations are statistically significant!), being more religious is associated with greater levels of happiness, regardless of political orientation. Generally, liberals tend to be happier than conservatives, who tend to be happier than moderates. Highly religious liberals are the happiest group, although the low religiosity conservatives and liberals demonstrate a very similar level of mean happiness.