1
$\begingroup$

If an answer is illustrated with R code, it would be even more gratefully accepted.

$\endgroup$
  • $\begingroup$ What is the statistical question? $\endgroup$ – utobi Nov 29 '16 at 14:34
  • 1
    $\begingroup$ @utobi the question is "how to calculate PRESS". In my opinion this is a perfectly valid question. $\endgroup$ – Tim Nov 29 '16 at 15:15
  • 3
    $\begingroup$ @Tim as far as I understood the question is "how to calculate PRESS using R", which sounds like performing routine operations within a statistical computing platform, hence off-topic. $\endgroup$ – utobi Nov 29 '16 at 15:45
  • 1
    $\begingroup$ @utobi In its current state, this question seems on-topic to me. I don't think the question is demanding only the R code but the details of computation. It is quite common for "how to compute" questions to express a language preference, but answerers are not obliged to respect it. That is, an answer without R code - using pseudo-code or Python or no code altogether - would still be a valid answer to the question as written. I think the line gets crossed when we see a question that asks how to implement in R. $\endgroup$ – Silverfish Nov 29 '16 at 19:45
  • $\begingroup$ @Tim Thanks for your great answer and I sorry about the way me asking this question.New to the neighbourhood, and still learning. $\endgroup$ – AkiyamaYukari Nov 30 '16 at 9:51
4
$\begingroup$

For linear regression model, given the hat matrix

$$ H = X (X'X)^{-1} X' $$

and residuals $e_i$, PRESS can be calculated as (see also here):

$$ \mathrm{PRESS} = \sum_i \left( \frac{e_i}{1-h_{ii}}\right)^2$$

This can be easily translated to the simple function:

PRESS <- function(linear.model) {
    pr <- residuals(linear.model)/(1 - lm.influence(linear.model)$hat)
    sum(pr^2)
}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.