\(\newcommand{\B}[1]{ {\bf #1} }\) \(\newcommand{\R}[1]{ {\rm #1} }\) \(\newcommand{\W}[1]{ \; #1 \; }\)
sample_random¶
View page sourceSimulation the Posterior Distribution for Random Effects¶
Syntax¶
sample_random (See Also¶
Prototype¶
std::string cppad_mixed::sample_random(
d_vector& sample ,
const std::string& random_ipopt_options ,
const d_vector& fixed_vec ,
const d_vector& random_lower ,
const d_vector& random_upper ,
const d_vector& random_in ,
double cov_factor )
Purpose¶
This routine draws samples from the asymptotic posterior distribution for the random effects given the model, the data, and the fixed effects; see Sparse Observed Information .
manage_gsl_rng¶
It is assumed that get_gsl_rng will return a pointer to a GSL random number generator.
mixed_object¶
We use mixed_object
to denote an object of a class that is
derived from the cppad_mixed base class.
sample¶
This argument has prototype
CppAD::vector<double>&sample
and its size is a multiple of n_random . The input value of its elements does not matter. We define
n_sample = sample_size / n_random
If error_msg is empty, upon return
for i = 0 , …, n_sample -1 ,
j = 0 , …, n_random -1 ,
sample [ i * n_random + j ]
is the j-th component of the i-th sample of the optimal random effects. The statistics of these samples is specified under Covariance below.
random_ipopt_options¶
This argument has prototype
const std::string&random_ipopt_options
and is the ipopt_options for optimizing the random effects.
fixed_vec¶
This argument specifies the value of the fixed effects vector \(\theta\).
random_lower¶
This argument must have size equal to n_random and specifies the lower limits for the optimization of the random effects vector \(u\). The value minus infinity can be used to specify no lower limit.
random_upper¶
This argument must have size equal to n_random and specifies the upper limits for the optimization of the random effect. The value plus infinity can be used to specify no lower limit.
random_in¶
This argument must have size equal to n_random and specifies the initial value used for the optimization of the random effects vector \(u\). It must hold that
random_lower [ i ] <= random_in [ i ] <= random_upper [ i ]
for each valid index i .
cov_factor¶
This argument is optional, must be greater than zero, and its default value is one. It can be used to expand or contract the random variation of the random effects; see Covariance below. Note that the factor corresponding to the standard deviations of the samples is the square root of cov_factor .
Covariance¶
Each sample of the random effects is an independent normal. The mean for this distribution is the optimal random effects \(\hat{u} ( \theta )\). The variance of this distribution is cov_factor times the inverse of the observed information matrix; i.e.
where \(\lambda\) is cov_factor . The samples from this normal distribution are censored to be within the limits random_lower , random_upper .
error_msg¶
If error_msg is empty (non-empty), sample values have been calculated (have not been calculated). If error_msg is non-empty, it is a message describing the problem.
Example¶
The file sample_random.cpp is an example
and test of sample_random .