-
Notifications
You must be signed in to change notification settings - Fork 1
/
figure_s7.R
145 lines (136 loc) · 6.89 KB
/
figure_s7.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
library(here)
library(tidyverse)
library(MetBrewer)
setwd(here::here("results"))
load("ic.RData")
ic <- ic |>
dplyr::filter( (nobs > 1 & ndist > 1) | is.na(nobs)) |>
dplyr::group_by(simrep) |>
dplyr::mutate(min_num_obs = min(nobs, na.rm = TRUE),
max_num_obs = max(nobs, na.rm = TRUE)) |>
dplyr::filter(nobs == min_num_obs | nobs == max_num_obs | is.na(nobs)) |>
dplyr::mutate( type = ifelse(nobs == min_num_obs, "rare",
ifelse(nobs == max_num_obs, "common", NA)),
nsp = length(unique(sp))) |>
dplyr::group_by(simrep, type) |>
dplyr::mutate(first_sp = first(sp)) |>
dplyr::filter( sp == first_sp | is.na(first_sp)) |>
tibble::add_column(model = "ic") |>
dplyr::select(model, simrep, param, type, truth, mean, sd, `2.5%`, `97.5%`)
load("dc.RData")
dc <- dc |>
dplyr::filter( (nobs > 1 & ndist > 1) | is.na(nobs)) |>
dplyr::group_by(simrep) |>
dplyr::mutate(min_num_obs = min(nobs, na.rm = TRUE),
max_num_obs = max(nobs, na.rm = TRUE)) |>
dplyr::filter(nobs == min_num_obs | nobs == max_num_obs | is.na(nobs)) |>
dplyr::mutate( type = ifelse(nobs == min_num_obs, "rare",
ifelse(nobs == max_num_obs, "common", NA))) |>
dplyr::group_by(simrep, type) |>
dplyr::mutate(first_sp = first(sp)) |>
dplyr::filter( sp == first_sp | is.na(first_sp)) |>
dplyr::filter(!is.na(mean)) |>
dplyr::select(model, simrep, param, type, truth, mean, sd, `2.5%`, `97.5%`)
load("cc.RData")
cc <- cc |>
dplyr::group_by(simrep) |>
dplyr::mutate(min_num_obs = min(nobs, na.rm = TRUE),
max_num_obs = max(nobs, na.rm = TRUE)) |>
dplyr::filter(nobs == min_num_obs | nobs == max_num_obs | is.na(nobs)) |>
dplyr::mutate(type = ifelse(nobs == min_num_obs, "rare",
ifelse(nobs == max_num_obs, "common", NA))) |>
dplyr::group_by(simrep, type) |>
dplyr::mutate(first_sp = first(sp)) |>
dplyr::filter(sp == first_sp | is.na(first_sp)) |>
dplyr::filter(!is.na(mean)) |>
dplyr::select(model, simrep, param, type, truth, mean, sd, `2.5%`, `97.5%`)
load("is.RData")
is <- is |>
dplyr::mutate(type = ifelse(model == "isr", "rare", "common")) |>
dplyr::select(model, simrep, param, type, truth, mean, sd, `2.5%`, `97.5%`) |>
dplyr::filter(!is.na(mean))
load("ds.RData")
ds <- ds |>
dplyr::mutate(type = ifelse(model == "dsr", "rare", "common")) |>
dplyr::select(model, simrep, param, type, truth, mean, sd, `2.5%`, `97.5%`) |>
dplyr::filter(!is.na(mean))
load("cs.RData")
cs <- cs |>
dplyr::mutate(type = ifelse(model == "csr", "rare", "common")) |>
dplyr::select(model, simrep, param, type, truth, mean, sd, `2.5%`, `97.5%`) |>
dplyr::filter(!is.na(mean))
all <- dplyr::full_join(ic, dc) |>
dplyr::full_join(cc) |>
dplyr::full_join(is) |>
dplyr::full_join(ds) |>
dplyr::full_join(cs)
all |>
dplyr::mutate( cv = sd / abs(mean)) |>
dplyr::group_by( model, type, param) |>
dplyr::summarise( mean_cv = mean(cv)) |>
dplyr::filter(param %in% c(
"gamma0_ds",
"gamma0_c",
"alpha0",
"alpha1")) |>
dplyr::mutate( model_name = ifelse( model == "csr", "Single species, counts",
ifelse( model == "csc", "Single species, counts",
ifelse(model == "dsr", "Single species, distance sampling",
ifelse(model == "dsc", "Single species, distance sampling",
ifelse(model == "isc", "Single species, integrated",
ifelse(model == "isr", "Single species, integrated",
ifelse( model == "cc", "Community, counts",
ifelse(model == "dc", "Community, distance sampling",
ifelse(model == "ic", "Community, integrated", NA)))))))))) |>
dplyr::mutate( model_name = factor(model_name,
levels = c(
"Single species, counts",
"Single species, distance sampling",
"Single species, integrated",
"Community, counts",
"Community, distance sampling",
"Community, integrated"))) |>
dplyr::mutate(type = paste(type, "species")) |>
dplyr::mutate(type = str_to_sentence(type)) |>
dplyr::mutate(type = factor(type, levels = c("Rare species", "Common species"))) |>
dplyr::mutate(param = ifelse(param == "alpha0", "Abundance intercept",
ifelse(param == "alpha1", "Abundance covariate coefficient",
ifelse(param == "gamma0_ds", "Detection (distance sampling)",
"Detection (counts)")))) |>
dplyr::mutate( param = factor(param, levels = c(
"Abundance intercept",
"Abundance covariate coefficient",
"Detection (distance sampling)",
"Detection (counts)"))) |>
dplyr::group_by(type, param) |>
dplyr:: mutate(rank_mean_cv = rank(mean_cv),
prec_lab = paste0( sprintf("%.2f", round(mean_cv, 2)))) |>
dplyr::mutate(prec_lab_x = rank_mean_cv + 0.75) |>
ggplot2::ggplot(aes(x = rank_mean_cv, y = model_name, color = type)) +
ggplot2::facet_grid(type~param, scales = "free_x") +
ggplot2::scale_x_continuous(limits = c(0, 7),
breaks = c(1:6)) +
ggplot2::geom_point(size = 3) +
ggplot2::geom_text(aes(x = prec_lab_x, label = prec_lab), size = 3, color = "black") +
ggplot2::xlab( "Rank precision") +
ggplot2::scale_color_manual(values = MetPalettes$Hiroshige[[1]][c(7,9)])+
ggplot2::theme(panel.grid.minor = element_blank(),
axis.line = element_line(color = "black", size = 0.2),
axis.ticks = element_line(color = "black", size = 0.2),
axis.text.x = element_text(size = 9, color = "black"),
axis.title.x = element_text(size = 10, color = "black"),
legend.text = element_text(size = 10, color = "black"),
strip.text = element_text(size = 9, color = "black"),
legend.title = element_blank(),
legend.position = "bottom",
axis.title.y = element_blank(),
axis.text.y = element_text( size = c(9,9,9,9,9,12), color = "black",
face = c("plain", "plain", "plain", "plain", "plain", "bold")))
setwd(here::here("figures"))
ggplot2::ggsave(
"figure_s7.png",
width = 10,
height = 5,
units = "in",
dpi = 300
)