pit: Probability integral transform

View source: R/pit.R

pitR Documentation

Probability integral transform

Description

Probability integral transform (PIT). LOO-PIT is given by a weighted sample.

Usage

pit(x, y, ...)

## Default S3 method:
pit(x, y, weights = NULL, log = FALSE, ...)

## S3 method for class 'draws_matrix'
pit(x, y, weights = NULL, log = FALSE, ...)

## S3 method for class 'rvar'
pit(x, y, weights = NULL, log = FALSE, ...)

Arguments

x

(draws) A draws_matrix object or one coercible to a draws_matrix object, or an rvar object.

y

(observations) A 1D vector, or an array of dim(x), if x is rvar. Each element of y corresponds to a variable in x.

...

Arguments passed to individual methods (if applicable).

weights

A matrix of weights for each draw and variable. weights should have one column per variable in x, and ndraws(x) rows.

log

(logical) Are the weights passed already on the log scale? The default is FALSE, that is, expecting weights to be on the standard (non-log) scale.

Details

The pit() function computes the probability integral transform of y using the empirical cumulative distribution computed from the samples in x. For continuous valued y and x, the PIT for the elements of y is computed as the empirical cumulative distribution value:

PIT(y_i) = Pr(x_i < y_i),

where x_i, is the corresponding set of draws in x. For draws objects, this corresponds to the draws of the ith variable, and for rvar the elements of y and x are matched.

The draws in x can further be provided (log-)weights in

If y and x are discrete, randomisation is used to obtain continuous PIT values. (see, e.g., Czado, C., Gneiting, T., Held, L.: Predictive model assessment for count data. Biometrics 65(4), 1254–1261 (2009).)

Value

A numeric vector of length length(y) containing the PIT values, or an array of shape dim(y), if x is an rvar.

Examples

# PIT for a draws object
x <- example_draws()
# Create a vector of observations
y <- rnorm(nvariables(x), 5, 5)
pit(x, y)

# Compute weighted PIT (for example LOO-PIT)
weights <- matrix(runif(length(x)), ncol = nvariables(x))

pit(x, y, weights)

# PIT for an rvar
x <- rvar(example_draws())
# Create an array of observations with the same dimensions as x.
y_arr <- array(rnorm(length(x), 5, 5), dim = dim(x))
pit(x, y_arr)


stan-dev/posterior documentation built on June 9, 2025, 12:42 a.m.