---------------------------------------------------- lines 17-171 of file: example/csv/prevalence2iota.py ---------------------------------------------------- {xrst_begin csv.prevalence2iota} {xrst_spell exp iter num pdf sincidence std tru } Example Simulating and Fitting Incidence From Prevalence Data ############################################################# Covariates ********** There are no covariates in this example. #. The covariate.csv file does not have any :ref:`csv.simulate@Input Files@covariate.csv@covariate_name` columns and is only used to set the value of omega and the covariate age time grid. #. The :ref:`csv.simulate@Input Files@multiplier_sim.csv` file is empty; i.e., it only has a header row. Age Time Grid ************* {xrst_code py}""" age_grid = [ 0.0, 20.0, 50.0, 80.0, 100.0] time_grid = [ 1980, 2000, 2020] """{xrst_code} Node Tree ********* {xrst_literal # BEGIN_NODE_FILE # END_NODE_FILE } True Rates ********** The only non-zero rates in this example are omega and iota. The true values for iota at node n0 and omega for all nodes are: {xrst_code py}""" true_iota_n0 = 0.01 true_omega_all = 0.02 """{xrst_code} True Prevalence *************** Note that iota does not depend on age or time, and prevalence does not depend on omega. If *true_iota* is the true iota for a node, the corresponding true prevalence is the following function of age: 1 - exp( - *true_iota* * *age* ) random_seed *********** {xrst_code py}""" random_seed = str( int( time.time() ) ) """{xrst_code} Random Effects ============== The random effect depends on the node (but not sex). Given an node and its random_effect, the true value of iota for that node is :: exp( random_effect ) * true_iota_n0 The value std_random_effects_iota specifies the corresponding standard deviation; see :ref:`csv.simulate@Input Files@option_sim.csv@std_random_effects_rate` The simulated random effects are reported in :ref:`csv.simulate@random_effect.csv`. Note that there are no random effects for node n0 (the root node). Simulated Data ************** There is a simulated data point for each of the following cases: see the setting of :ref:`csv.simulate@Input Files@simulate.csv`: #. For integrand_name equal to Sincidence and prevalence. #. For node_name equal to n0, n1, and n2. #. For sex equal to female and male. #. For each age in the age grid and each time in the time grid. Fit *** option_fit.csv ============== #. *refit_split* is set to false because the model does not depend on sex. #. *quasi_fixed* is false which means a full Newton method is used. #. *tolerance_fixed* is 1e-8 because the Newton method gets more accuracy. #. *max_num_iter_fixed* is 50 because the Newton method requires fewer iterations (but more work for each iteration). option_predict.csv ================== #. *plot* is true, so the plot files (pdf files) are generated for each fit. #. *db2csv* is true, so the csv files are generated for each fit. #. *float_precision* is 12 so that tru_predict.csv is very close to the truth. Note that we use the same value for *float_precision* , and a small value for *absolute_tolerance* in option_sim.csv , so that the simulated values are accurate. fit_goal.csv ============ This was set to n1 and n2 so that all the nodes, n0, n1, and n2 are fit. Fitting n0 takes most of the time because it has random effects. The four cases n1, n2 for female, male fit in parallel and are very fast because there are not random effects at that level. parent_rate.csv =============== The rate iota in constant w.r.t age and time (because there is only one prior for it in this file). data_in.csv =========== The data used during the fit is the same as the simulated data with the following exceptions: #. The :ref:`csv.simulate@Output Files@data_sim.csv@meas_mean` is used for the measurement value during the fit; i.e., :ref:`csv.fit@Input Files@data_in.csv@meas_value` . In addition, :ref:`csv.fit@Input Files@data_in.csv@meas_std` is set to a small value. Not having any noise in the measurement, and a small standard deviation, yields the effect of a much larger data set without long running times. #. The :ref:`csv.fit@Input Files@data_in.csv@density_name` is set to gaussian and eta, nu are set to the empty string; i.e., null. Prediction Files **************** The files :ref:`csv.predict@Output Files@fit_predict.csv` , :ref:`csv.predict@Output Files@tru_predict.csv` , and :ref:`csv.predict@Output Files@sam_predict.csv` are created by this example. Source Code *********** {xrst_literal BEGIN_PYTHON END_PYTHON } {xrst_end csv.prevalence2iota}