3
$\begingroup$

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

$\endgroup$
8
  • $\begingroup$ What is the statistical question? $\endgroup$
    – utobi
    Commented Nov 29, 2016 at 14:34
  • 1
    $\begingroup$ @utobi the question is "how to calculate PRESS". In my opinion this is a perfectly valid question. $\endgroup$
    – Tim
    Commented Nov 29, 2016 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
    Commented Nov 29, 2016 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
    Commented Nov 29, 2016 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$ Commented Nov 30, 2016 at 9:51

1 Answer 1

7
$\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$
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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