Skip to content

Instantly share code, notes, and snippets.

@jnpaulson
jnpaulson / stratified.R
Created November 15, 2017 06:29 — forked from mrdwab/stratified.R
Stratified random sampling from a `data.frame` in R
stratified <- function(df, group, size, select = NULL,
replace = FALSE, bothSets = FALSE) {
if (is.null(select)) {
df <- df
} else {
if (is.null(names(select))) stop("'select' must be a named list")
if (!all(names(select) %in% names(df)))
stop("Please verify your 'select' argument")
temp <- sapply(names(select),
function(x) df[[x]] %in% select[[x]])
@jnpaulson
jnpaulson / monotone_spline.R
Created February 2, 2017 20:03 — forked from willtownes/monotone_spline.R
monotone splines using package mgcv
library(mgcv)
#library(modules) #devtools::install_github(klmr/modules)
#mgcv<-import_package("mgcv")
mspline<-function(x,y,k=10,lower=NA,upper=NA){
#fits a monotonic spline to data
#small values of k= more smoothing (flatter curves)
#large values of k= more flexible (wiggly curves)
#k is related to effective degrees of freedom and number of knots
#use unconstrained gam to get rough parameter estimates
@jnpaulson
jnpaulson / server.R
Created May 12, 2016 14:03 — forked from xiaodaigh/server.R
A gist of programatically changing panel tabs in Shiny
library(shiny)
# Define server logic for random distribution application
shinyServer(function(input, output) {
# Reactive expression to generate the requested distribution. This is
# called whenever the inputs change. The renderers defined
# below then all use the value computed from this expression
data <- reactive({
dist <- switch(input$dist,
@jnpaulson
jnpaulson / springer-free-maths-books.md
Created December 29, 2015 15:14 — forked from bishboria/springer-free-maths-books.md
Springer have made a bunch of books available for free, here are the direct links