--------------------------------------------- lines 5-143 of file: example/user/residual.py --------------------------------------------- # {xrst_begin user_residual.py} # {xrst_comment_ch #} # # Weighted Residuals # ################## # # Example Parameters # ****************** # The following values are used to simulate the data and define the priors: # {xrst_spell_off} # {xrst_code py} omega_true = [ 0.01, 0.02 ] omega_mean = 0.15 minimum_meas_cv = 0.10 # {xrst_code} # {xrst_spell_on} # # Model # ***** # The only non-zero model variable for this example is # other cause mortality, :math:`\omega`, for the parent area. # The parent omega grid has two points, # one at age zero and the other at age 100. # The corresponding true values for :math:`\omega` are # ``omega_true[0]`` at age zero and ``omega_true[1]`` at age 100. # # Data # **** # The integrand for this data is # :ref:`avg_integrand@Integrand, I_i(a,t)@mtother` ; i.e., # a direct measurement of :math:`\omega`. # Both ages are included in the data for this example. # Both the Gaussian and Log-Gaussian :ref:`densities` # are included. # In addition, both the case where the # :ref:`data_table@meas_std` is above and below the bound specified # by :ref:`integrand_table@minimum_meas_cv` are included. # # Capital Delta # ============= # We use the notation # :ref:`Delta` for # the standard deviation adjusted by the minimum measurement cv. # # Lower delta # =========== # We use the notation # :ref:`delta` # for the transformed standard deviation. # # Gaussian Residuals # ================== # There are no measurement noise covariate multipliers, so # :math:`\delta = \Delta` and the residual is # # .. math:: # # (y - \mu) / \delta # # where :math:`y` is the measured value and :math:`\mu` is the # model value for the # :ref:`average integrand` . # # Log-Gaussian Residuals # ====================== # There are no measurement noise covariate multipliers, so # # .. math:: # # \delta = \log ( y + \eta + \Delta ) - \log( y + \eta ) # # where :math:`y` is the measured value # and :math:`\eta` is the offset in the log transform. # The residual is # # .. math:: # # \frac{ \log ( y + \eta ) - \log ( \mu + \eta ) } { \delta } # # where :math:`\mu` is the model value for the average integrand. # # Priors # ****** # # Value Residual # ============== # There are two value residuals, one for :math:`\omega` at age zero # and the other at age 100. # The density used for the value residuals is Log-Gaussian. # The mean value used in the prior for the value residuals :math:`\mu` is # ``omega_mean`` . # The standard deviation used for the value residuals in # ``omega_mean * 0.1`` # The log transformed standard deviation is # # .. math:: # # \delta = \log ( \mu + \eta + \sigma ) - \log( \mu + \eta ) # # The residual is # # .. math:: # # \frac{ \log ( y + \eta ) - \log ( \mu + \eta ) } { \delta } # # where :math:`y` is the :ref:`fit_var_table@fit_var_value` # for the model variable. # # Difference Residual # =================== # There is one difference residuals for the difference of # :math:`\omega` at age zero and age 100. # The density used for the value residuals is Log-Gaussian. # The mean value used in the prior for the difference residual # :math:`\mu = 0`. # The standard deviation used for the difference residual is ``0.1`` . # (This corresponds to a coefficient of variation of :math:`e^{0.1} - 1`. # which is approximately equal to ``0.1`` ; i.e., 10 percent.) # The age difference smoothing multiplier prior id # :ref:`mulstd_dage_prior_id` for this example is null, # so :math:`\delta` is equal to the standard deviation ``0.1`` . # The residual is # # .. math:: # # \frac{ \log ( z + \eta ) - \log ( y + \eta ) - \mu } { \delta } # # where :math:`y` (:math:`z`) # is the :ref:`fit_var_table@fit_var_value` # at age zero (age 100). # # Source Code # *********** # {xrst_literal # BEGIN PYTHON # END PYTHON # } # # {xrst_end user_residual.py}