1

For my homework, I am performing leave-one-out cross-validation using the cv.glm package.

Consider the following simplified example where the cross-validation estimates of prediction error are not equal:

set.seed(1)
x = rnorm(100)
y = x - 2 * x^2 + rnorm(100)
df <- data.frame(x, y)

model <- glm(y~poly(x, 2), data = df)

set.seed(1)
error_1 <- cv.glm(df, model)

set.seed(2)
error_2 <- cv.glm(df, model)

error_1$delta == error_2$delta

I understand that, when performing k-fold validation with K =! number of observations, random partitioning takes place. This would explain different values for error_1 and error_2.

However, since I am not specifying K, it should be equal to the number of observations in data which should give the usual leave-one-out cross-validation.

To my understanding, leave-one-out cross-validation should not require a random element. Why are the results different? Where is a random number being used when performing leave-one-out cross-validation?

mritz_p
  • 3,008
  • 3
  • 28
  • 40
  • I don't have the `cv.glm` package. However, using `caret`, LOOCV delivers the same delta. – lukeA Nov 19 '16 at 13:57

0 Answers0