Skip to content

Instantly share code, notes, and snippets.

View AaronGullickson's full-sized avatar

Aaron Gullickson AaronGullickson

View GitHub Profile
# Example of how to estimate ME inequality measure analytically and via
# bootstrap based on:
# https://sociologicalscience.com/articles-v12-7-115/
# load libraries ----------------------------------------------------------
library(palmerpenguins)
library(marginaleffects)
library(tidyverse)
@AaronGullickson
AaronGullickson / modelsummary.qmd
Created March 14, 2024 19:55
Using modelsummary to get model tables
```{r}
#| label: tbl-reg
#| tbl-cap: Models predicting miles per gallon
# build your models here - change these
model1 <- lm(mpg~cyl+disp, data=mtcars)
model2 <- lm(mpg~cyl+disp+hp, data=mtcars)
model3 <- lm(mpg~cyl+disp+hp+wt, data=mtcars)
modelsummary(list(model1, model2, model3), output = "gt",
@AaronGullickson
AaronGullickson / test_html_cap.Rmd
Last active March 24, 2023 16:21
This gist shows how to customize the caption for tables produced in R Markdown. You can do this by customizing css. Here I have done that through a code chunk in the document, but you can also define an external css file as shown by the commented-out yaml line.
---
title: "Test"
html_document:
# css: "style.css"
---
```{css custom-css, echo=FALSE}
caption {
color: black;
font-size: 1.2em;
@AaronGullickson
AaronGullickson / resources.md
Last active June 26, 2022 12:31
Resources for R Markdown from Code Horizons Course
@AaronGullickson
AaronGullickson / wesanderson_colors.R
Created April 15, 2022 21:30
Using Wes Anderson Color Palettes in ggplot
# I showed you how you can use wesanderson colors in your ggplots if you want in class. This script breaks
# down how to do that. The first thing you need to do is intall the "wesanderson" library in your project.
# You can do this with the following R command:
install.packages("wesanderson")
# PLEASE NOTE: You only need to install this once per project, so don't put it in a script you are going to run.
# Once it is installed, you can load it with a library call (and lets load ggplot2 at the same time)
library(wesanderson)
@AaronGullickson
AaronGullickson / marginal_effects_multinomial.R
Created January 20, 2022 00:33
Getting marginal effects from multinomial model
# put these library calls elsewhere
library(stringr)
library(dplyr)
library(ggplot2)
# A model for testing this out
model_PoliAff2 <- multinom(Poli_Aff~Race_Multi+birth_decade+I(Income/1000)+Education+Gender,
data=anes_combined)
# a function that will give you the average predicted proportions of party affilaition
@AaronGullickson
AaronGullickson / example_script.R
Created January 6, 2022 22:34
Example Script, Soc 512, Winter 2022
####################################
# example_script.R
# A basic example script
# Aaron Gullickson
####################################
# Load Libraries ----------------------------------------------------------
library(ggplot2)
library(ggthemes)
@AaronGullickson
AaronGullickson / code.R
Created February 11, 2021 20:26
Code we worked in nones dataset
#recoded_variable <- ifelse(true/false statement, replacement if true, original value)
#code missing values
#GSS$god <- ifelse(GSS$GOD==0 | GSS$GOD==8 | GSS$GOD==9, NA, GSS$GOD)
#summary(GSS$god)
#table(GSS$god, GSS$GOD, exclude=NULL)
#code numeric responses as categorical (factor)
GSS$god <- factor(GSS$GOD,
levels=1:6,
@AaronGullickson
AaronGullickson / aggregate.R
Created February 11, 2021 19:58
Code for aggregating from tracts to metro areas
metro <- aggregate(cbind(pop_total,
pop_nh_white,
pop_nh_black)~met2013+met_name,
data=tracts, sum)
@AaronGullickson
AaronGullickson / read_write_data.R
Last active February 4, 2021 19:37
Read and write R
## Reading in data adventures!
library(readr)
library(haven)
library(readxl)
# Reading in Text Files ---------------------------------------------------
#read in basic csv