1
"testLmAdjustedRSquare" <-
2
function(x, beta, y, testLevel = 0.95){
4
# Checking for NAs in y, beta is assumed not to contain any
5
indexNA <- which(is.na(y))
7
if(length(indexNA) > 0) {
11
# Checking for NAs in x, beta is assumed not to contain any
12
indexNA <- which(is.na(x), arr.ind=TRUE)
14
if(length(indexNA) > 0) {
16
x[indexNA[, 1], ] <- NA
19
x <- matrix(x[ ! is.na(x)], ncol = ncol(x))
24
completeX <- cbind(rep(1, nrow(x)), x)
25
predictedSample <- completeX %*% beta
27
# Computing Rsquared and Adjusted Rsquared.
28
Rsquare <- 1 - (sum((y - predictedSample) ^ 2)) / (sum((y - mean(y)) ^ 2))
29
adjustedRsquare <- ((nrow(x) - 1) * Rsquare - ncol(x)) / (nrow(x) - ncol(x) - 1)
31
return(list(test = "AdjustedRSquared",
32
testResult = as.numeric(adjustedRsquare > testLevel),
33
pValue = adjustedRsquare,
34
threshold = testLevel))