Step 1 reads the data file.
In step 2, we define two functions to perform k-fold cross-validation. Rows 1-5 define the first function, and rows 6-13 define the second function.
The first function rdacb.kfold.crossval.reg sets up the k-folds and uses the second one to build the model and compute the errors for each fold.
Line 2 creates the folds by randomly sampling from 1 to k. Thus, if a data frame has 1,000 elements, this line will generate 1,000 random integers from 1 to k. The idea is that if the ith random number is, say, 3, then the ith case of the data frame belongs to the third fold.
Line 3 invokes the second function to compute the errors for each fold.
Line 4 creates a list with the raw values of the mean squared ...