-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpred_r_squared.R
27 lines (23 loc) · 1.02 KB
/
pred_r_squared.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#====================================================================#
# Author: Damian Gwozdz (DG)
# Function: PRESS
# Creation date: 28JAN2018
# Last modified: -
# Description: Function to obtain the PRESS stat
# required to compute predicted R-squared
# Required functions: PRESS
# Sources: 1) "Predictive R-squared according to Tom Hopper",
# https://rpubs.com/RatherBit/102428
# (access: 28JAN2018)
#
#====================================================================#
pred_r_squared <- function(PRESS, model){
#====================================================================
# PARAMETERS:
#
# 1) PRESS - PRESS stat obtained from PRESS() function
# 2) model - Ordinary Least Squared Model created by lm() function
#====================================================================
avg <- sum(model$model[,1])/length(model$model[,1])
return( 1 - PRESS/(sum((model$model[,1] - avg)^2)) )
}