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) | |
| #### EASY QUANTILE EFFECTS FOR RCTs... | |
| ## MEDIAN EFFECT | |
| quantile(lalonde$re78[lalonde$treat == 1], probs = 0.5) - | |
| quantile(lalonde$re78[lalonde$treat == 0], probs = 0.5) | |
| #### 0.9 QUANTILE EFFECT |
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
| # DATA PREPROCESSING | |
| foo <- read.csv("https://tinyurl.com/y2zt2hyc") | |
| foo <- foo[, c(6:8, 11:16, 99, 50, 114, 49, 63, 136, 109, 126, 48, 160, 142, 10)] | |
| foo <- foo[c(-19, -47), ] | |
| which(is.na(foo) == TRUE) | |
| head(foo) | |
| # What is the 3 digit country code associated with the first row of the data set? | |
| foo$clust2[1] | |
| foo$yrbeg[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
| ## ----------------------------------------------------------------------------------------------------------- | |
| library(maps) | |
| data(us.cities) | |
| head(us.cities) | |
| map(database = "usa") | |
| capitals <- subset(us.cities, capital == 2) # subset state capitals |
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
| dd <- read.csv("progresa.csv") | |
| dim(dd) | |
| dd <- na.omit(dd) | |
| dim(dd) | |
| ### QUESTION 1 | |
| # An example of what I'm looking for | |
| par(mfrow = c(2,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
| install.packages("tree") | |
| library(MASS) | |
| library(tree) | |
| head(Pima.tr) | |
| ############# | |
| set.seed(1234) | |
| # enter your code here | |
| # fit a tree in the training set |
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
| # assuming you have downloaded the data (Data1.csv) correctly, | |
| # as discussed here: https://piazza.com/class/l7oq25mqbrz1nd/post/110 | |
| # you may need to change the file location in quotes below, to suit where your file is | |
| apple <- read.csv("~/Documents/Data1.csv", stringsAsFactors = F, encoding="UTF-8") | |
| str(apple) | |
| install.packages("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
| # assuming you have downloaded the data (Data1.csv) correctly, | |
| # as discussed here: https://piazza.com/class/l7oq25mqbrz1nd/post/110 | |
| # you may need to change the file location in quotes below, to suit where your file is | |
| apple <- read.csv("~/Documents/Data1.csv", stringsAsFactors = F, encoding="UTF-8") | |
| str(apple) | |
| 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
| ## We're going to be running regressions... | |
| ## If a predicted value is positive, we're going to say it's a prediction for hamilton authorship. | |
| ## If a predicted value is negative, we're going to say it's a prediction for madison authorship. | |
| author <- rep(NA, nrow(dtm1)) # a vector with a missing value | |
| author[hamilton] <- 1 # 1 if Hamilton | |
| author[madison] <- -1 # -1 if Madison | |
| ## data frame for regression | |
| author.data <- data.frame(author = author[c(hamilton, madison)], |
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
| ## Authorship prediction | |
| ## authorship of some Federalist Papers is unknown | |
| ## We use the 66 essays attributed to either Hamilton or Madison to | |
| ## predict the authorship of the 11 disputed papers. | |
| ## Since each paper deals with a different topic, we focus on usage of articles, | |
| ## prepositions, and conjuctions. We analyze the frequency of the following | |
| ## 10 words: although, always, commonly, consequently, considerable, enough, there, upon, while, | |
| ## and whilst. |