Skip to content

Instantly share code, notes, and snippets.

View ryanbthomas's full-sized avatar

Ryan Thomas ryanbthomas

View GitHub Profile
Missouri DOI allows you to request zip code level aggregated datasets for several lines of business. This has to be requested via email.
If combined with Census Information on income/race it could be used as a monitor for redlining.
https://insurance.mo.gov/reports/
@ryanbthomas
ryanbthomas / rsvr_design.md
Last active May 13, 2019 02:41
rsvr_design

Rsvr

This is document is an attempt to define the minimum viable product for a data structure which reserving methodologies can be built off of. The final section has some ideas about the API for rsvr.

tri_df (triangle dataframe)

A tabular data structure (a subset of tibble), used to hold historical claim data that is an input to reserving analysis. It has the following columns:

  • cohort: (integer or string) [required] A variable that groups claims, or policies together whose development is tracked over time. For example, this might be accident year or underwriting quarter.
x <- rnorm(1000, 7, 2)
noise <- rnorm(1000)
y <- 5 + 2 * x + noise
df <- data.frame(x = x, y = y)
test_idx <- sample(1000, 100)
test_df <- df[test_idx, ]
@ryanbthomas
ryanbthomas / safely_iterate.R
Created February 11, 2020 14:50
Iteration Safely over functions
# Rules
library(purrr)
library(dplyr)
library(tibble)
dat <- tibble(x = 1:3, y = 4:6)
f1 <- function(tbl) {
mutate(tbl, z = x*y) %>% select(z)
---
title: "R Notebook"
output: html_notebook
---
```{r}
# setup
library(readr)
library(dplyr)
library(forcats)
@ryanbthomas
ryanbthomas / example.R
Created June 17, 2020 03:02
Vectorize Example
library(microbenchmark)
library(purrr)
library(tibble)
num_sims <- 1000
lambda <- 0.15
mu <- 7
sigma <- 2
@ryanbthomas
ryanbthomas / ggtext_example.R
Created August 3, 2020 17:44
Example of using ggtext to add color to specific words in plot title instead of using a legend.
library(ggtext)
# flowers data from the GLMsData package.
flowers %>%
group_by(Timing, Light) %>%
summarise(expFlowers = mean(Flowers)) %>%
ggplot() +
aes(x = Light, y = expFlowers, group = Timing, color = Timing) +
geom_line(size = 1.5) +
geom_point(size = 3) +
scale_color_manual(values = c("#d83177", "#6c31d8")) +
@ryanbthomas
ryanbthomas / Color in ggplot title
Created October 16, 2020 17:33
Example of adding color to plot title instead of legend
library(GLMsData) #where the flowers dataset comes from
library(dplyr)
library(ggplot)
library(ggtext)
flowers %>%
group_by(Timing, Light) %>%
summarise(expFlowers = mean(Flowers)) %>%
ggplot() +
aes(x = Light, y = expFlowers, group = Timing, color = Timing) +
geom_line(size = 1.5) +
@ryanbthomas
ryanbthomas / gist:69713d6e13dee2c2d01f97b41036be29
Created November 14, 2020 20:18
Formatting JSsript dates in R
# my use case was for time in Zulu (or GMT). This is what the Z at the end of the format is doing.
a <- lubridate::now(tzone = "GMT")
a_str <- format(a, format = "%FT%TZ"
@ryanbthomas
ryanbthomas / bookmark_example.R
Created January 28, 2021 01:45
PoC of Custom Bookmarking in shiny. This example uses an in memory list to store data, but this could be replaced by calls to web API for caching data
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)