# Strength of association test with binary variables

I have a dataset with different purchases for two different items from the same users. So the users purchased the two items at different points in time. I also have 3 different variables: High, Mid, and Low twice (Low, Mid,High for each product) within this dataset. So the product are broken up into these categories. For example, suppose I bought item X and its classified as a High price item. I then want to see if the same user bought an item Y at the same classification level (High). My end goal is to see if there is an association of a customer buying items at the same classification level across different items.

My first thought was to use a Chi square test but I am not sure this is the best way to do it. I am doing this in R. All of the data are binary variables. Here is an example of what the dataset looks like.

User      Type             High  Mid  Low
1         Product 1        0     1    0
1         Product 2        1     0    0
2         Product 1        0     1    0
2         Product 2        0     1    0
3         Product 1        0     0    1
3         Product 2        0     1    0

• Are your datasets paired observations? E.g., is one object being rated High/Mid/Low by two raters for whom you're interested in quantifying agreement? – Nick Stauner Feb 27 '14 at 19:24
• The dataset are tier leves of purchases. So trying to see if the same person are buying items in each tier level. So the data was merged on an indiv_id who had purchases in both categories. I am trying to see if there is a relationship between the levels. For example, if they buy a Mid tier item in one level does that mean that they are are likely to buy an item in the Mid tier for another product. Sorry for the confusion – user3120266 Feb 27 '14 at 22:25
• I'm afraid confusion is bound to occur in matters of statistics. Your continuing efforts to clarify are most appreciated and unfortunately rare in our population of new users! We'll get to the bottom of this yet – I'll mull it over, keep an eye on answers, and offer my own if I have anything to add in the end. – Nick Stauner Feb 27 '14 at 22:31
• You seem to have an important choice to make: do you want to consider User 1's purchases of Products 1 and 2 more similar than the purchases of a User who selects one Product from the High price category and one from the Low category? BTW, if so, and if you have actual prices for the Products, it would be wise to use those instead of trichotomizing the price data. If you prefer not to consider Products of High price more similar to Mid than Low, you'd want to treat your price data as nominal, not ordinal. Your choice will greatly affect what results you'll get – Nick Stauner Mar 2 '14 at 17:01

At any rate, there are two approaches to handling these data: one in which frequencies are treated as unordered (suboptimal) and the other in which you borrow information across trends (low/mid/high immediately suggests an ordinal nature to these data). The plain-vanilla approach to option 1 is to create a $3 \times 3$ contingency table of frequencies and conduct a Pearson $\chi^2$ test of independence with 4 degrees of freedom. The test statistic is the squared differences between observed and expected values based on marginal frequencies of tabular data. The R syntax would be chisq.test(table(dat$rate1, dat$rate2)).
Alternately, for approach number 2, there have been several methods proposed to analyze such data. A perfectly valid test of association for this circumstance is a simple linear regression model treating ordinal values as numeric quantities: 0:low, 1:mid, 2:high and regressing the rate2 variable upon rate1 (or vice versa, depending on the nature of the quesiton). R syntax would require casting these variables to numeric lm(as.numeric(rate2) ~ as.numeric(rate1)) ensuring that levels(rate1) == levels(rate2) and levels(rate1) == c('low', 'mid', 'high').
• Wouldn't your option 1 test associations among low, mid, high within a single (or the combined) dataset? What if these are unordered, and the overall association between frequencies of each across datasets is desired? That's how I understood the OP...but I'm suspicious of treating these variables as unordered too. As for that option 2, wouldn't a rank correlation like Kendall's $\tau$ be more perfectly valid? – Nick Stauner Feb 27 '14 at 18:41
• @user3120266 what you claim to want measure makes little sense to me. Are you trying to infer whether, given a product has an average rating of $p$ (based on 0/1/2 codes) that the distribution of ratings are homogeneous among products with similar ratings? Do you have exactly two ratings on each product (n=1700)? Or are you aggregating a number of possible ratings together for products to find the "average rating"? – AdamO Feb 27 '14 at 22:28