Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test PR refactor branch #9

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
9bd8987
remove old stuff from build file
mikedecr Aug 6, 2019
31d38b3
not benefitting from {ggplot} if it's loaded in a diff file
mikedecr Aug 6, 2019
c74e499
comment out {extrafont}
mikedecr Aug 6, 2019
0e01c4a
pkg::fun in build file
mikedecr Aug 6, 2019
e84dac4
graphics theme uses Fira Sans
mikedecr Aug 6, 2019
6feca19
cleaner stan interfacing, file paths to MCMC objects
mikedecr Aug 6, 2019
2f91956
change preamble for race Rmd
mikedecr Aug 6, 2019
d0ec011
ignore(.dot output files, MCMC files, new figs/cache dirs)
mikedecr Aug 6, 2019
9eb23e3
fix fonts in .tex, graphics
mikedecr Aug 6, 2019
9ed862f
delete bootstrap notes
mikedecr Aug 6, 2019
fe04ca7
Fira heading/title fonts
mikedecr Aug 7, 2019
15f127c
did anything *really* change?
mikedecr Aug 7, 2019
79000a8
consolidate notes
mikedecr Aug 7, 2019
86e85a7
rename rproj
mikedecr Apr 3, 2022
59bb466
begin renv
mikedecr Apr 3, 2022
763e4d6
title changes
mikedecr Aug 7, 2019
d10ef8a
more text from R/ANES data
mikedecr Aug 7, 2019
c5475c2
author thanks, git info in footer
mikedecr Aug 7, 2019
2c12b93
read ANES data from remote! Ignore local files
mikedecr Aug 8, 2019
490ad2c
ugh todonotes line type
mikedecr Aug 8, 2019
8218c5d
times body font
mikedecr Aug 13, 2019
daab908
rework introduction
mikedecr Aug 13, 2019
a7164ff
dot options: Times font, fig path
mikedecr Aug 13, 2019
65db779
tiny admin stuff
mikedecr Aug 13, 2019
cf82ead
rdata dump filepaths
mikedecr Aug 13, 2019
a0616eb
update gray colors for ggtheme, data_frame is deprecated
mikedecr Aug 13, 2019
fd66c59
use tidybayes, create "DV Crosswalk" file for MCMC
mikedecr Aug 13, 2019
9bc575f
tiny changes
mikedecr Jan 21, 2020
e6f3d3d
modular script: clean ANES
mikedecr Apr 3, 2022
ce75c43
modular script: clean exits
mikedecr Apr 3, 2022
349341a
initialize qmd
mikedecr Jul 13, 2022
0c8f2f7
qmd style metadata
mikedecr Jul 13, 2022
3cc1e30
box path variable & unit test
mikedecr Jul 30, 2022
9231ff5
script: aggregate & export cycle-level data (ANES) for regressions
mikedecr Jul 31, 2022
e137799
confint helpers
mikedecr Aug 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .Rprofile
@@ -0,0 +1,4 @@
source("renv/activate.R")

options(box.path = "code")

7 changes: 7 additions & 0 deletions .gitignore
Expand Up @@ -75,3 +75,10 @@ data/clean
data/rmd-rdata
data/ANES-2016/docs/anes_timeseries_cdf_codebook_pdf
anes_timeseries_cdf.dta
data/mcmc
data/mcmc-params
writing-rmd/assets/dot-img
writing-rmd/paper-cache
writing-rmd/paper-figs
anes-cdf-2016.RDS
gender-gap-new.log
File renamed without changes.
240 changes: 0 additions & 240 deletions Gender gap notes.mdown

This file was deleted.

7 changes: 3 additions & 4 deletions README.md
Expand Up @@ -10,11 +10,10 @@ author: |
Groups in the electorate vote differently from one another. Racial minorities and young voters prefer Democratic candidates on average, while evangelicals and rural voters prefer Republican candidates. How do these group differences affect party vote shares, given that the underlying groups are differently sized? We provide a theoretical framework to understand group differences in voting and party vote by expressing each as the result of partisan predispositions in the electorate that are transformed through partisan mobilization, partisan defection, and the choices of unaffiliated voters. We apply this method to the gender gap in U.S. presidential voting. We find that the size of the gender gap has no necessary bearing on the partisan vote outcome. Rather, the relationship is contingent on the changing numerical impact of partisanship, partisan mobilization, and persuasion over time. Although the gender gap and the Democratic vote in presidential elections have both increased over the years, this relationship is spurious. The primary cause of the gender gap (partisan change) was actually harmful to the Democrats. Meanwhile, forces that increased the Democratic vote (mobilization and persuasion) were minor influences on the gender gap.


# To do notes
# Repo to-do notes

- [ ] fix Bitbucket link for website
- [ ] when next major version is done, change website link to Github
- [ ] Do something about raw ANES data (LFS? Download from remote if file not present?)
- don't forget to merge feature -> dev
- check w/ Barry dev -> master



Expand Down
20 changes: 4 additions & 16 deletions code/R/00-build.R
Expand Up @@ -3,30 +3,18 @@
# R master file: controls replication of all R things
# ----------------------------------------------------


# --- build it -----------------------

source(here::here("code", "R", "01-setup.R"), echo = TRUE)

source(here("code", "R", "02-recode-anes.R"), echo = TRUE)
source(here::here("code", "R", "02-recode-anes.R"), echo = TRUE)

source(here::here("code", "R", "03-descriptives.R"), echo = TRUE)
# save.image(file = here("data", "rmd-rdata", "03-descriptives.Rdata"))
save.image(file = here("data", "rmd-rdata", "03-descriptives.Rdata"))

source(here("code", "R", "04-MCMC.R"), echo = TRUE)
source(here::here("code", "R", "04-MCMC.R"), echo = TRUE)

source(here::here("code", "R", "05-viz.R"), echo = TRUE)
# save.image(file = here("data", "rmd-rdata", "05-viz.Rdata"))


# source("R/mcmc-viz.R",, echo = TRUE)
save.image(file = here("data", "rmd-rdata", "05-viz.Rdata"))

beepr::beep(2)

# source("R/04-define-model.R", echo = TRUE)

# source("R/05-run-model.R", echo = TRUE)

# source("R/06-OCD.R")

# source("R/07-ocd-viz.R")
17 changes: 11 additions & 6 deletions code/R/01-setup.R
Expand Up @@ -10,18 +10,19 @@
# library("colorout")
library("magrittr")
library("tidyverse")
library("ggplot2") # redundant but improves auto-complete
library("broom")
library("beepr")
library("latex2exp")
library("extrafont")
# library("extrafont")



library("rstan")
options(mc.cores = parallel::detectCores())
rstan_options(auto_write = TRUE)
library("ggmcmc")
library("tidybayes")

# --- working directory -----------------------

# set to project root
Expand All @@ -42,10 +43,14 @@ dir.create(here("tex/appendix"))

# --- graphics settings -----------------------

# custom ggtheme, import from Github
source("https://raw.githubusercontent.com/mikedecr/custom-R/master/theme-mgd/theme-mgd.R")
theme_set(theme_mgd()) # set default theme
# theme_set(theme_bw())
# graphics theme
update_geom_defaults("text", list(family = "Fira Sans"))
theme_set(
ggthemes::theme_base(base_family = "Fira Sans", base_size = 14) +
theme(plot.background = element_blank(),
axis.ticks = element_line(lineend = "square"),
axis.ticks.length = unit(0.25, "lines"))
)

dblue <- "#0072B2"
rred <- "#D55E00"
Expand Down
26 changes: 16 additions & 10 deletions code/R/02-recode-anes.R
Expand Up @@ -10,19 +10,25 @@

# --- ANES raw data -----------------------

# if RDS file is absent, create it:
if ("anes-cdf-2016.RDS" %in% list.files(here("data", "ANES-2016")) == FALSE) {
here("data", "ANES-2016", "ANES-2016/anes_timeseries_cdf.dta") %>%
haven::read_dta() %>%
saveRDS(here("data", "ANES-2016", "anes-cdf-2016.RDS"))
# if RDS file present, read the RDS file
# if no RDS, read it from Box
# (for Barry: dir contains .dta)

# if RDS file is absent, read from box and pull into R:
if ("anes-cdf-2016.RDS" %in% list.files(here("data", "ANES-2016"))) {
anes <-
readRDS(here("data", "ANES-2016", "anes-cdf-2016.RDS")) %>%
print()
message("ANES data read locally")
} else {
print("RDS file already found")
boxr::box_auth()
anes <-
boxr::box_read(504157238177) %>%
print() %>%
saveRDS(here("data", "ANES-2016", "anes-cdf-2016.RDS"))
message("ANES data read from Box (& local copy saved)")
}

# 2016 RDS file, remove labels
anes <- readRDS(here("data", "ANES-2016", "anes-cdf-2016.RDS")) %>%
mutate_all(labelled::remove_labels) %>%
print()



Expand Down