This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set up RStudio and JAGS on an Amazon EC2 instance | |
# Using Ubuntu 64-bit | |
# Partially from http://blog.yhathq.com/posts/r-in-the-cloud-part-1.html | |
# See yhat for EC2 instance set up | |
# Navigate to key pair | |
# ssh -i YOUR_KEYPAIR.pem ubuntu@PUBLIC_DNS | |
# Add a user/password. | |
# This will become your RStudio username and password. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' A function to create caterpillar plots from rstan's stanfit objects | |
#' | |
#' @param obj a \code{stanfit} object | |
#' @param pars character string, vector, or regular expression of paramater | |
#' labels that you would like to plot as declared in \code{model_code} from the | |
#' \code{\link{stan}} call. | |
#' @param pars_labels vector of parameter labels. Important: they must be in | |
#' the same order as in the \code{stanfit} object when \code{as.data.frame(obj)} | |
#' is called. | |
#' @param hpd logical. If \code{TRUE} then the 90% and 95% highest probability |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Inverse hyperbolic sine transformation | |
#' | |
#' @param x a numeric vector | |
#' | |
#' @details A useful transformation for skewed data that includes 0's and | |
#' negative values | |
ihs <- function(x) { | |
transformed <- log(x + sqrt(x ^ x + 1)) | |
return(transformed) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' @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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
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)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' An R function for creating simple D3 javascript directed network graphs. | |
#' | |
#' d3SimpleNetwork creates simple D3 javascript network graphs. | |
#' | |
#' @param data a data frame object with three columns. The first two are the names of the linked units. The third records an edge value. (Currently the third column doesn't affect the graph.) | |
#' @param Source character string naming the network source variable in the data frame. If \code{Source = NULL} then the first column of the data frame is treated as the source. | |
#' @param Target character string naming the network target variable in the data frame. If \code{Target = NULL} then the second column of the data frame is treated as the target. | |
#' @param height numeric height for the network graph's frame area. | |
#' @param width numeric width for the network graph's frame area. | |
#' @param file a character string of the file name to save the resulting graph. If a file name is given a standalone webpage is created, i.e. with a header and footer. If \code{file = NULL} then |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create Google Motion Chart from World Bank Finance Data | |
# Inspired by http://lamages.blogspot.com/2011/09/accessing-and-plotting-world-bank-data.html | |
# Written by Christopher Gandrud | |
# 15 October 2011 | |
library(WDI) | |
library(gregmisc) | |
library(googleVis) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |