ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
pearsonresiduals.cpp
Go to the documentation of this file.
00001 #include "statsLib.h"
00002 
00016 dvector pearson_residuals(long m, dvector obs_p, dvector pred_p)
00017 {
00018   {
00019     dvector O=obs_p/sum(obs_p);
00020     dvector P=pred_p/sum(pred_p);
00021 
00022     //double neff;    //effective sample size
00023     //neff=norm(elem_prod(pred_p,1.-pred_p))/norm2(obs_p-pred_p);
00024     dvector var=elem_prod(P,(1.-P))/m;
00025     //max(var)<=0 ? var=1.: var=var;
00026     if(max(var)<=0) var=1;
00027     dvector r=elem_div(O-P,sqrt(var+0.01/14));
00028     if(sum(P)==0) r=0;
00029     return(r);
00030   }
00031 }
00032