## For picking subset sizes:
## Minimize the RMSE
example <- data.frame(RMSE = c(1.2, 1.1, 1.05, 1.01, 1.01, 1.03, 1.00),
Variables = 1:7)
## Percent Loss in performance (positive)
example$PctLoss <- (example$RMSE - min(example$RMSE))/min(example$RMSE)*100
xyplot(RMSE ~ Variables, data= example)
xyplot(PctLoss ~ Variables, data= example)
absoluteBest <- pickSizeBest(example, metric = "RMSE", maximize = FALSE)
within5Pct <- pickSizeTolerance(example, metric = "RMSE", maximize = FALSE)
cat("numerically optimal:",
example$RMSE[absoluteBest],
"RMSE in position",
absoluteBest, "\n")
cat("Accepting a 1.5 pct loss:",
example$RMSE[within5Pct],
"RMSE in position",
within5Pct, "\n")
## Example where we would like to maximize
example2 <- data.frame(Rsquared = c(0.4, 0.6, 0.94, 0.95, 0.95, 0.95, 0.95),
Variables = 1:7)
## Percent Loss in performance (positive)
example2$PctLoss <- (max(example2$Rsquared) - example2$Rsquared)/max(example2$Rsquared)*100
xyplot(Rsquared ~ Variables, data= example2)
xyplot(PctLoss ~ Variables, data= example2)
absoluteBest2 <- pickSizeBest(example2, metric = "Rsquared", maximize = TRUE)
within5Pct2 <- pickSizeTolerance(example2, metric = "Rsquared", maximize = TRUE)
cat("numerically optimal:",
example2$Rsquared[absoluteBest2],
"R^2 in position",
absoluteBest2, "\n")
cat("Accepting a 1.5 pct loss:",
example2$Rsquared[within5Pct2],
"R^2 in position",
within5Pct2, "\n")
Run the code above in your browser using DataLab