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

Code for plotting continuous effect #198

Closed
SejerMeyhoff opened this issue Jan 14, 2020 · 16 comments
Closed

Code for plotting continuous effect #198

SejerMeyhoff opened this issue Jan 14, 2020 · 16 comments

Comments

@SejerMeyhoff
Copy link

SejerMeyhoff commented Jan 14, 2020

Hi Brian,

I have a quick question about the code you put together for plotting continuous effects in the alligator example (#180). I've been able to use your code for plotting diet proportion against time with my models, and it works great most of the time. However, once in a while I get a plot where the median line is outside of the upper and lower bound of the ribbon (95% CI), like in the plot I have attached.

I didn't really change anything in your script aside from the number of lines and ribbons in the plot. Is there an obvious reason for this that I am missing?

Time series MAHY V8 Three-source Trophic
MAHY V8 Three-source Trophic

@brianstock
Copy link
Owner

brianstock commented Jan 15, 2020

Hmm, that shouldn't be happening! Sorry, not sure. Have you convinced yourself it's the calculated values themselves and not a plotting issue with geom_ribbon? I.e., are the median values > upper CI, looking at df[df$source=="Prey insects","high"] vs. df[df$source=="Prey insects","median"]? The median p's look like they add to 1 (or close), so that's good.

Unrelated: are you sure you're plotting 95% CI? The script you linked to does 90% CI by default unless you've changed it on lines 84-89.

@SejerMeyhoff
Copy link
Author

I believe it is plotting the df correctly. Looking at the df for the first time interval in May, the median is 0.11, the 'low' value 0.04 and 'high' .05. For August it's: median 0.54, low 0.36, and high 0.52.

And yes, I did change it to 95% CI by just moving the #'s from the default.

Thanks.

@brianstock
Copy link
Owner

Shoot. Has anyone else seen this before? @AndrewLJackson @andrewcparnell @ericward-noaa

@andrewcparnell
Copy link
Collaborator

Haven't seen this before I'm afraid - though a possible thought is that's something to do with transformations from e.g. clr/ilr space to proportions. Sometimes errors bars can get out of order. Any chance of an MRE?

@SejerMeyhoff
Copy link
Author

Something else I noticed in the df is that for some of my sources the values in the 'high' and 'low' columns are reversed. As in the value in the 'high' column is lower than the 'low'. But in most cases still around the median.

@brianstock
Copy link
Owner

Interesting. If you can post/send a MRE like Andrew suggests, I can take a look since it seems like a problem with the transformation code.

@ericward-noaa
Copy link
Collaborator

I think there's a couple potential issues. First -- @SejerMeyhoff , I assume you have checked the way you're putting the dataframe together?

If that's not the case, looking at the plotting script for the alligator example, I think there's potentially a problem in the order of operations. The way it's set up now is that (1) the quantiles on the proportions are taken in ILR space, and then (2) transformed from ILR to normal space. I think these should be switched. It's computationally a lot more to back transform all the proportions, but then generating the quantiles wouldn't lead to wonky behavior.

@SejerMeyhoff
Copy link
Author

Thank you for the comments everyone. @ericward-noaa I must admit I am not that R savvy. I have a basic understanding of how the script works, but I hadn't thought of that. I will give it a shot, thanks.

@SejerMeyhoff
Copy link
Author

SejerMeyhoff commented Jan 17, 2020

@brianstock gladly, could you provide some guidance on how to do that?

e: sent you an email

@brianstock
Copy link
Owner

brianstock commented Oct 15, 2020

Sorry for taking so long to get to this. These bugs should be taken care of now. I tested the fix using your grouse data, so you should be all set.

I also added new options for these plots:

  • alphaCI lets you set the credible interval width (default = 0.05, gives 95% CI)
  • exclude_sources_below will not plot sources with median proportion below this level for the entire range of continuous variable (default = 0.10)

@SejerMeyhoff
Copy link
Author

SejerMeyhoff commented Nov 23, 2020 via email

@jwschloemer
Copy link

@SejerMeyhoff @brianstock I'm having a difficult time figuring out how to produce figure 5 from that report by modifying Brians script for figure 6. Would you perhaps give me a pointer (or several) or share your script with me so that I can produce a ribbon plot similar to yours? I'm trying to portray diets with 4 sources over a gradient of glacial coverage (continuous). My script can be provided. Arggh

@jwschloemer
Copy link

I'll add that plot_continuous_var isn't working for me, although that could be user error?

@brianstock
Copy link
Owner

plot_continuous_var() should be fixed in v3.1.12, such that you only need to run:

plot_continuous_var(jags.1, mix, source, output_options, alphaCI=0.05, exclude_sources_below=0.1)

Do you have v3.1.12 installed?

@jwschloemer
Copy link

Yes that is the version I am working with. An warning message is displayed:

Warning message:
In FUN(X[[i]], ...) : Failed to set trace monitor for ilr.global
Monitor already exists and cannot be duplicated

Furthermore, the output of plot_continuous_var() comes out NULL. Is there a degree of continuity required for the function to work? In my mix I am using dummy variables 1-5 to represent a continuous gradient that my sites were chosen by and there are two factors (one fixed, one random, neither nested). Sources are means with no factors.

If I run the model with only one fixed factor it seems to work. Thoughts?

@brianstock
Copy link
Owner

Sorry, it's hard for me to diagnose the problem without seeing your data and model output. If you send me an email I can try to troubleshoot: bstock09@gmail.com.

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

No branches or pull requests

5 participants