------------------------------------------------ lines 5-124 of file: example/user/jump_at_age.py ------------------------------------------------ # {xrst_begin user_jump_at_age.py} # {xrst_spell # apx # def # exp # } # {xrst_comment_ch #} # # Zero Rate Until a Jump at a Known Age # ##################################### # # Purpose # ******* # Usually the prior for the rate is smooth. # This requires lots of data, at a fine age spacing, # to resolve a jump in a rate at an unknown age. # If the age at which a jump occurs is known, it is possible to resolve # the jump with much less data by specifying a prior that has this knowledge. # # Parameters # ********** # The following values are used to simulate the data and define the priors # and can be changed: # {xrst_spell_off} # {xrst_code py} iota_near_zero = 1e-10 iota_after_20 = 1e-2 iota_eta = 1e-5 time_table = [ 2020.0, 2000.0 ] age_table = [ 100.0, 70.0, 40.0, 20.01, 19.99, 0.0 ] # {xrst_code} # {xrst_spell_on} # # iota_near_zero # ============== # This is the true value of *iota* up to and including age 20. # Note that it is close to zero, but not equal to zero, so that we can # use the rate case # :ref:`option_table@rate_case@iota_pos_rho_zero` . # # iota_after_20 # ============= # This is the true value of *iota* for ages greater than 20. # # iota_eta # ======== # Offset in log transformation used for values of eta. # # age_table # ========= # The :ref:`age_table-name` does not need to be monotone increasing. # For this example, it is the same as the table of ages at which # *iota* is modeled . # You can changed the order of ``age_table`` # and it will not affect the results. # Note that the age table has a point just before and after the jump # because iota is interpolated linear between age points. # # time_table # ========== # The :ref:`time_table-name` does not need to be monotone increasing. # You can changed the order of ``time_table`` # and it will not affect the results. # # Model Variables # *************** # This example's variables are all # :ref:`model_variables@Fixed Effects, theta@Parent Rates` # for :ref:`rate_table@rate_name@iota` . # The value of *iota* is modeled at each age in the ``age_table`` . # The prior for the value of *iota* up to age 20 is a constant equal to # ``iota_near_zero`` . # After age 20 it is uniform with lower limit ``iota_near_zero`` , # upper limit 1 and mean ``iota_after_20 / 4.0`` # (The mean is only used for the initial value and scaling the optimization.) # The prior for the forward age differences in *iota* at age 20 # is uniform, and above age 20 it is a Log-Gaussian with mean 0 and # standard deviation 0.1 (about 10 percent coefficient of variation). # # Truth # ***** # For this example the rate *iota* is constant # with value ``iota_near_zero`` for ages less than or equal 20, # and ``iota_after_20`` for ages greater than 20. # # Prevalence # ********** # There is no remission or other cause mortality in this example; i.e., # *rho* and *omega* are zero. # We approximation prevalence for ages less that 20 as zero. # {xrst_code py} def prevalence_apx(age) : import math if age < 20.0 : return 0.0 result = 1.0 - math.exp( - iota_after_20 * (age - 20 ) ) return result # {xrst_code} # # Simulated Data # ************** # For this example, the simulated data is all # :ref:`avg_integrand@Integrand, I_i(a,t)@prevalence` . # There is no noise simulated with the data; i.e., it is equal to # the approximation described above. # On the other hand, its is modeled as if it had standard deviation # {xrst_code py} meas_std = 0.01 # {xrst_code} # There is a measured value for each age in the ``age_table`` # that is greater than 20. # # Source Code # *********** # {xrst_literal # BEGIN PYTHON # END PYTHON # } # # {xrst_end user_jump_at_age.py}