Skip to content

Commit

Permalink
Update poly default
Browse files Browse the repository at this point in the history
  • Loading branch information
petersonR committed Jul 17, 2024
1 parent 67abc04 commit 15e3508
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 28 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# 0.3.0.9000

- Updated default `poly` to 2 so that limited non-linearities get discovered by default,
as advertised (thank you to the anonymous reviewer who noticed this)
- Fixed formatting issue in documentation for `sparseR`

# 0.3.0

- Fixed bug in the `effect_plot` function that was causing issues with
Expand Down
28 changes: 16 additions & 12 deletions R/sparseR.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
#' @param ncvgamma The tuning parameter for ncvreg (for MCP or SCAD)
#' @param lambda.min The minimum value to be used for lambda (as ratio of max,
#' see ?ncvreg)
#' @param k The maximum order of interactions to consider
#' @param poly The maximum order of polynomials to consider
#' @param k The maximum order of interactions to consider (default: 1; all
#' pairwise)
#' @param poly The maximum order of polynomials to consider (default: 2)
#' @param gamma The degree of extremity of sparsity rankings (see details)
#' @param cumulative_k Should penalties be increased cumulatively as order
#' interaction increases?
Expand Down Expand Up @@ -51,14 +52,17 @@
#' factors with low prevalence be combined?) - none (should no preprocessing be
#' done? can also specify a null object)
#'
#' The options that can be passed to `extra_opts` are: - centers (named numeric
#' vector which denotes where each covariate should be centered) - center_fn
#' (alternatively, a function can be specified to calculate center such as `min`
#' or `median`) - freq_cut, unique_cut (see ?step_nzv - these get used by the
#' filtering steps) - neighbors (the number of neighbors for knnImpute) -
#' one_hot (see ?step_dummy), this defaults to cell-means coding which can be
#' done in regularized regression (change at your own risk) - raw (should
#' polynomials not be orthogonal? defaults to true because variables are
#' The options that can be passed to `extra_opts` are:
#' - centers (named numeric vector which denotes where each covariate should be
#' centered)
#' - center_fn (alternatively, a function can be specified to calculate center
#' such as `min`
#' or `median`)
#' - freq_cut, unique_cut (see ?step_nzv; these get used by the filtering steps)
#' - neighbors (the number of neighbors for knnImpute)
#' - one_hot (see ?step_dummy), this defaults to cell-means coding which can be
#' done in regularized regression (change at your own risk)
#' - raw (should polynomials not be orthogonal? defaults to true because variables are
#' centered and scaled already by this point by default)
#'
#' \code{ia_formula} will by default interact all variables with each other up
Expand Down Expand Up @@ -96,7 +100,7 @@
sparseR <- function(formula, data, family = c("gaussian", "binomial", "poisson", "coxph"),
penalty = c("lasso", "MCP", "SCAD"), alpha = 1, ncvgamma = 3,
lambda.min = .005,
k = 1, poly = 1, gamma = .5, cumulative_k = FALSE,
k = 1, poly = 2, gamma = .5, cumulative_k = FALSE,
cumulative_poly = TRUE, pool = FALSE,
ia_formula = NULL,
pre_process = TRUE, model_matrix = NULL, y = NULL,
Expand Down Expand Up @@ -217,7 +221,7 @@ sparseR <- function(formula, data, family = c("gaussian", "binomial", "poisson",
ungroup() %>%
mutate(Vartype = as.character(.data$Vartype))

info <- list(k = k, poly = k, cumulative_k = cumulative_k,
info <- list(k = k, poly = poly, cumulative_k = cumulative_k,
cumulative_poly = cumulative_poly, pool = pool,
pre_process = pre_process, model_matrix = model_matrix, y = y,
poly_prefix = poly_prefix, int_sep = int_sep)
Expand Down
28 changes: 17 additions & 11 deletions man/sparseR.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions tests/testthat/test_plotting_sparseR.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ test_that("Plotting sparseR runs without error", {

test_that("Effect plots for sparseR run without error", {
expect_warning(effect_plot(obj1, coef_name = "Species"))
expect_warning(effect_plot(obj1, "Petal.Width", by = "Species"))
expect_silent(effect_plot(obj1, coef_name = "Petal.Width", by = "Species"))
expect_warning(effect_plot(obj1, coef_name = "Petal.Width"))
expect_warning(effect_plot(obj1, "Petal.Length", by = "Sepal.Length"))
expect_silent(effect_plot(obj1, coef_name = "Petal.Length", by = "Sepal.Length"))

expect_silent(effect_plot(obj2, coef_name = "Petal.Width"))
expect_silent(effect_plot(obj2, coef_name = "Species"))
expect_silent(effect_plot(obj2, "Petal.Width", by = "Species"))

expect_warning(effect_plot(obj3, coef_name = "Petal.Width"))
expect_warning(effect_plot(obj3, coef_name = "Species"))
expect_warning(effect_plot(obj3, "Petal.Width", by = "Species"))
expect_silent(effect_plot(obj3, "Petal.Width", by = "Species"))

expect_error(effect_plot(obj2, "Species", by = "Petal.Width"))
})
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test_sparseR_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ test_that("coef method works", {
obj2 <- sparseR(Sepal.Width ~ ., data = iris)
b <- coef(obj2, at = "cvmin")
sum(b != 0)
}, 18)
}, 16)

expect_equal({
sum(coef(obj2, at = "cv1se") != 0)
}, 11)
}, 6)
})

0 comments on commit 15e3508

Please sign in to comment.