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
### This exercise requires installing a bunch of packages--- | |
### Unfortunately, the precise sequence and rules for installing may vary | |
### depending upon your computer and configuration. | |
## ***Taken from Chapter 5 in Kosuke Imai's "Quantitative Social Science" | |
## Transcribed by Alexis Diamond, all errors my own... | |
########################################################################## |
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
install.packages("devtools") | |
library(devtools) | |
devtools::install_github("kosukeimai/qss-package", build_vignettes = TRUE) | |
library(qss) | |
install.packages("tm") | |
install.packages("SnowballC") | |
library(tm) |
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
############# | |
# Answer key to pre-class work for Lesson 1 | |
#***Step 1: | |
#Load dataset | |
#Note: This step may take several seconds to complete | |
# click the link for the data set and see that it's a .csv file | |
# so use "read.csv" -- also, don't name this data object "data" |
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
--- | |
title: "Assignment 3" | |
output: pdf_document | |
date: '2022-11-30' | |
--- | |
```{r setup, include=FALSE} | |
knitr::opts_chunk$set(echo = TRUE) | |
set.seed(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
## Code Cell 1 of 4 | |
# Show median treatment effect estimation here | |
#install.packages("quantreg") | |
library(quantreg) | |
library(Matching) | |
data(lalonde) | |
rqfit_r50 <- rq(re78 ~ treat, tau = 0.5, data = lalonde) | |
summary(rqfit_r50) |
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
# From class on Monday, Nov 14 | |
# Switching to the OBSERVATIONAL Lalonde data set | |
# do genetic matching using the observational lalonde data | |
# use a caliper = to 0.1 standard deviations for every x. | |
library(Matching) | |
lalonde <- read.csv("https://tinyurl.com/st9n3dl") | |
X = cbind(lalonde$age, lalonde$educ, lalonde$black, lalonde$hisp, lalonde$married, lalonde$nodegr, lalonde$u74, lalonde$u75, lalonde$re75, lalonde$re74) |
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
die_rolls <- 1:6 | |
storage <- c() | |
for(i in 1:1000) | |
{ | |
rolls_for_the_week <- sample(die_rolls, 7, replace = TRUE) | |
storage[i] <- sum(rolls_for_the_week == 1) == 0 # if there's no 1, then TRUE | |
} | |
cat("\nthe probability of not rolling a 1 all week is estimated =", |
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
conditional <- function(a,b) { | |
# inputs 2 Boolean variables representing atomic sentences a, b | |
# outputs the truth value of the sentence "a -> b" | |
return(!a | b) | |
} | |
premise1 <- function(a,b,c) {return(conditional(!a, !b))} | |
premise2 <- function(a,b,c) {return(a | !c)} |
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
###################################################################### | |
# Parts 1 and 2 (below) tell a story: | |
# If you fit your model using the "data = ___" approach, and you don't | |
# use $ to define your variables (i.e., you don't type "x = training$x") | |
# then you don't get into trouble when you use predict() and supply | |
# a "newdata = ____ " object that has the same structure as your orig data. | |
# However, if you fit your model using the $ approach, then you seem to be | |
# OK using "predict()" and "newdata = training$x" AS LONG AS IT'S LOESS. | |
# But if it's linear regression, you are out of luck. |