Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add coefplot and groupedcoefplot for StatisticalModel #491

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
RecipesPipeline = "01d81517-befc-4cb6-b9ec-a95719d0359c"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
StatsAPI = "82ae8749-77ed-4fe6-ae5f-f523153014b0"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
StatsModels = "3eaba693-59b7-5ba5-a881-562e759f1c8d"
TableOperations = "ab02a1b2-a7df-11e8-156e-fb1833f50b87"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
Widgets = "cc8bc4a8-27d6-5769-a93b-9d913e69aa62"
Expand All @@ -36,16 +38,21 @@ Plots = "1.29"
RecipesBase = "0.6, 1"
RecipesPipeline = "0.2 - 0.6"
Reexport = "0.2, 1"
StatsAPI = "1.2"
StatsBase = "0.32, 0.33, 0.34"
StatsModels = "0.6, 0.7"
TableOperations = "0.2 - 0.3, 1"
Tables = "1"
Widgets = "0.5 - 0.6"
julia = "1.6"

[extras]
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
GLM = "38e38edf-8417-5370-95a0-9cbb8c7f171a"
NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "NaNMath", "StableRNGs"]
test = ["Test", "NaNMath", "StableRNGs", "DataFrames", "CategoricalArrays", "GLM"]
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -514,3 +514,23 @@ covellipse([0,2], [2 1; 1 4], n_std=2, aspect_ratio=1, label="cov1")
covellipse!([1,0], [1 -0.5; -0.5 3], showaxes=true, label="cov2")
```
![covariance ellipses](https://user-images.githubusercontent.com/4170948/84170978-f0c2f380-aa82-11ea-95de-ce2fe14e16ec.png)

## Coefficient plot

Coefficients of a `StatsAPI.RegressionModel` can be plotted with their standard deviation to easily visualize effect size.
A collection of models can be plotted together if the response variable is identical.

```julia
using GLM, RobustModels, RDatasets, StatsPlots

iris = dataset("datasets", "iris")
m = lm(@formula(PetalLength ~ SepalLength * Species), iris)
coefplot(m; intercept=true, orientation=:h)
coefplot(m; headers=true)

m2 = quantreg(@formula(PetalLength ~ SepalLength * Species), iris)
groupedcoefplot(m, m2; intercept=true, orientation=:h, label=["lm" "qr"])
groupedcoefplot(m, m2; headers=true, label=["lm" "qr"])
```

![coef plot]()
4 changes: 4 additions & 0 deletions src/StatsPlots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import Clustering: Hclust, nnodes
using Interpolations
using MultivariateStats: MultivariateStats
using AbstractFFTs: fft, ifft
using StatsAPI
using StatsModels
using StatsModels: hasintercept, TableRegressionModel, kron_insideout, vectorize
import KernelDensity
using NaNMath
@recipe f(k::KernelDensity.UnivariateKDE) = k.x, k.density
Expand Down Expand Up @@ -47,5 +50,6 @@ include("andrews.jl")
include("ordinations.jl")
include("covellipse.jl")
include("errorline.jl")
include("statsmodels.jl")

end # module
Loading