GLYLIB
0.3.0b
|
00001 #include <stats.h> 00002 #include <mylib.h> 00003 //#include "../inc/stats.h" 00004 //#include "../inc/mylib.h" 00005 00006 /********* get_meanvar_array *********/ 00007 // written by BLFoley May 2008 00008 //meanvar get_meanvar_array(statsarray S); 00009 meanvar get_meanvar_array(statsarray S){ 00010 meanvar M; 00011 int i=0; 00012 00013 // initialize 00014 M=zero_meanvar(); 00015 M.t=S.t; 00016 M.n=S.n; 00017 00018 for(i=0;i<S.n;i++){ 00019 M.m+=S.d[i]; 00020 M.v+=S.d[i]*S.d[i]; 00021 } 00022 M.v-=(M.m*M.m/(double)M.n); 00023 M.m/=(double)M.n; 00024 switch(M.t){ // calculate standard deviation 00025 case 's': 00026 M.v/=(double)(M.n-1); // for sample / unbiased pop estimate 00027 break; 00028 case 'p': 00029 M.v/=(double)(M.n); // for whole population or biased sample 00030 break; 00031 default: mywhine("unknown type for statistical set in get_meanvar_array"); 00032 } 00033 M.s=sqrt(M.v); 00034 return M; 00035 }