##### SCA-21 ##### ##### Two-Sample Means Tests ##### ### This gives a few examples of the analysis process for comparing ### two population means. ### Preamble # Import extra functionality source("http://rfs.kvasaheim.com/stat200.R") ### Part I: OPEC Wealth # # I would like to determine if OPEC members have a different # level of wealth than non-members. dt = read.csv("http://rfs.kvasaheim.com/data/gdp.csv") attach(dt) # To answer this question, I would like to use the two- # population t-test because it is the most powerful test # available. However, it requires the variables to be # Normally distributed in both populations. shapiroTest(gdpcap~OPEC) # According to the Shapiro-Wilk test, neither population is # Normal. Because of this, we should use the Mann-Whitney # test. wilcox.test(gdpcap~OPEC, conf.int=TRUE) # According to the Mann-Whitney test, there is no significant # evidence that OPEC membership is associated with higher -- # or lower -- average wealth levels. boxplot(gdpcap~OPEC, ylab="GDP per Capita", xlab="OPEC Membership") detach(dt) ### Part II: OPEC Corruption # # I would like to determine if OPEC members have a different # level of corruption than non-members. dt = read.csv("http://rfs.kvasaheim.com/data/gdp.csv") attach(dt) # To answer this question, I would like to use the two- # population t-test because it is the most powerful test # available. However, it requires the variables to be # Normally distributed in both populations. shapiroTest(corruption~OPEC) # According to the Shapiro-Wilk test, neither population is # Normal. Because of this, we should use the Mann-Whitney # test. wilcox.test(corruption~OPEC, conf.int=TRUE) # According to the Mann-Whitney test, there is no significant # evidence that OPEC membership is associated with higher -- # or lower -- average corruption levels. boxplot(corruption~OPEC, ylab="Corruption Level", xlab="OPEC Membership") detach(dt) ### Part III: OPEC Democracy # # I would like to determine if OPEC members have a LOWER # level of democracy than non-members. dt = read.csv("http://rfs.kvasaheim.com/data/gdp.csv") attach(dt) # To answer this question, I would like to use the two- # population t-test because it is the most powerful test # available. However, it requires the variables to be # Normally distributed in both populations. shapiroTest(democracy~OPEC) # According to the Shapiro-Wilk test, the non-member population is # not Normal. Because of this, we should use the Mann-Whitney # test. wilcox.test(democracy~OPEC, alternative="less", conf.int=TRUE) # n.b.: m TRUE # non-Western > Western # # According to the Mann-Whitney test, there is significant # evidence that Western States tend to have higher levels of # democaracy than non-Western States. # # In fact, we are 95% confident that the average difference # is at least 4 points. boxplot(democracy~(region=="Western"), ylab="Democracy Level", xlab="Western State") detach(dt) ##### # n.b.: Always draw a graphic. Then, make sure the results # shown in the graphic are consistent with the results # of your analysis. In that way, the graphic also helps # you make sure you did the analysis correctly.