This file contains hidden or 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 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 |
This file contains hidden or 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 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 |
This file contains hidden or 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
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 |
This file contains hidden or 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
#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) |
This file contains hidden or 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
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) |
This file contains hidden or 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
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 |
NewerOlder