# measuring variance of differences between two sets of corresponding means with significance

I have a dataframe id, w, x, y1, y2 (two categorical variables, two dependent variables)

• id is the index which is not particularly informative
• w, x are categorical variables - w in {0,1}, x in {0,1,2,3}
• y1 is counts which I calculate rates from
• y2 is price data which I use for average price

I want to ensure w and x are unrelated - with statistical significance.

I think I should do this by comparing differences in y1, y2 in samples [w=0] to [w=1] for each x

• d0y1 [from w0x0 and w1x0] and
• d1y1 [from w0x1 and w1x1] and
• d2y1 [from w0x2 and w1x2] and
• d3y1 [from w0x3 and w1x3]

where dn is the difference between group means x in {0,1,2,3} for metric y1

Questions:

• is this the correct approach?
• what's the best statistical test to use?
• can I generate confidence intervals?

python packages/code to accomplish these would be greatly appreciated

You just want to know if 'w' and 'x' are unrelated? You don't need y1 and y2. Just make a contingency table for w and x and perform a Pearson's Chi-squared test.

import pandas as
import scipy.stats as st
w=[0,1,0,0,0,1,0,1,1,0]
x=[3,1,0,2,0,1,2,3,1,0]
df=pd.DataFrame()
df["w"]=w
df["x"]=x
contingency_table=pd.crosstab(df.w,df.x)
chi2, p_value, dof, exptected=st.chi2_contingency(contingency_table)


You don't need confidence intervals, all that matters is the 'p-value', the lower it is more probably is that w and x are related.

You need to put a threshold. In the example above the p-vale gotten was 0.04776571858126222, if my threshold was 0.05(5%) my p-value was lower, so I conclude that w and y are not unrelated with a significance of 5%.

See this for the scipy.stat function: Pearson's chi-squared tests and other similar tests you can use