Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View svmiller's full-sized avatar
🤷‍♂️
¯\_(ツ)_/¯

Steven V. Miller svmiller

🤷‍♂️
¯\_(ツ)_/¯
View GitHub Profile
@svmiller
svmiller / interp_urdf.R
Created December 14, 2022 11:31 — forked from hankroark/interp_urdf.R
This R function helps to interpret the output of the urca::ur.df function
############################################################################################
# This R function helps to interpret the output of the urca::ur.df function.
# The rules are based on https://stats.stackexchange.com/questions/24072/interpreting-rs-ur-df-dickey-fuller-unit-root-test-results
#
# urdf is the output of the urca::ur.df function
# level is one of c("1pct", "5pct", "10pct")
#
# Author: Hank Roark
# Date: October 2019
############################################################################################
library(tidyverse)
library(stevemisc)
jenny()
num_nums <- tibble()
for (i in 1:100) {
tibble(x = runif(50),
runsum = cumsum(x),
@svmiller
svmiller / read-tibbles-julia.jl
Created August 25, 2021 15:20
Read tibbles in Julia
# I'm teaching myself some shit. Bear with me.
using RData, DataFrame
df = load("/home/steve/Dropbox/projects/stevemisc/data/strategic_rivalries.rda")
df # not what I want...
df2 = DataFrame(df)[:, 1] # what I want...
@svmiller
svmiller / for-raphael.Rmd
Created June 10, 2021 13:42
A reprex of the article template in {stevetemplates}
---
output:
stevetemplates::article:
fig_caption: true
keep_tex: TRUE
#bibliography: master.bib
biblio-style: apsr
title: "A Pandoc Markdown Article Starter and Template"
thanks: "Replication files are available on the author's Github account (http://github.com/svmiller). **Current version**: `r format(Sys.time(), '%B %d, %Y')`; **Corresponding author**: svmille@clemson.edu."
author:
@svmiller
svmiller / fearon-laitin-kind-of-analysis-in-peacesciencer.R
Last active June 5, 2021 20:57
Do a Fearon and Laitin (2003) type civil conflict analysis in {peacesciencer}
create_stateyears(system = 'gw') %>%
filter(year %in% c(1946:2019)) %>%
add_ucdp_acd(type=c("intrastate"), only_wars = TRUE) %>%
add_peace_years() %>%
add_democracy() %>%
add_creg_fractionalization() %>%
add_sdp_gdp() %>%
add_rugged_terrain() -> Data
Data %>%
@svmiller
svmiller / peacesciencer-times.R
Last active May 31, 2021 18:57
{peacesciencer} times
library(tidyverse)
library(peacesciencer)
library(stevemisc)
# https://stackoverflow.com/questions/10893611/storing-tic-toc-values-in-r
library(tictoc)
tic.clearlog()
for (x in 1:100) {
# passing x to tic() makes it a label at time of the matching toc() call.
@svmiller
svmiller / famous-five-example.R
Last active April 29, 2021 01:10
"Famous Five" Example... something to riff on for later
set.seed(8675309)
tibble(age = round(runif(25,18,80)),
e = rnorm(25,0,5),
approval = round(1.25*age + e)) -> Dat
Dat %>%
ggplot(.,aes(age, approval)) +
geom_point()
@svmiller
svmiller / an-idiot-approach-to-priors.R
Last active February 8, 2021 22:09
How to be an idiot with priors in R
library(tidyverse)
library(stevedata)
library(brms)
# what follows is me being an idiot. Don't be Steve. Don't be an idiot.
?therms
# For anyone with a brain: the better you think of Obama, the worse you think of Trump (and vice-versa).
@svmiller
svmiller / 1-clmm-sim-example.R
Last active April 14, 2020 13:12
Simulate Ordinal Mixed Model Coefficients and Make Posterior Predictions
# Let's load the packages and the data. -----
# See this instead: http://svmiller.com/blog/2020/04/summarizing-ordinal-models-with-simulation-multivariate-normal/
library(stevemisc)
library(post8000r)
library(tidyverse)
TV16 %>%
filter(racef == "White") %>%
filter(state %in% c("Indiana","Ohio","Pennsylvania","Wisconsin","Michigan")) %>%
@svmiller
svmiller / 0-make-diff-formats.R
Last active February 19, 2020 16:07
Make/Test Various GSS Formats
setwd("~/Dropbox/data/gss/GSS_spss-2018")
library(tidyverse)
# haven::read_sav method -----
# ----------------------------
readsav_times = data.frame()
for(i in 1:10) {