# 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.

• I ended up using GLMM to model the time spent on activities (formula: time ~ activity + group + (1 | participant), then using the marginal means method through the emmeans package for multiple comparisons. Commented Dec 13, 2022 at 13:45

## 2 Answers

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. Commented 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
Commented Aug 5, 2020 at 16:57

This seems like a standard use case for multinomial regression, described for example on this UCLA web page. If the assumptions are met, the multinomial model can be interrogated to evaluate any comparisons of interest.

You do, however, have to provide information on the denominators underlying the proportions to evaluate the statistical significance of any differences. A proportion estimate of 0.10 is more reliable if it's based on 1000 cases than if it's based on only 10. That can be done by treating the outcome as a categorical variable and supplying a weights argument for the corresponding number of cases. Then you can use post-modeling tools like those provided by the emmeans package to make and evaluate specific comparisons.

• Thank you. The reason I was using proportions was to account for participants having a different baseline. Using a mixed model fixed that, then I used emmeans as suggested to do multiple comparisons. Commented Dec 13, 2022 at 13:47