The covariance of a curve's derivative that is not coefficient uncertainty
Source:R/extra-deriv.R
frm_extra_cov_deriv.RdThe derivative counterpart of extra_cov from frm_lp_basis(): the
n x n covariance, over the rows of newdata, of the order-th
derivative in var of the part of the linear predictor that is not
a function of the coefficients. Two sources contribute, and each is
differentiated before its covariance is formed:
Usage
frm_extra_cov_deriv(
object,
newdata,
var,
order = 1L,
eps = NULL,
dpar = NULL,
resp = NULL,
re_formula = NULL,
allow_new_levels = FALSE
)Arguments
- object
A fitted
frmtmb_fit.- newdata
The grid, a data frame.
- var
The variable to differentiate in, a column of
newdata.- order
1 or 2.
- eps
The stencil's step for a new level's design rows.
- dpar, resp
The distributional parameter and response to take the linear predictor of. Both default the way
predict()defaults them.- re_formula
NULLkeeps every random effect,NAdrops the group-level terms and keeps every smooth, a one-sided formula keeps the terms it names. Seefrm_linpred()for the full rule.- allow_new_levels
Whether a grouping level the fit never saw is allowed.
Value
An n x n matrix, as extra_cov is: a sparse
Matrix::sparseMatrix() where the sources cover few of its entries
(an empty one when there is no source), dense otherwise.
Details
An exact
gp()term's kriging residual. Its derivative's covariance is the kernel's closed form,d^o_x d^o_x' k(x, x') - d^o_x k(x, X) K^-1 d^o_x' k(X, x'), from the squared exponential kernel's Hermite-polynomial derivatives. It is not zero at an observed position: the field's slope there is not fixed by its value. The nugget is white noise and has no derivative, so it is not in this covariance.A grouping level the fit never saw (
allow_new_levels = TRUE). The design rows of its draw are differenced with the central stencil of stepeps, as a design is, and the covariance is then(L M) S (L M)', which carries no differenced rounding.
A Hilbert-space gp(k = ) and a smooth have no such part: their
uncertainty is all in their coefficients.
See also
frm_lp_basis(), whose extra_cov this differentiates.
Examples
set.seed(5)
d <- data.frame(x = sort(runif(40, 0, 4)))
d$y <- sin(d$x) + rnorm(40, 0, 0.2)
fit <- frm(bf(y ~ gp(x)), data = d)
nd <- data.frame(x = c(4.5, 5, 6))
# the slope's and the curvature's variance past the data
diag(frm_extra_cov_deriv(fit, nd, var = "x", order = 1))
#> [1] 3.060007e-06 1.122850e-04 8.706461e-03
diag(frm_extra_cov_deriv(fit, nd, var = "x", order = 2))
#> [1] 5.940085e-05 1.007320e-03 2.142198e-02