-------------------------------------------------- lines 5-93 of file: example/user/sample_asy_sim.py -------------------------------------------------- # {xrst_begin user_sample_asy_sim.py} # {xrst_spell # cc # } # {xrst_comment_ch #} # # Sampling From The Asymptotic Distribution for a Simulated Data Fit # ################################################################## # # Purpose # ******* # This example demonstrates using the commands # # | |tab| ``dismod_at`` *database* ``set truth_var prior_mean`` # | |tab| ``dismod_at`` *database* ``simulate`` *number_sample* # | |tab| ``dismod_at`` *database* ``sample simulate`` *number_sample* # | |tab| ``dismod_at`` *database* ``sample asymptotic both`` *number_sample* # # To obtain the specified number of samples from the posterior distribution; # see :ref:`posterior@Simulation` . # This is very simple case because it has only one rate, no random effects, # and no data. # # Discussion # ********** # We use :math:`\bar{\omega}` to denote the prior mean for omega. # The following describes the model and data for this example: # # #. The :ref:`age_table-name` has values # ``0.0`` , ``100.0`` . # The :ref:`time_table-name` has values # ``1995.0`` , ``2015.0`` . # #. The only node is the world. # #. The only :ref:`model_variables-name` in this example are # :ref:`rate_table@rate_name@omega` for the world. # This rate is modeled as constant with respect to age and # linear between time 1995 and 2015. # #. There are no measurements for this example. # #. The prior for the world omega is a gaussian with mean :math:`\bar{\omega}` # and standard deviation :math:`\bar{\omega}`. # #. The prior for the difference in omega between time 1995 # and time 2015 is a Gaussian # with mean zero and standard deviation :math:`\bar{\omega}`. # # Posterior Variance # ****************** # We use :math:`\omega_0` and :math:`\omega_1` for the value # of omega at times 1995 and 2015 respectively. # Dropping terms that are constant with respect to :math:`\omega` # the negative log likelihood :math:`\ell ( \omega )` for this case is # given by # # .. math:: # # \ell ( \omega ) # = \frac{1}{2} \bar{\omega}^{-2} \left[ # ( \omega_0 - \bar{\omega} )^2 # + ( \omega_1 - \omega_0 )^2 # + ( \omega_1 - \bar{\omega} )^2 # \right] # # The Hessian of this function is given by # # .. math:: # # \ell^{(2)} ( \omega ) = \bar{\omega}^{-2} # \left( \begin{array}{cc} # 2 & -1 \\ # -1 & 2 # \end{array} \right) # # It follows that the variance of the maximum likelihood estimator is # # .. math:: # # [ \ell^{(2)} ( \omega ) ]^{-1} = \bar{\omega}^2 # \left( \begin{array}{cc} # 2/3 & 1/3 \\ # 1/3 & 2/3 # \end{array} \right) # # Source Code # *********** # {xrst_literal # BEGIN PYTHON # END PYTHON # } # # {xrst_end user_sample_asy_sim.py}