Skip to content

Instantly share code, notes, and snippets.

@jeffeaton
jeffeaton / scam-example.R
Created February 27, 2019 12:10
working example of shape constrained additive models from scam package in Stan
library(scam)
library(rstan)
library(ggplot2)
set.seed(0)
n <- 200
x1 <- runif(n)*6-3
f1 <- 3*exp(-x1^2) # unconstrained term
f1 <- (f1-min(f1))/(max(f1)-min(f1)) # function scaled to have range [0,1]
x2 <- runif(n)*4-1;
@jeffeaton
jeffeaton / dide-deploy-shiny.R
Created July 7, 2018 15:08
Deploying app on DIDE Shiny server
devtools::install_github("mrc-ide/hivmappr@shiny")
## 1. Bundle app using `rsconnect` internals.
appDir <- "~/Documents/Code/R/hivmappr/inst/shiny/hivmappr/"
appPath <- appDir
target <- rsconnect:::deploymentTarget(appPath,
appName = NULL,
@jeffeaton
jeffeaton / report.R
Last active January 23, 2020 03:28
Simple YAML header for reports with `knitr::spin()`
#' ---
#' title: "<title>"
#' author: Jeff Eaton
#' output: pdf_document
#' ---
#'
##+ setup, include=FALSE
library(knitr)
opts_chunk$set(tidy=TRUE, warning=FALSE, cache=TRUE, message=FALSE)
@jeffeaton
jeffeaton / gist:f804da95e109e2e7242642a4d927514f
Created November 19, 2016 18:57
read a stata dataset into R from a zip file
read_zipdta <- function(zfile){
tmp <- tempfile()
on.exit(unlink(tmp))
return(foreign::read.dta(unzip(zfile, grep(".dta", unzip(zfile, list=TRUE)$Name, TRUE, value=TRUE), exdir=tmp)))
}