############################## # # Script: assignment03a.R # Answers to the third # homework assignment # ############################## # Preamble library(RFS) gd <- read.csv("http://courses.kvasaheim.com/pols6123/data/gdpcap.csv") names(gd) attach(gd) ##### # Problem 1 summary(gd) sd(gd) ##### # Problem 2 cor(gd) # Missing values # Which ones are missing? del <- which(is.na(democracy)) #let's remove them from consideration cor(gd[-del,]) # Correlation tests cor.test(gdpcap,hig) cor.test(democracy[-del],hig[-del]) cor.test(democracy[-del],gdpcap[-del]) # Alternatively summary(lm(hig~democracy)) 0.1986^0.5 summary(lm(gdpcap~democracy)) 0.02294^0.5 ##### # Problem 3 png("boxplot3.png", height=4,width=6,units="in",res=600) boxplot(gdpcap[region=="Africa"], horizontal=TRUE) dev.off() shapiro.test(gdpcap[region=="Africa"]) t.test(gdpcap[region=="Africa"], mu=5000) # Wrong! (why?) wilcox.test(gdpcap[region=="Africa"], mu=5000) # Correct! (why?) ##### # Problem 4 (and 5) =) png("boxplot4.png", height=5,width=6,units="in",res=600) boxplot(gdpcap[region=="Africa"], gdpcap[region=="Latin America"]) # Ugly! dev.off() shapiro.test(gdpcap[region=="Africa"]) t.test(gdpcap[region=="Africa"], gdpcap[region=="Latin America"]) # Wrong! wilcox.test(gdpcap[region=="Africa"], gdpcap[region=="Latin America"]) # Correct! ##### # Problem 6 model1 <- lm(gdpcap ~ hig + region) summary.aov(model1) summary(model1)