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.