-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhyp2sidedProportion.m
More file actions
21 lines (18 loc) · 875 Bytes
/
hyp2sidedProportion.m
File metadata and controls
21 lines (18 loc) · 875 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
function result = hyp2sidedProportion(n1, p1, n2, p2, hyp)
if ~exist('hyp','var')
hyp = 0;
end
ph1 = p1/n1;
sprintf("ph1 = p1/n1 = %f", ph1)
ph2 = p2/n2;
sprintf("ph2 = p2/n2 = %f", ph2)
phdiff = ph1-ph2;
sprintf("phdiff = ph1-ph2 = %f", phdiff);
pooledP = (p1 + p2) / (n1 + n2);
sprintf("pooledP = (p1 + p2) / (n1 + n2) = %f", pooledP)
z = ((ph1 - ph2) - hyp)/(sqrt(pooledP * (1 - pooledP))*sqrt((1/n1) + (1/n2)));
sprintf("z = ((ph1 - ph2) - hyp)/(sqrt(pooledP * (1 - pooledP))*sqrt((1/n1) + (1/n2))) = %f", z)
sprintf("P(<=z) => = %f| %s", normcdf(z), estrength(normcdf(z)))
sprintf("P(>=z) => = %f| %s", 1 - normcdf(z), estrength(1 - normcdf(z)))
sprintf("P(!=z) => = %f| %s", 2 * min(normcdf(z), 1 - normcdf(z)), estrength(2 * min(normcdf(z), 1 - normcdf(z))))
end