Now let's 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 NESARC 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's my code to create this secondary variable, where zero will indicate non-daily smokers. Three will indicate those smoking 1-5 cigarettes per day, eight indicating 6-10 cigarettes per day, 13 indicating 11-15 cigarettes per day, 18 indicating 16-20 cigarettes per day, and 37 indicating greater than 20 cigarettes smoked per day. Now we're going to request a Chi-Square 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. Among non-daily smokers, only 25 percent are nicotine-dependent. Among those smoking 1-5 cigarettes per day, indicated by a code of three, about 48 percent meet 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 significant 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 DataFrames 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 MAJORDEPLIFE levels is here. Notice that I'm using the appropriate DataFrames 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 12 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. 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 DataFrame 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 of the relationship is similar between 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.