Skip to content

A julia package to implement model selection algorithms on basic regression models.

License

Notifications You must be signed in to change notification settings

waitasecant/BestModelSubset.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BestModelSubset.jl

A julia package to implement model selection algorithms on basic regression models.

Build Status Coverage License

Installation

You can install BestModelSubset.jl using Julia's package manager

julia> using Pkg; Pkg.add(url="https://github.com/waitasecant/BestModelSubset.jl.git")

Example 1

Instantiate a ModelSelection object

# To execute forward step-wise selection with primary parameter to be R-squared score  
# and secondary parameter to be aic.
julia> obj = ModelSelection("forward", "r2", "aic")
ModelSelection(BestModelSubset.forward_stepwise, nothing, StatsAPI.r2, nothing,
               StatsAPI.aic, nothing, StatsAPI.r2, StatsAPI.aic)

Fit the ModelSelectionobject to the data

# The fit! function updates the fields of the `ModelSelection` object.
julia> Random.seed!(123); df = hcat(rand(Float64, (50, 21))); # 50*21 Matrix

julia> fit!(obj, df)
1-element Vector{Vector{Int64}}:
 [4, 5, 6, 16, 17, 18, 20]

Access various statistics like r2, adjr2, aic and bic for the selected model

julia> obj.r2
0.8174272341858757

julia> obj.aic
22.84823396671912

Example 2

Instantiate a ModelSelection object

# To execute best subset selection with primary parameter to be deviance  
# and secondary parameter to be bic.
julia> obj = ModelSelection("best", "deviance", "bic")
ModelSelection(BestModelSubset.best_subset, StatsAPI.deviance, nothing, nothing,
               nothing, StatsAPI.bic, StatsAPI.deviance, StatsAPI.bic)

Fit the ModelSelectionobject to the data

# The fit! function updates the fields of the `ModelSelection` object.
julia> Random.seed!(123); df = hcat(rand(Float64, (50, 20)), rand([0, 1], (50, 1))); # 50*21 Matrix

julia> fit!(obj, df)
1-element Vector{Vector{Int64}}:
 [8, 13]

Access various statistics like r2, adjr2, aic and bic for the selected model

julia> obj.deviance
61.39326332090434

julia> obj.bic
69.2173093317606

About

A julia package to implement model selection algorithms on basic regression models.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages