Skip to content

Instantly share code, notes, and snippets.

import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
%matplotlib inline
#Given the data, the binomial likelihood function would be appropriate for this data, as the support matches the data (>0)
#the unobserved parameter is the percentage of treated patients who improve with the vaccination
#the beta distribution would be appropriate because we really don't know what percentage of the population improves
#therefore, the prior hyperparameters of a = 1 and b = 1
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
%matplotlib inline
'''
Function definitions for the normal-inverse-gamma distribution. The parameters
of the distribution, namely mu, lambda / nu, alpha, beta, are as defined here:
https://en.wikipedia.org/wiki/Normal-inverse-gamma_distribution
@mtramba
mtramba / CS112 Final
Last active April 19, 2018 17:24
CS112 Final
library(foreign)
data2 <- read.dta("peace.dta")
#removing observations with missing data
data2 <- data2[-c(47),]
data2 <- data2[-c(19),]
#logistic regression
rg <- glm(pbs2s3 ~ wartype + logcost + wardur + factnum +factnum2 +trnsfcap+ develop+ exp+ decade+ treaty +untype4, family = binomial(link = "logit"), data = data2)
rg$coefficients
#1
nswre74_controls <- read.table("nswre74_control.txt")
nswre74_treated <- read.table("nswre74_treated.txt")
names(nswre74_controls) <- c("treat", "age", "education", "black", "hispanic",
"married", "nodegree", "re74", "re75", "re78")
names(nswre74_treated) <- c("treat", "age", "education", "black", "hispanic",
"married", "nodegree", "re74", "re75", "re78")
nswre74 <- rbind(nswre74_controls, nswre74_treated)
#Difference in Means Treatment Effect
treat.effect <- mean(nswre74_treated$re78) - mean(nswre74_controls$re78)
city.names <- c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J")
observed.turnout = c(17, 30, 13, 55, 26, 29, 48, 43, 17, 30)
observed.diffmeans <- mean(observed.turnout[c(2,4,6,8,10)]) -
mean(observed.turnout[c(1,3,5,7,9)])
print(observed.diffmeans)
foo <- data.frame(city.names, observed.turnout)
@mtramba
mtramba / Lalonde3Ways
Last active February 26, 2024 12:53
Lalonde 3 Ways, CS112, Meredith Ramba
library(Matching)
data("lalonde")
attach(lalonde)
set.seed(1)
#seperate data depending on value for nodegr
nodegree <- lalonde[which (nodegr == 1),]
degree <- lalonde[which(nodegr == 0),]
#Random Forests