Skip to content

Instantly share code, notes, and snippets.

View christophergandrud's full-sized avatar

Christopher Gandrud christophergandrud

View GitHub Profile
@christophergandrud
christophergandrud / poisson_mle_sims_bias_comp.R
Created August 13, 2018 15:16
Compare bias in Poisson MLE and various Sim methods (10 August)
library(pacman)
p_load(MASS, tidyverse)
# set seed
set.seed(4321)
# set simulation paramters
n <- 100 # sample size
@christophergandrud
christophergandrud / transformation_bias_blog.R
Last active August 9, 2018 04:30
Replication material for
library(pacman)
p_load(MASS, tidyverse)
# set seed
set.seed(8764)
# set simulation paramters
n <- 100 # sample size
@christophergandrud
christophergandrud / quick_mod_to_intuition_plot.R
Last active August 8, 2018 07:28
Quick modification to Rainey and Kern Figure 2 to remove transformation bias https://github.com/carlislerainey/unnecessary/blob/master/R/intuition-sims.R
set.seed(19743)
library(tidyverse)
library(ggrepel)
library(forcats)
tau <- function(x) {
x^2
}
@christophergandrud
christophergandrud / beta_plot_basic.R
Created June 13, 2017 17:28
Simple function for simulating/plotting beta distributions for Dataverse 2017 Package Development Workshop
#' @import ggplot2
#' @export
beta_plot <- function(n = 10000, a = 1, b = 3) {
# draw distributions
sims <- rbeta(n = n, shape1 = a, shape2 = b)
# convert to data frame for ggplot2 compatability
sims <- data.frame(x = sims)
---
title: "The zeligverse and beyond"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
[for Zelig version 5.1.1.9000, [setdirect branch](https://github.com/IQSS/Zelig/tree/setxdirect)]
@christophergandrud
christophergandrud / rrst_to_rmd.R
Last active May 8, 2017 17:32
Convert an R reStructuredText document (Rrst) to R Markdown (Rmd)
#' Converts an R reStructuredText document (Rrst) to R Markdown (Rmd)
#'
#' @param input character string with the path of the file to convert
#' @param output optional character string with the path for the output file
#' @param out_dir optional character string with the output directory. Not used
#' if \code{output} is supplied.
#' @param output_file logical whether to return the output to a file or not.
#' If \code{FALSE}, then \code{output} and \code{out_dir} are ignored.
#'
#' @importFrom readr read_file write_file
@christophergandrud
christophergandrud / parse.formula.R
Last active March 22, 2017 14:03
parse.formula function from Zelig 3.5
parse.formula<-function( formula, model,data=NULL){
if(class(formula)[[1]]=="multiple")
return(formula)
nrUserOpt<-nrUserReq<-nrUserFixed<-nrUserSubreq<-0
userOpt<-userReq<-userFixed<-userSubreq<-list()
fc <- paste("describe.", model, sep = "")
if (!exists(fc))
stop("describe.",model," does not exsist")
modelReq<-do.call(fc,list())
# Initialize Zelig5 least squares object
z5 <- zls$new()
# Estimate ls model
z5$zelig(Fertility ~ Education, data = swiss)
# Simulate quantities of interest
z5$sim()
# Plot quantities of interest
# Estimate ls model
z4 <- zelig(Fertility ~ Education, data = swiss, model = 'ls')
# Set Eductation to 5 and 15
z4_set_low <- setx(z4, Education = 5)
z4_set_high <- setx(z4, Education = 15)
# Simulate results
z4_sim <- sim(z4, x = z4_set_low, x1 = z4_set_high)
# Load the Zelig package
library(Zelig)
# Initialize Zelig5 least squares object
z5 <- zls$new()
# Estimate ls model
z5$zelig(Fertility ~ Education, data = swiss)
# Set Education to 5 and 15