O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

Step 1 reads the data.

Step 2 creates two functions for performing LOOCV. Lines 1 to 4 define the first function rdacb.loocv.reg and lines 5 to 9 define the second one, rdacb.loocv.reg.iter:

  • Line 2 of the first function rdacb.loocv.reg repeatedly calls the second function rdacb.loocv.reg.iter to build the regression model leaving one case out and compute the squared error
  • Line 3 creates a list with the output elements
  • Line 6 in the second function rdacb.loocv.reg.iter builds the regression model on the data frame leaving out one case
  • Line 7 generates the prediction for the case that was left out
  • Line 8 computes the squared error

Step 3 uses the preceding functions to perform LOOCV and displays the results.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required