Reduce predicted functions to scalars via a user-supplied wrapper
Source:R/predict_target.R
apply_wrapper.RdMany downstream quantities of interest (average treatment effect,
pointwise predictions, or other functionals of \(f^{(0)}\)) are scalar
summaries of the predicted function. apply_wrapper() applies any
user-supplied reduction to each row of a function matrix, with a default
of the weighted mean with respect to grid_weights (which coincides with
\(\int f\,d\mu\) when grid_weights represents \(\mu\)).
Arguments
- F_mat
An
n-by-G_gridnumeric matrix; each row a function on a shared grid (e.g. the output ofpredict_target()).- wrapper
Either
NULL(default, weighted mean) or a function that takes a single numeric vector of lengthG_gridand returns a scalar. Examples:mean,median,max,function(f) f[17](point evaluation),function(f) sum(f^2).- grid_weights
Optional length-
G_gridnon-negative numeric vector. Used only whenwrapper = NULL. Defaults to uniform1 / G_grid.
Examples
F_mat <- matrix(1:12, nrow = 3, byrow = TRUE) # 3 "functions" on a 4-point grid
apply_wrapper(F_mat) # row means (uniform grid weights)
#> [1] 2.5 6.5 10.5
apply_wrapper(F_mat, wrapper = max) # row maxes
#> [1] 4 8 12
apply_wrapper(F_mat, wrapper = function(f) f[2]) # point evaluation at grid idx 2
#> [1] 2 6 10