-
Notifications
You must be signed in to change notification settings - Fork 230
Description
For diagnostics about my models I had the need to save spesific generated values. for example the individual predictions IPRED in longitudinal models or the cumulative hazard for survival models. It there a way to save such values already?
In the beginning i developt a cumstom distribution to help with this. Later on I found the Dirac distribution which basically gives this functionality. The value given to the distribution is the value that will be sampled. For the Turing framework it will look like a prior and thus will populate this value and then save it to the chains output.
E.g. how to save IPRED in the linear regression turorial
# Bayesian linear regression.
@model function linear_regression(x, y)
# Set variance prior.
σ² ~ truncated(Normal(0, 100); lower=0)
# Set intercept prior.
intercept ~ Normal(0, sqrt(3))
# Set the priors on our coefficients.
nfeatures = size(x, 2)
coefficients ~ MvNormal(Zeros(nfeatures), 10.0 * I)
# Calculate all the mu terms.
mu = intercept .+ x * coefficients
# Use dirac distrubution to save the individual predictions IPRED
IPRED ~ Dirac.(mu)
return y ~ MvNormal(mu, σ² * I)
endThis allows you to plot IPRED vs OBS and lets you define IRES = IPRED - OBS and plot IRES vs come covariates etc. I assume some people would be interested in this functionality. This could be included in the documentation somewhere. I am not sure how the documentation is structured or where to put it.