-
Notifications
You must be signed in to change notification settings - Fork 2
/
bpstudy.m
32 lines (27 loc) · 898 Bytes
/
bpstudy.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function pvalue = bpstudy(N)
% bpstudy(N)
% simulate the blood pressure study with
% N subjects receiving the drug and
% N subjects receiving the placebo.
% the returned value is the p-value of the
% difference.
% generate data for the placebo group
placebo = normal(N, -4, 21);
% and for the drug group
drug = normal(N, -14, 21);
% Now compute the p-value of the difference between the two groups
% Use a permutation test
observedval = mean(drug) - mean(placebo);
z = starttally;
nulldata = concat(placebo, drug);
for trials = 1:100
pinds = 1:length(placebo);
newdata = shuffle(nulldata);
sampplacebo = newdata(pinds);
sampdrug = exclude(newdata, pinds);
teststat = mean(sampdrug) - mean(sampplacebo);
tally teststat z;
end
% The observed difference in means is expected to be < 0.
% So we'll look for trials where z is even more negative.
pvalue = proportion(z < observedval);