Functions created at the Quantitative Fisheries Center(QFC), Michigan State University.
User-Contributed Libraries.

Files

file  qfc_est.cpp

negative log likelihood functions with other functions useful for model estimation

file  qfc_sim.cpp

functions useful for simulation model in admb

Functions

dvar_vector boundp (const dvar_vector &x, const double fmin, const double fmax, const dvariable &fpen)

bool doubleEqual (double nVal1, double nVal2, int nPrecision)
determine if two double values are equal within some precision
find the number of values(numVals) for one specific variable(varName) from an admb output file
dvar_vector invLogitProp (const dvar_vector &p)
reverse function for LogitProp
df1b2vector log_comb (const df1b2vector &n, const df1b2vector &x)
overloading function for log_comb(n choose x) for randome effect, used in nllBinomial below, ADMB built in function log_comb() not for vector type in RE
dvar_vector logitProp (const dvar_vector &a)
constrain probability vector as 1 and I forgot who create this first, may give credit to Punt., let logit(p)=log(p/(1-p))=a, so p=exp(a)/(1+exp(a)) ~[0,1]
dvector matrix2vector (const dmatrix &input, int byrow=1)
convert the matrix as a vector eithter by row=1(default) or by column=0,
dvar_vector matrix2vector (const dvar_matrix &input, int byrow=1)
convert the matrix as a vector eithter by row=1(default) or by column=0, overloading function
df1b2vector matrix2vector (const df1b2matrix &input, int byrow=1)
convert the matrix as a vector eithter by row=1(default) or by column=0, overloading function
dvariable mf_upper_bound2 (const dvariable &x, const double fmax, dvariable &fpen)
constrain parameter with upper threshold, if return bigger than it, then with penalty ADMB have built in function mf_upper_bound(), which have more constrain on the values higher than the bounds with bigger penalty than this version
double nllBeta (const double x, const double a, const double b)
nll for beta for one sample
df1b2variable nllBeta (const df1b2variable &x, const double a, const double b)
nll for beta for one sample for random effect
dvariable nllBeta (const dvar_vector &x, const double a, const double b)
nll for beta for many samples
df1b2variable nllBeta (const df1b2vector &x, const double a, const double b)
nll for beta for many samples for random effect
double nllBinomial (const double x, const double n, const double p)
nll for binomial for one sample
df1b2variable nllBinomial (const df1b2variable &x, const double n, const double p)
nll for binomial for one sample for random effect
dvariable nllBinomial (const dvar_vector &x, const dvector &n, const double p)
nll for binomial for many samples
df1b2variable nllBinomial (const dvector &x, const df1b2vector &n, const df1b2variable &p)
nll for binomial for many samples for random effect
double nllDirichlet (const dvector &p, const dvector &shape)
nll for dirichlet for one sample
df1b2variable nllDirichlet (const df1b2vector &p, const dvector &shape)
nll for dirichlet for one sample for random effect
double nllGamma (const double &x, const double a, const double b)
nll for gamma for one sample Gamma(a,b) similar to log_gamma_density(r,mu) in admb, in which a=r, b=mu
df1b2variable nllGamma (const df1b2variable &x, const double a, const double b)
nll for gamma for one sample for random effect Gamma(a,b) similar to log_gamma_density(r,mu) in admb, in which a=r, b=mu
double nllGamma (const dvector &x, const double a, const double b)
nll for gamma for many samples
df1b2variable nllGamma (const df1b2vector &x, const double a, const double b)
nll for gamma for many samples for random effect
double nllInverseGamma (const double x, const double a, const double b)
nll for inverse gamma for one sample
df1b2variable nllInverseGamma (const df1b2variable &x, const double a, const double b)
nll for inverse gamma for one sample for random effect
dvariable nllInverseGamma (const dvar_vector &x, const double a, const double b)
nll for inverse gamma for many samples
df1b2variable nllInverseGamma (const dvector &x, const df1b2variable &a, const df1b2variable &b)
nll for inverse gamma for many samples for random effect
double nllLognormal (const double x, const double mu, const double sigma)
nll for lognormal for one sample
df1b2variable nllLognormal (const df1b2variable &x, const double mu, const double sigma)
nll for lognormal for one sample for random effect
dvariable nllLognormal (const dvar_vector &x, const double mu, const double sigma)
nll for lognormal for many samples
df1b2variable nllLognormal (const df1b2vector &x, const double mu, const double sigma)
nll for lognormal for many samples for random effect
dvariable nllLognormal (const dvar_vector &x, const dvector &mu, const double sigma)
nll for lognormal for many samples, each has its mean
df1b2variable nllLognormal (const df1b2vector &x, const dvector &mu, const double sigma)
nll for lognormal for many samples, each has its mean, for random effect
dvariable nllLognormal2 (const double x, const dvariable &mu, const dvariable &tau)
nll for lognormal(mu,tau) for one sample
df1b2variable nllLognormal2 (const df1b2variable x, const double mu, const double tau)
nll for lognormal(mu,tau) for one sample for random effect
dvariable nllLognormal2 (const dvar_vector &x, const double mu, const double tau)
nll for lognormal(mu,tau) for many samples
df1b2variable nllLognormal2 (const dvector &x, const df1b2variable &mu, const df1b2variable &tau)
nll for lognormal(mu,tau) for many samples for random effect
dvariable nllLognormal2 (const dvar_vector &x, const dvector &mu, const double tau)
nll for lognormal(mu,tau) for many samples, each has its mean
df1b2variable nllLognormal2 (const df1b2vector &x, const dvector &mu, const double tau)
nll for lognormal(mu,tau) for many samples, each has its mean, overload for random effect,
double nllMultiNomial (const dvector &obsN, const dvector &p)
nll for Multinomial for one sample
df1b2variable nllMultiNomial (const df1b2vector &obsN, const dvector &p)
nll for Multinomial for one sample for random effect
double nllNegativeBinomial (const double obs, const double m, const double s)
nll for negative binomial N(m,s) for one sample, admb built in log_negbinomial_density(obs,mu,tau), in which tau=1.
df1b2variable nllNegativeBinomial (const df1b2variable &obs, const double m, const double s)
nll for negative binomial N(m,s) for one sample,overload for random effect, admb built in log_negbinomial_density(obs,mu,tau), in which tau=1.
dvariable nllNegativeBinomial (const dvector &obs, const dvariable &m, const dvariable &s)
nll for negative binomial N(m,s) for many samples, admb built in log_negbinomial_density(obs,mu,tau), in which tau=1.
df1b2variable nllNegativeBinomial (const df1b2vector &obs, const double m, const double s)
nll for negative binomial N(m,s) for many samples, overload for random effect, admb built in log_negbinomial_density(obs,mu,tau), in which tau=1.
double nllNegativeBinomial2 (const double obs, const double m, const double tau)
nll for negative binomial N(mu,tau) for one sample, admb built in log_negbinomial_density(obs,mu,tau), in which tau=1.
df1b2variable nllNegativeBinomial2 (const df1b2variable &obs, const double m, const double tau)
nll for negative binomial N(mu,tau) for one sample,overload for random effect admb built in log_negbinomial_density(obs,mu,tau), in which tau=1.
double nllNormal (const double x, const double mu, const double sigma)
nll for normal for one sample
df1b2variable nllNormal (const df1b2variable &x, const double mu, const double sigma)
nll for normal for one sample for random effect
double nllNormal (const dvector &x, const double mu, const double sigma)
nll for normal for many samples, but mu is for common
df1b2variable nllNormal (const df1b2vector &x, const double mu, const double sigma)
nll for normal for many samples, but mu is for common, overload for random effect
dvariable nllNormal (const dvar_vector &x, const dvector &mu, const double sigma)
nll for normal for many samples, each has its own mean
df1b2variable nllNormal (const df1b2vector &x, const dvector &mu, const double sigma)
nll for normal for many samples, each has its own mean for random effect
dvariable nllNormal2 (const dvariable &x, const double mu, const double tau)
nll for normal(mu,tau) for one sample
df1b2variable nllNormal2 (const df1b2variable &x, const double mu, const double tau)
nll for normal(mu,tau) for one sample for random effect
dvariable nllNormal2 (const dvar_vector &x, const double mu, const double tau)
nll for normal(mu,tau) for many samples
df1b2variable nllNormal2 (const df1b2vector &x, const double mu, const double tau)
nll for normal(mu,tau) for many samples for random effect
dvariable nllNormal2 (const dvar_vector &x, const dvector &mu, const double tau)
nll for normal(mu,tau) for many samples, each has its own mean
df1b2variable nllNormal2 (const df1b2vector &x, const dvector &mu, const double tau)
nll for normal(mu,tau) for many samples, each has its own mean, overload for random effect,
double nllPoisson (const double x, const double lambda)
nll for poisson for one sample
df1b2variable nllPoisson (const df1b2variable &x, const double lambda)
nll for poisson for one sample for random effect
dvariable nllPoisson (const dvar_vector &x, const double lambda)
nll for poisson for many samples
df1b2variable nllPoisson (const dvector &x, const df1b2variable &lambda)
nll for poisson for many samples for random effect
dvar_vector normalize_p (dvar_vector &p, dvariable fpen)
normailize p as sum(p)=1, return p and penalty if sum(p)!=1
get how many rows for one specific variable(varName) in admb output file(filename)
dvar_vector posfun (dvar_vector &x, const dvector &eps, dvariable &pen)
dvar_matrix posfun (dvar_matrix &x, const dmatrix &eps, dvariable &pen)
double rbeta (double alpha, double beta, random_number_generator &rng)
generate random beta(alpha, beta) number,
dvector rdirichlet (const dvector &shape, random_number_generator &rng)
generate random dirichlet number
double rgamma (double alpha, random_number_generator &rng)
generate random gamma number, pseudo code see http://en.wikipedia.org/wiki/Gamma_distribution , Gamma(alpha, belta)=x^(alpha-1)*belta^alpha*exp(-belta*x)/gamma(alpha)
double rgamma (double alpha, double beta, random_number_generator &rng)
generate random gamma number, mean is alpha/belta, variance is alpha/(belta^2)
double rlnorm (double mu, double sigma, random_number_generator &rng)
generate one random lognormal number LN(mu,sigma)
double rnorm (double mu, double sigma, random_number_generator &rng)
generate one random normal number N(mu,sigma)
double runif (double low, double upper, random_number_generator &rng)
generate one random uniform from (low,upper)
ivector sample (const dvector &source, int nSample, int withReplace, const random_number_generator &rng)
generate a random sample index(size is nSample) based on the input samples(source) with or without replacement
dvector unique (const dvector &in)
find the unique values from input vector and only return the unique (by remove the duplicate) values in ascending order
dmatrix vector2matrix (dvector &input, int nrow, int ncol, int byrow=1)
convert the Vector as a Matrix eithter by row=1(default) or by column=0,
df1b2matrix vector2matrix (df1b2vector &input, int nrow, int ncol, int byrow=1)
convert the Vector as a Matrix eithter by row=1(default) or by column=0, overloading function
dvar_matrix vector2matrix (const dvar_vector &input, int nrow, int ncol, int byrow=1)
convert the Vector as a Matrix eithter by row=1(default) or by column=0, overloading function

Detailed Description

Contributed by Weihai Liu

Function Documentation

 dvar_vector boundp ( const dvar_vector & x, const double fmin, const double fmax, const dvariable & fpen )

Parameters:
 x : being constrained input value fmin : lower bound value fmax : upper bound value fpen : hold extra penalty, need add to objective function value later
Returns:
return value within the bounds (fmin,fmax) without penalty or return outbouds value with fpen

Definition at line 238 of file qfc_est.cpp.

 bool doubleEqual ( double nVal1, double nVal2, int nPrecision )

determine if two double values are equal within some precision

Parameters:
 nVal1 : double value used for comparison nVal2 : another double value used for comparison nPrecision : the number of decimals
Returns:
return true/false for two double values compare based on some specific number of decimals

Definition at line 383 of file qfc_sim.cpp.

find the number of values(numVals) for one specific variable(varName) from an admb output file

Parameters:
 filename : search for admb output file name varName : variable name being searched for numVals : number of values following that specific variable names for return
Returns:
return the found number of values for that variable name, if having unique name, then return one row matrix if having same name, return several rows matrix

Definition at line 74 of file qfc_sim.cpp.

 dvar_vector invLogitProp ( const dvar_vector & p )

reverse function for LogitProp

Parameters:
 p : the prob. vector
Returns:
return the a, one element less than input p

Definition at line 77 of file qfc_est.cpp.

 df1b2vector log_comb ( const df1b2vector & n, const df1b2vector & x )

overloading function for log_comb(n choose x) for randome effect, used in nllBinomial below, ADMB built in function log_comb() not for vector type in RE

Parameters:
 n : number of trials x : number of selected trial
Returns:
return n choose x

Definition at line 266 of file qfc_est.cpp.

 dvar_vector logitProp ( const dvar_vector & a )

constrain probability vector as 1 and I forgot who create this first, may give credit to Punt., let logit(p)=log(p/(1-p))=a, so p=exp(a)/(1+exp(a)) ~[0,1]

Parameters:
 a : defined as real number without bounds in parameter_section, one element less than return p
Returns:
return the prob. vector p in procedure_section

Definition at line 46 of file qfc_est.cpp.

 dvector matrix2vector ( const dmatrix & input, int byrow = 1 )

convert the matrix as a vector eithter by row=1(default) or by column=0,

Parameters:
 input : the matrix being converted, can also be ragged matrix byrow : default as by row, use 1, anynumber other than 1 as by column
Returns:
return a vector which index starting from 1

Definition at line 208 of file qfc_sim.cpp.

 dvar_vector matrix2vector ( const dvar_matrix & input, int byrow = 1 )

convert the matrix as a vector eithter by row=1(default) or by column=0, overloading function

Parameters:
 input : the matrix being converted, can also be ragged matrix byrow : default as by row, use 1, anynumber other than 1 as by column
Returns:
return a vector which index starting from 1

Definition at line 232 of file qfc_sim.cpp.

 df1b2vector matrix2vector ( const df1b2matrix & input, int byrow = 1 )

convert the matrix as a vector eithter by row=1(default) or by column=0, overloading function

Parameters:
 input : the matrix being converted, can also be ragged matrix byrow : default as by row, use 1, anynumber other than 1 as by column
Returns:
return a vector which index starting from 1

Definition at line 256 of file qfc_sim.cpp.

 dvariable mf_upper_bound2 ( const dvariable & x, const double fmax, dvariable & fpen )

constrain parameter with upper threshold, if return bigger than it, then with penalty ADMB have built in function mf_upper_bound(), which have more constrain on the values higher than the bounds with bigger penalty than this version

Parameters:
 x : mean parameter fmax : upper threshold or maximum value, be positive fpen : penalty
Returns:
return itself without penalty if input value <fmax , or return ajusted value which >fmax but with penalty

Definition at line 205 of file qfc_est.cpp.

 double nllBeta ( const double x, const double a, const double b )

nll for beta for one sample

Parameters:
 x : data a : alpha parameter,>0 b : beta parameter,>0
Returns:
return the nll for beta for one sample

Definition at line 880 of file qfc_est.cpp.

 df1b2variable nllBeta ( const df1b2variable & x, const double a, const double b )

nll for beta for one sample for random effect

Parameters:
 x : data a : alpha parameter,>0 b : beta parameter,>0
Returns:
return the nll for beta for one sample

Definition at line 935 of file qfc_est.cpp.

 dvariable nllBeta ( const dvar_vector & x, const double a, const double b )

nll for beta for many samples

Parameters:
 x : data a : alpha parameter b : beta parameter
Returns:
return the nll for beta for many samples

Definition at line 976 of file qfc_est.cpp.

 df1b2variable nllBeta ( const df1b2vector & x, const double a, const double b )

nll for beta for many samples for random effect

Parameters:
 x : data a : alpha parameter b : beta parameter
Returns:
return the nll for beta for many samples

Definition at line 1012 of file qfc_est.cpp.

 double nllBinomial ( const double x, const double n, const double p )

nll for binomial for one sample

Parameters:
 x : data n : number of trials p : probability
Returns:
return the nll for binomial for one samples

Definition at line 1508 of file qfc_est.cpp.

 df1b2variable nllBinomial ( const df1b2variable & x, const double n, const double p )

nll for binomial for one sample for random effect

Parameters:
 x : data n : number of trials p : probability
Returns:
return the nll for binomial for one samples

Definition at line 1547 of file qfc_est.cpp.

 dvariable nllBinomial ( const dvar_vector & x, const dvector & n, const double p )

nll for binomial for many samples

Parameters:
 x : data n : number of trials p : probability
Returns:
return the nll for binomial for many samples

Definition at line 1577 of file qfc_est.cpp.

 df1b2variable nllBinomial ( const dvector & x, const df1b2vector & n, const df1b2variable & p )

nll for binomial for many samples for random effect

Parameters:
 x : data n : number of trials p : probability
Returns:
return the nll for binomial for many samples

Definition at line 1610 of file qfc_est.cpp.

 double nllDirichlet ( const dvector & p, const dvector & shape )

nll for dirichlet for one sample

Parameters:
 p : observation proportion, sum as 1 shape : alpha parameter, >0
Returns:
return the nll for dirichlet for one sample

Definition at line 628 of file qfc_est.cpp.

 df1b2variable nllDirichlet ( const df1b2vector & p, const dvector & shape )

nll for dirichlet for one sample for random effect

Parameters:
 p : observation proportion, sum as 1 shape : alpha parameter, >0
Returns:
return the nll for dirichlet for one sample

Definition at line 666 of file qfc_est.cpp.

 double nllGamma ( const double & x, const double a, const double b )

nll for gamma for one sample Gamma(a,b) similar to log_gamma_density(r,mu) in admb, in which a=r, b=mu

Parameters:
 x : data a : alpha parameter,also call shape,>0 b : beta parameter,also call rate,>0
Returns:
return the nll for gamma for one sample

Definition at line 703 of file qfc_est.cpp.

 df1b2variable nllGamma ( const df1b2variable & x, const double a, const double b )

nll for gamma for one sample for random effect Gamma(a,b) similar to log_gamma_density(r,mu) in admb, in which a=r, b=mu

Parameters:
 x : data a : alpha parameter,>0 b : beta parameter,>0
Returns:
return the nll for gamma for one sample

Definition at line 757 of file qfc_est.cpp.

 double nllGamma ( const dvector & x, const double a, const double b )

nll for gamma for many samples

Parameters:
 x : data a : alpha parameter,>0 b : beta parameter,>0
Returns:
return the nll for gamma for many samples

Definition at line 798 of file qfc_est.cpp.

 df1b2variable nllGamma ( const df1b2vector & x, const double a, const double b )

nll for gamma for many samples for random effect

Parameters:
 x : data a : alpha parameter,>0 b : beta parameter,>0
Returns:
return the nll for gamma for many samples

Definition at line 841 of file qfc_est.cpp.

 double nllInverseGamma ( const double x, const double a, const double b )

nll for inverse gamma for one sample

Parameters:
 x : data a : alpha parameter,>0 b : beta parameter,>0
Returns:
return the nll for inverse gamma for one sample

Definition at line 2269 of file qfc_est.cpp.

 df1b2variable nllInverseGamma ( const df1b2variable & x, const double a, const double b )

nll for inverse gamma for one sample for random effect

Parameters:
 x : data a : alpha parameter,>0 b : beta parameter,>0
Returns:
return the nll for inverse gamma for one sample

Definition at line 2308 of file qfc_est.cpp.

 dvariable nllInverseGamma ( const dvar_vector & x, const double a, const double b )

nll for inverse gamma for many samples

Parameters:
 x : data a : alpha parameter,>0 b : beta parameter,>0
Returns:
return the nll for inverse gamma for many samples

Definition at line 2350 of file qfc_est.cpp.

 df1b2variable nllInverseGamma ( const dvector & x, const df1b2variable & a, const df1b2variable & b )

nll for inverse gamma for many samples for random effect

Parameters:
 x : data a : alpha parameter,>0 b : beta parameter,>0
Returns:
return the nll for inverse gamma for many samples

Definition at line 2386 of file qfc_est.cpp.

 double nllLognormal ( const double x, const double mu, const double sigma )

nll for lognormal for one sample

Parameters:
 x : data mu : mean parameter sigma : std deviation parameter
Returns:
return the nll for lognormal for one sample

Definition at line 1650 of file qfc_est.cpp.

 df1b2variable nllLognormal ( const df1b2variable & x, const double mu, const double sigma )

nll for lognormal for one sample for random effect

Parameters:
 x : data mu : mean parameter sigma : std deviation parameter
Returns:
return the nll for lognormal for one sample

Definition at line 1705 of file qfc_est.cpp.

 dvariable nllLognormal ( const dvar_vector & x, const double mu, const double sigma )

nll for lognormal for many samples

Parameters:
 x : data mu : mean parameter sigma : std deviation parameter
Returns:
return the nll for lognormal for many samples

Definition at line 1747 of file qfc_est.cpp.

 df1b2variable nllLognormal ( const df1b2vector & x, const double mu, const double sigma )

nll for lognormal for many samples for random effect

Parameters:
 x : data mu : mean parameter sigma : std deviation parameter
Returns:
return the nll for lognormal for many samples

Definition at line 1783 of file qfc_est.cpp.

 dvariable nllLognormal ( const dvar_vector & x, const dvector & mu, const double sigma )

nll for lognormal for many samples, each has its mean

Parameters:
 x : data mu : mean parameter sigma : std deviation parameter
Returns:
return the nll for lognormal for many samples

Definition at line 1815 of file qfc_est.cpp.

 df1b2variable nllLognormal ( const df1b2vector & x, const dvector & mu, const double sigma )

nll for lognormal for many samples, each has its mean, for random effect

Parameters:
 x : data mu : mean parameter sigma : std deviation parameter
Returns:
return the nll for lognormal for many samples

Definition at line 1851 of file qfc_est.cpp.

 dvariable nllLognormal2 ( const double x, const dvariable & mu, const dvariable & tau )

nll for lognormal(mu,tau) for one sample

Parameters:
 x : data mu : mean parameter tau : precision parameter, 1/variance
Returns:
return the nll for lognormal for one sample

Definition at line 1892 of file qfc_est.cpp.

 df1b2variable nllLognormal2 ( const df1b2variable x, const double mu, const double tau )

nll for lognormal(mu,tau) for one sample for random effect

Parameters:
 x : data mu : mean parameter tau : precision parameter, 1/variance
Returns:
return the nll for lognormal for one sample

Definition at line 1925 of file qfc_est.cpp.

 dvariable nllLognormal2 ( const dvar_vector & x, const double mu, const double tau )

nll for lognormal(mu,tau) for many samples

Parameters:
 x : data mu : mean parameter tau : precision parameter, 1/variance
Returns:
return the nll for lognormal for many samples

Definition at line 1967 of file qfc_est.cpp.

 df1b2variable nllLognormal2 ( const dvector & x, const df1b2variable & mu, const df1b2variable & tau )

nll for lognormal(mu,tau) for many samples for random effect

Parameters:
 x : data mu : mean parameter tau : precision parameter, 1/variance
Returns:
return the nll for lognormal for many samples

Definition at line 2003 of file qfc_est.cpp.

 dvariable nllLognormal2 ( const dvar_vector & x, const dvector & mu, const double tau )

nll for lognormal(mu,tau) for many samples, each has its mean

Parameters:
 x : data mu : mean parameter tau : precision parameter, 1/variance
Returns:
return the nll for lognormal for many samples

Definition at line 2050 of file qfc_est.cpp.

 df1b2variable nllLognormal2 ( const df1b2vector & x, const dvector & mu, const double tau )

nll for lognormal(mu,tau) for many samples, each has its mean, overload for random effect,

Parameters:
 x : data mu : mean parameter tau : precision parameter, 1/variance
Returns:
return the nll for lognormal for many samples

Definition at line 2086 of file qfc_est.cpp.

 double nllMultiNomial ( const dvector & obsN, const dvector & p )

nll for Multinomial for one sample

Parameters:
 obsN : observation data p : proportion vector, sum as 1
Returns:
return the nll for Multinomial for one sample

Definition at line 555 of file qfc_est.cpp.

 df1b2variable nllMultiNomial ( const df1b2vector & obsN, const dvector & p )

nll for Multinomial for one sample for random effect

Parameters:
 obsN : observation data p : proportion vector, sum as 1
Returns:
return the nll for Multinomial for one sample

Definition at line 593 of file qfc_est.cpp.

 double nllNegativeBinomial ( const double obs, const double m, const double s )

nll for negative binomial N(m,s) for one sample, admb built in log_negbinomial_density(obs,mu,tau), in which tau=1.

+mu/s for NB(m,s), winbug use NB(p,r), in which p=s/(m+s) and r=s,

Parameters:
 obs : observation data x m : mean s : scaling factor, some use r NB(p,r)
Returns:
return the nll for neg. binomial for one sample

Definition at line 310 of file qfc_est.cpp.

Referenced by nllNegativeBinomial2().

 df1b2variable nllNegativeBinomial ( const df1b2variable & obs, const double m, const double s )

nll for negative binomial N(m,s) for one sample,overload for random effect, admb built in log_negbinomial_density(obs,mu,tau), in which tau=1.

+mu/s for NB(m,s), winbug use NB(p,r), in which p=s/(m+s) and r=s,

Parameters:
 obs : observation data x m : mean s : scaling factor, some use r NB(p,r)
Returns:
return the nll for neg. binomial for one sample

Definition at line 367 of file qfc_est.cpp.

 dvariable nllNegativeBinomial ( const dvector & obs, const dvariable & m, const dvariable & s )

nll for negative binomial N(m,s) for many samples, admb built in log_negbinomial_density(obs,mu,tau), in which tau=1.

+mu/s for NB(m,s), winbug use NB(p,r), in which p=s/(m+s) and r=s,

Parameters:
 obs : observation data m : mean s : scaling factor
Returns:
return the nll for neg. binomial for many samples

Definition at line 412 of file qfc_est.cpp.

 df1b2variable nllNegativeBinomial ( const df1b2vector & obs, const double m, const double s )

nll for negative binomial N(m,s) for many samples, overload for random effect, admb built in log_negbinomial_density(obs,mu,tau), in which tau=1.

+mu/s for NB(m,s), winbug use NB(p,r), in which p=s/(m+s) and r=s,

Parameters:
 obs : observation data m : mean s : scaling factor
Returns:
return the nll for neg. binomial for many samples

Definition at line 450 of file qfc_est.cpp.

 double nllNegativeBinomial2 ( const double obs, const double m, const double tau )

nll for negative binomial N(mu,tau) for one sample, admb built in log_negbinomial_density(obs,mu,tau), in which tau=1.

+mu/s for NB(m,s), winbug us NB(p,r), in which p=s/(m+s) and r=s,

Parameters:
 obs : observation data m : mean tau : overdispersion parameter,
Returns:
return the nll for neg. binomial for one sample

Definition at line 490 of file qfc_est.cpp.

 df1b2variable nllNegativeBinomial2 ( const df1b2variable & obs, const double m, const double tau )

nll for negative binomial N(mu,tau) for one sample,overload for random effect admb built in log_negbinomial_density(obs,mu,tau), in which tau=1.

+mu/s for NB(m,s), winbug us NB(p,r), in which p=s/(m+s) and r=s,

Parameters:
 obs : observation data m : mean tau : overdispersion parameter,
Returns:
return the nll for neg. binomial for one sample

Definition at line 524 of file qfc_est.cpp.

 double nllNormal ( const double x, const double mu, const double sigma )

nll for normal for one sample

Parameters:
 x : data mu : mean parameter sigma : std deviation parameter
Returns:
return the nll for normal for one sample

Definition at line 1051 of file qfc_est.cpp.

 df1b2variable nllNormal ( const df1b2variable & x, const double mu, const double sigma )

nll for normal for one sample for random effect

Parameters:
 x : data mu : mean parameter sigma : std deviation parameter
Returns:
return the nll for normal for one sample

Definition at line 1106 of file qfc_est.cpp.

 double nllNormal ( const dvector & x, const double mu, const double sigma )

nll for normal for many samples, but mu is for common

Parameters:
 x : data mu : mean parameter sigma : std deviation parameter
Returns:
return the nll for normal for many samples sharing one mu

Definition at line 1147 of file qfc_est.cpp.

 df1b2variable nllNormal ( const df1b2vector & x, const double mu, const double sigma )

nll for normal for many samples, but mu is for common, overload for random effect

Parameters:
 x : data mu : mean parameter sigma : std deviation parameter
Returns:
return the nll for normal for many samples sharing one mu

Definition at line 1190 of file qfc_est.cpp.

 dvariable nllNormal ( const dvar_vector & x, const dvector & mu, const double sigma )

nll for normal for many samples, each has its own mean

Parameters:
 x : data mu : mean parameter sigma : std deviation parameter
Returns:
return the nll for normal for many samples, each has own mean

Definition at line 1222 of file qfc_est.cpp.

 df1b2variable nllNormal ( const df1b2vector & x, const dvector & mu, const double sigma )

nll for normal for many samples, each has its own mean for random effect

Parameters:
 x : data mu : mean parameter sigma : std deviation parameter
Returns:
return the nll for normal for many samples, each has own mean

Definition at line 1258 of file qfc_est.cpp.

 dvariable nllNormal2 ( const dvariable & x, const double mu, const double tau )

nll for normal(mu,tau) for one sample

Parameters:
 x : data mu : mean parameter tau : precision, 1/variance
Returns:
return the nll for normal for one sample

Definition at line 1299 of file qfc_est.cpp.

 df1b2variable nllNormal2 ( const df1b2variable & x, const double mu, const double tau )

nll for normal(mu,tau) for one sample for random effect

Parameters:
 x : data mu : mean parameter tau : precision, 1/variance
Returns:
return the nll for normal for one sample

Definition at line 1332 of file qfc_est.cpp.

 dvariable nllNormal2 ( const dvar_vector & x, const double mu, const double tau )

nll for normal(mu,tau) for many samples

Parameters:
 x : data mu : mean parameter tau : precision, 1/variance
Returns:
return the nll for normal for many samples

Definition at line 1362 of file qfc_est.cpp.

 df1b2variable nllNormal2 ( const df1b2vector & x, const double mu, const double tau )

nll for normal(mu,tau) for many samples for random effect

Parameters:
 x : data mu : mean parameter tau : precision, 1/variance
Returns:
return the nll for normal for many samples

Definition at line 1398 of file qfc_est.cpp.

 dvariable nllNormal2 ( const dvar_vector & x, const dvector & mu, const double tau )

nll for normal(mu,tau) for many samples, each has its own mean

Parameters:
 x : data mu : mean parameter tau : precision, 1/variance
Returns:
return the nll for normal for many samples, each has own mean

Definition at line 1430 of file qfc_est.cpp.

 df1b2variable nllNormal2 ( const df1b2vector & x, const dvector & mu, const double tau )

nll for normal(mu,tau) for many samples, each has its own mean, overload for random effect,

Parameters:
 x : data mu : mean parameter tau : precision, 1/variance
Returns:
return the nll for normal for many samples, each has own mean

Definition at line 1466 of file qfc_est.cpp.

 double nllPoisson ( const double x, const double lambda )

nll for poisson for one sample

Parameters:
 x : data lambda : mean parameter
Returns:
return the nll for poisson for one sample

Definition at line 2127 of file qfc_est.cpp.

 df1b2variable nllPoisson ( const df1b2variable & x, const double lambda )

nll for poisson for one sample for random effect

Parameters:
 x : data lambda : mean parameter
Returns:
return the nll for poisson for one sample

Definition at line 2165 of file qfc_est.cpp.

 dvariable nllPoisson ( const dvar_vector & x, const double lambda )

nll for poisson for many samples

Parameters:
 x : data lambda : mean parameter
Returns:
return the nll for poisson for many samples

Definition at line 2193 of file qfc_est.cpp.

 df1b2variable nllPoisson ( const dvector & x, const df1b2variable & lambda )

nll for poisson for many samples for random effect

Parameters:
 x : data lambda : mean parameter
Returns:
return the nll for poisson for many samples

Definition at line 2228 of file qfc_est.cpp.

 dvar_vector normalize_p ( dvar_vector & p, dvariable fpen )

normailize p as sum(p)=1, return p and penalty if sum(p)!=1

Parameters:
 p : the prob. vector fpen : penalty
Returns:
return p as sum(p)=1 the a, one element less than input p

Definition at line 110 of file qfc_est.cpp.

get how many rows for one specific variable(varName) in admb output file(filename)

Parameters:
 filename : search for admb output file name varName : variable name being searched for
Returns:
return 1 for unique name or many rows for same name , return 0 for not found

Definition at line 40 of file qfc_sim.cpp.

Referenced by findValFromFile().

 dvar_vector posfun ( dvar_vector & x, const dvector & eps, dvariable & pen )

Parameters:
 x : being constrained input value eps : positive vector as lower thresholds pen : hold extra penalty, need add to objective function value later
Returns:
return value between (0,eps) with penalty fpen for input x< eps, or return x itself if x>=eps with no penalty

Definition at line 137 of file qfc_est.cpp.

 dvar_matrix posfun ( dvar_matrix & x, const dmatrix & eps, dvariable & pen )

Parameters:
 x : being constrained input value eps : positive vector as lower thresholds pen : hold extra penalty, need add to objective function value later
Returns:
return value between (0,eps) with penalty fpen for input x< eps, or return x itself if x>=eps with no penalty

Definition at line 167 of file qfc_est.cpp.

 double rbeta ( double alpha, double beta, random_number_generator & rng )

generate random beta(alpha, beta) number,

Parameters:
 alpha : alpha parameter beta : beta parameter rng : admb build in random number generator
Returns:
return beta random number

Definition at line 511 of file qfc_sim.cpp.

 dvector rdirichlet ( const dvector & shape, random_number_generator & rng )

generate random dirichlet number

Parameters:
 shape : shape parameter rng : admb build in random number generator
Returns:
return dirichlet random number

Definition at line 524 of file qfc_sim.cpp.

 double rgamma ( double alpha, random_number_generator & rng )

generate random gamma number, pseudo code see http://en.wikipedia.org/wiki/Gamma_distribution , Gamma(alpha, belta)=x^(alpha-1)*belta^alpha*exp(-belta*x)/gamma(alpha)

Parameters:
 alpha : shape parameter, >0 =1/CV^2 rng : admb build in random number generator
Returns:
return gamma random number

Definition at line 449 of file qfc_sim.cpp.

Referenced by rbeta(), rdirichlet(), and rgamma().

 double rgamma ( double alpha, double beta, random_number_generator & rng )

generate random gamma number, mean is alpha/belta, variance is alpha/(belta^2)

Parameters:
 alpha : shape parameter, >0 =1/CV^2 beta : rate =1/scale,inverse of the scale parameter, >0 =1/(mean*CV^2) rng : admb build in random number generator
Returns:
return gamma random number

Definition at line 497 of file qfc_sim.cpp.

 double rlnorm ( double mu, double sigma, random_number_generator & rng )

generate one random lognormal number LN(mu,sigma)

Parameters:
 mu : mean sigma : std. deviation rng : admb build in random number generator
Returns:
return lognormal random number LN(mu,sigma)

Definition at line 433 of file qfc_sim.cpp.

 double rnorm ( double mu, double sigma, random_number_generator & rng )

generate one random normal number N(mu,sigma)

Parameters:
 mu : mean sigma : std. deviation rng : admb build in random number generator
Returns:
return normal random number N(mu,sigma)

Definition at line 418 of file qfc_sim.cpp.

 double runif ( double low, double upper, random_number_generator & rng )

generate one random uniform from (low,upper)

Parameters:
 low : low range upper : high range rng : admb build in random number generator
Returns:
return uniform random number within range (low, upper)

Definition at line 403 of file qfc_sim.cpp.

 ivector sample ( const dvector & source, int nSample, int withReplace, const random_number_generator & rng )

generate a random sample index(size is nSample) based on the input samples(source) with or without replacement

Parameters:
 source : baseline samples as input nSample : random sample size for output withReplace : if 0 for without replacement, nonzero means with replacement rng : admb build in random number generator
Returns:
return an index vector which are the index from the samples, if want to access the values, use return dvector version

Definition at line 171 of file qfc_sim.cpp.

 dvector unique ( const dvector & in )

find the unique values from input vector and only return the unique (by remove the duplicate) values in ascending order

Parameters:
 in : contain duplicate values in the input vector
Returns:
return a vector comprised of unique values in ascending order and its index starting from 1

Definition at line 127 of file qfc_sim.cpp.

 dmatrix vector2matrix ( dvector & input, int nrow, int ncol, int byrow = 1 )

convert the Vector as a Matrix eithter by row=1(default) or by column=0,

Parameters:
 input : long vector/array being converted nrow : the number of rows for output matrix ncol : the number of columns for output matrix byrow : default as by row, use 1, which fill the each row from top to bottom Or any number other than 1 as by column, which fill each column from left to right
Returns:
return a matrix which row and column index all starting from 1

Definition at line 286 of file qfc_sim.cpp.

 df1b2matrix vector2matrix ( df1b2vector & input, int nrow, int ncol, int byrow = 1 )

convert the Vector as a Matrix eithter by row=1(default) or by column=0, overloading function

Parameters:
 input : long vector/array being converted nrow : the number of rows for output matrix ncol : the number of columns for output matrix byrow : default as by row, use 1, which fill the each row from top to bottom Or any number other than 1 as by column, which fill each column from left to right
Returns:
return a matrix which row and column index all starting from 1

Definition at line 317 of file qfc_sim.cpp.

 dvar_matrix vector2matrix ( const dvar_vector & input, int nrow, int ncol, int byrow = 1 )

convert the Vector as a Matrix eithter by row=1(default) or by column=0, overloading function

Parameters:
 input : long vector/array being converted nrow : the number of rows for output matrix ncol : the number of columns for output matrix byrow : default as by row, use 1, which fill the each row from top to bottom Or any number other than 1 as by column, which fill each column from left to right
Returns:
return a matrix which row and column index all starting from 1

Definition at line 348 of file qfc_sim.cpp.