Skip to content

Instantly share code, notes, and snippets.

View fditraglia's full-sized avatar

Francis DiTraglia fditraglia

View GitHub Profile
@fditraglia
fditraglia / drop-regressor.R
Created September 15, 2018 19:26
An example where dropping the "more important" predictor from a regression makes the "less important" predictor become statistically insignificant
# In this example, both x1 and x2 predict y and the two predictors are correlated
# with each other, but x2 has a much larger regression coefficient that x1. In a
# regression with both x1 and x2, both predictors are statistically significant.
# However if we drop x2, then x1 becomes insignificant. This is because dropping
# x2 dramatically increases the residual standard error. This effect overwhelms the
# increase in the estimated coefficient of x1 that arises from its correlation with
# the omitted variable x2.
library(MASS)
set.seed(1234)
@fditraglia
fditraglia / how-to-install-latest-gcc-on-ubuntu-lts.txt
Created February 17, 2017 17:00 — forked from application2000/how-to-install-latest-gcc-on-ubuntu-lts.txt
How to install latest gcc on Ubuntu LTS (12.04, 14.04, 16.04)
These commands are based on a askubuntu answer http://askubuntu.com/a/581497
To install gcc-6 (gcc-6.1.1), I had to do more stuff as shown below.
USE THOSE COMMANDS AT YOUR OWN RISK. I SHALL NOT BE RESPONSIBLE FOR ANYTHING.
ABSOLUTELY NO WARRANTY.
If you are still reading let's carry on with the code.
sudo apt-get update && \
sudo apt-get install build-essential software-properties-common -y && \
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
@fditraglia
fditraglia / ubuntu-eol.md
Created January 26, 2017 20:50 — forked from dergachev/ubuntu-eol.md
What to do when your ubuntu distro is End-of-Life

Let's say you're using Ubuntu 13.04 (Raring Ringtail, released in April 2013) and it just went End-of-Life on you, because it's supported for only 6 months, and the deprecated packages are taken down after 12 months.

You'll probably figure this out the hard way. When you run sudo apt-get update, it will eventually report these errors:

Ign http://archive.ubuntu.com raring-updates/universe Sources/DiffIndex
Err http://security.ubuntu.com raring-security/main Sources
  404  Not Found [IP: 91.189.91.15 80]
Err http://security.ubuntu.com raring-security/universe Sources
  404  Not Found [IP: 91.189.91.15 80]
@fditraglia
fditraglia / collapse_3darray.R
Created August 22, 2016 18:17
A simple example of how to collapse a 3d array into a matrix in R
# ------------------------------------------------------------------------------
# Here's a simple but slightly confusing task in R: collapsing a 3d array into a
# matrix. Specifically, we want to convert a 3d array of this form:
# ------------------------------------------------------------------------------
# , , 1
#
# [,1] [,2] [,3]
# [1,] "1.1.1" "1.2.1" "1.3.1"
# [2,] "2.1.1" "2.2.1" "2.3.1"
#
@fditraglia
fditraglia / refreport.sublime-snippet
Created April 3, 2014 18:13
LaTeX Snippet: refreport
<snippet>
<content><![CDATA[
\documentclass[12pt,letterpaper]{article}
\usepackage{amssymb, amsmath, amsthm, graphicx}
\usepackage[left=1.25in, right=1.25in, top=1.25in, bottom=1.25in, nohead] {geometry}
\title{Referee Report}
@fditraglia
fditraglia / gist:9959681
Created April 3, 2014 18:11
Template for Referee Report
We couldn’t find that file to show.
@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}
@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 / 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 / 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)