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
library(haven) | |
df <- read_dta("C:/Users/Vinic/Downloads/turnout.dta") | |
View(df) | |
df[1,1] | |
df[1,] | |
lm2 <- glm(turnout ~ ., data = df, family = binomial) | |
summary(lm2) | |
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
library(boot) | |
#estimate the mean via bootstrapping | |
boot.mean <- function(data,index) return(mean(data[index])) | |
#calculate the CI via t-distribution | |
t.dist.ci <- function(samp) { | |
df <- length(samp) - 1 | |
factors <- qt(c(0.025, 0.975), df = df) | |
samp.mean <- mean(samp) |
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
# EXERCISE TO BUILD INTUITION FOR CORRELATED VS. UNCORRELATED DATA | |
# PLEASE FOCUS ON UNDERSTANDING THE BELOW | |
### DO NOT JUST EXECUTE ALL THE CODE IN ONE BATCH--RUN IT LINE BY LINE... | |
### Simulation of analysis on correlated data | |
set.seed(1314) | |
nsims <- 10000 |
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
################ PRELIMINARIES | |
library(MASS) | |
data(Pima.tr) | |
library(tree) | |
library(randomForest) | |
## STEP 1: Logistic regression ## | |
logistic_reg <- glm(type ~ ., data = Pima.tr, family = binomial) # basic model | |
predict_logistic.tr <- predict(logistic_reg, type = "response") # predicted probabilities (TRAINING SET) |
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
storage.vector <- NA | |
# Function that assigns treatment/control depending on | |
# propensity scores (assignment probabilities) | |
experiment <- function(vector.of.probabilities = NULL) { | |
k = 0 | |
for (i in 1:length(vector.of.probabilities)) { | |
if( | |
sample(x = c(1,0), size = 1, prob = c(vector.of.probabilities[i], | |
1 - vector.of.probabilities[i])) == 1) { |
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 addition | |
5 + 5 | |
# A subtraction | |
5 - 5 | |
# A multiplication | |
3 * 5 | |
# A division |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
# Comparison of logicals | |
TRUE == FALSE | |
# Comparison of numerics | |
-6 * 14 != 17 - 101 | |
# Comparison of character strings | |
"useR" == "user" | |
# Compare a logical with a numeric |
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
PEACEKEEPING WORKOUT (based on King, Gary;Zeng, Langche, 2007, | |
"Replication data for: When Can History be Our Guide? | |
The Pitfalls of Counterfactual Inference", | |
https://hdl.handle.net/1902.1/DXRXCFAWPK, | |
Harvard Dataverse, V4, | |
UNF:3:DaYlT6QSX9r0D50ye+tXpA== [fileUNF] ) | |
# CONSIDER USING THE JUPYTER NOTEBOOK WITH R-SERVER KERNEL (NEVER R-SAGE KERNEL) | |
foo <- read.csv("https://course-resources.minerva.kgi.edu/uploaded_files/mke/00086677-3767/peace.csv") | |
# extract relevant columns |
OlderNewer