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

Coloring the posterior estimates by CP would make interpretation of plots easier #102

Open
jw5 opened this issue Jan 30, 2021 · 6 comments
Labels
enhancement New feature or request

Comments

@jw5
Copy link

jw5 commented Jan 30, 2021

First, fantastic package! Thank you.

When plotting the results of the model fit it can often be challenging to determine which posterior cp estimates (blue lines at bottom) correspond to the visual change points shown in the upper model curves. This is particularly difficult when one or more of the posterior estimates are bimodal, and worse still if overlapping :-(

8N6oKh8ewjEwHq8

If the individual CP posterior estimates were color coded things would be easier. You will note in my graph an attempt to identify the CP range using shaded regions and lines for the mean value.

Thanks,
Jim

Define the model with 3 CP

model = list(
y ~ 1, # plateau (int_1)
~ 0 + x, # joined slope (time_2) at cp_1
~ 1 + x, # disjoined slope (int_3, time_3) at cp_2
~ 1 + x # disjoined slope (int_4, time_4) at cp_3
)

model.string <- paste(sapply(model, function(x) Reduce(paste, deparse(x))), collapse = ", ")

Add prior knowledge to improve model

prior = list(
int_1 = 0, # Constant, not estimated
cp_1 = "dunif( 0, 200)", # has to occur in this interval
cp_3 = "dunif(300, 400)" # has to occur in this interval
)

@lindeloev
Copy link
Owner

It's definitely a good idea to identify the change point number in addition to their location! Thanks for a great mock-up to make this more specific.

A minimal version would be coloring the posterior densities - either just the line or also using a shade for the area. I will likely be working a bit with colors for categorical predictors (#90) in the next release, so we'll have to figure out a way to do both without having multiple meanings of each color. An issue could also be over-crowding.

Perhaps there's no catch-all solution. So we could let the user choose between a few options. plot(..., cp_dens = x) where x could be FALSE (or c()), c("dens", "color"), c("dens", "band"), c("dens", "color", "band"). This may be overkill and too much code to support, though.

@lindeloev lindeloev added the enhancement New feature or request label Feb 24, 2021
@mattmoo
Copy link

mattmoo commented Mar 16, 2021

I like the idea of shading only. As far as I can see, it doesn't really matter what number chain you're talking about, so it doesn't really make sense to distinguish them.

image

@MZelko82
Copy link

MZelko82 commented Aug 2, 2021

Excuse me if my etiquette is inappropriate here, but I've produced this for my own dataset, let me know if the code would be useful for your needs

GGplotEx

@jw5
Copy link
Author

jw5 commented Aug 2, 2021 via email

@MZelko82
Copy link

MZelko82 commented Aug 21, 2021

Hey Jim,

Apologies for the delay here, I've been familiarising myself with the practice of sharing code as well as adding some comments to the function to make it more readable.

Here is a link to the script in my repository:
https://github.com/MZelko82/mcp_scripts/blob/main/Predict_mcp_Graph.rmd

As it's my first one, I am very open to suggestions about how to improve it, etc.

Cheers,

Matt

@jw5
Copy link
Author

jw5 commented Aug 21, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants