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

plot_cap() can have different model parameters as output #627

Merged
merged 8 commits into from
Jan 14, 2023

Conversation

tomicapretto
Copy link
Collaborator

@tomicapretto tomicapretto commented Jan 14, 2023

The function plot_cap() gains a new argument, target. This determines what parameter of the distribution is plotted as a function of the covariates. This is useful in distributional models. See the example

import bambi as bmb
import numpy as np
import pandas as pd

from bambi.plots import plot_cap

rng = np.random.default_rng(121195)
N = 200
a, b = 0.5, 1.1
x = rng.uniform(-1.5, 1.5, N)
shape = np.exp(0.3 + x * 0.5 + rng.normal(scale=0.1, size=N))
y = rng.gamma(shape, np.exp(a + b * x) / shape, N)
data_gamma = pd.DataFrame({"x": x, "y": y})

formula = bmb.Formula("y ~ x", "alpha ~ x")
model = bmb.Model(formula, data_gamma, family="gamma")
idata = model.fit(random_seed=1234)

The default behavior still shows the mean parameter.

plot_cap(model, idata, "x")

image

But we can have other targets as well

plot_cap(model, idata, "x", target="alpha")

image

Closes #622

tomicapretto and others added 6 commits January 14, 2023 13:38
Co-authored-by: Ravin Kumar <7213793+canyon289@users.noreply.github.com>
Co-authored-by: Ravin Kumar <7213793+canyon289@users.noreply.github.com>
Co-authored-by: Ravin Kumar <7213793+canyon289@users.noreply.github.com>
@codecov-commenter
Copy link

codecov-commenter commented Jan 14, 2023

Codecov Report

Merging #627 (2534768) into main (6fec04f) will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main     #627   +/-   ##
=======================================
  Coverage   86.63%   86.63%           
=======================================
  Files          37       37           
  Lines        2200     2200           
=======================================
  Hits         1906     1906           
  Misses        294      294           
Impacted Files Coverage Δ
bambi/plots/plot_cap.py 90.82% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@tomicapretto tomicapretto merged commit 9ba92e1 into bambinos:main Jan 14, 2023
@tomicapretto tomicapretto deleted the cap_multiple_outputs branch January 14, 2023 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow plot_cap() to work with any distribution parameter
3 participants