install.packages("remotes")
::install_github("https://github.com/Damian-Oswald/PRE") remotes
2 Installation
All functions that are used repeatedly throughout this projec are implemented in an R package called PRE
. The source code of this package is stored in a publically accessible way on GitHub. You can install the package directly from GitHub using the install_github
function from the remotes
package.
Alternatively, you could download the GitHub repository and manually install the PRE
package locally. Once the package is installed, you can attach it to the search path in the usual way.
library(PRE)
2.1 What do the various functions do?
The R code shown on this project help page is extremely simplified. If you want want to understand what a specific function of the PRE
package does, simple visit the corresponding R help page. For example, you could read on the function crossValidate
by using one of the the following commands.
help("crossValidate", package = "PRE")
?crossValidate
If you want to jump really deep into a function, you could print it out in your console.
print(crossValidate)
function (FUN, x, y, k = nrow(x), r = 1, ...)
{
results <- data.frame()
for (R in 1:r) {
I <- matrix(c(sample(1:nrow(x)), rep(NA, k - nrow(x)%%k)),
ncol = k, byrow = TRUE)
for (K in 1:k) {
i <- na.omit(I[, K])
result <- cbind(cost = FUN(x_train = x[-i, ], y_train = y[-i,
], x_test = x[i, ], y_test = y[i, ], ...), r = R,
k = K)
results <- rbind(results, result)
}
}
return(results)
}
<bytecode: 0x7f8d94e65e08>
<environment: namespace:PRE>
Note this function source code output is lacking any comments. Those were automatically removed when compiling the R package. To see the commented source code, you’ll have to jump into the package files, or visit the GitHub page. Simply use the following URL:
https://github.com/Damian-Oswald/PRE/blob/main/R/crossValidate.R
Notice how the base name (the last part of the URL) matches the function name. You can replace that by any function name of your liking.