Data Analysis Tools, Week 4: Exploring statistical interaction
LIBNAME mydata "/courses/d1406ae5ba27fe300 " access=readonly;
data new; set mydata.gapminder;
/* data management polityscore */
if polityscore <= -6 then regtype="Autocracy";
if polityscore > -6 and polityscore < 6 then regtype="Anocracy";
if polityscore  >= 6 then regtype="Democracy";
/* data management residential electricity consumption */
if relectricperperson < 50 then reselec="Low";
if relectricperperson >= 50 then reselec="High";
/* data management internet use */
if internetuserate < 50 then intuser="Low";
if internetuserate >= 50 then intuser="High";
/* ANOVA F test */
proc sort; by regtype;
proc anova; class reselec;
model internetuserate=reselec;
means reselec;
by regtype;
/* chi square test of independence */
proc sort; by regtype;
proc freq; tables intuser*reselec/chisq; by regtype;
/* pearson correlation coefficient test */
proc sort; by regtype;
proc corr; var relectricperperson internetuserate; by regtype;
(a) Output of testing moderation of the categorical third variable regime type(s) (i.e. Anocracy, Autocracy, Democracy) with residential electricity consumption and no. of internet users, in the context of ANOVA
( b ) Â Output of testing moderation of the categorical third variable regime type(s) (i.e. Anocracy, Autocracy, Democracy) with residential electricity consumption and no. of internet users, in the context of chi square test of independence
( c ) Â Output of testing moderation of the categorical third variable regime type(s) (i.e. Anocracy, Autocracy, Democracy) with residential electricity consumption and no. of internet users, in the context of pearson correlation
This week, I am attempting to find if the categorical explanatory variable (e.g. rate of residential electricity consumption - high vs. low) is associated with the quantitative response variable (e.g. no. of internet users) across each population sub-group or each level of the third categorical variable (e.g. regime type of countries, or anocracy / autocracy / democracy). Â
Key question: Does the regime type category affect the strength or the direction of the association between residential electricity consumption and no. of internet users?
Null hypothesis is that the regime type category does not affect the strength or the direction of the association between residential electricity consumption and no. of internet users.Â
( a ) Testing moderation in the context of ANOVAÂ
Countries that are in the anocracy (15.93) and the democracy (27.95) groups show large F values, and significantly associated p values (anocracy 0.0002; democracy <.0001). Countries, within anocratic and democratic regime type categories, that have high residential electricity consumption rates, have much higher mean no. of internet users, compared to the lower mean no. of internet users in countries (within the same regime type categories) that have low rates of residential electricity consumption rates.Â
On the other hand, countries that are in the autocracy group, show a small F-value (0.37) and the p-value is not significant (0.5458). The mean no. of internet users are very close to each other (high 45.29; low 41.11) between high and low residential electricity consumption categories (i.e. high vs. low).
The regime type categories anocracy and democracy are similar in how and where the mean no. of internet users appear across high and low residential electricity consuming countries.Â
The mean no. of internet users in high residential electricity consuming countries is much higher for democracy regime type category, than the mean no. of internet users in high residential electricity consuming countries for anocracy regime type category.Â
In fact, the overall mean no. of internet users (in high residential electricity consuming countries) for democracy regime type is more than twice the value observed for the mean no. of internet users (in high residential electricity consuming countries) for anocracy regime type.
A similar statement can also be made for the mean no. of internet users observed for low residential electricity consuming countries among democracy regime type and anocracy regime type categories.Â
The mean no. of internet users among autocratic regime type category countries are very close / similar among those that have high residential electricity consumption rates and those that have low residential electricity consumption rates.
The regime type category affects the association between the variables, when comparing the no. of internet users across high and low residential electricity consuming countries, only for democracy and anocracy regime type categories, with significantly higher mean no. of internet users for democracies. The autocracy regime type category is an exception to this finding, and does not affect the association between no. of internet users and rates of residential electricity consumption. Â Â
( b ) Testing moderation in the context of chi square test of independenceÂ
Anocracy and autocracy regime type categories have low chi square values (anocracy 0.9396; autocracy 2.1181), and the p-values are not significant in the association between residential electricity consumption and no. of internet users (anocracy 0.3324; autocracy 0.1456).Â
Democracy regime type has a low chi square value (7.3052) but the p-value is signficant in the association between residential electricity consumption and no. of internet users (0.0069).
The rates of residential electricity consumption and no. of internet users are not significantly associated in anocracy and autocracy regime type categories (low chi square values, and p value higher than 0.05).Â
50% of the cells in the chi square analysis for anocracy regime type category have expected counts less than 5, so chi-square may not be a valid test.
Column percents do not reveal a linear relationship between rates of residential electricity consumption and the no. of internet users across anocracy and autocracy regime type categories. Â
The democracy regime type has a significant moderating effect in the association between residential electricity consumption and no. of internet users (p-value 0.0069), although it has a very low chi square value (7.3052); this may indicate a weaker statistically significant relationship.
( c )Â Testing moderation in the context of pearson correlation
The correlation coefficients across democracy (0.73484) and anocracy (0.85310) regime types are quite high and indicate positive linear relationships, and significant p-values (democracy and anocracy p-values are both <.0001).
The correlation coefficient between residential electricity consumption and no. of internet users  has a weaker positive relationship in the autocracy regime type (0.42283), with a slightly more modest p-value (0.034) although this relationship is significant (i.e. less than 0.05).Â
The analysis of the results indicate that the correlation of rates of residential electricity consumption and no. of internet users may only slightly differ based on the regime type category.
For all three regime type categories, the association between residential electricity consumption and no. of internet users are positive linear relationships with varying degrees of strength within the relationships.Â
The low p-values indicate there is a strong association between rates of residential electricity consumption and the no. of internet users among all regime type categories, although it is more modest in autocracy regime types.Â
The strongest correlation (close to +1) among residential electricity consumption and no. of internet users is found among anocracy regime type category countries.