robjhyndman / forecast

Forecasting Functions for Time Series and Linear Models
http://pkg.robjhyndman.com/forecast
1.1k stars 340 forks source link

Documentation or code incorrect for CV()'s "cv" value. #868

Closed JaySumners closed 3 years ago

JaySumners commented 3 years ago

The documentation at https://pkg.robjhyndman.com/forecast/reference/CV.html says that the function "Computes the leave-one-out cross-validation statistic (also known as PRESS -- prediction residual sum of squares)...", but the code calculates the mean rather than the sum.

The CV() function defines the cv value as: cv <- mean((residuals(obj) / (1 - hatvalues(obj))) ^ 2, na.rm = TRUE)

Where (residuals(obj) / (1 - hatvalues(obj))) ^ 2 is a vector of the squared LOOCV residuals.

Should the documentation say "mean of PRESS" or should the code be sum(..., na.rm=TRUE) instead of mean(..., na.rm=TRUE)?

robjhyndman commented 3 years ago

Thanks. Fixed in https://github.com/robjhyndman/forecast/commit/78c27d1ae5cd982e58da6f37d783df5bb65ca5e6