---------------------------------------------- lines 5-99 of file: example/user/sample_asy.py ---------------------------------------------- # {xrst_begin user_sample_asy.py} # {xrst_comment_ch #} # # Sample from Asymptotic Distribution for Model Variables # ####################################################### # # Purpose # ******* # The command # # | |tab| ``dismod_at`` *database* ``sample asymptotic both`` *number_sample* # | |tab| ``dismod_at`` *database* ``sample asymptotic fixed`` *number_sample* # # samples form an asymptotic approximation for the posterior distribution # of the :ref:`model_variables-name` . # # Notation # ******** # # .. csv-table:: # :widths: auto # # :math:`\iota_n`,model incidence for ``north_america`` # *u_m*,incidence random effect for ``mexico`` # *u_c*,incidence random effect for ``canada`` # *y_n*,measured incidence for ``north_america`` # *y_m*,measured incidence for ``mexico`` # *y_c*,measured incidence for ``canada`` # *s_n*,standard deviation for *y_n* # *s_m*,standard deviation for *y_m* # *s_c*,standard deviation for *y_c* # *s_r*,standard deviation for random effects # # The only fixed effect in this model is :math:`\iota_n`. # The random effects are :math:`u_m` and :math:`u_c`. # # Likelihood # ********** # We define :math:`h( y, \mu , \delta )` # to be the log-density for a :math:`\B{N}( \mu, \delta^2 )` distribution; # i.e., # # .. math:: # # h( y, \mu, \delta ) = # - \frac{ ( y - \mu )^2 }{ \delta^2 } # - \log \left( \delta \sqrt{ 2 \pi } \right) # # The total log-likelihood for # :ref:`fit fixed` is # # .. math:: # # h[ y_n, \iota_n, s_n ] + # h[ y_m, \iota_n, s_m ] + # h[ y_c, \iota_n, s_c ] # # The total log-likelihood for # :ref:`fit both` is # # .. math:: # # h[ y_n, \iota_n, s_n ] + # h[ y_m, \exp( u_m ) \iota_n, s_m ] + # h[ y_c, \exp( u_c ) \iota_n, s_c ] + # h( u_m, 0, s_r ) + h( u_c , 0 , s_r ) # # Problem Parameters # ****************** # {xrst_spell_off} # {xrst_code py} measure = { 'north_america' : 1.0e-2 , # y_n 'mexico' : 2.0e-2 , # y_m 'canada' : 0.5e-2 # y_c } standard = { 'north_america' : 1.0e-3 , # s_n 'mexico' : 2.0e-3 , # s_m 'canada' : 0.5e-3 # s_c } standard_random_effect = 1.0 # s_r number_sample = 500 # number of posterior samples to generate number_metropolis = 10 * number_sample # {xrst_code} # {xrst_spell_on} # # Source Code # *********** # {xrst_literal # BEGIN PYTHON # END PYTHON # } # # {xrst_end user_sample_asy.py}