sample_fixed

View page source

Sample Posterior for Fixed Effects

Syntax

error_msg = mixed_object . sample_fixed (
      sample ,
      hes_fixed_obj_rcv ,
      solution ,
      fixed_lower ,
      fixed_upper
)

See Also

sample_random

Prototype

std::string cppad_mixed::sample_fixed(
   CppAD::vector<double>&                 sample               ,
   const d_sparse_rcv&                    hes_fixed_obj_rcv    ,
   const CppAD::mixed::fixed_solution&    solution             ,
   const CppAD::vector<double>&           fixed_lower          ,
   const CppAD::vector<double>&           fixed_upper          )

Purpose

This routine draws independent samples from the asymptotic posterior distribution for the fixed effects (given the model and the data).

Constant Fixed Effects

If the upper and lower limits for the j-th fixed effect are equal:

fixed_lower[j] == fixed_upper[j]

we refer to the j-th fixed effect as constant.

Constraints

Only the constant fixed effect constants are taken into account. (This is an over estimate of the variance, but is faster to calculate than trying to identify active constraints and treating them as equality constraints.) It can result in samples that are outside the limits for the fixed effects that are not constant. You may want to adjust the samples to be within their upper and lower limits before you use them.

Covariance

Each sample of the fixed effects (excluding the constant fixed effects) has covariance equal to the inverse of the information matrix (where the constant fixed effects have been removed).

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

The size sample . size () is a multiple of n_fixed . The input value of its elements does not matter. We define:

n_sample = sample_size / n_fixed

If error_msg is empty, upon return for i = 0 , …, n_sample-1 , j = 0 , …, n_fixed-1

sample[i * n_fixed + j]

is the j-th component of the i-th sample of the optimal fixed effects \(\hat{\theta}\).

  1. These samples are independent for different \(i\) .

  2. For each \(i\), the corresponding sample has the specified Covariance .

  3. The constraints are only enforced for the Constant Fixed Effects ; i.e., if the j-th fixed effect is not constant, the sample may not satisfy the condition:

    fixed_lower[j] <= sample[i * n_fixed + j] <= fixed_upper[j]
    

hes_fixed_obj_rcv

This is a sparse matrix representation for the lower triangle of the observed information matrix corresponding to solution ; i.e., the matrix returned by

hes_fixed_obj_rcv = mixed_object . hes_fixed_obj (
      solution , random_opt
)

where random_opt is the optimal random effects corresponding to solution .

solution

is the solution for a the call to optimize_fixed corresponding to hes_fixed_obj_rcv . The only necessary information in this structure is solution . fixed_opt .

fixed_lower

is the same as fixed_lower in the call to optimize_fixed that corresponding to solution .

fixed_upper

is the same as fixed_upper in the call to optimize_fixed that corresponding to solution .

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_fixed.cpp is an example and test of sample_fixed .

Other Method

The routine sample_conditional , is a old method that is no longer used for computing these samples.