bart_star() accepts known offsets
(exposures)
in the BART-STAR model for counts, for example survey effort or
detection proportion in point-count data. The CDF-based transformations
are estimated with the offsets through the offsets argument
of g_cdf().
Model
Original STAR model with a BART mean:
The observation corresponds to , with , and .
With offsets, is applied to and nothing else changes:
Since and is increasing,
with . The cut points become ; the upper endpoint is , not . The likelihood is
For this is the usual log-offset: .
In the code, a_y = a_j(y, y_max)/offsets,
a_yp1 = a_j(y + 1, y_max)/offsets,
z_lower = g(a_y) and z_upper = g(a_yp1). These
are used in the
sampling step (rtruncnormRcpp), in the
update for 'box-cox', and in the pointwise log-likelihood,
so also in the WAIC. The BART step (dbarts) is
unchanged.
Transformation
Box-Cox family ('identity', 'log',
'sqrt', 'box-cox').
is applied to
.
For 'box-cox',
is sampled as in the original; its likelihood uses the intervals
.
CDF-based ('np', 'pois',
'neg-bin'). As in the original,
at a set of knots, infinite values are dropped, and the knots are joined
by the same monotone spline
(splinefun(..., method = 'monoH.FC')). With offsets,
is applied to
,
so
must describe
.
bart_star() calls
g_cdf(y, transformation, offsets).
-
'np': is the empirical CDF of the observed rates , evaluated just below each knot (the unique nonzero ):
It is computed with one call to ecdf(), as
n/(n+1)*(1 - ecdf(-y/offsets)(-t)). With
,
and
are integers, so
and
is the original qnorm(F_y(t0 - 1)).
-
'pois','neg-bin': the offsets enter through the standard count models with exposure,
In the STAR model , and the distribution of does not depend on , so is the latent count at unit exposure (). The transformation is therefore built, as in the original, from the CDF of the count at unit exposure, Pois() or NB():
The offsets change only the estimates of and , which solve the moment equations of the exposure model,
where the second is averaged over , is the sample variance of , and . This gives
is also the Poisson MLE. With , these are the original estimates.
'ispline' is not available with
offsets. The function stops if any offsets or
offsets_test differs from 1; otherwise it calls the
original bart_star_ispline().
Predictions, conditional expectation, scores
Posterior predictive draws. At each saved iteration, and
computed as
round_floor(g_inv(z_tilde) * offsets, y_max). Test draws
(post.pred.test) use offsets_test. As in the
original,
is exact for the Box-Cox family and a grid approximation
(g_inv_approx()) for 'np', 'pois'
and 'neg-bin'.
Conditional expectation.
Here
is the 0.9999 quantile of
,
capped at
.
Since
,
the term
is
.
expectation_gRcpp() sums up to Jmax
,
so the code uses Jmax
and the cut points a_j(., y_max).
Without offsets, the original single call to
expectation_gRcpp() is used. With offsets, the cut points
differ by observation, while expectation_gRcpp() takes one
vector of cut points for all observations. To avoid a loop over
observations, the same sum is computed in R for all observations at
once, over one long vector of the pairs
,
,
where
is the 0.0001 quantile of
.
This is used for every transformation. The checks of this design are in
README_check.md.
Log-predictive scores for the test data use the
intervals
[a_j(y_test, y_max)/offsets_test, a_j(y_test + 1, y_max)/offsets_test),
so a test value at
has the cell
,
as in the likelihood.
Initialization
The original rules, applied to the scale :
| Quantity | Code |
|---|---|
Initial z_star
|
g((y + abs(rnorm(n)))/offsets) |
sigest (when NULL) |
sd(g((y + 1)/offsets)) |
sigest, 'box-cox'
|
the original pilot MCMC if all offsets equal 1; otherwise the rule above at the initial , because the pilot MCMC does not take offsets |
Grid for g_inv_approx()
|
250 equally spaced points on , plus 250 quantiles of the unique over |
Usage
library(countSTAR)
fit = bart_star(y = y, X = X, offsets = e, # e: known exposures
X_test = X, offsets_test = 1,
transformation = 'np', save_y_hat = TRUE)
fit$post.pred # predictive draws of y at the observed exposures e
fit$fitted.values # E(y | x, e) at the observed exposures e
colMeans(fit$post.fitted.values.test) # E(y | x, e = 1): expected count per unit exposure-
offsets:n x 1vector or scalar, ; the default is 1.offsets_test:n_test x 1vector or scalar; the default is 1. Scalars are recycled, and wrong lengths or values stop with an error. -
post.pred,post.log.like.pointand the fitted values are atoffsets.post.pred.test,post.fitted.values.testandpost.log.pred.testare atoffsets_test. -
post.mu.testandpost.sigmaare on the scale of . With'np'they do not depend on the units of . With'log', using instead of is the same model with shifted by . With'pois'and'neg-bin', is the CDF transformation at , so the units of define the reference exposure.