Last active
December 23, 2015 20:19
-
-
Save jwbowers/6688473 to your computer and use it in GitHub Desktop.
Code to copy and paste for class 8.
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
##Load a small version of Fortna's data. | |
load(url("http://jakebowers.org/PS230Data/pk2.df.rda")) | |
## Make a new dataframe with no missing values and adding UNpk (UN | |
## peacekeeping) and year the civil war started | |
pk.good<-na.omit(subset(pk.df,select=c('ridp','wardur','warstart.yr','warstart.hist.yr','UNpk','id'))) | |
## Load the mosaic library for plotting etc | |
library(mosaic) | |
##Recall that | |
lm3<-lm(ridp~UNpk,data=pk.good) | |
signif(coef(lm3),4) | |
lm.big<-lm(ridp~UNpk+warstart.yr+UNpk:warstart.yr,data=pk.good) | |
coef(lm.big) | |
lm.small<-lm(ridp~warstart.yr,data=pk.good) | |
coef(lm.small) | |
## Min and max of the warstart.yr variable | |
range(pk.good$warstart.yr) | |
## range(pk.good$UNpk) | |
preddat<-expand.grid(UNpk=c(0,1), | |
warstart.yr=c(0,53)) | |
preddat | |
preddat$lm.big.fit<-predict(lm.big,newdata=preddat) | |
preddat | |
table(1945+pk.good$warstart.yr[pk.good$UNpk==1]) | |
table(pk.good$warstart.yr[pk.good$UNpk==1]) | |
lm.fair<-lm(ridp~UNpk*warstart.yr,data=pk.good,subset=(1945+warstart.yr)>=1963) | |
lm.fair | |
preddat2<-expand.grid(UNpk=c(0,1),warstart.yr=c(1963-1945,1998-1945)) | |
preddat2$fit<-predict(lm.fair,newdata=preddat2) | |
preddat2 | |
summary(residuals(lm.fair)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment