Skip to content

Instantly share code, notes, and snippets.

View fditraglia's full-sized avatar

Francis DiTraglia fditraglia

View GitHub Profile
@fditraglia
fditraglia / friends_of_normal.R
Created October 23, 2013 16:16
Source Code for "Friends of the Normal Distribution," available at http://www.ditraglia.com/econ103/friends_of_normal.html
#Function to draw a single Chi-squared random variable with degrees of freedom equal to df
my.rchisq <- function(df){
#Draw df independent standard normals
normal.sims <- rnorm(df)
#Square them and sum the result
chi.sims <- sum(normal.sims^2)
@fditraglia
fditraglia / HW8.R
Last active December 26, 2015 17:58
R code to accompany solutions to Homework #8
ones <- rep(1, 10)
ones
cumsum(ones)
cumsum(1:10)
n <- 10000
sims <- rnorm(n, mean = 0, sd = 10)
running.mean <- cumsum(sims)/(1:n)
@fditraglia
fditraglia / tikz_flowcharts.tex
Created November 1, 2013 16:37
This file contains some simple flowchart examples in tikz. The content is based on slides from my presentation at the 2013 Midwest Econometrics Group meetings.
% I learned how to make these flowcharts by looking at some very helpful examples online:
%
% http://www.texample.net/tikz/examples/simple-flow-chart/
% http://www.texample.net/tikz/examples/borrowers-and-lenders/
% http://www.texample.net/tikz/examples/entity-relationship-diagram/
%
% For a long list of tikz examples, see http://www.texample.net/tikz/examples/
\documentclass{beamer}
\usepackage{amssymb, amsmath, amsthm}
@fditraglia
fditraglia / HW9.R
Created November 4, 2013 01:05
R Code to Accompany Solutions to Homework 9
pnorm(10, mean = 12, sd = 2)
pnorm(250, mean = 300, sd = 10)
n <- 950:961
width <- 2 * qnorm(1 - 0.01/2) * 6/sqrt(n)
@fditraglia
fditraglia / HW10.R
Created November 18, 2013 03:28
R Code to Accompany Solutions to Homework #10
group <- c('treatment', 'control', 'refused')
n.children <- 1000 * c(200, 200, 340)
n.polio <- c(57, 142, 157)
rate <- n.polio/n.children
polio.data <- data.frame(group, n.children, n.polio, rate)
polio.data
treatment <- subset(polio.data, group == 'treatment')
@fditraglia
fditraglia / lecture22.R
Created November 25, 2013 21:13
R Code for Power Example from Lecture 22
coin.power <- function(a, p, n){
c <- qnorm(1 - a/2)
mu <- sqrt(n) * (2 * p - 1)
sigma <- sqrt(4 * p * (1 - p))
less.than <- pnorm( -c, mean = mu, sd = sigma)
greater.than <- 1 - pnorm(c, mean = mu, sd = sigma)
power <- less.than + greater.than
return(power)
}
@fditraglia
fditraglia / HW11.R
Last active December 30, 2015 03:49
R Code to Accompany Solutions to Homework #11
data.url <- "http://www.ditraglia.com/econ103/survey_clean.csv"
survey <- read.csv(data.url)
anchoring <- survey[,c("rand.num", "africa.percent")]
lo <- subset(anchoring, rand.num == "10")$africa.percent
hi <- subset(anchoring, rand.num == "65")$africa.percent
lo <- lo[!is.na(lo)]
hi <- hi[!is.na(hi)]
SE.lo <- sd(lo)/sqrt(length(lo))
SE.hi <- sd(hi)/sqrt(length(hi))
SE <- sqrt(SE.hi^2 + SE.lo^2)
@fditraglia
fditraglia / lecture24_child_test.R
Last active December 30, 2015 03:58
Lecture 24 Child Test Score Example
install.packages("arm")
library('arm')
data <- read.csv("http://www.ditraglia.com/econ103/child_test_data.csv")
attach(data)
head(data)
@fditraglia
fditraglia / HW12.R
Created December 3, 2013 17:21
R Code to Accompany Solutions to Homework #12
data.url <- 'http://www.ditraglia.com/econ103/ex_13_5.csv'
election <- read.csv(data.url)
lm(y ~ x1 + x2, data = election)
library(arm)
data.url <- "http://www.ditraglia.com/econ103/child_test_data.csv"
data <- read.csv(data.url)
attach(data)
@fditraglia
fditraglia / paper.sublime-snippet
Created January 20, 2014 02:25
LaTeX snippet: paper
<snippet>
<content><![CDATA[
\documentclass[12pt]{article}
\usepackage[margin=1.5in]{geometry}
\usepackage{todonotes}
\usepackage{amssymb,amsmath,amsthm,graphicx}
\usepackage{geometry}
\usepackage{rotating}
\usepackage{amssymb, amsmath, amsthm, graphicx}
\usepackage{multirow}