Statistics
| Revision:

root / branches / pthreads-737 / contrib / statslib / pearsonresiduals.cpp @ 765

History | View | Annotate | Download (688 Bytes)

1
#include "statsLib.h"
2

    
3
/**
4
* @file pearsonresiduals.cpp
5
* @brief // Pearson residuals
6
* 
7
* \ingroup STATLIB
8
* @author Chris Grandin, Steve Martell
9
* 
10
* @date 12/13/2011
11
* @remarks
12
* This function calculates the pearson residuals for a multinomial
13
* distribution.
14
*/
15

    
16
dvector pearson_residuals(long m, dvector obs_p, dvector pred_p)
17
{
18
        {
19
                dvector O=obs_p/sum(obs_p);
20
                dvector P=pred_p/sum(pred_p);
21

    
22
                //double neff;                //effective sample size
23
                //neff=norm(elem_prod(pred_p,1.-pred_p))/norm2(obs_p-pred_p);
24
                dvector var=elem_prod(P,(1.-P))/m;
25
                //max(var)<=0 ? var=1.: var=var;
26
                if(max(var)<=0) var=1;
27
                dvector r=elem_div(O-P,sqrt(var+0.01/14));
28
                if(sum(P)==0) r=0;
29
                return(r);
30
        }
31
}
32