I would like to calculate the Standard Error (SE) of the Mean Squared Error (MSE) of a test set for a certain model size of nnet. It's purpose is to give the 1 SE to serve in the "one-standard-error-rule" (the program is a bit long, because I need some pre-calculations, however if you scroll down to "the interesting part", the question is quite short) How do I get the SE of the MSE/is my calculation right?:
library(nnet)
# only some prerequisits
set.seed(2718)
OBS <- 1000
x1 <- rnorm(OBS, 10, 4)
x2 <- rnorm(OBS, 20, 8)
y <- 100 - x2*40 + x1 * 10 + x1*(x2**2) * 0.5 + rnorm(OBS, 0, 10)
d <- data.frame(y, x1, x2)
FOLDS <- 5
group_index <- rep(0:FOLDS, length.out = OBS)
# scale
my_scale <- function(x) {
res <- (x - min(x)) / (max(x) - min(x))
res
}
d <- data.frame(lapply(d, my_scale))
# nnet/train
nnet_mod <- nnet(y ~ ., data = d[group_index == 0, ], size = 5)
# INTERESTING PART
# ----------------
MSE <- lapply((1:FOLDS), function(i) {
mean((d$y[group_index == i] - predict(nnet_mod, d[group_index == i, ])) ** 2)
})
names(MSE) <- paste0("Fold", 1:FOLDS)
print("individual MSE's:")
print(MSE)
print("Is the SE of the MSE's equal to the standard dev of the MSE's?")
print(sd(unlist(MSE)))
print("If the current model with size = 5 had the lowest MSE, ..")
print(".. the best model would the smallest net that has MSE smaller than:")
print(mean(unlist(MSE)) + sd(unlist(MSE)))