API Reference

SLOPE.slopeFunction
slope(x, y; kwargs...) -> NamedTuple

Fit a SLOPE (Sorted L1 Penalized Estimation) model to the provided data.

SLOPE is a regularization method that combines the L1 norm with a sorted penalty, encouraging both sparsity and grouping of features.

Arguments

  • x: Matrix of predictors (dense or sparse)
  • y: Response variable (vector)

Keyword Arguments

  • α::Union{AbstractVector,Real,Nothing}=nothing: Alpha sequence for regularization path
  • λ::Union{AbstractVector,Nothing}=nothing: Lambda sequence for regularization path
  • fit_intercept::Bool=true: Whether to fit an intercept term
  • loss::Symbol=:quadratic: Type of loss function
  • centering::Symbol=:mean: Method for centering predictors
  • scaling::Symbol=:sd: Method for scaling predictors
  • path_length::Int=100: Number of regularization path points
  • tol::Float64=1e-5: Convergence tolerance for optimization
  • max_it::Int=10000: Maximum number of iterations
  • q::Float64=0.1: Parameter controlling the shape of the penalty weights sequence. Should be in the range (0, 1).
  • max_clusters::Union{Int,Nothing}=nothing: Early path stopping criteria for maximum number of clusters (defaults to n+1)
  • dev_change_tol::Float64=1e-5: Early path stopping criteria for tolerance for change in deviance
  • dev_ratio_tol::Float64=0.999: Early path stopping criteria for tolerance for ratio of deviance
  • α_min_ratio::Union{Float64,Nothing}=nothing: Fraction of maximum α to use as minimum value in the regularization path. Defaults to 1e-2 if n > p * m, otherwise 1e-4.

Returns

A SlopeFit object.

source
SLOPE.SlopeFitType
SlopeFit

A structure containing the results of fitting a SLOPE model.

Fields

  • intercepts::Vector{Vector{Float64}}: A vector of intercept vectors along the regularization path. For each point in the path, contains a vector of length m with class-specific intercepts.
  • coefficients::Vector{SparseMatrixCSC{Float64,Int}}: A vector of sparse coefficient matrices along the regularization path. Each matrix is of size p×m where p is the number of predictors and m is the number of response classes (1 for regression).
  • α::Vector{Float64}: The alpha values used at each point of the regularization path.
  • λ::Vector{Float64}: The lambda values used at each point of the regularization path.
  • m::Int: The number of response classes (1 for regression, >1 for multinomial).
  • loss::Symbol: The loss function used in the model fitting process.
  • classes::Union{Vector,Nothing}: A vector of unique class labels for the response variable. This is nothing for regression models (continuous responses).
source
SLOPE.slopecvFunction
slopecv(
  x,
  y;
  α=nothing,
  λ=nothing,
  γ=[0.0],
  q=[0.1],
  n_folds=10,
  n_repeats=1,
  metric=:mse,
  kwargs...
)

Perform cross-validation for SLOPE to find optimal hyperparameters.

Arguments

  • x::Union{AbstractMatrix,SparseMatrixCSC}: Input feature matrix, can be dense or sparse.
  • y::AbstractVector: Response vector.

Keyword Arguments

  • α::Union{AbstractVector,Real,Nothing}=nothing: SLOPE regularization path. If nothing, it's automatically generated.
  • λ::Union{AbstractVector,Nothing}=nothing: Sequence of regularization parameters. If nothing, it's automatically generated.
  • γ::Union{AbstractVector,Real}=[0.0]: Parameter controlling the regularization sequence. Multiple values create a grid search.
  • q::Union{AbstractVector}=[0.1]: FDR parameter for BH sequence. Multiple values create a grid search.
  • n_folds::Int=10: Number of cross-validation folds.
  • n_repeats::Int=1: Number of times to repeat the CV process with different fold assignments.
  • metric::Symbol=:mse: Evaluation metric for cross-validation. Options include :mse, :mae, :accuracy, etc.
  • kwargs...: Additional parameters passed to the SLOPE solver.

Returns

A SlopeCvResult object.

Examples

# Basic usage with default parameters
result = slopecv(X, y)

# Cross-validation with custom parameters
result = slopecv(X, y, γ=[0.0, 0.1, 0.5], q=[0.1, 0.05], n_folds=5, metric=:accuracy)

# Access best parameters and score
best_q = result.best_params["q"]
best_γ = result.best_params["γ"]
best_score = result.best_score

See Also

  • slope: For fitting a SLOPE model with fixed parameters.
source
SLOPE.SlopeGridResultType
SlopeGridResult

Results for a specific hyperparameter combination in the SLOPE cross-validation grid search.

Fields

  • params::Dict{String,Any}: Dictionary of hyperparameter values (e.g., "q", "γ")
  • scores::Matrix{Real}: Cross-validation scores for each fold and alpha value
  • alphas::Vector{Real}: Sequence of alpha values for the regularization path
  • scores_means::Vector{Real}: Mean score across folds for each alpha
  • scores_errors::Vector{Real}: Standard errors of scores across folds
source
SLOPE.SlopeCvResultType
SlopeCvResult

Result structure from SLOPE cross-validation.

Fields

  • metric::Symbol: The evaluation metric used (e.g., :mse, :accuracy)
  • best_score::Real: The best score achieved during cross-validation
  • best_ind::Int: Index of the best parameter combination
  • best_α_ind::Int: Index of the best alpha value in the regularization path
  • best_params::Dict{String,Any}: Dictionary with the best parameter values
  • results::Vector{SlopeGridResult}: Grid search results, of type SlopeGridResult for each parameter combination
source

Plotting

RecipesBase.apply_recipeMethod
plot(cvresult::SlopeCvResult; xvar=:α, index=1; kwargs...)

Plots the cross-validation results from a cross-validated SLOPE model.

Arguments

  • cvresult::SLOPE.SlopeCvResult: The result of a cross-validated SLOPE model, containing multiple cross-validation results for different parameters.
  • xvar::Symbol=:α: Variable for the x-axis, options:
    • : Plot against the regularization parameter alpha (default)
    • :step: Plot against the step number in the regularization path
  • index::Int=1: Index of the cross-validation result to plot. If there are multiple values of γ or q, this specifies which set of these to visualize.

Keyword Arguments

  • kwargs...: Additional arguments passed to the plot, such as:
    • title: Title for the plot
    • legend: Legend position (default: :none)
    • lw: Line width
    • color: Color scheme

Returns

A plot object showing the cross-validation error, with ribbons for standard error.

source
RecipesBase.apply_recipeMethod
plot(fit::SLOPE.SlopeFit; xvar=:α, response=1, kwargs...)

Plot the coefficient paths from a SLOPE model regularization path.

This function visualizes how the coefficients change along the regularization path, allowing you to see which variables enter the model and how their effects change as the regularization strength varies.

Arguments

  • fit::SLOPE.SlopeFit: A fitted SLOPE model object containing the regularization path
  • xvar::Symbol=:α: Variable for the x-axis, options:
    • : Plot against the regularization parameter alpha (default)
    • :step: Plot against the step number in the regularization path
  • response::Int=1: For multi-response models, specifies which response's coefficients to plot
  • layout: (DEPRECATED) Layout for multi-class plots, e.g., (rows, cols). Default is (m, 1) for m classes.

Keyword Arguments

  • kwargs...: Additional arguments passed to the plot, such as:
    • title: Title for the plot
    • legend: Legend position (default: :none)
    • lw: Line width
    • color: Color scheme

Returns

A plot object showing the coefficient paths

source