-------------------------------------------- lines 6-134 of file: example/csv/coverage.py -------------------------------------------- {xrst_begin csv.coverage} {xrst_spell cv meas random random sincidence std } Csv Example Checking Coverage For Asymptotic Samples #################################################### In order to keep this example simple, and fast to execute: #. The only model variable is iota and it is constant with respect to age and time; see no_effect_rate.csv. #. The only node (location) is n0 and only the 'both' sex value is fit for this node; see node.csv and refit_split in option_fit.csv below. #. The measurements used the Sincidence integrand so that fitting does not need to solve the ode and hence is faster; see simulate.csv. (This example is checked every time the at_cascade automated tests are run.) #. The predictions use the prevalence integrand; see predict_integrand.csv below. We use posterior samples, instead of the standard deviation of the samples, to approximate the confidence interval because the asymptotic distribution of prevalence is not Gaussian (The asymptotic distribution of iota is Gaussian). Age-Time Grid ************* These are the age and time points that appear in the :ref:`csv.simulate@Input Files@covariate.csv` file and the prediction files; see :ref:`csv.predict@Output Files@fit_predict.csv@age` and time in csv.predict. {xrst_code py}''' age_grid = [ 0.0, 100.0] time_grid = [ 1980, 2020] '''{xrst_code} Note that Sincidence is predicted for the different age and time pairs (but do not depend on age or time for this example). Truth ***** These are the true value for iota and omega; i.e., the values used by :ref:`csv.simulate-name` when it simulates the data: {xrst_code py}''' true_iota = 0.01 true_omega = 0.02 '''{xrst_code} The value of omega is specified in covariate.csv below and constrained to this value during :ref:`csv.fit-name` The value of iota is estimated by maximizing the likelihood of the data. Random Seed *********** This is the random seed for this example. Seeding the random number generator is made complicated by the fact that this example uses multiple calls to :ref:`csv.simulate-name` and :ref:`csv.fit-name` and each call needs to use a different random seed. This is done in a way so that if the random seed below is the same, the result for this example will be reproduced. {xrst_code py}''' import time import random random_seed = int( time.time() ) random.seed( random_seed ) '''{xrst_code} Note that the choice above for the random seed changes each time this example is run. Number Data Per Fit ******************* This is the number of data points in each data set; i.e., each fit. {xrst_code py}''' n_data_per_fit = 5 '''{xrst_code} We can use a very small number of data points because the measurement noise is Gaussian and the model for Sincidence is a linear function of the model variable iota. Number Samples Per Fit ********************** This is the number of samples from the asymptotic distribution that generated for each fit. This is also the number of times each prediction is repeated. {xrst_code py}''' n_sample_per_fit = 40 '''{xrst_code} The more samples per fit, the more accurate the standard deviation that approximates the posterior statistics. Number of Fits ************** This is the number of times a data set is simulated and fit. The larger this number, the more accurate sample probability that the fit will be within the confidence limits. {xrst_code py}''' number_fit = 40 assert number_fit % 4 == 0 '''{xrst_code} The more fits, the more accurate the test of how often the fit is in the confidence limits. The time to run this example divided by *number_fit* should be nearly constant. We require number_fit to be zero mod 4 because the lower and upper confidence limits correspond to 1/4 below and 1/4 above. Measurement Noise CV ******************** This the coefficient of variation for the Gaussian measurement noise; i.e., the measurement standard deviation is the measurement mean times this value. {xrst_code py}''' meas_std_cv = 0.25 '''{xrst_code} Note that the data generated by :ref:`csv.simulate-name` is actually a censored Gaussian (values below zero are converted to zero). So we make *meas_std_cv* small enough so the censoring will be very unlikely. Source Code *********** {xrst_literal # BEGIN PYTHON # END PYTHON } {xrst_end csv.coverage}