This file contains 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
library(rvest) | |
library(data.table) | |
library(lubridate) | |
doc = read_html("http://history.house.gov/Institution/Session-Dates/All/") | |
sessions = doc %>% | |
html_nodes(xpath = "//div[contains(@class, 'manual-table')]/table") %>% | |
html_table() %>% | |
as.data.frame() |
This file contains 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
plot_rhats <- function(dgirt_out) { | |
# Save to disk plots of split R-hats for theta-bars (from a particular model) | |
# | |
# This function produces two plots showing the average R-hat in each year by | |
# 1) state and 2) party, each averaging over the other. It assumes that | |
# particular variable names exist in dgirt_out as the grouping variable (D_pid3), | |
# time variable (D_year), and geographic variable (D_abb). | |
# From the stanfit object extract R-hats and effective sample sizes | |
tb_sum <- summary(dgirt_out, par = "theta_bar", verbose = TRUE)$summary |
This file contains 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
smooth_years <- function(d, varnames = NULL) { | |
# Smooth variables over years using a loess interpolation | |
# | |
# param d: a dataframe | |
# param varnames: the names of the variables to smooth over; | |
# if NULL names will be guessed. | |
# | |
# Returns a data.frame 2.5x larger than the input, | |
# containing the original values and predicted values from a | |
# loess fit. Assumes that a variable called 'year' exists. |
NewerOlder