Skip to content

Tutorial: Compare outcomes

When two treatments are compared, you may care about more than the typical relief score: did more people report very little relief? This example uses a patient-reported scale from 4 to 16, where higher scores mean better relief. The tests compare the groups; they cannot show that treatment caused a difference.

1. Load the data

The array contains 70 relief scores. The first 28 are from Armanaleg and the remaining 42 are from Bowl. We use Armanaleg as the reference group (source) and Bowl as the group under review (target).

import numpy as np

datalines = (
  "9 14 13 8 10 5 11 9 12 10 9 11 8 11 "
  "4 8 11 16 12 10 9 10 13 12 11 13 9 4 "
  "7 14 8 4 10 11 7 7 13 8 8 13 10 9 "
  "12 9 11 10 12 7 8 5 10 7 13 12 13 11 "
  "7 12 10 11 10 8 6 9 11 8 5 11 10 8"
).split()
relief = np.array([float(s) for s in datalines])
armanaleg, bowl = relief[:28], relief[28:]  # source: standard, target: challenger

Higher relief is better, so lower scores point toward worse outcomes. Dsos expects higher numbers to mean more harm. Negate the relief scores before using it.

2. Run the tests

Run both checks on the same groups. MannWhitneyU compares the overall ordering of the relief scores. Dsos checks whether the group under review has moved toward the low-relief end.

import samesame as ss

test = ss.MannWhitneyU(armanaleg, bowl)
test = test.set_permutation(seed=np.random.default_rng(12345))
shift = test()

test = ss.Dsos(-armanaleg, -bowl)
test = test.set_permutation(seed=np.random.default_rng(12345))
harm = test()

3. Read the results

For these comparisons, the tests shuffle which group each relief score belongs to while keeping the scores fixed. This is a way to compare the observed groups, not a simulation of treatment assignment. The questions stay separate:

  • MannWhitneyU (p = 0.25) checks whether values in one group tend to rank higher than values in the other. These data give little evidence of a difference.
  • Dsos (p = 0.15) checks for movement into the low-relief tail. These data do not provide clear evidence of that harmful movement.

The groups are small—28 and 42 patients—so the tests may miss real differences. A lack of clear evidence does not mean the treatments are equal.

For a model-monitoring example, see Monitor model scores.