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

mcmc_pairs bivariate off-diagonal plot axis incorrect. #132

Open
strahl2e opened this issue Dec 17, 2017 · 6 comments
Open

mcmc_pairs bivariate off-diagonal plot axis incorrect. #132

strahl2e opened this issue Dec 17, 2017 · 6 comments

Comments

@strahl2e
Copy link

Data file: https://drive.google.com/open?id=1pnAUDCz9uscccSaUISodF9cqGF23uNzU

Off-diagonal bivariate scatter plot axes are out of line

My understanding from the documentation is that half the chains are used for each of the off-diagonal plots. In this example case (see posterior data file linked above) the chains have not converged and so the lower off-diagonal plot seems to be using chains that only sampled from one mode, using default condition I think this should be correct. I believe the x-axis should be inline with the above univariate marginal plot and the y-axis inline scaled as the x-axis of the upper off-diagonal bivariate plot?

load(file = "posterior.arr.RData")
mcmc_pairs(posterior, pars = c("u","v"))

mcmc_pairs_joint_samples_missing_data

@bob-carpenter
Copy link
Member

Thanks for the report.

It'd help to label the axes in the scatterplots. Are the histograms combining the draws from from both scatterplots? If so, I don't see anything wrong witht his plot other than that it's confusing having both histograms be aligned along the x axis and to have the scales not line up).

@jgabry
Copy link
Member

jgabry commented Dec 19, 2017

@strahl2e thanks for reporting.

@bob-carpenter Yes, the histograms along the diagonal combine all the draws.

I do think the axes are a bit confusing but I often find it nice to let them vary freely based on the contents of the plot. What if I add arguments that allow the user to specify whether the shared axes should or should not be the same across the plots?

@strahl2e
Copy link
Author

The first thing that made me think this was wrong is how it was different from the Stan version of pairs for the same data:

bayesplotaxeserrorstanpairsexample

Note: I had to recreate the above pairs plot from the Stan model, so it isn't exactly the same as the attached data in the original post - I've attached a link to this data below.

Interestingly this example produces an even more confusing BayesPlot:

bayesplotaxeserrorexample2

The data for the above is here:

https://drive.google.com/file/d/11Hcfs2D3BRH9XBJ5r2hoH5r5-2BltZZ8/view?usp=sharing

I understand that the difference is that mcmc_pairs is using half or so chains for one off-diagonal plot and the remaining chains for the other off-diagonal plot and so it can be that half the chains fit one mode and the remaining chains fit another, that I think is exactly what has happened here. I think this is very useful, to visualise what subsets of the chains are doing. But, I think the axes should be for the full space, of all modes, and then it is clear which mode is being fit by each subset of chains, plus it will line up with the histogram plots. The chains for this data look like this btw:

bayesplotaxeserrorchainseg2

@bob-carpenter
Copy link
Member

bob-carpenter commented Dec 22, 2017 via email

@strahl2e
Copy link
Author

@bob-carpenter Looking at the Stan pairs plot I think it is clear that on the right the histogram below lines up with the bivariate samples plotted above. It clearly shows the aliasing close to zero. I can see that in the mcmc version but it takes a bit longer to check the axes values and imagine the full plot.

@jgabry The idea of an option to align the axes sounds helpful, at least for me (and likely others) to understand the plot it would help.

jgabry added a commit that referenced this issue Mar 22, 2018
@jgabry jgabry added the bug label May 9, 2019
@martinmodrak
Copy link
Contributor

Was just bitten by this slightly. I'll just add an even simpler example:

N <- 1000
dd <- posterior::draws_array(a = c(runif(N * 2) * 0.5, runif(N * 2) * 0.5 + 0.5),
                             b = c(runif(N * 2) * 0.5, runif(N * 2) * 0.5 + 0.5),
                                  .nchains = 4
                                   )

bayesplot::mcmc_pairs(dd)                     

Produces a plot where you need to compare the scale labels to see any sort of an issue:

image

While there in fact is a substantial issue:

bayesplot::mcmc_pairs(dd, condition = bayesplot::pairs_condition(chains = list(c(1,3), c(2,4))))

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants