Instantly share code, notes, and snippets.

View poisson_mle_sims_bias_comp.R
library(pacman)
p_load(MASS, tidyverse)
# set seed
set.seed(4321)
# set simulation paramters
n <- 100 # sample size
View transformation_bias_blog.R
library(pacman)
p_load(MASS, tidyverse)
# set seed
set.seed(8764)
# set simulation paramters
n <- 100 # sample size
View quick_mod_to_intuition_plot.R
set.seed(19743)
library(tidyverse)
library(ggrepel)
library(forcats)
tau <- function(x) {
x^2
}
View beta_plot_basic.R
#' @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)
View zeligverse_worflow_5.1.1.9000.R
---
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)]
View rrst_to_rmd.R
#' 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
View parse.formula.R
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())
View set_skip_ex.R
# 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
View z4_simple_ex.R
# 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)
View zls_simple_example.R
# 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