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

orchard_plot() not robust to moderators with non-capitalised categories #64

Open
befriendabacterium opened this issue Aug 12, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@befriendabacterium
Copy link
Contributor

Describe the bug
When the levels of a categorical moderator are not capitalised to begin with, orchard_plot() breaks with changes to 'upper' or 'tree.order' options. Below I demonstrate with a reproducible example where I turn the factor to lowercase first. I also provide a workaround for the 'tree.order' break that might help you come up with a fix.

To Reproduce

# NON-CAPITALISED CATEGORIES --------------------------------------------------

data(lim)

#assume phylum is a lower-cased categorical variable from the start
lim$Phylum<-tolower(lim$Phylum)

# Add in the sampling variance
lim$vi <- (1/sqrt(lim$N - 3))^2

# Lets fit a meta-regression - I will do Article non-independence. The
# phylogenetic model found phylogenetic effects, however, instead we could fit
# Phylum as a fixed effect and explore them with an Orchard Plot
lim_MR <- metafor::rma.mv(yi = yi, V = vi, mods = ~ Phylum, random = list(~1 |
                                                                            Article, ~1 | Datapoint), data = lim)
summary(lim_MR)

## UPPER = F (WORKS) ------------------------------------------------

# Plot the meta-regression model with default order
orchard_plot(lim_MR, mod = "Phylum", group = "Article", xlab = "Correlation coefficient",
             alpha = 0.5, transfm = "tanh", angle = 45, N = "N", cb = FALSE, 
             upper = T)

## UPPER = F (BREAKS) ------------------------------------------------

orchard_plot(lim_MR, mod = "Phylum", group = "Article", xlab = "Correlation coefficient",
             alpha = 0.5, transfm = "tanh", angle = 45, N = "N", cb = FALSE, 
             upper = F)

## CHANGE ORDER (BREAKS) ------------------------------------------------

new.order<-rev(sort(unique(lim_MR$data$Phylum)))

# Plot the meta-regression model with new order
orchard_plot(lim_MR, mod = "Phylum", group = "Article", xlab = "Correlation coefficient",
             alpha = 0.5, transfm = "tanh", angle = 45, N = "N", cb = FALSE,
             tree.order = new.order)

## WORKAROUND FOR CHANGING ORDER BUG ------------------------------------------------

#Apply firstup to new.order to get it to work (workaround)
new.order_firstup<-firstup(new.order)

# Plot the meta-regression model with new order
orchard_plot(lim_MR, mod = "Phylum", group = "Article", xlab = "Correlation coefficient",
             alpha = 0.5, transfm = "tanh", angle = 45, N = "N", cb = FALSE,
             tree.order = new.order_firstup)

Expected behavior

# CAPITALISED CATEGORIES --------------------------------------------------

data(lim)

# Add in the sampling variance
lim$vi <- (1/sqrt(lim$N - 3))^2

# Lets fit a meta-regression - I will do Article non-independence. The
# phylogenetic model found phylogenetic effects, however, instead we could fit
# Phylum as a fixed effect and explore them with an Orchard Plot
lim_MR <- metafor::rma.mv(yi = yi, V = vi, mods = ~ Phylum, random = list(~1 |
                                                                               Article, ~1 | Datapoint), data = lim)
summary(lim_MR)

## UPPER = T (WORKS) ------------------------------------------------

# Plot the meta-regression model with default order
orchard_plot(lim_MR, mod = "Phylum", group = "Article", xlab = "Correlation coefficient",
             alpha = 0.5, transfm = "tanh", angle = 45, N = "N", cb = FALSE, 
             upper = T)

## UPPER = F (WORKS) ------------------------------------------------

orchard_plot(lim_MR, mod = "Phylum", group = "Article", xlab = "Correlation coefficient",
             alpha = 0.5, transfm = "tanh", angle = 45, N = "N", cb = FALSE, 
             upper = F)

## CHANGE ORDER (WORKS) ------------------------------------------------

new.order<-rev(sort(unique(lim_MR$data$Phylum)))

# Plot the meta-regression model with new order
orchard_plot(lim_MR, mod = "Phylum", group = "Article", xlab = "Correlation coefficient",
                      alpha = 0.5, transfm = "tanh", angle = 45, N = "N", cb = FALSE,
                      tree.order = new.order)

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser: NA
  • Version: NA

Additional context
Add any other context about the problem here.

@daniel1noble
Copy link
Owner

@befriendabacterium Thanks for this mate! So sorry I didn't see this. I can't understand why I'm not getting notified when there's a new issue. I have all the notifications setup to be received (or so I thought). I'll see if I can find some time to fix this, but feel free to chuck in a pull request as this looks fairly simple

@daniel1noble daniel1noble self-assigned this Sep 15, 2024
@daniel1noble daniel1noble added the bug Something isn't working label Sep 15, 2024
@befriendabacterium
Copy link
Contributor Author

Hi Dan - no worries, not sure why that is. I rely on the email notifications to be honest so only thing I can suggest is make sure they're not going to your junk?!

I don't have a fix for this right now, just the workaround above sorry! Bit hectic at the mo to give this the brain power it needs, but I hope it's an easy fix.

Thanks!
Matt

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

2 participants