Git Product home page Git Product logo

Comments (2)

egouldo avatar egouldo commented on September 27, 2024

New Corrections to implement:

the big blue tit outliers were still present after the exclusions of highly collinear data, so this led to me to investigate why. It turns out that (a) they were not on the list to exclude because (b) they used conflicting language to describe one of the relevant variables which (apparently) caused me to code two variables incorrectly.

So, here are the two additional rows that should be excluded.

R_3rIdpCqsQtsmgqT	Adelong-1-1-1	1	1	1
R_3rIdpCqsQtsmgqT	Adelong-2-2-1	2	2	1

Also, we should correct the wrong coding so that, in the Sorensen's analysis, the correct comparisons are made. That correction would be (for these above two rows) the following:

  • rear_nest_CS should be 'NA' for both rows
  • d14_rear_nest_brood_size should 'd14_rear_nest_brood_size' for both rows.
  • Update create_internal_pkg_data.R
  • Ensure variables are recoded (locate file used in Sorensen's index calcs, see _targets.R)

from manyecoevo.

egouldo avatar egouldo commented on September 27, 2024

Reprex

(posting for record / transparency)

library(ManyEcoEvo)
library(tidyverse)
library(ggplot2)
library(ggforestplot)
library(NatParksPalettes)
library(metafor)
#> Loading required package: Matrix
#> 
#> Attaching package: 'Matrix'
#> The following objects are masked from 'package:tidyr':
#> 
#>     expand, pack, unpack
#> Loading required package: metadat
#> Loading required package: numDeriv
#> 
#> Loading the 'metafor' package (version 4.6-0). For an
#> introduction to the package please type: help(metafor)
plot_forest <- function(data, intercept = TRUE, MA_mean = TRUE){
  if (MA_mean == FALSE){
    data <- filter(data, Parameter != "overall")
  }
  
  p <- ggplot(data, aes(y = estimate, 
                        x =  term, 
                        ymin = conf.low, 
                        ymax = conf.high,
                        shape = parameter_type,
                        colour = parameter_type)) +
    geom_pointrange(fatten = 2) +
    ggforestplot::theme_forest() +
    theme(axis.line = element_line(linewidth = 0.10, colour = "black"),
          axis.line.y = element_blank(),
          text = element_text(family = "Helvetica")#,
          # axis.text.y = element_blank()
    ) +
    guides(shape = guide_legend(title = NULL), 
           colour = guide_legend(title = NULL)) +
    coord_flip() +
    ylab(bquote(Standardised~Effect~Size~Z[r])) +
    xlab(element_blank()) +
    # scale_y_continuous(breaks = c(-4,-3,-2,-1,0,1),
    # minor_breaks = seq(from = -4.5, to = 1.5, by = 0.5)) +
    NatParksPalettes::scale_color_natparks_d("Glacier")
  
  if(intercept == TRUE){
    p <- p + geom_hline(yintercept = 0)
  }
  if(MA_mean == TRUE){
    p <- p + geom_hline(aes(yintercept = meta_analytic_mean), 
                        data = data,
                        colour = "#01353D", 
                        linetype = "dashed")
  }
  
  return(p)
}
filter_params <- rlang::exprs(exclusion_set == "complete", 
                              publishable_subset == "All", 
                              expertise_subset == "All", 
                              # collinearity_subset == "All",
                              model_name == "MA_mod",
                              dataset == "blue tit")
summary_output_params <- rlang::exprs(tidy_mod_summary, MA_fit_stats, mod_fit_stats)
map2(.x = list(ManyEcoEvo_viz %>% filter(!!!filter_params)), 
     .y = summary_output_params, 
     .f = ~ select(.x, collinearity_subset, all_of(.y)) %>% unnest(.y) %>% knitr::kable(format = "pipe"))

[[1]]

collinearity_subset term type estimate std.error statistic p.value conf.low conf.high
All overall summary -0.3512059 0.0318587 -11.02388 0 -0.4136477 -0.2887640
collinearity_removed overall summary -0.3505434 0.0331427 -10.57678 0 -0.4155019 -0.2855848

[[2]]

collinearity_subset sigma2_1 sigma2_2 I2_Total I2_TeamIdentifier I2_TeamIdentifier/study_id
All 0.0315043 0.0522588 97.60961 36.71212 60.89749
collinearity_removed 0.0283110 0.0561354 97.64318 32.73525 64.90793

[[3]]

collinearity_subset AIC BIC TAU2 CochransQ p_CochransQ df_error Omnibus p_Omnibus
All 43.48352 52.08612 0 7441.531 0 130 121.5258 0
collinearity_removed 43.00683 51.31889 0 7160.488 0 118 111.8683 0
ManyEcoEvo_viz %>% filter(!!!filter_params) %>% 
  mutate(plot_data = map(model, 
                         .f = ~ broom::tidy(.x, 
                                            conf.int = TRUE, 
                                            include_studies = TRUE)%>% 
                           dplyr::mutate(point_shape = 
                                           ifelse(stringr::str_detect(term, "overall"), 
                                                  "diamond", 
                                                  "circle"),
                                         Parameter = 
                                           forcats::fct_reorder(term, 
                                                                estimate) %>% 
                                           forcats::fct_reorder(., 
                                                                point_shape,
                                                                .desc = TRUE))
  ),
  meta_analytic_mean = map_dbl(plot_data, 
                               ~ filter(.x, Parameter == "overall") %>% 
                                 pull(estimate))) %>% 
  group_by(collinearity_subset) %>% 
  group_split() %>% 
  map( ~ select(.x, plot_data, meta_analytic_mean) %>% 
         unnest(cols = c("plot_data")) %>% 
         mutate(parameter_type = case_when(str_detect(Parameter, "overall") ~ "mean",
                                           TRUE ~ "study")) %>% 
         arrange(desc(type)) %>% 
         mutate(type = forcats::as_factor(type)) %>% 
         group_by(type) %>% 
         arrange(desc(estimate),.by_group = TRUE) %>% 
         mutate(term = forcats::as_factor(term),
                point_shape = case_when(str_detect(type, "summary") ~ "mean",
                                        TRUE ~ "study")) %>% 
         plot_forest(intercept = TRUE, MA_mean = TRUE) +
         theme(axis.text.x = element_text(size = 15), 
               axis.title.x = element_text(size = 15),
               axis.text.y = element_blank()
         )) 

[[1]]

[[2]]

Created on 2024-06-14 with reprex v2.1.0

from manyecoevo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.