Skip to content

Commit

Permalink
fix: revert
Browse files Browse the repository at this point in the history
  • Loading branch information
aravindhebbali committed Jul 19, 2024
1 parent 6bfef19 commit e40e7f0
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 65 deletions.
52 changes: 26 additions & 26 deletions R/ols-best-subsets-regression.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#' # maximum subset
#' model <- lm(mpg ~ disp + hp + drat + wt + qsec, data = mtcars)
#' ols_step_best_subset(model, max_order = 3)
#'
#'
#' # plot
#' model <- lm(mpg ~ disp + hp + wt + qsec, data = mtcars)
#' k <- ols_step_best_subset(model)
Expand All @@ -50,8 +50,8 @@ ols_step_best_subset <- function(model, ...) UseMethod("ols_step_best_subset")

#' @export
#' @rdname ols_step_best_subset
#'
ols_step_best_subset.default <- function(model, max_order = NULL,
#'
ols_step_best_subset.default <- function(model, max_order = NULL,
include = NULL, exclude = NULL,
metric = c("rsquare", "adjr", "predrsq",
"cp", "aic", "sbic", "sbc",
Expand All @@ -77,7 +77,7 @@ ols_step_best_subset.default <- function(model, max_order = NULL,
stop(paste(paste(exclude[!npm], collapse = ", "), "not part of the model and hence cannot be forcibly excluded. Please verify the variable names."), call. = FALSE)
}
}

if (is.numeric(include)) {
if (any(include > lenterms)) {
stop(paste0("Index of variable to be included should be between 1 and ", lenterms, "."), call. = FALSE)
Expand All @@ -88,7 +88,7 @@ ols_step_best_subset.default <- function(model, max_order = NULL,

if (is.numeric(exclude)) {
if (any(exclude > lenterms)) {
stop(paste0("Index of variable to be excluded should be between 1 and ", lenterms, "."), call. = FALSE)
stop(paste0("Index of variable to be excluded should be between 1 and ", lenterms, "."), call. = FALSE)
} else {
exclude <- indterms[exclude]
}
Expand Down Expand Up @@ -152,23 +152,23 @@ ols_step_best_subset.default <- function(model, max_order = NULL,
lpreds <- c()

for (i in seq_len(len_elig)) {
predictors <- predicts[[i]]
lp <- length(predictors)
out <- ols_regress(paste(response, "~", paste(predictors, collapse = " + ")), data = data)
mcount <- mcount + 1
lpreds[mcount] <- lp
rsq[[mcount]] <- out$rsq
adjr[[mcount]] <- out$adjr
cp[[mcount]] <- ols_mallows_cp(out$model, model)
aic[[mcount]] <- ols_aic(out$model)
sbic[[mcount]] <- ols_sbic(out$model, model)
sbc[[mcount]] <- ols_sbc(out$model)
gmsep[[mcount]] <- ols_msep(out$model)
jp[[mcount]] <- ols_fpe(out$model)
pc[[mcount]] <- ols_apc(out$model)
sp[[mcount]] <- ols_hsp(out$model)
predrsq[[mcount]] <- ols_pred_rsq(out$model)
preds[[mcount]] <- paste(predictors, collapse = " ")
predictors <- predicts[[i]]
lp <- length(predictors)
out <- ols_regress(paste(response, "~", paste(predictors, collapse = " + ")), data = data)
mcount <- mcount + 1
lpreds[mcount] <- lp
rsq[[mcount]] <- out$rsq
adjr[[mcount]] <- out$adjr
cp[[mcount]] <- ols_mallows_cp(out$model, model)
aic[[mcount]] <- ols_aic(out$model)
sbic[[mcount]] <- ols_sbic(out$model, model)
sbc[[mcount]] <- ols_sbc(out$model)
gmsep[[mcount]] <- ols_msep(out$model)
jp[[mcount]] <- ols_fpe(out$model)
pc[[mcount]] <- ols_apc(out$model)
sp[[mcount]] <- ols_hsp(out$model)
predrsq[[mcount]] <- ols_pred_rsq(out$model)
preds[[mcount]] <- paste(predictors, collapse = " ")
}

ui <- data.frame(
Expand Down Expand Up @@ -197,13 +197,13 @@ ols_step_best_subset.default <- function(model, max_order = NULL,
} else {
temp <- lapply(l, function(x) x[order(x[[metrics]]), ][1, ])
}

sorted <- do.call(rbind, temp)
mindex <- seq_len(nrow(sorted))
sorted <- cbind(mindex, sorted)
result <- list(metrics = sorted)
class(result) <- c("ols_step_best_subset")

return(result)

}
Expand Down Expand Up @@ -261,8 +261,8 @@ best_subset_plot <- function(d, var, title = "R-Square") {
ggplot(d1, aes(x = a, y = b)) +
geom_line(color = "blue") +
geom_point(color = "blue", shape = 1, size = 2) +
xlab("") +
ylab("") +
xlab("") +
ylab("") +
ggtitle(title) +
theme(axis.ticks = element_blank())

Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/_snaps/all-possible.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
ols_step_all_possible(model)
Output
Index N Predictors R-Square Adj. R-Square Mallow's Cp
1 1 1 disp 0.7183433 0.7089548 0.6751205
2 2 1 hp 0.6024373 0.5891853 0.5096958
3 3 2 disp hp 0.7482402 0.7308774 0.6945438
1 1 1 disp 0.7183433 0.7089548 4.443792
2 2 1 hp 0.6024373 0.5891853 17.794906
3 3 2 disp hp 0.7482402 0.7308774 3.000000

12 changes: 6 additions & 6 deletions tests/testthat/_snaps/step-backward-output.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
Model Summary
-------------------------------------------------------------------
R 0.884 RMSE 184.276
R-Squared 0.781 MSE 38202.426
R-Squared 0.781 MSE 33957.712
Adj. R-Squared 0.758 Coef. Var 27.839
Pred R-Squared 0.700 AIC 730.620
MAE 137.656 SBC 744.543
Expand Down Expand Up @@ -100,7 +100,7 @@
Model Summary
-------------------------------------------------------------------
R 0.884 RMSE 184.276
R-Squared 0.781 MSE 38202.426
R-Squared 0.781 MSE 33957.712
Adj. R-Squared 0.758 Coef. Var 27.839
Pred R-Squared 0.700 AIC 730.620
MAE 137.656 SBC 744.543
Expand Down Expand Up @@ -201,7 +201,7 @@
Model Summary
-------------------------------------------------------------------
R 0.884 RMSE 184.276
R-Squared 0.781 MSE 38202.426
R-Squared 0.781 MSE 33957.712
Adj. R-Squared 0.758 Coef. Var 27.839
Pred R-Squared 0.700 AIC 730.620
MAE 137.656 SBC 744.543
Expand Down Expand Up @@ -258,7 +258,7 @@
Model Summary
-------------------------------------------------------------------
R 0.884 RMSE 184.276
R-Squared 0.781 MSE 38202.426
R-Squared 0.781 MSE 33957.712
Adj. R-Squared 0.758 Coef. Var 27.839
Pred R-Squared 0.700 AIC 730.620
MAE 137.656 SBC 744.543
Expand Down Expand Up @@ -337,7 +337,7 @@
Model Summary
-------------------------------------------------------------------
R 0.884 RMSE 184.276
R-Squared 0.781 MSE 38202.426
R-Squared 0.781 MSE 33957.712
Adj. R-Squared 0.758 Coef. Var 27.839
Pred R-Squared 0.700 AIC 730.620
MAE 137.656 SBC 744.543
Expand Down Expand Up @@ -488,7 +488,7 @@
Model Summary
-------------------------------------------------------------------
R 0.884 RMSE 184.276
R-Squared 0.781 MSE 38202.426
R-Squared 0.781 MSE 33957.712
Adj. R-Squared 0.758 Coef. Var 27.839
Pred R-Squared 0.700 AIC 730.620
MAE 137.656 SBC 744.543
Expand Down
12 changes: 6 additions & 6 deletions tests/testthat/_snaps/step-forward-output.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
Model Summary
-------------------------------------------------------------------
R 0.884 RMSE 184.276
R-Squared 0.781 MSE 38202.426
R-Squared 0.781 MSE 33957.712
Adj. R-Squared 0.758 Coef. Var 27.839
Pred R-Squared 0.700 AIC 730.620
MAE 137.656 SBC 744.543
Expand Down Expand Up @@ -106,7 +106,7 @@
Model Summary
-------------------------------------------------------------------
R 0.884 RMSE 184.276
R-Squared 0.781 MSE 38202.426
R-Squared 0.781 MSE 33957.712
Adj. R-Squared 0.758 Coef. Var 27.839
Pred R-Squared 0.700 AIC 730.620
MAE 137.656 SBC 744.543
Expand Down Expand Up @@ -290,7 +290,7 @@
Model Summary
-------------------------------------------------------------------
R 0.884 RMSE 184.276
R-Squared 0.781 MSE 38202.426
R-Squared 0.781 MSE 33957.712
Adj. R-Squared 0.758 Coef. Var 27.839
Pred R-Squared 0.700 AIC 730.620
MAE 137.656 SBC 744.543
Expand Down Expand Up @@ -348,7 +348,7 @@
Model Summary
-------------------------------------------------------------------
R 0.878 RMSE 188.249
R-Squared 0.771 MSE 39053.801
R-Squared 0.771 MSE 35437.709
Adj. R-Squared 0.753 Coef. Var 28.147
Pred R-Squared 0.695 AIC 730.924
MAE 140.619 SBC 742.858
Expand Down Expand Up @@ -428,7 +428,7 @@
Model Summary
-------------------------------------------------------------------
R 0.878 RMSE 188.249
R-Squared 0.771 MSE 39053.801
R-Squared 0.771 MSE 35437.709
Adj. R-Squared 0.753 Coef. Var 28.147
Pred R-Squared 0.695 AIC 730.924
MAE 140.619 SBC 742.858
Expand Down Expand Up @@ -578,7 +578,7 @@
Model Summary
-------------------------------------------------------------------
R 0.878 RMSE 188.249
R-Squared 0.771 MSE 39053.801
R-Squared 0.771 MSE 35437.709
Adj. R-Squared 0.753 Coef. Var 28.147
Pred R-Squared 0.695 AIC 730.924
MAE 140.619 SBC 742.858
Expand Down
18 changes: 9 additions & 9 deletions tests/testthat/_snaps/stepaic-b-output.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
Model Summary
-------------------------------------------------------------------
R 0.884 RMSE 184.276
R-Squared 0.781 MSE 38202.426
R-Squared 0.781 MSE 33957.712
Adj. R-Squared 0.758 Coef. Var 27.839
Pred R-Squared 0.700 AIC 730.620
MAE 137.656 SBC 744.543
Expand Down Expand Up @@ -100,7 +100,7 @@
Model Summary
-------------------------------------------------------------------
R 0.884 RMSE 184.276
R-Squared 0.781 MSE 38202.426
R-Squared 0.781 MSE 33957.712
Adj. R-Squared 0.758 Coef. Var 27.839
Pred R-Squared 0.700 AIC 730.620
MAE 137.656 SBC 744.543
Expand Down Expand Up @@ -251,7 +251,7 @@
Model Summary
-------------------------------------------------------------------
R 0.884 RMSE 184.276
R-Squared 0.781 MSE 38202.426
R-Squared 0.781 MSE 33957.712
Adj. R-Squared 0.758 Coef. Var 27.839
Pred R-Squared 0.700 AIC 730.620
MAE 137.656 SBC 744.543
Expand Down Expand Up @@ -309,7 +309,7 @@
Model Summary
-------------------------------------------------------------------
R 0.878 RMSE 188.249
R-Squared 0.771 MSE 39053.801
R-Squared 0.771 MSE 35437.709
Adj. R-Squared 0.753 Coef. Var 28.147
Pred R-Squared 0.695 AIC 730.924
MAE 140.619 SBC 742.858
Expand Down Expand Up @@ -389,7 +389,7 @@
Model Summary
-------------------------------------------------------------------
R 0.878 RMSE 188.249
R-Squared 0.771 MSE 39053.801
R-Squared 0.771 MSE 35437.709
Adj. R-Squared 0.753 Coef. Var 28.147
Pred R-Squared 0.695 AIC 730.924
MAE 140.619 SBC 742.858
Expand Down Expand Up @@ -556,7 +556,7 @@
Model Summary
-------------------------------------------------------------------
R 0.878 RMSE 188.249
R-Squared 0.771 MSE 39053.801
R-Squared 0.771 MSE 35437.709
Adj. R-Squared 0.753 Coef. Var 28.147
Pred R-Squared 0.695 AIC 730.924
MAE 140.619 SBC 742.858
Expand Down Expand Up @@ -613,7 +613,7 @@
Model Summary
-------------------------------------------------------------------
R 0.878 RMSE 188.249
R-Squared 0.771 MSE 39053.801
R-Squared 0.771 MSE 35437.709
Adj. R-Squared 0.753 Coef. Var 28.147
Pred R-Squared 0.695 AIC 730.924
MAE 140.619 SBC 742.858
Expand Down Expand Up @@ -693,7 +693,7 @@
Model Summary
-------------------------------------------------------------------
R 0.878 RMSE 188.249
R-Squared 0.771 MSE 39053.801
R-Squared 0.771 MSE 35437.709
Adj. R-Squared 0.753 Coef. Var 28.147
Pred R-Squared 0.695 AIC 730.924
MAE 140.619 SBC 742.858
Expand Down Expand Up @@ -860,7 +860,7 @@
Model Summary
-------------------------------------------------------------------
R 0.878 RMSE 188.249
R-Squared 0.771 MSE 39053.801
R-Squared 0.771 MSE 35437.709
Adj. R-Squared 0.753 Coef. Var 28.147
Pred R-Squared 0.695 AIC 730.924
MAE 140.619 SBC 742.858
Expand Down
Loading

0 comments on commit e40e7f0

Please sign in to comment.