brianstock / MixSIAR

A framework for Bayesian mixing models in R:
http://brianstock.github.io/MixSIAR/
91 stars 75 forks source link

"plot_intervals" scale problem #317

Open wholthuijzen opened 2 years ago

wholthuijzen commented 2 years ago

Hello! I am trying to plot the credible intervals of the proportion estimates to examine differences among factor levels (i.e., different habitat types). When I try to use the "plot_intervals" function, I receive the following message:

"Scale for 'y' is already present. Adding another scale for 'y', which will replace the existing scale. Scale for 'x' is already present. Adding another scale for 'x', which will replace the existing scale."

This is the code that I am running: plot_intervals(combined, toplot = "fac1", levels = NULL, groupby = "factor")

How do I fix this? Thanks in advance--I really appreciate all the documentation and help that you have provided for this package!

brianstock commented 2 years ago

That looks like a warning and not an error. Is there a problem with the plot?

You'd need to give more information - post a minimal example (data and code).

wholthuijzen commented 2 years ago

To give more context, I am running a model with 6 sources and then I used the combine_sources function to aggregate sources after running the model: combine.mod6habxses <- combine_sources(jags.mod6habxses, mix, source, groups=list(C3= "C3", C4= "C4", Albatross="LAYALB", Arthropods= c("Arthropods","Blattodea", "Megaselia scalaris")))

In trying to recreate the error messages that I got when I originally ran the model, I now encountered a couple of different error messages when using the summary _stat or plot_interval functions:

summary_stat(combine.mod6habxses, meanSD=FALSE, quantiles=c(.025,.5,.975), savetxt=FALSE) Error in dimnames(x) <- dn : length of 'dimnames' [1] not equal to array extent

summary_stat(combine.mod6habxses) Error in cbind(fac1_means, fac1_quants) : number of rows of matrices must match (see arg 2)

And, when I try to just plot the posterior interval estimates for the 4 aggregated sources for the 4 levels of habitat types in my model, I get this:

plot_intervals(combine.mod6habxses, toplot="fac1") Error in select_parameters(): ! No matches for 'regex_pars'. Run rlang::last_error() to see where the error occurred.

I've gone back through my mix and source files to see if there were any errors there, but I'm not sure what the problem is exactly? Any help is much appreciated!

brianstock commented 2 years ago

I can't help unless you post a minimal reproducible example: https://stackoverflow.com/help/minimal-reproducible-example.

On Tue, Aug 16, 2022, 5:35 PM Wieteke Holthuijzen @.***> wrote:

To give more context, I am running a model with 6 sources and then I used the combine_sources function to aggregate sources after running the model: combine.mod6habxses <- combine_sources(jags.mod6habxses, mix, source, groups=list(C3= "C3", C4= "C4", Albatross="LAYALB", Arthropods= c("Arthropods","Blattodea", "Megaselia scalaris")))

In trying to recreate the However, when I run the summary _stat or plot_interval functions, I got a few error messages:

summary_stat(combine.mod6habxses, meanSD=FALSE, quantiles=c(.025,.5,.975), savetxt=FALSE) Error in dimnames(x) <- dn : length of 'dimnames' [1] not equal to array extent

summary_stat(combine.mod6habxses) Error in cbind(fac1_means, fac1_quants) : number of rows of matrices must match (see arg 2)

And, when I try to just plot the posterior interval estimates for the 4 aggregated sources for the 4 levels of habitat types in my model, I get this:

plot_intervals(combine.mod6habxses, toplot="fac1") Error in select_parameters(): ! No matches for 'regex_pars'. Run rlang::last_error() to see where the error occurred.

I've gone back through my mix and source files to see if there were any errors there, but I'm not sure what the problem is exactly? Any help is much appreciated!

— Reply to this email directly, view it on GitHub https://github.com/brianstock/MixSIAR/issues/317#issuecomment-1216805534, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABHDA46L6V6RJ4GDYKPBP5TVZOYLZANCNFSM542V357Q . You are receiving this because you commented.Message ID: @.***>

wholthuijzen commented 2 years ago

Ok, let me switch over to the "Mantis Example” data from deVries et al. in the MixSIAR GUI User Manual v3.1--when I run that script and try to use the plot_intervals function, I still get a warning message that I originally posted about--or, at least I can't view these plots:

Original 6-source model

plot_intervals(original,toplot="fac1") Scale for 'y' is already present. Adding another scale for 'y', which will replace the existing scale. Scale for 'x' is already present. Adding another scale for 'x', which will replace the existing scale.

Aggregated posteriors, 6 sources combined into 2 groups

plot_intervals(combined,toplot="fac1") Scale for 'y' is already present. Adding another scale for 'y', which will replace the existing scale. Scale for 'x' is already present. Adding another scale for 'x', which will replace the existing scale.

level 1 = Seagrass

plot_intervals(combined,toplot="fac1",levels=1) Scale for 'y' is already present. Adding another scale for 'y', which will replace the existing scale. Scale for 'x' is already present. Adding another scale for 'x', which will replace the existing scale.

level 2 = Coral

plot_intervals(combined,toplot="fac1",levels=2) Scale for 'y' is already present. Adding another scale for 'y', which will replace the existing scale. Scale for 'x' is already present. Adding another scale for 'x', which will replace the existing scale.

brianstock commented 2 years ago

Sorry, I don't know why. I get those warnings about scale already present, but the plots also come out fine as in the manual

> plot_intervals(combined,toplot="fac1")
Scale for 'y' is already present. Adding another scale for 'y', which will
replace the existing scale.
Scale for 'x' is already present. Adding another scale for 'x', which will
replace the existing scale.

fac1_intervals

wholthuijzen commented 2 years ago

Ok, I have uninstalled/reinstalled MixSIAR, re-run the Mantis example and now I can get the plots to show up, despite the warnings about scale already being present. Whew--at least that is working now!

However, with my own data set, when I use the plot_intervals function to plot the multiplicative error terms ("epsilon"), that works (the plot pops up with the scale already present warning). However, when I try to use the plot_intervals function to plot for my fixed effect factor (habitat, of which there are four levels), I still get this error message:

plot_intervals(combine.mod6habxses, toplot="fac1") Error in select_parameters(): ! No matches for 'regex_pars'. Run rlang::last_error() to see where the error occurred.

It wouldn't be such an issue if I could just get the summary stats for the aggregated sources, but even when I run the summary_stat function, I get this error:

summary_stat(combine.mod6habxses) Error in cbind(fac1_means, fac1_quants) : number of rows of matrices must match (see arg 2)

Any idea on how to troubleshoot either one of these error messages? I have gone through many other posts about these error messages more generally, but am pretty stuck on trying to figure out how to fix or address this issue. Again, thank you for taking the time to help me with all of this! MixSIAR has been really helpful in my work--thank you to you and your colleagues for putting this package and all of the thorough documentation together!

wholthuijzen commented 2 years ago

To ask my question a little more specifically--is there another way to extract the summary statistics (mean, SD, quantiles) for the aggregated sources (after using the combine_sources function) other than the summary_stat function?

shwalters commented 6 months ago

I have been having the same error with the summary_stat function. I would like to know what arg 2 is... Does this function not work on models with more than 2 factors?