comparison rDiff/src/tests/comp_nbin_p_value_mean_variance.m @ 0:0f80a5141704

version 0.3 uploaded
author vipints
date Thu, 14 Feb 2013 23:38:36 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:0f80a5141704
1 function [P_VALUE,FLAG_ERR]=comp_nbin_p_value_mean_variance(MEAN1,MEAN2,SIGMA1,SIGMA2,COUNTS1,COUNTS2)
2 %This function computes the p_value for a negative binomial
3 %hypothesis test given the mean and variance of two nbin
4 %distributions and counts from the respective distributions
5
6 FLAG_ERR=0;
7 r1=(MEAN1^2)/(SIGMA1-MEAN1);
8 p1=1-(MEAN1/(SIGMA1));
9 r2=(MEAN2^2)/(SIGMA2-MEAN2);
10 p2=1-(MEAN2/(SIGMA2));
11
12 P_OBS=calcl_nbin_pdf(COUNTS1,r1,1-p1)*calcl_nbin_pdf(COUNTS2,r2,1-p2);
13
14
15 P_A=calcl_nbin_pdf(0:(COUNTS1+COUNTS2),r1,1-p1);
16 P_B=calcl_nbin_pdf((COUNTS1+COUNTS2):(-1):0,r2,1-p2);
17 P_COMB=sort(P_A.*P_B);
18
19 if sum(P_COMB)>0
20 POS= find(P_COMB<=P_OBS,1,'last');
21 if isempty(POS)
22 P_VALUE=min(P_COMB);
23 else
24 P_VALUE=sum(P_COMB(1:POS))/sum(P_COMB);
25 end
26 else
27 P_VALUE=1;
28 end
29
30
31