########################################################################### # PUBLG100: Introduction to Quantitative Methods # # Week 3 Solutions: T-test for Difference in Means and Hypothesis Testing # # ## ------------------------------------------------------------------------ library(foreign) library(dplyr) df <- read.dta("http://uclspp.github.io/PUBLG100/data/QoG2012.dta") df <- rename(df, pol.stability = wbgi_pse) ## ------------------------------------------------------------------------ df$former_col <- factor(df$former_col, labels = c("not ex colony", "ex colony")) t.test(df$pol.stability ~ df$former_col, mu=0, alt="two.sided", conf=0.95) ## ------------------------------------------------------------------------ t.test(df$pol.stability ~ df$former_col, mu=0, alt="two.sided", conf=0.99) ## ------------------------------------------------------------------------ t.test(df$pol.stability ~ df$former_col, mu=0.3, alt="two.sided", conf=0.99) ## ------------------------------------------------------------------------ df <- rename(df, latitude = lp_lat_abst) ## ------------------------------------------------------------------------ table(df$latitude) ## ------------------------------------------------------------------------ plot(df$latitude, df$pol.stability) ## ------------------------------------------------------------------------ r <- cor.test(df$latitude, df$pol.stability, use="complete.obs", conf.level = 0.99) r