###
# Project: QMSS 201 Final Project
# Purpose: Final Project
# Author: Leah Adams
# Date: April 6 2025
# Data: W25 50 State Data Set
###

states_data25 <- read.csv("Copy of W25 50 State Data Set.csv", header=TRUE)

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.1     ✔ tibble    3.2.1
## ✔ lubridate 1.9.4     ✔ tidyr     1.3.1
## ✔ purrr     1.0.4     
## ── 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
library(dplyr)
renamed_states_data25 <- states_data25 %>% 
  rename("Religiosity" = X..who.attend.religious.services.at.least.once.a.week)%>% 
  rename("PoliticalIdeology" = Percent.Trump.2024)%>% 
  rename("HealthcareAccess" = X..without.health.insurance.2023)%>% 
  rename("RestrictivenessScore" = guttmacher.abortion.restrictiveness.score..Feb.2025)%>% 
  rename("Education" = X..25.and.older.w.4.year.college.degree.or.higher.2021)

class(renamed_states_data25$Religiosity)
## [1] "integer"
class(renamed_states_data25$PoliticalIdeology)
## [1] "numeric"
class(renamed_states_data25$HealthcareAccess)
## [1] "numeric"
class(renamed_states_data25$Education)
## [1] "numeric"
class(renamed_states_data25$RestrictivenessScore)
## [1] "integer"
lm1 <- lm(RestrictivenessScore ~ Religiosity + PoliticalIdeology + HealthcareAccess + Education, data=renamed_states_data25)

summary(lm1)
## 
## Call:
## lm(formula = RestrictivenessScore ~ Religiosity + PoliticalIdeology + 
##     HealthcareAccess + Education, data = renamed_states_data25)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.20004 -0.72779  0.04308  0.77295  2.11383 
## 
## Coefficients:
##                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)       -3.74951    2.83353  -1.323 0.192433    
## Religiosity        0.06296    0.03024   2.082 0.043025 *  
## PoliticalIdeology  0.12221    0.02959   4.130 0.000155 ***
## HealthcareAccess   0.05076    0.07934   0.640 0.525591    
## Education         -0.02327    0.04505  -0.517 0.607982    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.159 on 45 degrees of freedom
##   (3 observations deleted due to missingness)
## Multiple R-squared:  0.7207, Adjusted R-squared:  0.6959 
## F-statistic: 29.03 on 4 and 45 DF,  p-value: 5.907e-12