# Correlation between products

I have an idea of what I want to achieve, but have no clue what it is called in statistical analysis world, hence impossible to implement.

I have a database with unique order numbers, customer names, products etc. I would like to see the correlation between products within orders. I.e. if I pick product X, what is the likelihood that I will also choose a product Y.

I would like to know what to research to help me with this.

• Thank you all for your input! I will try these and come back to you. – Marcius Jul 15 '15 at 16:26
• I have found that Data Mining add-in for excel can do wonders, but while add-in itself is free, it uses SQL Server's Analysis Services module, which unfortunately is not included in free products. Maybe somebody knows some other way that could be implemented in Excel? – Marcius Jul 19 '15 at 21:47
• I notice that you’ve edited your title to say “[solved]”. If one of the answers has addressed your problem, the way that you show that is by accepting an answer: click the check mark next to the answer that helped you the most. Please review the help center for more information about how to use this website. – Sycorax Sep 11 '18 at 17:34

## 3 Answers

Such relationships are called association rules.

One of the widely used algorithms for deriving association rules is Apriori, which is implemented in both R and Python.

It's called conditional probability $P(Y|X)$, i.e. probability of picking Y given that a customer picked X. There are relationships such as this one: $P(Y\&X)=P(Y|X)P(X)$, i.e. the probability that you pick Y and X is equal to probability of picking X multiplied by probability of picking Y conditional on picking X etc.

Basically you're wondering if the event where an individual chooses product $X$ is independent of the event where they choose product $Y$, or if these events are positively correlated. You can check this by testing the hypothesis $p_1 = p_0$ against the alternative $p_1 > p_0$, where $p_1$ is the probability of choosing product $Y$ given that you've chosen product $X$, and $p_0$ is the same probability given that you didn't choose product $X$. If your sample sizes are large you can test this with the statistic $$z = \frac{\hat{p}_1 - \hat{p}_0}{ \sqrt{\frac{\hat{p} (1 - \hat{p})}{n_1} + \frac{\hat{p} (1 - \hat{p})}{n_0}} }$$ where $\hat{p}_1$ is the proportion of individuals who purchased product $Y$ among those who purchased product $X$, $\hat{p}_0$ is the proportion among those who didn't purchase product $X$ ($n_1$ and $n_0$ are the respective sample sizes), and $\hat{p}$ is the overall proportion. When $p_1 = p_0$ this approximately follows a standard normal distribution, which can be used for the calculation of $p$-values. Do you know where to go from here?