Now lets evaluate third variables as potential moderators in the context of Chi-Square Test of Independence. For this, we're going to return to our original Python program using the NYSARC data and asking the question, is smoking associated with nicotine dependence? We're going to create another smoking variable for this purpose, reflecting how many cigarettes each young adult smoker smokes per day. Here is my code to create this secondary variable. Where 0 will indicate non-daily smokers. Three will indicate those smoking one to five cigarettes per day, 8 indicating six to ten cigarettes per day, 13 indicating 11 to 15 cigarettes per day, 18 indicating 16 to 20 cigarettes per day. And 37 indicating greater then 20 cigarettes smoked per day. Now, we're going to request a chi-squared test of independence examining the association between nicotine dependence in the past 12 months and this new smoking variable called USQUAN. As we can see from the large chi-square value, and significant P value, smoking quantity and nicotine dependence are significantly associated. In examining the column percents here of each smoking group with nicotine dependence, we see generally higher rates of nicotine dependence among groups that smoke more. So among non-daily smokers, only 25% Percent are nicotine dependent. Among those smoking one to five cigarettes per day, indicated by a code of three, about 48% meet the criteria for nicotine dependence. These numbers increase with higher levels of smoking. To graph these proportions, we use the following code. And this gives us the graphic representation of this positive linear relationship. As smoking quantity increases, so does the proportion of individuals with nicotine dependence. This finding is accurate with regard to the larger population of young adult smokers in the US. But might a third variable moderate this significant association between smoking quantity and nicotine dependence? We are going to evaluate major depressive disorder as the third variable. Our question will be, does major depression affect either the strength or the direction of the relationship between smoking and nicotine dependence? Put another way, does major depression moderate the signficant statistical relationship between smoking and nicotine dependence? Is smoking related to nicotine dependence for each level of this third variable? That is for those with major depression and for those without major depression. Similar to our ANOVA example, syntax to be added includes setting new data frames that include either individuals with or without major depression. Since we will look at these groups separately, the specific syntax for the chi-square test of independence by major dep life levels is here. Notice that I am using the appropriate data frames for each contingency table, column percent table, and chi-square test, sub3, and sub4. When this syntax is added to the Python program, here are the results. You can see the cross-tabs or cross tabulation table looking at usual quantity by tobacco dependence in the past twelve months. First for major depression equal to zero which is those without major depression, the chi-square value is large and the P value is quite small. So we can say that this is a statistically significant relationship for those without major depression. For those with major depression, again we find a large chi-square value and a small P value which is statistically significant. Using a line graph to examine the rates of nicotine dependence by different levels of smoking, we would use the following code changing only the data frame and kind of graph. Here we are asking for a point or line graph. As you can see, it seems that both the direction and the size for the relationship is similar for smoking and nicotine dependence. For those with major depression and for those without. Although those with major depression do show higher rates of nicotine dependence at every level of smoking quantity. Still, in this case, we would say that a diagnosis of major depression does not moderate the relationship between smoking and nicotine dependence. For both young adult smokers with major depression and for those without. Higher levels of smoking behavior is associated with higher rates of nicotine dependence.