ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pearsonresiduals.cpp
Go to the documentation of this file.
1 #include "statsLib.h"
2 
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 
d3_array elem_prod(const d3_array &a, const d3_array &b)
Returns d3_array results with computed elements product of a(i, j, k) * b(i, j, k).
Definition: d3arr2a.cpp:92
Vector of double precision numbers.
Definition: dvector.h:50
double sum(const d3_array &darray)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: d3arr.cpp:21
d3_array elem_div(const d3_array &a, const d3_array &b)
Returns d3_array results with computed elements division of a(i, j, k) / b(i, j, k).
Definition: d3arr2a.cpp:112
d3_array sqrt(const d3_array &arr3)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: d3arr2c.cpp:11
double var(const dvector &vec)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: cranfill.cpp:23
Library of statistic functions.
dvector pearson_residuals(long m, dvector obs_p, dvector pred_p)
#define max(a, b)
Definition: cbivnorm.cpp:189