Skip to content

Instantly share code, notes, and snippets.

View acbass49's full-sized avatar

alex acbass49

  • Data Science Contractor
  • Salt Lake City, UT
View GitHub Profile
@acbass49
acbass49 / 11_mormon_2024_2026_vote_flow.R
Created November 7, 2026 01:02
Mormon CHEP vote charts: 2024-vs-2026 vote flow, demographic margin shifts, and House-voter party ID (Mormon vs U.S.)
#!/usr/bin/env Rscript
# Mormon CHEP vote charts (two charts, one script).
# Chart 1: 2024 presidential v 2026 House vote flow (alluvial/Sankey-style).
# Replicates the NORC-style "Presidential election 2024 v House election
# 2026, vote share" chart for Mormons.
# Chart 2: demographic breakdown of the change in vote margin 2024 -> 2026.
# Replicates the NORC-style "Demographic breakdown / Change in House vote
# margin" chart for Mormons. Tall (non-square) output.
#
# Sample (both charts): LDS LIKELY voters, weighted by CHEP_WEIGHT.
@acbass49
acbass49 / 50_midterm_blue_wave.R
Last active November 6, 2026 03:08
Mormon Metrics Post 50: Did the midterm blue wave reach Latter-day Saints? (LDS districts, 2026 results, CHEP party/approval/House vote)
# Post 50 — Did the midterm blue wave reach Latter-day Saints?
# Single-file merge of the two election posts (old 50: LDS districts +
# 2026 results; old 51: CHEP party/approval/House-vote by religion).
# Only the 9 charts in the published analysis are generated:
# 50_midterm_1 UT House districts: expected share vs 2026 partial + swing
# 50_midterm_2 western hex cartogram, top-20 LDS districts labeled
# 50_midterm_3 western zoom map, top-20 LDS districts labeled
# 50_midterm_4 top-20 LDS districts expected-vs-actual table
# 50_midterm_5 UT 20 most LDS counties: Trump 2024 vs House 2026
# 50_midterm_6 ID 20 most LDS counties: Trump 2024 vs House 2026
@acbass49
acbass49 / 49_physically_in_mentally_out.R
Last active November 3, 2026 08:01
Post 49: Physically In, Mentally Out (PIMO) Mormons — pooled Pew Religious Landscape Study 2007 & 2014 crosstabs and charts
# Title: Physically In, Mentally Out (PIMO) Mormons — Pooled Pew RLS Crosstabs
# Description: Pools Pew Religious Landscape Study 2007 and 2014 (no over-time
# comparisons; 2023-24 excluded because it did not ask a one-true-church
# question — verified in data/rls/codebook2024.xlsx and the official
# 2023-24 RLS topline). Defines PIMOs among current Latter-day Saints as
# weekly+ attenders who do not affirm the one-true-church claim
# (One_True in 2:3 = "Many religions can lead to eternal life" or
# "Neither/Both equally"; Don't know excluded). Homosexuality acceptance
# and Right_and_Wrong are NOT part of the definition; they are profiled
# as crosstab rows. Compares five columns — LDS overall, Active (non-PIMO),
@acbass49
acbass49 / 48_lds_converts_vs_leavers_ratio.R
Created October 27, 2026 05:00
Post 48: Latter-day Saint leavers per 1 joiner, by religion (GSS, Pew RLS 2007-2024, GFS) - Mormon Metrics
# Title: Latter-day Saint Converts vs. Leavers — The Out/In Exchange Ratio (GSS, Pew RLS, & GFS)
# Post Number: 48
# Author: Mormon Metrics
# Output Images:
# 1. images/48_lds_exchange_ratio_heatmap_1.png
# 2. images/48_lds_exchange_ratio_overall_2.png
#
# Question: Post 47 (Fig. 2) showed where former Latter-day Saints land.
# This post gives every religion its own base: for each religion, how many
# leavers does it have for every 1 joiner? Leavers were raised in the row
@acbass49
acbass49 / 47_predicting_lds_leavers_gfs.R
Last active October 15, 2026 23:57
Predicting Latter-day Saint Disaffiliation & Destination Traditions (GFS, GSS, & Pew RLS)
# Title: Predicting Latter-day Saint Disaffiliation & Destination Traditions (GFS, GSS, & Pew RLS)
# Post Number: 47
# Author: Mormon Metrics
# Output Images:
# 1. images/47_predicting_lds_leavers_forest_plot_1.png
# 2. images/47_predicting_lds_leavers_landing_table_2.png
library(haven)
library(tidyverse)
library(showtext)
@acbass49
acbass49 / 46_gfs_religious_inflow_outflow.R
Created October 6, 2026 21:02
Mormon Metrics Post 46: Religious in-flow, out-flow, and retention across traditions (GFS 2022–2024 panel)
# Title: Religious In-Flow, Out-Flow, and Retention in the United States (Global Flourishing Study)
# Post Number: 46
# Author: Mormon Metrics
# Output Images:
# 1. images/46_gfs_inflow_outflow_table_1.png
# 2. images/46_gfs_retention_ranking_2.png
# 3. images/46_gfs_lds_outflow_destinations_3.png
# 4. images/46_gfs_lds_inflow_origins_4.png
# 5. images/46_gfs_inflow_outflow_broad_5.png
@acbass49
acbass49 / 44_lds_scouting_exit_did.R
Last active October 1, 2026 21:45
Mormon Metrics: LDS Scouting Exit & Mountain West Outdoor Economy
# ==============================================================================
# 44_lds_scouting_exit_did.R
# Comprehensive Econometric Study: Causal Impact of the LDS Scouting Exit (2005–2024)
# 1. 19-Year Western Counties Panel DiD & Event Studies (2005–2023)
# 2. Utah Regional Trends & Category Comparisons (2012–2023)
# 3. Western Counties Panel Event Studies & Storefront DiD (2012–2023)
# 4. Macroeconomic BEA Outdoor Recreation Activity Accounts (BEA ORSA 2012–2024)
# Mormon Metrics
# ==============================================================================
@acbass49
acbass49 / 45_idaho_abortion_attitudes.R
Last active September 25, 2026 03:11
Idaho & Nevada abortion attitudes & LDS demographics (CES 2018–2025)
# Title: Idaho & Nevada Abortion Attitudes & Latter-day Saint Demographics (CES 2018–2025)
# Post Number: 45
# Author: Mormon Metrics
# Output Images:
# 1. images/45_idaho_registered_voter_religion_1.png
# 2. images/45_idaho_abortion_support_calc_2.png
# 3. images/45_nevada_registered_voter_religion_3.png
# 4. images/45_nevada_abortion_support_calc_4.png
# 5. images/45_idaho_abortion_scenarios_5.png
# 6. images/45_nevada_abortion_scenarios_6.png
@acbass49
acbass49 / 43_devotion_and_fertility_heatmaps.R
Created September 20, 2026 19:23
Mormon Metrics Post 43: Devotion and Completed Fertility (CES & Pew RLS)
# Mormon Metrics — Post 43
# Title: Devotion Metric and Total Fertility Heatmaps
# Description: Visualizing the joint distribution of religious devotion and completed fertility
# comparing the Cooperative Election Study (CES 2020) and the Pew Religious Landscape
# Study (2014 & 2024 combined) among Latter-day Saints aged 40 and older.
# - CES: Devout metric coded as 0 and 1
# - Pew RLS: Devotion index divided in half (median split) among LDS.
library(tidyverse)
library(haven)
@acbass49
acbass49 / 42_religious_index_over_time.R
Last active September 17, 2026 05:23
Post 42: Religious Behavior Index Across Faiths (2007–2024)
# Title: Religious Behavior Index Over Time (2007–2024)
# Description: Harmonizing Pew Religious Landscape Study data across 2007, 2014, and 2024
# to track longitudinal trends in religious behavior across religious traditions,
# building on Ryan Burge's 2024 Religious Behavior Index.
# Excludes religiously unaffiliated across all charts.
library(tidyverse)
library(haven)
library(scales)
library(ggtext)