View source: R/diagnostics_sim.R
| pit_residuals | R Documentation |
For each observation, computes the quantile of the observed value within the posterior predictive distribution. If the model is correct, PIT residuals follow Uniform(0, 1).
pit_residuals(object, ...)
## Default S3 method:
pit_residuals(object, observed = NULL, nsim = 250L, seed = 123L, ...)
object |
A fitted model with a |
... |
Passed to methods. |
observed |
Observed response vector (required if |
nsim |
Number of simulations (default 250) |
seed |
Random seed (default 123) |
For integer-valued responses, a randomisation step avoids discrete artefacts: the residual is drawn uniformly between P(sim < obs) and P(sim <= obs).
Numeric vector of length n_obs with values in [0, 1]
# From a matrix of replicates (n_obs x nsim) and the observed response:
set.seed(1)
y <- rpois(30, 3)
sims <- matrix(rpois(30 * 100, 3), nrow = 30)
r <- pit_residuals(sims, observed = y)
summary(r)
# From a fitted model with a simulate() method:
set.seed(1)
d <- data.frame(x = rnorm(80))
d$y <- rpois(80, exp(0.3 + 0.5 * d$x))
fit <- tulpa(y ~ x, data = d, family = "poisson", mode = "laplace")
head(pit_residuals(fit, nsim = 50))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.