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

Wrong normalization in rho plotting? #342

Closed
lorenzo-zuccato opened this issue Nov 20, 2023 · 6 comments
Closed

Wrong normalization in rho plotting? #342

lorenzo-zuccato opened this issue Nov 20, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@lorenzo-zuccato
Copy link

Hi,
I wanted to ask clarifications about the rho plotting from the function plot.BayesMallows. I was perplexed about the normalization in line 69 of the file plot.BayesMallows.R. In case of multiple clusters I think the results does not sum to 1 for every cluster. I would use something like

df$pct <- ave(df$n, df$cluster, df$item, FUN = function(x){x / sum(x)})

instead of

df$pct <- df$n / sum(df$n)

Hope that this makes sense :)

@wleoncio
Copy link
Member

It would be useful to get a reproducible example for the case of multiple clusters. I've probably misunderstood, but at least in the 2 examples in the test-plot.R file the current code adds to 1 and the proposal doesn't (see images below, where a breakpoint was added just before that line).

bilde
(...)
bilde

Lorenzo, can you confirm you're running the latest build (currently, 1.4.0.9002) of the package?

@lorenzo-zuccato
Copy link
Author

The sum you are performing returns the number of clusters fitted by the model. This is because I think there is a different distribution of the consensus for every cluster.

set.seed(1234)
bm <- compute_mallows(mini_test, n_clusters = 3, nmc = 10000)

bm$burnin <- 1000

plot(bm, parameter = "rho", item = 1)

Rplot

Here you see that you obtain 1 if you sum the values in all graphs. Instead I would expect something where every single graph sums to 1.
Rplot01

@wleoncio
Copy link
Member

Thanks for the clarification! This goes over my head, so I'll leave it to @osorensen to analyse the case. :)

@osorensen
Copy link
Collaborator

Thanks @lorenzo-zuccato and @wleoncio. I'll take a look.

@osorensen
Copy link
Collaborator

Issue fixed now. Thanks for reporting @lorenzo-zuccato. It actually turned out the ggplot2 could do much of the data processing job, so was able to remove a couple of codelines at the same time.

Note that the plot design is different now, since I'm using ggplot2::geom_histogram(), but since a ggplot object is returned, it's possible to define exactly the style you like.

library(BayesMallows)
set.seed(1234)
bm <- compute_mallows(potato_visual, n_clusters = 3, nmc = 1000)

bm$burnin <- 500

plot(bm, parameter = "rho", item = 1)

Created on 2023-11-23 with reprex v2.0.2

@osorensen osorensen added the bug Something isn't working label Nov 23, 2023
@osorensen
Copy link
Collaborator

Closed by #343

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants