# Comparing multiple proportions across groups for time spent on activities

I have a stacked column chart comparing time spent on 3 activities (here illustrated as A, B and C) by novices and experts. The proportions will always add up to 1; the participants could not do anything else than activities A, B or C. And here's the sample data:

   Activity Group  prop
1:  A       Novice 0.51158063
2:  B       Novice 0.17284939
3:  C       Novice 0.31556998
4:  A       Expert 0.88694859
5:  B       Expert 0.03311815
6:  C       Expert 0.05220782


Looking at the chart, it appears that experts spend more time on A and less on B and C.

Is there a test that would allow me to both check for differences at group level (e.g. "novices spent more time on C than on B") and between groups (e.g. "experts spent less time on B and on C than novices") ? The solutions that I found so far seem to apply to binary outcome (success / failure) and they use counts while I use a proportion of time spent by individuals.

There are a few issues in your sample data, not adding up to 1.0 as stated (see bar plot below).

You can use the Pearson ChiSquare test If you know the approximate total-time spent on activities per group . See here for introductory details for the ChiSquare test.

The Pearson ChiSquare test answers: time spent on activities is independent of the participant Group (H0), or time spent on activities is dependent on participant Group (reject H0)?

In python this solution is as follows:

import pandas as pd
import numpy as np
from scipy import stats

df = pd.DataFrame(data={'Activity':['A','B','C','A','B','C'],
'Group':['Novice','Novice','Novice','Expert','Expert','Expert'],
'prop':[0.51158063,0.17284939,0.09504048,0.88694859,0.03311815,0.05220782]})

# calculate minutes from proportions - assuming 2 hours total time
df['Minutes'] = np.round(df['prop']*120) cont = pd.crosstab(df.Group,df.Activity,values=df.Minutes,aggfunc=np.sum)
stat, p, dof, expected = stats.chi2_contingency(cont)

alpha = 1-0.95
if p <= alpha:
print(f'Reject H0, dependent: X2={stat:.3f} p-value={p:.4f}')
else:
print('Fail to Reject H0: independent: X2={stat:.3f} p-value={p:.4f}')

• Thanks for spotting the error in the sample data. Fixed that. Running a X2 would demonstrate that something is different, but not that a certain pair (e.g. A vs C in the Novice group, or Novice's A vs Expert's A) is different. Aug 3, 2020 at 21:28
• Well, you could run the test on those pairs too. So you would have an Overall Comparison of Experts and Novices, and then by class. And indeed all possible pairs if relevant to your questions. I don’t know enough about your use case to suggest further tests.
– BenP
Aug 5, 2020 at 16:57