Projects predictions from a fitted regression model onto the accounting constraint using a provided residual covariance matrix. This ensures that each set of local estimates satisfies the accounting identity. Local estimates may be truncated to variable bounds.
Usage
ei_est_local(
regr,
data,
r_cov = NULL,
bounds = NULL,
conf_level = FALSE,
unimodal = TRUE
)
# S3 method for class 'ei_est_local'
as.array(x, ...)
Arguments
- regr
A fitted regression model, from
ei_ridge()
, or another kind of regression model wrapped withei_wrap_model()
.- data
The data frame, matrix, or ei_spec object that was used to fit the regression.
- r_cov
A covariance matrix of the residuals to use in projecting the local estimates onto the accounting constraint, or a list of matrices, one for each outcome variable. Defaults to the identity matrix scaled by the residual variance of
regr
, corresponding to orthogonal projection. Setr_cov=1
to use a degenerate covariance matrix corresponding to a (local) neighborhood model. When there are multiple outcome variables andr_cov
is a matrix, it will be applied identically to each outcome.- bounds
A vector
c(min, max)
of bounds for the outcome, to which the local estimates will be truncated. In general, truncation will lead to violations of the accounting identity. Ifbounds = NULL
, they will be inferred from the outcome variable: if it is contained within \([0, 1]\), for instance, then the bounds will bec(0, 1)
. The defaultbounds = FALSE
forces unbounded estimates.- conf_level
A numeric specifying the level for confidence intervals. If
FALSE
(the default), no confidence intervals are calculated. Forregr
arguments fromei_wrap_model()
, confidence intervals will not incorporate uncertainty in the prediction itself, just the residual. This will trigger a warning periodically.- unimodal
If
TRUE
, assume a unimodal residual distribution. Improves width of confidence intervals by a factor of 4/9.- x
An object of class
ei_est_local
- ...
Additional arguments (ignored)
Value
A data frame with estimates. The .row
column in the output
corresponds to the observation index in the input. It has class
ei_est_local
, supporting several methods.
Details
Local estimates are produced independently for each outcome variable. Truncation to bounds, if used, will in general lead to estimates that do not satisfy the accounting identity.
Methods (by generic)
as.array(ei_est_local)
: Format estimates an array with dimensions<rows>*<predictors>*<outcomes>
. Does not work if the object has been sorted.