Skip to content

Commit

Permalink
preparations for archiving
Browse files Browse the repository at this point in the history
  • Loading branch information
sablowes committed Jan 4, 2024
1 parent 7d54f8e commit 4539b7c
Show file tree
Hide file tree
Showing 16 changed files with 36 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ library(tidyverse)
library(brms)


# load('/data/idiv_chase/sablowes/homogenisation/data/allLRR_meta.Rdata')
load('~/Dropbox/1current/spatial_composition_change/results/allLRR_meta-new.Rdata')
load('~/Dropbox/1current/spatial_composition_change/results/ts-regions.Rdata')

load('~/Dropbox/1current/spatial_composition_change/WhittakerBetaChange/analysis/data/all_meta-new.Rdata')
load('~/Dropbox/1current/spatial_composition_change/WhittakerBetaChange/analysis/data/allLRR_meta-new.Rdata')
# id for regions in time series analyses
load('~/Dropbox/1current/spatial_composition_change/WhittakerBetaChange/analysis/data/ts-regions.Rdata')

regional_jk_summary <- regional_jknife_LRR %>%
group_by(regional_level) %>%
Expand Down Expand Up @@ -61,7 +63,7 @@ regional_ES_jk_norm_sigma2_ts_anti <- brm(bf(ES_gamma ~ 1 + (1 | regional_level)
mutate(logdt = log(dt),
regional_level = ifelse(regional_level == 'i_Lee (Florida (United States))',
'i_Lee', regional_level)) %>%
filter(regional_level %in% ts_regions$regional_level),
filter(!regional_level %in% ts_regions$regional_level),
prior = c(prior(normal(0,1), class = Intercept),
prior(normal(0,1), class = sd),
prior(normal(0,1), class = Intercept, dpar = sigma),
Expand Down
Binary file added analysis/01-processed-data/allLRR_meta-new.Rdata
Binary file not shown.
Binary file added analysis/01-processed-data/all_meta-new.Rdata
Binary file not shown.
File renamed without changes.
Binary file added analysis/01-processed-data/ts-regions.Rdata
Binary file not shown.
8 changes: 4 additions & 4 deletions analysis/Fig2-1-wrangle.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ library(tidybayes)
library(cowplot)


load('~/Dropbox/1current/spatial_composition_change/results/model_fits/local-ES-norm-sigma-641269.Rdata')
load('~/Dropbox/1current/spatial_composition_change/results/model_fits/local-ES-norm-sigma-3823365.Rdata')
load('~/Dropbox/1current/spatial_composition_change/results/model_fits/regional-ES-jk-norm-sigma.Rdata')
load('~/Dropbox/1current/spatial_composition_change/data/all_meta-new.Rdata')

Expand All @@ -15,7 +15,7 @@ all_meta <- all_meta %>%
'i_Lee', regional_level))

set.seed(101)
local_overall_post <- gather_draws(local_ES_norm_sigma2, b_Intercept) %>%
local_overall_post <- gather_draws(local_ES_norm_sigma, b_Intercept) %>%
# 90% credible interval of intercept
median_qi(.width = 0.9)

Expand All @@ -33,8 +33,8 @@ overall_intercept <- bind_cols(local_overall_post %>%
regional_Q05 = .lower) %>%
select(regional_intercept, regional_Q95, regional_Q05))

local_posterior_ES <- local_ES_norm_sigma2$data %>%
add_predicted_draws(object = local_ES_norm_sigma2, ndraws = 1000)
local_posterior_ES <- local_ES_norm_sigma$data %>%
add_predicted_draws(object = local_ES_norm_sigma, ndraws = 1000)

local_summary_ES <- local_posterior_ES %>%
group_by(regional_level) %>%
Expand Down
8 changes: 4 additions & 4 deletions analysis/Fig2-2-plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ alt_A <-

# use full posterior of the overall intercept estimates to calculate average rate of
# change in beta-diversity (d)
overall_d <- bind_cols(gather_draws(local_ES_norm_sigma2, b_Intercept, ndraws = 4000) %>%
overall_d <- bind_cols(gather_draws(local_ES_norm_sigma, b_Intercept, ndraws = 4000) %>%
ungroup() %>%
select(x = .value),
gather_draws(regional_ES_jk_norm_sigma2, b_Intercept, ndraws = 4000) %>%
Expand Down Expand Up @@ -162,6 +162,6 @@ ggsave('~/Dropbox/1current/spatial_composition_change/figures/results/Fig2.pdf',
width = 184, height = 100, units = 'mm')

overall_d %>%
summarise(median(dS),
quantile(dS, 0.05),
quantile(dS, 0.95))
summarise(median(d),
quantile(d, 0.05),
quantile(d, 0.95))
2 changes: 1 addition & 1 deletion analysis/FigS2.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,5 @@ ggplot() +


# two column fig Sci Adv
ggsave('~/Dropbox/1current/spatial_composition_change/figures/results/FigS1.pdf',
ggsave('~/Dropbox/1current/spatial_composition_change/figures/results/FigS2.pdf',
width = 184, height = 150, units = 'mm')
2 changes: 1 addition & 1 deletion analysis/FigS3.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ gamma_forest <- ggplot() +

# use full posterior of the overall average rates of changes at the alpha-
# and gamma-scales to estimate average beta-scale change
overall_d <- bind_cols(gather_draws(local_ES_norm_sigma2, b_Intercept, ndraws = 4000) %>%
overall_d <- bind_cols(gather_draws(local_ES_norm_sigma, b_Intercept, ndraws = 4000) %>%
ungroup() %>%
select(x = .value),
gather_draws(regional_ES_jk_norm_sigma2, b_Intercept, ndraws = 4000) %>%
Expand Down
22 changes: 11 additions & 11 deletions analysis/FigS4-and-S6.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ library(tidybayes)
library(cowplot)

# anti-ts data (models fit to two time points only)
load('~/Dropbox/1current/spatial_composition_change/results/model_fits/local-ES-norm-sigma-ts-anti-730659.Rdata')
load('~/Dropbox/1current/spatial_composition_change/results/model_fits/local-ES-norm-sigma-ts-anti-3823550.Rdata')
load('~/Dropbox/1current/spatial_composition_change/results/model_fits/regional-ES-jk-norm-sigma-ts-anti.Rdata')
# time series data (models fit to data > 2 time points)
load('~/Dropbox/1current/spatial_composition_change/results/model_fits/local-ES-norm-sigma-ts-730645.Rdata')
load('~/Dropbox/1current/spatial_composition_change/results/model_fits/local-ES-norm-sigma-ts-3802034.Rdata')
load('~/Dropbox/1current/spatial_composition_change/results/model_fits/regional-ES-jk-norm-sigma-ts.Rdata')
load('~/Dropbox/1current/spatial_composition_change/data/all_meta-new.Rdata')

Expand All @@ -25,7 +25,7 @@ all_meta <- all_meta %>%
'i_Lee', regional_level))

set.seed(101)
anti_ts_local <- gather_draws(local_ES_norm_sigma2_ts_anti, b_Intercept) %>%
anti_ts_local <- gather_draws(local_ES_norm_sigma_ts_anti, b_Intercept) %>%
# 90% credible interval of intercept
median_qi(.width = 0.9)

Expand Down Expand Up @@ -122,7 +122,7 @@ anti_ts_two_scale <-
labs(y = expression(paste(gamma-scale, ' effect size [log(S) / year]')),
x = expression(paste(alpha-scale, ' effect size [log(S) / year]')),
# tag = 'a',
title = expression(paste('Models fit to data with only\ntwo time points (n = 298)'))
title = expression(paste('Models fit to data with only\ntwo time points (n = 296)'))
) +
scale_x_continuous(breaks = c(0, 3e-3, 6e-3)) +
scale_y_continuous(breaks = c(0, 3e-4, 6e-4)) +
Expand All @@ -142,7 +142,7 @@ ts_d <- bind_cols(gather_draws(local_ES_norm_sigma2_ts, b_Intercept, ndraws = 40
select(y = .value)) %>%
mutate(d = y - x)

anti_ts_d <- bind_cols(gather_draws(local_ES_norm_sigma2_ts_anti, b_Intercept, ndraws = 4000) %>%
anti_ts_d <- bind_cols(gather_draws(local_ES_norm_sigma_ts_anti, b_Intercept, ndraws = 4000) %>%
ungroup() %>%
select(x = .value),
gather_draws(regional_ES_jk_norm_sigma2_ts_anti, b_Intercept, ndraws = 4000) %>%
Expand Down Expand Up @@ -186,7 +186,7 @@ fig3_beta_anti_ts <-
.width = c(0.50, 0.9)) +
geom_vline(xintercept = 0, lty = 2, colour = '#bdbdbd') +
scale_x_continuous(breaks = seq(from = -0.01, to = 0.01, by = 0.001),
labels = c('-0.01', '', '-0.008', '', '', '', '-0.004', '', '', '', '0', '', '' , '',
labels = c('', '', '-0.008', '', '', '', '-0.004', '', '', '', '0', '', '' , '',
'0.004', '', '', '', '', '', '0.01')) +
labs(x = expression(paste(Delta, beta, ' - diversity . ', year^-1)),
y = '') +
Expand Down Expand Up @@ -218,8 +218,8 @@ ggsave('~/Dropbox/1current/spatial_composition_change/figures/results/FigS4.pdf'
ts_local_posterior_ES <- local_ES_norm_sigma2_ts$data %>%
add_predicted_draws(object = local_ES_norm_sigma2_ts, ndraws = 1000)

anti_ts_local_posterior_ES <- local_ES_norm_sigma2_ts_anti$data %>%
add_predicted_draws(object = local_ES_norm_sigma2_ts_anti, ndraws = 1000)
anti_ts_local_posterior_ES <- local_ES_norm_sigma_ts_anti$data %>%
add_predicted_draws(object = local_ES_norm_sigma_ts_anti, ndraws = 1000)

ts_regional_posterior_ES <- regional_ES_jk_norm_sigma2_ts$data %>%
add_predicted_draws(object = regional_ES_jk_norm_sigma2_ts, ndraws = 1000)
Expand Down Expand Up @@ -301,9 +301,9 @@ concept_colour = c('Gain low occupancy' = '#61CDE0',
'Gain high occupancy' = '#D9D956')

# first, a plot to create the legend
load('~/Dropbox/1current/spatial_composition_change/results/model_fits/local-ES-norm-sigma-641269.Rdata')
load('~/Dropbox/1current/spatial_composition_change/results/model_fits/local-ES-norm-sigma-3823365.Rdata')
col_shape_leg_plot <- left_join(anti_ts_regional_d_summary,
local_ES_norm_sigma2$data %>%
local_ES_norm_sigma$data %>%
distinct(regional_level, sample_type, logdt)) %>%
mutate(dt = exp(logdt)) %>%
left_join(all_meta) %>%
Expand Down Expand Up @@ -333,7 +333,7 @@ col_shape_leg <- gg_legend(col_shape_leg_plot)

anti_ts_beta_dt <-
left_join(anti_ts_regional_d_summary,
local_ES_norm_sigma2_ts_anti$data %>%
local_ES_norm_sigma_ts_anti$data %>%
distinct(regional_level, logdt)) %>%
mutate(dt = exp(logdt)) %>%
left_join(all_meta) %>%
Expand Down
8 changes: 4 additions & 4 deletions analysis/FigS5.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ library(tidybayes)
library(cowplot)


load('~/Dropbox/1current/spatial_composition_change/results/model_fits/local-ES-norm-sigma-641269.Rdata')
load('~/Dropbox/1current/spatial_composition_change/results/model_fits/local-ES-norm-sigma-3823365.Rdata')
load('~/Dropbox/1current/spatial_composition_change/results/model_fits/regional-ES-jk-norm-sigma.Rdata')


dt <- local_ES_norm_sigma2$data %>%
dt <- local_ES_norm_sigma$data %>%
as_tibble() %>%
mutate(dt = exp(logdt)) %>%
group_by(sample_type) %>%
Expand All @@ -25,7 +25,7 @@ dt <- local_ES_norm_sigma2$data %>%
values_from = min_dt:max_logdt)


sigma_model_summary <- gather_draws(local_ES_norm_sigma2,
sigma_model_summary <- gather_draws(local_ES_norm_sigma,
b_sigma_Intercept,
b_sigma_sample_typeresurvey,
b_sigma_logdt,
Expand All @@ -47,7 +47,7 @@ sigma_model_summary <- gather_draws(local_ES_norm_sigma2,
values_from = c(.value, .lower, .upper)) %>%
bind_cols(dt)

sigma_local_CI <- local_ES_norm_sigma2$data %>%
sigma_local_CI <- local_ES_norm_sigma$data %>%
as_tibble() %>%
group_by(sample_type) %>%
modelr::data_grid(logdt, n = 51) %>%
Expand Down
8 changes: 4 additions & 4 deletions analysis/FigS6-1-wrangle-anti-ts-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ library(tidybayes)
library(cowplot)


load('~/Dropbox/1current/spatial_composition_change/results/model_fits/local-ES-norm-sigma-ts-anti-730659.Rdata')
load('~/Dropbox/1current/spatial_composition_change/results/model_fits/local-ES-norm-sigma-ts-anti-3823550.Rdata')
load('~/Dropbox/1current/spatial_composition_change/results/model_fits/regional-ES-jk-norm-sigma-ts-anti.Rdata')
load('~/Dropbox/1current/spatial_composition_change/data/all_meta-new.Rdata')

set.seed(101)
local_overall_post <- gather_draws(local_ES_norm_sigma2_ts_anti, b_Intercept) %>%
local_overall_post <- gather_draws(local_ES_norm_sigma_ts_anti, b_Intercept) %>%
# 90% credible interval of intercept
median_qi(.width = 0.9)

Expand All @@ -29,8 +29,8 @@ overall_intercept <- bind_cols(local_overall_post %>%
regional_Q05 = .lower) %>%
select(regional_intercept, regional_Q95, regional_Q05))

local_posterior_ES <- local_ES_norm_sigma2_ts_anti$data %>%
add_predicted_draws(object = local_ES_norm_sigma2_ts_anti, ndraws = 1000)
local_posterior_ES <- local_ES_norm_sigma_ts_anti$data %>%
add_predicted_draws(object = local_ES_norm_sigma_ts_anti, ndraws = 1000)

local_summary_ES <- local_posterior_ES %>%
group_by(regional_level) %>%
Expand Down
2 changes: 1 addition & 1 deletion analysis/FigS6-1-wrangle-ts-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ library(cowplot)


# load('~/Dropbox/1current/spatial_composition_change/results/model_fits/local-es-norm-sigma2-25428714.Rdata')
load('~/Dropbox/1current/spatial_composition_change/results/model_fits/local-ES-norm-sigma-ts-730645.Rdata')
load('~/Dropbox/1current/spatial_composition_change/results/model_fits/local-ES-norm-sigma-ts-3802034.Rdata')
# load('~/Dropbox/1current/spatial_composition_change/results/model_fits/regional-es-jk-norm-sigma2-25428781.Rdata')
load('~/Dropbox/1current/spatial_composition_change/results/model_fits/regional-ES-jk-norm-sigma-ts.Rdata')
load('~/Dropbox/1current/spatial_composition_change/data/all_meta-new.Rdata')
Expand Down
Binary file removed analysis/data/allLRR_meta-new.Rdata
Binary file not shown.
Binary file removed analysis/data/all_meta-new.Rdata
Binary file not shown.

0 comments on commit 4539b7c

Please sign in to comment.