pa_nlm: Prediction Accuracy for Continuous Outcomes

View source: R/pa_nlm.R

pa_nlmR Documentation

Prediction Accuracy for Continuous Outcomes

Description

Evaluate observed and predicted continuous responses using the R-squared and L-squared measures of Li and Wang (2019). Predictions may come from a linear or nonlinear model; the original fitted model is not required.

Usage

pa_nlm(y, y.predict)

pam.nlm(y, y.predict)

Arguments

y

A finite numeric vector of observed continuous responses.

y.predict

A finite numeric vector of predictions, paired with y in the same order and of the same length. At least two pairs are required. Missing and infinite values are rejected.

Details

An ordinary least-squares regression of y on y.predict, with an intercept, gives the corrected predictions \hat y_c. The measures are

R^2 = \frac{\sum_i (\hat y_{c,i} - \bar y)^2} {\sum_i (y_i - \bar y)^2}

and

L^2 = \frac{\sum_i (y_i - \hat y_{c,i})^2} {\sum_i (y_i - y.predict_i)^2}.

R-squared describes explained response variation after affine correction; L-squared compares the corrected and original prediction errors. These are the original PAmeasures definitions, not 1 - L^2.

Constant predictions use the intercept-only correction mean(y). A constant observed response makes R-squared undefined. Predictions exactly equal to the observations make L-squared undefined because its denominator is zero. Undefined measures are NA_real_, with a warning; any other defined measure is retained. Inputs whose squared deviations overflow or whose nonzero deviations underflow to zero are rejected with an error and should be rescaled to common units.

pam.nlm() is the retained PAmeasures 0.1.0 compatibility entry point. It uses the same calculation, then rounds and formats each result to four decimal places as in the historical package. Its ordinary, defined results retain the historical field names and character format; input validation and undefined-result handling follow pa_nlm(). No deprecation warning is issued for this supported compatibility entry.

Value

A list with R.squared and L.squared. pa_nlm() returns unrounded numeric scalars. pam.nlm() returns the historical formatted character scalars.

References

Li, G. and Wang, X. (2019). Prediction Accuracy Measures for a Nonlinear Model and for Right-Censored Time-to-Event Data. Journal of the American Statistical Association, 114, 1815–1825. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1080/01621459.2018.1515079")}.

Examples

y <- c(1, 2, 4, 5)
prediction <- c(1, 2, 3, 4)
pa_nlm(y, prediction)
pam.nlm(y, prediction)

data(moore)
fit <- stats::lm(log2(count) ~ time, data = moore)
pa_nlm(moore$count, 2^stats::predict(fit))

PAmeasures documentation built on Oct. 29, 2026, 1:08 a.m.