Permutation test

From Rosetta Code
Revision as of 12:33, 1 February 2011 by rosettacode>Sluggo (created the task and the Ursala solution)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Task
Permutation test
You are encouraged to solve this task according to the task description, using any language you may know.

A new medical treatment was tested on a population of volunteers, with each volunteer randomly assigned either to a group of treatment subjects, or to a group of control subjects. Members of the treatment group were given the treatment, and members of the control group were given a placebo. The effect of the treatment or placebo on each volunteer was measured and reported in this table.

Table of experimental results
Treatment group Control group
0.85 0.68
0.88 0.41
0.75 0.10
0.66 0.49
0.25 0.16
0.29 0.65
0.83 0.32
0.39 0.92
0.97 0.28
0.98

Write a program that performs a permutation test to judge whether the treatment had a significantly stronger effect than the placebo.

  • Do this by considering every possible alternative assignment from the same pool of volunteers to a treatment group of size and a control group of size (i.e., the same group sizes used in the actual experiment but with the group members chosen differently), while assuming that each volunteer's effect remains constant regardless.
  • Note that the number of alternatives will be the binomial coefficient .
  • Compute the mean effect for each group and the difference in means between the groups in every case.
  • Report the percentage of alternative groupings for which the difference in means is less or equal to the actual experimentally observed difference in means, and the percentage for which it is greater.
  • Note that they should sum to 100%.

Extremely dissimilar values are evidence of an effect not entirely due to chance, but your program need not draw any conclusions.

You may assume the experimental data are known at compile time if that's easier than loading them at run time. Test your solution on the data given above.

Ursala

<lang Ursala>#import std

  1. import nat
  2. import flo

treatment_group = <0.85,0.88,0.75,0.66,0.25,0.29,0.83,0.39,0.97> control_group = <0.68,0.41,0.10,0.49,0.16,0.65,0.32,0.92,0.28,0.98>

f = # returns the fractions of alternative mean differences above and below the actual

-+

  vid^~G(plus,~&)+ fleq*|@htX; ~~ float+ length,
  minus*+ mean^~*C/~& ^DrlrjXS(~&l,choices)^/-- length@l+-
  1. show+

t = --* *-'%'@lrNCC printf/$'%0.2f' times/$100. f(treatment_group,control_group)</lang> output:

13.03%
86.97%