Last active
March 31, 2025 02:27
-
-
Save acbass49/ece233016234665d63b9b3c2d0a4629b to your computer and use it in GitHub Desktop.
BYU More Liberal With FIRE Data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # load packages | |
| library(tidyverse) | |
| library(sjlabelled) | |
| library(clipr) | |
| data <- read.csv("./data/fire/fire.csv") | |
| labels <- read.csv("./data/fire/labels.csv") | |
| # checking labels | |
| labels |> | |
| filter(Variable == "religion") | |
| # create variables for analysis | |
| data$party <- factor(case_when( | |
| data$partyid %in% c(1,2,3) ~ "Dem", | |
| data$partyid %in% c(4) ~ "Ind", | |
| data$partyid %in% c(5,6,7) ~ "Rep", | |
| data$partyid %in% c(8) ~ "Other", | |
| ), levels = c("Rep", "Ind", "Dem", "Other")) | |
| data$BYU <- as.integer(data$school == "Brigham Young University-Provo") | |
| data$is_anxious <- as.integer(data$anxious %in% c(3,4,5)) | |
| data$is_lonely <- as.integer(data$lonely %in% c(3,4,5)) | |
| data$no_time_self <- as.integer(data$notime %in% c(3,4,5)) | |
| data$is_depressed <- as.integer(data$depressed %in% c(3,4,5)) | |
| data$is_stressed <- as.integer(data$stressed %in% c(3,4,5)) | |
| recodes <- c( | |
| '1' = 'business', #Accounting | |
| '2' = 'social sciences', #African/Afr-American Studies | |
| '3' = 'natural sciences', #Agricultural/Food Sciences | |
| '4' = 'natural sciences',#Animal Science | |
| '5' = 'social sciences',#Anthropology | |
| '6' = 'natural sciences',#Archaeology | |
| '7' = 'engineering',#Architecture | |
| '8' = 'humanities/arts',#Art History | |
| '9' = 'humanities/arts',#Asian/Mideast Lang & Lit | |
| '10' = 'humanities/arts',#Asian/Mideast Studies | |
| '11' = 'natural sciences',#Physics and Astronomy | |
| '12' = 'natural sciences',#Biochemistry and Molecular Biology | |
| '13' = 'natural sciences',#Biological Sciences | |
| '14' = 'business',#business | |
| '15' = 'natural sciences',#Chemistry | |
| '16' = 'humanities/arts',#classics | |
| '17' = 'social sciences',#Cognitive Science | |
| '18' = 'humanities/arts',#Communication | |
| '19' = 'engineering',#Computer Science | |
| '20' = 'humanities/arts',#Dance | |
| '21' = 'engineering',#Data Science | |
| '22' = 'social sciences',#Development Studies | |
| '23' = 'business',#Digital Media Design | |
| '24' = 'natural sciences',#Earth Sciences | |
| '25' = 'social sciences',#Economics | |
| '26' = 'teaching',#Education | |
| '27' = 'engineering',#Education | |
| '28' = 'humanities/arts',#English | |
| '29' = 'natural sciences',#Environmental Studies | |
| '30' = 'social sciences',#Ethnicity and Race Studies | |
| '31' = 'humanities/arts',#European Cultural Studies | |
| '32' = 'humanities/arts',#Fashion | |
| '33' = 'humanities/arts',#Film and Media Studies | |
| '34' = 'business',#Finance | |
| '35' = 'humanities/arts',#Fine Arts | |
| '36' = 'humanities/arts',#French and Italian | |
| '37' = 'natural sciences',#Geography | |
| '38' = 'humanities/arts',#German Studies | |
| '39' = 'humanities/arts',#History | |
| '40' = 'business',#Hotel Administration | |
| '41' = 'social sciences',#International Relations | |
| '42' = 'humanities/arts',#Jewish Studies | |
| '43' = 'humanities/arts',#Lat Am/Latino/Carib Studies | |
| '44' = 'social sciences',#Law/Criminology | |
| '45' = 'humanities/arts',#Linguistics | |
| '46' = 'business',#Marketing | |
| '47' = 'engineering',#Mathematics | |
| '48' = 'humanities/arts',#Music | |
| '50' = 'natural sciences',#Neuroscience | |
| '51' = 'natural sciences',#Nursing | |
| '52' = 'humanities/arts',#Philosophy | |
| '53' = 'teaching',#Physical Education | |
| '54' = 'social sciences',#Political Science | |
| '55' = 'humanities/arts',#Portuguese and Brazilian Studies | |
| '56' = 'natural sciences',#Pre-Medical | |
| '57' = 'natural sciences',#Psychological and Brain Sciences | |
| '58' = 'natural sciences',#Public Health | |
| '59' = 'social sciences',#Public Policy | |
| '61' = 'business',#Real Estate | |
| '62' = 'humanities/arts',#Religion | |
| '63' = 'engineering',#Robotics and Intelligent Systems | |
| '65' = 'social sciences',#Sociology | |
| '66' = 'humanities/arts',#Spanish and Portuguese | |
| '67' = 'natural sciences',#Statistics | |
| '68' = 'humanities/arts',#SStudio Art | |
| '69' = 'humanities/arts',#Theater | |
| '70' = 'other',#Undecided | |
| '71' = 'social sciences',#Urban Studies | |
| '72' = 'humanities/arts',#Visual Arts | |
| '73' = 'social sciences',#Women's and Gender Studies (and Sexuality) | |
| '74' = 'other'#other | |
| ) | |
| data$major_type <- as.character(recodes[data$major1]) | |
| data$religattend_rc <- car::recode(data$religattend, '8:9=1;else=0') | |
| data$gender_rc <- factor(car::recode(data$gender, '1="male";2="female";3:6="other";-99=NA'), | |
| levels = c('male', 'female', 'other')) | |
| data$grad_level <- factor(car::recode( | |
| data$gradyear, | |
| "2024='Senior';2025='Junior';2026='Sophomore';2027='Freshman'"), | |
| levels = c('Freshman', 'Sophomore', 'Junior', 'Senior')) | |
| data$grad_level2 <- factor(car::recode( | |
| data$gradyear, | |
| "2024='Junior/Senior';2025='Junior/Senior';2026='Freshman/Sophomore';2027='Freshman/Sophomore'"), | |
| levels = c('Freshman/Sophomore', 'Junior/Senior')) | |
| # Summarizing data for post | |
| ## Is BYU one of the most conservative universities? | |
| data |> | |
| filter(school == "Brigham Young University-Provo") |> | |
| nrow() | |
| data |> | |
| group_by(school) |> | |
| count(party, wt=schoolweight) |> | |
| drop_na() |> | |
| mutate(prop = n / sum(n)) |> | |
| pivot_wider(id_cols = school,names_from = party, values_from = prop) |> | |
| arrange(desc(Rep)) |> | |
| head(10) |> | |
| write_clip() | |
| # Do students become more democrats over time in college? | |
| data |> | |
| group_by(grad_level) |> | |
| count(party, wt=weight) |> | |
| drop_na() |> | |
| mutate(prop = n / sum(n)) |> | |
| pivot_wider(id_cols = grad_level,names_from = party, values_from = prop) |> | |
| write_clip() | |
| # In other universities, they go from independents and others to democrats | |
| # Do BYU students become more democrats over time? | |
| data |> | |
| filter(BYU == 1) |> | |
| group_by(grad_level) |> | |
| count(party, wt=schoolweight) |> | |
| drop_na() |> | |
| mutate(prop = n / sum(n)) |> | |
| pivot_wider(id_cols = grad_level,names_from = party, values_from = prop) |> | |
| write_clip() | |
| # In BYU, they go from Republican to independents and democrats | |
| # Now let's look by major type overall | |
| # its too sparse so need to collapse major type again | |
| data$major_type2 <- as.character(recode_factor(data$major_type, | |
| 'business' = 'business/engineering/natural sciences', | |
| 'social sciences' = 'social sciences/humanities/arts/teaching/other', | |
| 'natural sciences' = 'business/engineering/natural sciences', | |
| 'engineering' = 'business/engineering/natural sciences', | |
| 'humanities/arts' = 'social sciences/humanities/arts/teaching/other', | |
| 'teaching' = 'social sciences/humanities/arts/teaching/other', | |
| 'other' = 'social sciences/humanities/arts/teaching/other' | |
| )) | |
| # Now let's look by major type overall | |
| data |> | |
| group_by(major_type2, grad_level2) |> | |
| count(party, wt=weight) |> | |
| drop_na() |> | |
| mutate(prop = n / sum(n)) |> | |
| pivot_wider(id_cols = c(grad_level2,major_type2),names_from = party, values_from = prop) |> | |
| write_clip() | |
| data |> | |
| filter(BYU == 1) |> | |
| group_by(major_type2, grad_level2) |> | |
| count(party, wt=schoolweight) |> | |
| drop_na() |> | |
| mutate(prop = n / sum(n)) |> | |
| pivot_wider(id_cols = c(grad_level2,major_type2),names_from = party, values_from = prop) |> | |
| write_clip() | |
| ## Lets look at breaks by gender | |
| data |> | |
| group_by(gender_rc, grad_level2) |> | |
| count(party, wt=weight) |> | |
| drop_na() |> | |
| mutate(prop = n / sum(n)) |> | |
| pivot_wider(id_cols = c(grad_level2,gender_rc),names_from = party, values_from = prop) |> | |
| filter(gender_rc != "other") | |
| data |> | |
| filter(BYU == 1) |> | |
| group_by(gender_rc, grad_level2) |> | |
| count(party, wt = schoolweight) |> | |
| drop_na() |> | |
| mutate(prop = n / sum(n)) |> | |
| pivot_wider(id_cols = c(grad_level2,gender_rc),names_from = party, values_from = prop) |> | |
| filter(gender_rc != "other") |> | |
| write_clip() | |
| ## by gender and major | |
| data |> | |
| filter(BYU == 1) |> | |
| group_by(gender_rc, grad_level2, major_type2) |> | |
| count(party, wt = schoolweight) |> | |
| drop_na() |> | |
| mutate(prop = n / sum(n)) |> | |
| pivot_wider(id_cols = c(grad_level2,gender_rc,major_type2),names_from = party, values_from = prop) |> | |
| filter(gender_rc != "other") |> | |
| arrange(gender_rc, major_type2) | |
| data |> | |
| filter(BYU == 1) |> | |
| group_by(gender_rc, grad_level2, major_type2) |> | |
| count(party, wt = schoolweight) |> | |
| drop_na() |> | |
| mutate(prop = n / sum(n)) |> | |
| pivot_wider(id_cols = c(grad_level2,gender_rc,major_type2),names_from = party, values_from = prop) |> | |
| filter(gender_rc != "other") |> | |
| arrange(gender_rc, major_type2) |> | |
| mutate(dem_ind = Dem + Ind) |> | |
| select(dem_ind) |> | |
| pivot_wider(names_from = grad_level2, values_from = dem_ind) |> | |
| mutate(diff = `Junior/Senior` - `Freshman/Sophomore`) | |
| # Getting a breakdown of Males + Females | |
| data |> | |
| filter(BYU == 1) |> | |
| group_by(gender_rc) |> | |
| count(major_type2, wt = schoolweight) |> | |
| drop_na() |> | |
| mutate(prop = n / sum(n)) |> | |
| select(-n) |> | |
| pivot_wider(names_from = major_type2, values_from = prop) | |
| # Just curious about a breakdown of majors by gender | |
| # Lets do some statistical tests! | |
| # First, lets look at the proportion identifying as repulican over the years at BYU | |
| data |> | |
| filter(BYU == 1) |> | |
| group_by(grad_level) |> | |
| count(party, wt = schoolweight) |> | |
| drop_na() |> | |
| mutate(prop = n / sum(n)) | |
| freshman <- c(42.2, 15.36) | |
| senior <- c(77.5, 58.5) | |
| contingency_table <- matrix(c(freshman, senior), nrow=2, byrow = TRUE) | |
| colnames(contingency_table) <- c("Republican", "Independent/Democrat") | |
| rownames(contingency_table) <- c("Freshman", "Senior") | |
| print(contingency_table) | |
| chi_result <- chisq.test(contingency_table) | |
| print(chi_result) | |
| # There is a statistically significant difference in the proportion of students identifying as Independnet/Democrat between Freshman and Seniors | |
| # Now lets look at majors | |
| data |> | |
| filter(BYU == 1) |> | |
| group_by(major_type2, grad_level2) |> | |
| count(party, wt=schoolweight) |> | |
| drop_na() |> | |
| mutate(prop = n / sum(n)) |> | |
| pivot_wider(id_cols = c(grad_level2,major_type2),names_from = party, values_from = n) | |
| # business/engineering/natural sciences majors | |
| freshman <- c(62.5, 30.1) | |
| senior <- c(104, 69.4) | |
| contingency_table <- matrix(c(freshman, senior), nrow=2, byrow = TRUE) | |
| colnames(contingency_table) <- c("Republican", "Independent/Democrat") | |
| rownames(contingency_table) <- c("Freshman/Soph", "Junior/Senior") | |
| print(contingency_table) | |
| chi_result <- chisq.test(contingency_table) | |
| print(chi_result) | |
| # social sciences/humanities/arts/teaching/other majors | |
| freshman <- c(40, 25.41) | |
| senior <- c(46.7, 54.2) | |
| contingency_table <- matrix(c(freshman, senior), nrow=2, byrow = TRUE) | |
| colnames(contingency_table) <- c("Republican", "Independent/Democrat") | |
| rownames(contingency_table) <- c("Freshman/Soph", "Junior/Senior") | |
| print(contingency_table) | |
| chi_result <- chisq.test(contingency_table) | |
| print(chi_result) | |
| # Now lets look at the 3 way interaction | |
| data |> | |
| filter(BYU == 1) |> | |
| group_by(gender_rc, grad_level2, major_type2) |> | |
| count(party, wt = schoolweight) |> | |
| drop_na() |> | |
| mutate(prop = n / sum(n)) |> | |
| pivot_wider(id_cols = c(grad_level2,gender_rc,major_type2),names_from = party, values_from = n) |> | |
| filter(gender_rc != "other") |> | |
| arrange(gender_rc, major_type2) |> | |
| mutate(dem_ind = Dem + Ind) | |
| # MALE: business/engineering/natural sciences majors | |
| freshman <- c(37.5, 18.1) | |
| senior <- c(76.1, 21.2) | |
| contingency_table <- matrix(c(freshman, senior), nrow=2, byrow = TRUE) | |
| colnames(contingency_table) <- c("Republican", "Independent/Democrat") | |
| rownames(contingency_table) <- c("Freshman/Soph", "Junior/Senior") | |
| print(contingency_table) | |
| chi_result <- chisq.test(contingency_table) | |
| print(chi_result) | |
| # MALE: social sciences/humanities/arts/teaching/other majors | |
| freshman <- c(19.3, 3.7) | |
| senior <- c(16.5, 14.2) | |
| contingency_table <- matrix(c(freshman, senior), nrow=2, byrow = TRUE) | |
| colnames(contingency_table) <- c("Republican", "Independent/Democrat") | |
| rownames(contingency_table) <- c("Freshman/Soph", "Junior/Senior") | |
| print(contingency_table) | |
| chi_result <- chisq.test(contingency_table) | |
| print(chi_result) | |
| # fEMALE: business/engineering/natural sciences majors | |
| freshman <- c(25, 11.9) | |
| senior <- c(27.7, 32.1) | |
| contingency_table <- matrix(c(freshman, senior), nrow=2, byrow = TRUE) | |
| colnames(contingency_table) <- c("Republican", "Independent/Democrat") | |
| rownames(contingency_table) <- c("Freshman/Soph", "Junior/Senior") | |
| print(contingency_table) | |
| chi_result <- chisq.test(contingency_table) | |
| print(chi_result) | |
| # fEMALE: social sciences/humanities/arts/teaching/other majors | |
| freshman <- c(20.7, 21.7) | |
| senior <- c(30.1, 36) | |
| contingency_table <- matrix(c(freshman, senior), nrow=2, byrow = TRUE) | |
| colnames(contingency_table) <- c("Republican", "Independent/Democrat") | |
| rownames(contingency_table) <- c("Freshman/Soph", "Junior/Senior") | |
| print(contingency_table) | |
| chi_result <- chisq.test(contingency_table) | |
| print(chi_result) | |
| # gist: https://gist.github.com/acbass49/ece233016234665d63b9b3c2d0a4629b | |
| # Do non mormon byu students become more democrats over time? | |
| data |> | |
| filter(BYU == 1) |> | |
| filter(religion != 3) |> | |
| group_by(grad_level2) |> | |
| count(party) |> | |
| drop_na() |> | |
| mutate(prop = n / sum(n)) |> | |
| pivot_wider(id_cols = c(grad_level2),names_from = party, values_from = prop) | |
| data |> | |
| filter(BYU == 1) |> | |
| filter(religion != 3) |> | |
| nrow() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment