-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreport_summary.Rmd
422 lines (261 loc) · 12.2 KB
/
report_summary.Rmd
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
---
output:
word_document:
fig_caption: true
fig_height: 10
fig_width: 10
reference_docx: bootstrap/initial/data/summaryTemplate.docx
toc: false
keep_md: false
params:
summary_title: ""
strata: NULL
---
```{r introduction, include = FALSE}
# INTRODUCTION ################################################################
# This markdown documents and integrated scripts analyse biological
# age readings.
# The output is a .docx template that includes
# the results of the analysis and should be used as a standard for
# reporting of age reading comparisons.
```
```{r chunk_setup, include=FALSE}
# CHUNK SETUPS #################################################################
knitr::opts_chunk$set(echo = FALSE, warning = FALSE,
message=FALSE, results = 'asis', dpi=400)
```
```{r pander_settings, include = FALSE}
# PANDER OPTIONS ##############################################################
panderOptions('table.split.table', Inf)
panderOptions('keep.trailing.zeros', TRUE)
panderOptions('table.alignment.default', "center")
panderOptions('knitr.auto.asis', FALSE)
group <- "adv"
# from extrafont
# font_import(pattern=c("Cali"))
# loadfonts(device="win")
```
---
title: `r params$summary_title`
---
# Executive summary
# Overview of samples and advanced readers
\br
```{r sample_overview}
modal_age_range <- range(ad_long_all$modal_age, na.rm = TRUE)
# Table caption
set.caption(paste('**Table X:** Overview of samples used for the exchange event', config$event_id, '. The modal age range for all samples is ', modal_age_range[1], "-", modal_age_range[2], '.', sep=""))
# Output table
pander(style_table0(sample_data_overview), style = "simple")
```
\br
```{r participants_overview}
# PARTICIPATANTS OVERVIEW #####################################################
# Table caption
set.caption('**Table X:** Overview of number of readers.')
# Output table
datab=filter(reader_data, Expertise!="Basic")
selvar=colnames(datab)[-c(1, 3)]
datab=ddply(datab, c(selvar), summarise, N_readers=length(Expertise))
pander(style_table0(datab))
```
<!-- ## Advanced readers -->
<!-- **All samples included** -->
# Results overview
## Multimodal cases
<!-- Total number of samples (NSample), number (CountMM) and percentage of multimodal cases (PercMM) text -->
```{r summary_multiple_modes}
summary_multiple_modes <-
c(NSample = length(unique(ad_long_adv$SampleID)),
PercMM_traditional=unique(ifelse(multimode_cases_tab_traditional_adv$NModes_trad=="zero", paste(0,"%"), paste(round((nrow(multimode_cases_tab_traditional_adv)/length(unique(ad_long_adv$SampleID)))*100, digits=0),"%"))),
PercMM_linear_weight=unique(ifelse(multimode_cases_tab_linear_adv$NModes_linear=="zero", paste(0,"%"), paste(round((nrow(multimode_cases_tab_linear_adv)/length(unique(ad_long_adv$SampleID)))*100, digits=0),"%"))),
PercMM_negexp_weight=unique(ifelse(multimode_cases_tab_negexp_adv$NModes_negexp=="zero", paste(0,"%"), paste(round((nrow(multimode_cases_tab_negexpweight_adv)/length(unique(ad_long_adv$SampleID)))*100, digits=0),"%"))),
PercMM_multistage=unique(ifelse(multimode_cases_tab_multistage_adv$NModes_multistage=="zero", paste(0,"%"), paste(round((nrow(multimode_cases_tab_multistage_adv)/length(unique(ad_long_adv$SampleID)))*100, digits=0),"%"))))
# Table caption
set.caption('**Table X:** Summary of statistics; Total number of samples (NSample), a percentage of cases (fish samples) with multiple modes depending on the approach to weight the experience of the reader which will be considered when defining the fish age mode. PercMM_traditional shows the percentage of the total samples for which multiple modes are obtained when all the readers are equally weighted. PercMM_linear_weight shows the percentage of the total samples for which multiple modes are obtained when the weight assigned to the different readers decreases linearly with the experience, while in the PercMM_negexp the weight applied decreases with a negative exponential shape with the experience. The PercMM_multistage shows the percentage of multiple mode cases when a combination of the different methodologies is used, as explained in the material and methods section')
# Output table
pander(style_table0(summary_multiple_modes), missing="")
```
## Age readings
```{r num_read_adv}
# Age readings TABLE - Advanced readers #################################################
# Table caption
set.caption('**Table X:** Age reading table shows the
number of readings by modal age.')
# Output table
pander(style_table1(num_read_tab_adv[,colnames(num_read_tab_adv) %in% c("Modal age", "total")]), missing = "-")
```
## CV table
```{r cv_adv}
# CV TABLE - Advanced readers #################################################
# Table caption
set.caption('**Table X:** Coefficient of Variation (CV) table presents the
CV per modal age for all advanced readers combined.')
# Output table
pander(style_table1(cv_tab_adv[,colnames(cv_tab_adv) %in% c("Modal age", "all")]), missing = "-")
```
## PA table
```{r percentage_agreement_adv}
# PERCENTAGE AGREEMENT TABLE - Advanced readers ###############################
# Table caption
set.caption('**Table X:** Percentage agreement (PA) table represents the PA per
modal age for all advanced readers combined.')
# Output table
pander(style_table1(pa_tab_adv[,colnames(pa_tab_adv) %in% c("Modal age", "total")]), missing = "-")
```
## APE table
```{r average_percentage_error_adv}
# AVERAGE PERCENTAGE ERROR TABLE - Advanced readers ###############################
# Table caption
set.caption('**Table X:** Average Percentage Error (APE) table represents the APE per
modal age for all advanced readers combined.')
# Output table
pander(style_table1(ape_tab_adv[,colnames(ape_tab_adv) %in% c("Modal age", "all")]), missing = "-")
```
## Relative bias table
```{r rb_adv,results='asis'}
# RELATIVE BIAS TABLE - Advanced readers ######################################
# Table caption
set.caption('**Table X:** The relative bias (as the difference between the mean and modal age) per
modal age for all advanced readers combined.')
# Output table
pander(style_table1(rel_bias_tab_adv[,colnames(rel_bias_tab_adv) %in% c("Modal age", "all")]), missing = "-")
```
## Bias plot
```{r bias_plots_exp, fig.width = 5, fig.height = 4, fig.cap = cap_in}
# BIAS PLOT - Advanced readers ################################################
# Table caption
cap_in <- '**Figure X:** Age bias plot for advanced readers.'
# Output table
plot_bias_all(ad_long_adv, max_age, max_modal, sel_readers="Advanced readers")
```
\br
## Growth analysis
```{r growth_analysis_exp, fig.width = 6, fig.height = 4, fig.cap = cap_in}
# GROWTH ANALYSIS - Advanced readers ##########################################
# Table caption
cap_in <- '**Figure X:** Plot of average distance from the centre to the winter
rings for advanced readers. The boxes represent
the median, upper and lower box boundaries of the interquartile range,
whiskers extend no further than 1.5 * IQR (where IQR is the inter-quartile
range) from the box boundary. Data beyond the end of the whiskers are
represent outlers and are plotted individually.'
# Output table
plot_growth(dist, ad_long_all, stratif = "no_stratification")
```
## Age error matrices AEM
### General Age Error Matrix (AEM)
```{r age_error_matrix_adv, results='asis'}
# General AEM - Advanced readers #################################################
# Table caption
cap_i <- "**Table X:** General Age error matrix (AEM). The modal age is in rows and the age classifications by the advanced readers in columns."
set.caption(cap_i)
pander(style_table3(ae_mat_adv[[1]]), missing = "-")
```
### AEM by ICES area
```{r age_error_matrix_by_area_adv, results='asis'}
# AEM by area - Advanced readers #################################################
# Loop through each area and output AEM for that area
for (i in seq_along(ae_mat_by_area_adv)) {
# name of strata
ices_area <- names(ae_mat_by_area_adv)[i]
# Table caption
cap_i <- paste0("**Table X:** Age error matrix (AEM) for ICES area ", ices_area,".")
set.caption(cap_i)
pander(style_table3(ae_mat_by_area_adv[[i]]), missing = "-")
}
```
### AEM by strata
```{r age_error_matrix_by_strata_adv, results='asis'}
# AEM by strata - Advanced readers #################################################
# Loop through each area and output AEM for that area
for (i in seq_along(ae_mat_by_strata_adv)) {
# name of strata
strata_name <- names(ae_mat_by_strata_adv)[i]
# Table caption
tempdat=t(as.data.frame(as.matrix(strsplit(strata_name, ", ")[[1]])))
colnames(tempdat)=config$strata
cap_i <- paste0("**Table X:** Age error matrix (AEM) for ", apply(tempdat, 1, function(x) {paste(str_to_title(config$strata), x, sep="_", collapse="_and_")}),".")
set.caption(cap_i)
pander(style_table3(ae_mat_by_strata_adv[[i]]), missing = "-")
}
```
<!-- Overall comparison of results by strata -->
```{r set_by_strata_adv}
# initialise strata loop
istrata <- 0
group <- "adv"
print_strata <- function() length(params$strata) >= istrata
```
```{r ref.label= 'strata_plus_one'}
```
```{r text_comparison, eval= print_strata()}
asis_output("***Overall comparison of results by strata***")
```
```{r ar_by_strata_adv, eval= print_strata()}
group <- "adv"
# NUMBER OF AGE READINGS PER STOCK - Advanced readers #########################
# Table caption
set.caption('**Table X:** Number of age readings per strata and modal age for all advanced readers combined.')
# Output table
pander(style_table1(get(vname("num_read_tab_by_strata"))), missing = "-")
```
\
```{r text_comparison_adv_I, eval= print_strata()}
asis_output("*Coefficient of Variation (CV)*")
```
```{r cv_by_strata_adv, eval= print_strata()}
# Table caption
set.caption('**Table X:** CV per strata and modal age for all advanced readers combined.')
# Output table
pander(style_table2(get(vname("cv_tab_by_strata"))), missing = "-")
```
\
```{r text_comparison_adv_II, eval= print_strata()}
asis_output("*Percentage of Agreement (PA)*")
```
```{r pa_by_strata_adv, eval= print_strata()}
# Section title
# Table caption
set.caption('**Table X:** Percentage Agreement per strata and modal age for all advanced readers combined.')
# Output table
pander(style_table2(get(vname("pa_tab_by_strata"))), missing = "-")
```
\
```{r text_comparison_adv_III, eval= print_strata()}
asis_output("*Average Percentage Error (APE)*")
```
```{r ape_by_strata_adv, eval= print_strata()}
# Section title
# Table caption
set.caption('**Table X:** Average Percentage Error per strata and modal age for all advanced readers combined.')
# Output table
pander(style_table2(get(vname("ape_tab_by_strata"))), missing = "-")
```
\
```{r text_comparison_adv_IV, eval= print_strata()}
asis_output("*Relative bias*")
```
```{r rb_by_strata_adv, eval= print_strata()}
# Section title
# Table caption
set.caption('**Table X:** Relative Bias per strata and modal age for all advanced readers combined.')
# Output table
pander(style_table2(get(vname("rel_bias_tab_by_strata"))), missing = "-")
```
\
```{r text_comparison_adv_V, eval= print_strata()}
asis_output("*Growth analysis*")
```
```{r growth_analysis_adv_by, fig.width = 8, fig.height = 4, fig.cap = cap_in, eval= print_strata()}
# GROWTH ANALYSIS - All readers ##########################################
# Table caption
cap_in <- '**Figure X:** Plot of average distance from the centre to the winter
rings for all advanced readers by strata. The boxes represent
the median, upper and lower box boundaries of the interquartile range,
whiskers represent the minimum and maximum values and the dots represent
the outliers.'
# Output table
plot_growth(dist, ad_long_adv, stratif = "all_strata")
```
# Conclusion