This file contains hidden or 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
# Set the parameters which are beyond the player's control | |
prob_win <- 0.6 | |
alpha <- 1000000L | |
beta <- 10000L | |
# List the possible choices available to the player | |
minimum_games <- 1L:50L | |
# List the series lengths which result from each available choice | |
# and, for each choice, list the corresponding probability of winning the series |
This file contains hidden or 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
example_strings <- c("Heres the sentince", "Here's anothr") | |
highlight_bad_text <- function(strings, match = NA) { | |
bad_text <- hunspell::hunspell(text = as.character(strings), | |
format = "text", | |
dict = hunspell::dictionary("en_us"), | |
ignore = hunspell::en_stats) | |
names(bad_text) <- names(strings) |
This file contains hidden or 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
g_statistic_lr_test <- function(x) { | |
chisq_results <- chisq.test(x) | |
expected_counts <- chisq_results[['expected']] | |
observed_counts <- chisq_results[['observed']] | |
G_Statistic <- 2 * sum(observed_counts * log(observed_counts/expected_counts), | |
na.rm = TRUE) | |
This file contains hidden or 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(magrittr) | |
library(dplyr) | |
library(tidyr) | |
library(stringr) | |
library(readr) | |
# Import the race/hispanic-origin ACS data downloaded through American Fact-Finder ---- | |
b03002_data <- read_csv(file = "Data/ACS/ZCTA/2013-2017/Raw/B03002/ACS_17_5YR_B03002_with_ann.csv", | |
skip = 1L, |
This file contains hidden or 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
#' @title Extract ggplot2 plots from a list | |
#' @description Takes a list (potentially containing sublists) and extracts all of the ggplot2 'plot-type' objects from that list into a simple list of 'plot-type' objects. | |
#' @param x A list object, potentially containing sublists. | |
#' @return Returns a 'flat', single-level list of all the ggplot2 'plot-type' objects from within `x`, reaching recursively into sub-lists as needed. If there are no 'plot-type' objects, returns an empty list. | |
#' @note Whether an object is a ggplot2 'plot-type' object is defined here as an object with classes 'gg', 'gTree', or 'gtable'. | |
#' @export | |
#' @examples | |
#' | |
#' library(ggplot2) | |
#' |
This file contains hidden or 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(ggplot2) | |
# This function will udpate the ggplot2 print method used in the session | |
wrap_labels_in_print_method <- function (dev_scaler = 12) { | |
if (!"ggplot2" %in% .packages()) { | |
stop("The ggplot2 package must be installed and loaded.") | |
} | |
# This is a custom printing function that will update wrapping in plot labels | |
# to match the width of the current device. (in RStudio, this is the 'Plots' pane) |
This file contains hidden or 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(ggplot2) | |
# This is a custom printing function that will update wrapping in plot labels | |
# to match the width of the current device. (in RStudio, this is the 'Plots' pane) | |
wrap_title_to_device <- function(ggplot_obj, dev_scaler = 12) { | |
# Retrieve width of current device in inches | |
dev_width <- dev.size("in")[1] | |
This file contains hidden or 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
# Define the function | |
get_hessian <- function(f, as_matrix = FALSE, eval_at = NULL) { | |
fn_inputs <- all.vars(f); names(fn_inputs) <- fn_inputs | |
n_inputs <- length(fn_inputs) | |
# Obtain the symbolic Hessian as a nested list | |
result <- lapply(fn_inputs, function(x) lapply(fn_inputs, function(x) NULL)) |
This file contains hidden or 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(magrittr) | |
library(tidyverse) | |
library(readr) | |
library(readxl) | |
library(schneidr) | |
theme_set(theme_schneidr(base_font_family = 'sans', | |
titles_font_family = 'sans')) | |
# Generate population |
This file contains hidden or 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(survey) | |
# Get example data | |
data(api) | |
dclus1<-svydesign(id=~dnum, weights=~pw, data=apiclus1, fpc=~fpc) | |
# Estimate means by subpopulation | |
# Use `covmat = TRUE` to also estimate covariances | |
mns <- svyby(~api99, ~stype, | |
dclus1, |
OlderNewer