---------------------------------------------------- lines 5-140 of file: example/user/lasso_covariate.py ---------------------------------------------------- # {xrst_begin user_lasso_covariate.py} # {xrst_spell # exp # } # {xrst_comment_ch #} # # Using Lasso on Covariate Multiplier # ################################### # # See Also # ******** # :ref:`user_group_mulcov.py-name` # # Purpose # ******* # This example uses a :ref:`density_table@density_name@laplace` # prior distribution on two covariate multipliers # to detect which covariate is present in the data. # It then refits the data with a uniform on the multiplier that is present # and the other multiplier constrained to be zero. # # Problem Parameters # ****************** # The following values are used to simulate the data and set the priors # for fitting the data: # {xrst_literal # begin problem parameters # end problem parameters # } # # Age and Time Values # ******************* # The age and time values do not matter for this problem # because all the functions are constant in age and time. # This can be seen by the fact that all of the smoothings have one age # and one time point. # # Variables # ********* # The are three model variables in this example: # # .. list-table:: # :widths: auto # # * - *iota_reference* # - :ref:`iota` # corresponding to reference value of covariates # * - *alpha_income* # - :ref:`covariate multiplier` # corresponding to income. # * - *alpha_sex* # - covariate multiplier corresponding to sex. # # Covariate Table # *************** # There are two :ref:`covariates` , # ``income`` and ``sex`` , in this example. # Income is a linear function of :ref:`data_table@data_id` . # It starts with 0.0 and ends with 1.0. # To be specific, # # *income* = *data_id* / ( *n_data* ``- 1`` ) # # Sex cycles between the values -0.5, 0.0, +0.5 # as a function of *data_id* . # Note that income and sex have range 1.0. # This makes the scaling of the covariate multipliers simpler. # The reference value for each covariate has been set to the midpoint # of its range. # We use *x_income* ( *x_sex* ) to denote the difference # of income (sex) minus its reference value. # # Mulcov Table # ************ # The :ref:`covariate multiplier table` has two rows, # one for each covariate multiplier. # Both multipliers affects the value of # :ref:`iota` , # but one multiplies income and the other sex. # We use *alpha_income* ( *alpha_sex* ) to denote the # covariate multiplier corresponding to income (sex). # The model for the value of *iota* is # # *iota_reference* * ``exp`` ( *alpha_income* * *x_income* + *alpha_sex* * *x_sex* ) # # Rate Table # ********** # The :ref:`rate_table-name` only specifies that *iota* for the parent # is the only nonzero rate for this example. # In addition, it specifies the smoothing for that rate which has only # one grid point. Hence there is only one model variable corresponding to # the rates. # # Data Table # ********** # For this example, all the data is # :ref:`avg_integrand@Integrand, I_i(a,t)@Sincidence` , # with a Gaussian density, with mean value # # *iota_reference* * ``exp`` ( *alpha_income* * ``x_income`` ) # # and with standard deviation equal 10% of the mean. # # Prior Table # *********** # There are three priors in the :ref:`prior_table-name` , one for each # model variable. # # iota # ==== # The prior for fitting the reference value of *iota* # is uniform with lower limit 0.001, and upper limit 1. # Its mean value 0.1 is only used as a starting and scaling point for the # fitting process; see :ref:`start_var_table-name` and :ref:`scale_var_table-name` . # # alpha # ===== # There is a separate prior for *alpha_income* and *alpha_sex* . # For the first fit, they are both a Laplace density with # mean zero and standard deviation *laplace_std* . # The first fit is used to decide that *alpha_income* is nonzero # and *alpha_sex* is zero. # The prior for *alpha_income* is changed to a uniform # and the prior for *alpha_sex* is change to have upper and lower # limit zero. # A second fit is done to recover the value of *alpha_income* # without shrinkage due to the Laplace prior. # # Source Code # *********** # {xrst_literal # BEGIN PYTHON # END PYTHON # } # # {xrst_end user_lasso_covariate.py}