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 ,
        rcond ,
        factor ,
)

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          ,
    double&                                rcond                ,
    double                                 cov_factor           )

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 results in an over estimate of the variance, but is faster to calculate than trying to identify active constraints and treating them as equality constraints. In addition, the 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

The sample of the fixed effects, excluding the constant fixed effects, has covariance equal to the cov_factor times the inverse of the information matrix where the constant fixed effects have been removed. If cov_factor is one, this is the asymptotic covariance for the estimates (excluding the constraints that are not on the constant fixed effects).

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 .

Factorization

The subset of the matrix hes_fixed_obj_rcv that corresponds to fixed effects that are not constant is factored into L * D * L^T where L is lower triangular and D is diagonal.

rcond

This argument is optional and its input value does not matter. Upon return it is the reciprocal of the condition number for the diagonal matrix D in the factorization. In other words, it is the minimum absolute entry in D divided by the maximum absolute entry in D . If the matrix D is singular, or any entry in D is nan or infinite, rcond is zero.

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 fixed effects; see Covariance . Note that the factor corresponding to the standard deviations of the samples is the square root of cov_factor . Also note that cov_factor does not affect the factorization or rcond .

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.