00001 #ifndef _STATSLIB_H_
00002 #define _STATSLIB_H_
00003
00004 #include <fvar.hpp>
00005 #include <admodel.h>
00006 #include <df1b2fun.h>
00007 #include <adrndeff.h>
00008
00009
00010
00011 dvar_matrix ageLengthKey( const dvar_vector& mu, const dvar_vector& sig, const dvector& x );
00012 dmatrix ageLengthKey( const dvector& mu, const dvector& sig, const dvector& x );
00013 dvar_matrix ALK(dvar_vector mu, dvar_vector sig, dvector x);
00014
00015 void fill( const dmatrix& _d,const dvector& _v );
00016 void fill( const dvar_matrix& _d,const dvar_vector& _v );
00017
00018 double get_ft(const double& ct, const double& m, const dvector& va, const dvector& ba );
00019 dvector get_ft( dvector& ct,const double& m, const dmatrix& V,const dvector& ba );
00020 dvector get_ft( dvector& ct,const double& m, const dmatrix& V,const dvector& na, const dvector& wa );
00021
00022 dvector pearson_residuals(long m, dvector obs_p, dvector pred_p);
00023
00024
00025
00026
00027 dvariable dunif( const dvariable& x, const double min, const double max );
00028
00029
00030 dvariable dstudent_t( const dvar_vector& residual, const dvar_vector& df);
00031
00032
00033 dvariable dinvgamma( const dvariable& x, const double a, const double b );
00034
00035
00036 dvariable dbinom( const prevariable& x,const double& n,const double& p );
00037 dvariable dbinom( const prevariable& x,const prevariable& n,const double& p );
00038 dvariable dbinom( const prevariable& x,const prevariable& n,const prevariable& p );
00039 dvariable dbinom(const dvar_vector& x,const dvar_vector& n,const dvar_vector& p);
00040 dvariable dbinom(const prevariable& x,const dvar_vector& n,const dvar_vector& p);
00041 dvariable dbinom(const dvar_vector& x,const prevariable& n,const dvar_vector& p);
00042 dvariable dbinom(const dvar_vector& x,const dvar_vector& n,const prevariable& p);
00043 df1b2variable dbinom( const df1b2variable& x,const double& n,const double& p );
00044 df1b2variable dbinom( const df1b2variable& x,const df1b2variable& n,const double& p );
00045 df1b2variable dbinom( const df1b2variable& x,const df1b2variable& n,const df1b2variable& p );
00046 df1b2variable dbinom(const df1b2vector& x,const df1b2vector& n,const df1b2vector& p);
00047 df1b2variable dbinom(const df1b2variable& x,const df1b2vector& n,const df1b2vector& p);
00048 df1b2variable dbinom(const df1b2vector& x,const df1b2variable& n,const df1b2vector& p);
00049 df1b2variable dbinom(const df1b2vector& x,const df1b2vector& n,const df1b2variable& p);
00050
00051
00052 dvariable dnbinom(const double& x,const prevariable& mu, const prevariable& k);
00053 df1b2variable dnbinom(const double& x, const df1b2variable& mu, const df1b2variable& k);
00054 df1b2variable dnbinom(const dvector& x, const df1b2vector& mu, const df1b2variable& k);
00055 df1b2variable dnbinom(const dvector& x, const df1b2vector& mu, const df1b2vector& k);
00056 dvariable dnbinom(const dvector& x, const dvar_vector& mu, const prevariable& k);
00057 dvariable dnbinom(const dvector& x, const dvar_vector& mu, const dvar_vector& k);
00058
00059
00060 dvariable dnbinom_tau(const double& x,const prevariable& mu, const prevariable& tau);
00061 df1b2variable dnbinom_tau(const double& x, const df1b2variable& mu, const df1b2variable& tau);
00062 df1b2variable dnbinom_tau(const dvector& x, const df1b2vector& mu, const df1b2variable& tau);
00063 df1b2variable dnbinom_tau(const dvector& x, const df1b2vector& mu, const df1b2vector& tau);
00064 dvariable dnbinom_tau(const dvector& x, const dvar_vector& mu, const prevariable& tau);
00065 dvariable dnbinom_tau(const dvector& x, const dvar_vector& mu, const dvar_vector& tau);
00066
00067
00068 df1b2variable dzinbinom(const double& x, const df1b2variable& mu, const df1b2variable& k, const df1b2variable& p);
00069 dvariable dzinbinom(const double& x, const prevariable& mu, const prevariable& k, const prevariable& p);
00070 df1b2variable dzinbinom(const dvector& x, const df1b2vector& mu, const df1b2variable& k, const df1b2variable& p);
00071 df1b2variable dzinbinom(const dvector& x, const df1b2vector& mu, const df1b2vector& k, const df1b2variable& p);
00072 dvariable dzinbinom(const dvector& x, const dvar_vector& mu, const prevariable& k, const prevariable& p);
00073 dvariable dzinbinom(const dvector& x, const dvar_vector& mu, const dvar_vector& k, const prevariable& p);
00074 df1b2variable dzinbinom(const dvector& x, const df1b2vector& mu, const df1b2variable& k, const df1b2vector& p);
00075 df1b2variable dzinbinom(const dvector& x, const df1b2vector& mu, const df1b2vector& k, const df1b2vector& p);
00076 dvariable dzinbinom(const dvector& x, const dvar_vector& mu, const prevariable& k, const dvar_vector& p);
00077 dvariable dzinbinom(const dvector& x, const dvar_vector& mu, const dvar_vector& k, const dvar_vector& p);
00078
00079
00080 dvariable dgamma( const dvariable &x, const double& a, const double& b );
00081 dvariable dgamma( const dvariable &x, const dvariable& a, const dvariable &b );
00082 dvariable dgamma( const dvector &x, const prevariable& a, const prevariable& b );
00083 dvariable dgamma( const dvector &x, const prevariable& a, const dvar_vector& b );
00084 dvariable dgamma( const dvector &x, const dvar_vector& a, const dvar_vector& b );
00085 dvariable dgamma( const dvector &x, const dvar_vector& a, const prevariable& b );
00086
00087
00088 dvariable dnorm( const prevariable& x, const double& mu, const double& std );
00089 dvariable dnorm( const dvar_vector& x, const double& mu, const double& std );
00090 dvariable dnorm( const prevariable& x, const double& mu, const double& std, bool bLog );
00091 dvariable dnorm( const dvector& x, const prevariable& mu, const prevariable& std );
00092 dvariable dnorm( const dvector& x, const prevariable& mu, const prevariable& std, bool dLog );
00093 dvariable dnorm( const dvar_vector& residual, const prevariable& std );
00094 dvariable dnorm( const dvar_vector& residual, const double& std );
00095 dvariable dnorm( const dvar_vector& residual, const dvector& std );
00096 dvariable dnorm( const dvar_vector& residual, const dvar_vector std );
00097 dvariable dnorm( const dvar_vector& residual );
00098 dvariable dnorm( const dmatrix& obs, const dvar_matrix& pred );
00099 df1b2variable dnorm( const df1b2variable& x, const double& mu, const double& std );
00100 df1b2variable dnorm( const df1b2variable& x, const double& mu, const double& std, bool bLog );
00101 df1b2variable dnorm( const df1b2variable& x, const df1b2variable& mu, const df1b2variable& std, bool bLog );
00102 df1b2variable dnorm( const df1b2vector& x, const df1b2variable& mu, const df1b2variable& std, bool dLog );
00103
00104
00105
00106 #ifndef LOGISTIC_HPP
00107 #define LOGISTIC_HPP
00108
00109 template <typename T>
00110 class plogisTraits;
00111
00112 template<>
00113 class plogisTraits<double> {
00114 public:
00115 typedef dvector plogisT;
00116 };
00117
00118 template<>
00119 class plogisTraits<named_dvariable> {
00120 public:
00121 typedef dvar_vector plogisT;
00122 };
00123
00124 template<>
00125 class plogisTraits<dvariable> {
00126 public:
00127 typedef dvar_vector plogisT;
00128 };
00129
00130
00131 template<typename T, typename T1>
00132 inline
00133 typename plogisTraits<T>::plogisT plogis(const T1 &x, const T &location, const T &scale)
00134 {
00135 typedef typename plogisTraits<T>::plogisT plogisT;
00136 plogisT y = 1./(1.+mfexp((location - x) / scale));
00137 return (y);
00138 }
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 #endif
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221 dvar_vector eplogis(const dvar_vector& x, const dvariable& alpha, const dvariable& beta, const dvariable& gamma);
00222 dvector eplogis(const dvector& x, const double& alpha, const double& beta, const double& gamma);
00223
00224
00225 dvariable dbeta( const dvariable& x, const double& shape1, const double& shape2 );
00226 dvariable dbeta( const dvariable& x, const dvariable& shape1, const dvariable& shape2 );
00227 dvariable dbeta( const dvariable& x, const prevariable& shape1, const prevariable& shape2 );
00228
00229
00230 dvariable dlnorm( const prevariable& x, const double& mu, const double& std );
00231 dvariable dlnorm( const prevariable& x, const prevariable& mu, const double& std );
00232 dvariable dlnorm( const prevariable& x, const prevariable& mu, const prevariable& std );
00233 dvariable dlnorm( const dvar_vector& x, const double& mu, const double& std );
00234 dvariable dlnorm( const dvar_vector& x, const prevariable& mu, const double& std );
00235 dvariable dlnorm( const dvar_vector& x, const prevariable& mu, const prevariable& std );
00236
00237
00238 dvariable dpois(const double& k, const prevariable& lambda);
00239 dvariable dpois(const prevariable& k, const prevariable& lambda);
00240
00241
00242 dvariable dmultinom(const dvector& x, const dvar_vector& p);
00243
00244 dvariable dmultinom(const dmatrix o, const dvar_matrix& p,dvar_matrix& nu,double& tau2,const double minp);
00245 double neff(const dvector& obs, const dvar_vector& pred);
00246
00247
00248 dvariable dmvlogistic(const dmatrix o, const dvar_matrix& p,dvar_matrix& nu, double& tau2,const double minp);
00249 dvariable dmvlogistic(const dmatrix o, const dvar_matrix& p, double& tau2);
00250
00251
00252 dvector rmvlogistic(const dvector& p, const double& tau2, const int& seed);
00253
00254
00255 dvariable multifan(const dmatrix oprop,const dvar_matrix& pprop, const int& Nsamp);
00256 dvariable multifan(const int& n, const dmatrix obs, const dvar_matrix pred,double& nef);
00257 dvariable multifan(const double& s,const dvector obsQ,const dvar_vector& preQ, double& nmle);
00258
00259
00260
00261 typedef vcubic_spline_function * pvcubic_spline_function;
00262
00269 class vcubic_spline_function_array
00270 {
00271 public:
00272
00273 int indexmin(void) {return index_min;}
00274 int indexmax(void) {return index_max;}
00275
00276
00277 vcubic_spline_function_array(int,int,const dvector & x, const dvar_matrix& _y);
00278 vcubic_spline_function_array(const dvector & x);
00279 vcubic_spline_function_array(const vcubic_spline_function_array&);
00280
00281
00282 ~vcubic_spline_function_array();
00283
00284
00285 vcubic_spline_function & operator () (int i);
00286 dvar_matrix operator( ) (const dvector & v);
00287
00288 private:
00289 vcubic_spline_function ** ptr;
00290 int index_min;
00291 int index_max;
00292 };
00293
00294 void bicubic_spline(const dvector& x, const dvector& y, dvar_matrix& knots, dvar_matrix& S);
00295
00296 dvar_vector cubic_spline(const dvar_vector& spline_nodes, const dvar_vector& ip);
00297
00298 dvariable splin2(const dvector& _x1a,const dvector& _x2a, const dvar_matrix _ya,dvar_matrix& _y2a, const double& x1,const double& x2);
00299
00300 dvar_matrix splie2(const dvector& _x1a,const dvector& _x2a,const dvar_matrix& _ya);
00301
00302 dvar_vector spline(const dvector &_x,const dvar_vector&_y,double yp1,double ypn);
00303 dvariable splint(const dvector& _xa,const dvar_vector& _ya, const dvar_vector& _y2a,double x);
00304
00321 #endif
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338