Skip to content

Instantly share code, notes, and snippets.

View ctesta01's full-sized avatar
🌱

Christian Testa ctesta01

🌱
View GitHub Profile
@ctesta01
ctesta01 / math-reading.md
Last active April 17, 2017 22:21
Recommended Mathematics Reading

Recommendations

This is a list of writings about mathematics that I think are accessible to a mathematically interested audience, as well as quite worth the read. I have read many of these multiple times, and will be quite happy if somebody finds something they enjoy on this list.

General Mathematics

@ctesta01
ctesta01 / qsf_explanation.md
Last active May 1, 2026 11:42
How does a Qualtrics Survey File work?

Quickstart Guide to undertsanding the Qualtrics Survey File

This information is likely to quickly become outdated when Qualtrics next changes the formatting of the QSF file. This guide was started February 2017. I hope that it is a useful introduction to understanding the contents of the QSF file that one can download from Qualtrics.

This document includes:

# Let's try and find out what parameters are undocumented in my package QualtricsTools.
# July 2017
# Christian Testa
# This uses some internals (such as parse_rd and .Rd_get_argument_names) from the tools package
# with the .Rd files generated by Roxygen with the args function to get arguments of functions
# loaded from the QualtricsTools in order to approximately tell which parameters are undocumented
# in the package.
# The script below seems to be prone to false-positives where the documentation for a parameter does
coerce_df_coltypes <- function(df, ...) {
types <- list(...)
# check for arguments
if (length(types) > 0) {
# if types is named, use names to coerce columns
typenames <- names(types)
if (!is.null(typenames) && length(typenames) == length(types)) {
if (!all(typenames %in% colnames(df)))
stop("the names of types must be colnames of df.")
for (i in seq(types)) {
@ctesta01
ctesta01 / save_absms.R
Last active November 13, 2020 15:35
Save Area Based Measures
library(tidyverse)
library(tidycensus)
library(magrittr)
variables_dict <-
tibble::tribble(
~var, ~desc,
"B03002_001", 'total_race', "total pop for race/non-hispanic estimate",
"B03002_003", 'white_nh', "white non-hispanic pop",
"B25014_001", 'total_crowd', "total for occupants by room by owner/renter",
@ctesta01
ctesta01 / friendly_cut_labels.R
Created December 9, 2020 22:46
Creating Friendly Quantile Cut Labels in R
library(tidyverse)
library(magrittr)
# 1. here's some made up data
df <- data.frame(
value = rgamma(n=1000, 1, .1))
@ctesta01
ctesta01 / check_out_new_2020_census_tracts.R
Created August 13, 2021 13:52
check_out_new_2020_census_tracts.R
install.packages("tigris")
library(tigris)
library(sp)
fulton20 <- tracts(state = 'GA', county = c('Fulton'), year = 2020)
fulton10 <- tracts(state = 'GA', county = c('Fulton'), year = 2010)
fulton00 <- tracts(state = 'GA', county = c('Fulton'), year = 2000)
library(leaflet)
@ctesta01
ctesta01 / nyt_7day_avg.R
Last active October 26, 2021 15:06
Reconstructing the 7-day moving average function NYT uses in their COVID-19 rolling averages data which omits negative counts
library(tidyverse)
library(magrittr)
# New York Times style 7-day moving average
#
# Use each value from the given vector and the prior 6 values
# to compute a moving average where values less than 0 are dropped
# both from the sum in the numerator and from the count of days
# in the denominator.
#
library(plotly)
library(sf)
library(dplyr)
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
N <- 10
# make random data
df <- lapply(1:N, function(x) nc) %>% bind_rows %>%
# animate a saddle differential equation system
#
# dX = -x - y
# dY = x - y
# dZ = .25 * z
#
# 25 trajectories are simulated and animated -- rendered using rgl in R
#
# Read more about rgl: https://dmurdoch.github.io/rgl/