-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreport_full.Rmd
3485 lines (2086 loc) · 99.1 KB
/
report_full.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
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
output:
word_document:
fig_caption: true
fig_height: 10
fig_width: 10
reference_docx: bootstrap/initial/data/reportTemplate.docx
toc: true
keep_md: false
params:
report_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")
```
---
title: `r params$report_title`
---
# Executive summary
# Terms of reference
# Agenda and participant list
The agenda can be found in Annex 1 and the list of participants in Annex 2.
# Introduction
This part should include a background to the species, the workshop/exchange
and what to expect to read about in the report.
# Methods
This report contains statistical analyses and comparisons of age readings
in the form of tables and graphical plots.
First, an overview of participating age readers and the samples are presented.
Before each table or plot there is a short explanation. This text is
thought as a help to understand the tables/plots and can just be deleted in
the final output report if deemed unnecessary. The document can be edited just like any other
.docx file. New text can be added, additional figures and tables can be included and
the existing tables can be edited. If some tables which are presently in the annexes need to
be moved to the body of the report this is also possible. Only the plots
cannot be changed.
The first part of the results section include the tables and plots from the
Guus Eltink Excel sheet 'Age Reading Comparisons (Eltink, A.T.G.W. 2000).
The order and numbering of tables and plots are the same as in the excel sheet.
Tables 6.1 - 6.4 from the 'Age Reading Comparisons' sheet are not outputted
since these are merely used to do calculations for the other tables.
```{r text_mode_definition}
if(config$mode_definition=="standard") {
asis_output("**Modal age: a standard approach to define the modal age by sampled fish**
\
In this event, the standard approach to calculate the modal age has been used. When summarizing the output and reporting the results of the exchange events developed within the SmarDots framework, the modal age (the most common age decided by the readers for every fish sample) is the most relevant measurement. It is a key statistic by itself, but it is also fundamental for the estimation of some other relevant statistics to assess the performance of the techniques assessed in the exchange event, like the Percentage Agreement (PA), or input for stock assessments like the Age Error Matrix (AEM) (see below). It is important that with the standard approach to define the modal age by fish individual, the difference in the expertise of the readers is not accounted for, and, in case there are more that one modal age (two or more age categories with the same number of annotations by readers) the mode is decided as the lowest age of all the modal ages. If this standard approach has been selected by the event coordinator, it is specially important checking the table that indicates the percentage of multimodal cases (in the results section) and the table with the fishID and sampleID that obtained multiple modes (included in annex 3). It is important to consider that if the number of cases (FishID or sampleID) with multiple modes is high, this might lead to bias in the calculation of the PA and AEM.")
} else {if(config$mode_definition=="multistage"){
asis_output("**Modal age: a multistage approach to define the modal age by sampled fish**,
\
In this event, the multistage approach to calculate the modal age has been used. When summarizing the output and reporting the results of the exchange events developed within the SmarDots framework, the modal age (the most common age decided by the age readers for every fish sample) is the most relevant measurement. It is a key statistic by itself, but it is also fundamental for the estimation of some other relevant statistics to assess the performance of the techniques assessed in the exchange event, like the Percentage Agreement (PA), or input for stock assessments like the Age Error Matrix (AEM) (see below). However, the standard approach of calculating the mode (each reader has the same weight=1) the mode is taken as the lowest age of the multiple modal ages. This way renders multiple cases (fish samples) with multiple modal ages (i.e. different ages got the same highest number of readers). Accordingly, this imply a wrong perception of the age by fish individual and introduction of bias in the calculation of the PA and AEM. As a solution, in this report a multistage approach to select the modal age is used. This multistage approach is based in the different weight given to the age readers according to their experience. Two different weight scores scales were assigned, a weight score decreasing linearly with the experience and another decreasing with a negative exponential shape. The modal age by fish individual is decided following the next approach:
\
1.-If there is a single mode estimated with the standard approach (equal weight for all readers) this value is used as the modal age, if not
\
2.-Adding up, for each age category, the score assigned with the linear weighting for all the readers that decided that age for that fish. Next, the modal age is selected as the age category that obtains the highest score sum. If, despite this approach, there were still multiple ages with the same score (and hence multiple modes), the next step is applied:
\
3.-Adding up, for each age category, the score assigned with the negative exponential weighting for all the readers that decided that age for that fish. Select as the modal age the age with the highest score sum.
\
During the WGBIOP 2019 meeting it was found that the combination of the modes decided using these three methods (so called 'multistage approach'), allows assigning a single modal age to each fish individual.
\
It is important checking the table that indicates the percentage of multimodal cases (in the results section) and the table with the fishID and sampleID that obtained multiple modes (included in annex 3).
")
}
}
asis_output("***Samples split by strata***")
```
**Pecentage Agreement (PA)**
The percentage agreement per reader per modal age tells how large is the part of readings that are equal to the modal age. The percentage agreement is estimated by modal age and reader as the proportion (as percentage) of times that the lectures of that reader agreed with the resulting modal age.This percentage is estimated as the number of times that a reader agreed with the modal age divided by the total number of otoliths read by a reader for each modal age.
$$PA = { \frac{ {number \,of \,readings \,that \,agree \,with \,modal \,age}} {total \,number \,of \,readings \,by \,modal \,age} } \cdot {100 \%} $$
**Coefficient of Variation (CV)**
The table presents the Coefficient of Variation (CV) per modal age and reader. The CV's are calculated
as the ratio between the standard deviation (σ) and mean value (μ) per
reader and modal age:
$$CV = { \frac{ {\sigma}} {\mu} } \cdot {100 \%} $$
To the table is also added the CV of all readers combined per modal age and
a weighted mean of the CV per reader.
**Relative bias**
The relative bias is calculated as the difference between the mean and the modal age. This statistic is presented in first place by modal age and reader, but it is also calculated as an average value by modal age for all readers together (or only advanced readers).
**Average Percentage Error (APE)**
The Average Percentage Error (APE) was calculated based on the method outlined by Beamish & Fournier (1981).
This method is dependent of fish age and thus provides a better estimate
of precision than percentage agreement. As the calculations of both CV and APE pose problems if the mean
age is close to 0, all observations for which modal age was 0 were omitted
from the CV and APE calculations.
The average percentage error is calculated per image as:
$$APE = { \frac{ {100 \%}} {n} \sum_{i=1}^n |\frac{a_i-\bar{a}}{\bar{a}}| } $$
where $a_i$ is the age reading of reader $i$ and ${\bar{a}}$ is the mean
of all readings from 1 to $n$.
**Age error matrix (AEM)**
Age error matrices (AEM) were produced following procedures outlined
by WKSABCAL (2014) where the matrix shows the proportion of each modal
age mis-aged as other ages. The sum of each row is 1, which equals 100%.
The age data was analysed twice, the first time all readers were included
and the second time only the “advanced” readers were included. If a reader
is “advanced” then they are considered well trained and they provide ages
for stock assessment or similar purposes. When the AEM is compiled for
assessment purposes it uses only those readers who provide age data for
the stock assessment in that specific area.
**Otolith Growth Analysis**
SmartDots provides a measure of distance between the annotations made by
the readers and thus provides a measure of growth increment width.
This data is used to establish growth curves for each otolith (fish) and for each reader.
## Analysis of age calibration exercise (ToR?)
# Overview of samples and readers
\br
```{r sample_overview}
# Table caption
set.caption(paste('**Table X:** Overview of samples used for the exchange event number', config$event_id))
# Output table
pander(style_table0(sample_data_overview), style = "simple")
```
\br
```{r participants_overview}
# PARTICIPATANTS OVERVIEW #####################################################
# Table caption
set.caption('**Table X:** Reader overview.')
# Output table
pander(style_table0(reader_data), missing = "-")
```
## Results
### All readers
**All samples included**
Those writing the report put TEXT here describing the results
\
*Multimodal cases*
<!-- Total number of samples (NSample), number (CountMM) and percentage of multimodal cases (PercMM) text -->
```{r summary_multiple_modes_all}
summary_multiple_modes_all <-
c(NSample = length(unique(ad_long_all$SampleID)),
PercMM_traditional=unique(ifelse(multimode_cases_tab_traditional_all$NModes_trad=="zero", paste(0,"%"), paste(round((nrow(multimode_cases_tab_traditional_all)/length(unique(ad_long_all$SampleID)))*100, digits=0),"%"))),
PercMM_linear_weight=unique(ifelse(multimode_cases_tab_linear_all$NModes_linear=="zero", paste(0,"%"), paste(round((nrow(multimode_cases_tab_linear_all)/length(unique(ad_long_all$SampleID)))*100, digits=0),"%"))),
PercMM_negexp_weight=unique(ifelse(multimode_cases_tab_negexp_all$NModes_negexp=="zero", paste(0,"%"), paste(round((nrow(multimode_cases_tab_negexp_all)/length(unique(ad_long_all$SampleID)))*100, digits=0),"%"))),
PercMM_multistage=unique(ifelse(multimode_cases_tab_multistage_all$NModes_multistage=="zero", paste(0,"%"), paste(round((nrow(multimode_cases_tab_multistage_all)/length(unique(ad_long_all$SampleID)))*100, digits=0),"%"))))
# Table caption
set.caption('**Table X:** Total number of samples (NSample) and 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_all), missing="")
```
\
*List of multimodal cases*
```{r table_with_multimode_cases}
# Table of Multimodal cases - All readers ########################################
# Table caption
set.caption('**Table X:** List of cases for which multiple modes where obtained when all readers are considered. The column NModes_trad shows the number of multiple modes for each FishID or SampleID when all readers are given the same expertise weight.')
# Output table
pander(style_table2(get(vname("multimode_cases_tab_traditional"))),missing="-")
```
\
*Summary statistics*
<!-- Total number of samples (NSample), number (CountMM) and percentage of multimodal cases (PercMM), PA, CV and APE text -->
```{r summary_statistics_all}
summary_statistics_all <-
c(NSample = length(unique(ad_long_all$SampleID)),
CV = cv_tab_all[nrow(cv_tab_all), "all"],
PA = pa_tab_all[nrow(pa_tab_all), "total"],
APE = ape_tab_all[nrow(ape_tab_all), "all"])
# Table caption
set.caption('**Table X:** Summary of statistics; Total number of samples (NSample), coefficient of variance (CV), percentage of agreement (PA) and average percentage error (APE) for all ages and readers')
# Output table
pander(style_table0(summary_statistics_all), missing="")
```
In this exchange event, `r summary_statistics_all[1]` otolith fish individuals were aged. Of those, `r summary_multiple_modes_all[2]`when the traditional approach (all readers equally weighted) is used to define the mode. The percentage of multiple mode cases is reduced to `r summary_multiple_modes_all[5]`. The complete list of cases with multiple modes is presented in table X in the annex 3 section, where the ageing from each of the readers participating in the exchange event is presented. When all the otolith samples are considered (both single and multimodal cases) the weighted average percentage agreement based on modal ages for all readers is `r summary_statistics_all[3]`, with the weighted average CV of `r summary_statistics_all[2]` and APE of `r summary_statistics_all[4]`.
\
*Coefficient of Variation (CV)*
```{r cv_table}
# CV TABLE - All readers #####################################################
data=cv_tab_all
nstagers=length(unique(reader_data$'Reader code'))
ncols=dim(data[,!colnames(data) %in% c("all")])[2]
basicols=ncols-nstagers
Z=8
nfig=ceiling((dim(data)[2]-basicols)/Z)
N=min(Z,ncols)
for(i in 1:nfig)
{
if(i==1){
# Table caption
set.caption('**Table X:** Coefficient of Variation (CV) table presents the CV
per modal age and reader, the CV of all readers combined per modal
age and a weighted mean of the CV per reader')
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):((i+basicols+((N-1)*(i-1)))+(N-1)))]
pander(style_table1(selec), missing = "-")
} else { if(i<nfig){
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):((i+basicols+((N-1)*(i-1)))+(N-1)))]
pander(style_table1(selec), missing = "-")
} else {
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):dim(data)[2])]
pander(style_table1(selec), missing = "-")
}
}
}
```
\
*Percentage of Agreement (PA)*
<!-- PA text -->
The percentage agreement per reader per modal age tells how large part of the
readings that are equal to the modal age. The weighted mean including at the
bottom of the table is weighted according to number of age readings.
```{r percentage_agreement}
# PERCENTAGE AGREEMENT TABLE - All readers ####################################
data=pa_tab_all
nstagers=length(unique(reader_data$'Reader code'))
ncols=dim(data[,!colnames(data) %in% c("total")])[2]
basicols=ncols-nstagers
Z=8
nfig=ceiling((dim(data)[2]-basicols)/Z)
N=min(Z,ncols)
for(i in 1:nfig)
{
if(i==1){
# Table caption
set.caption('**Table X:** Percentage agreement (PA) table represents the PA per
modal age and reader, the PA of all readers combined per modal
age and a weighted mean of the PA per reader.')
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):((i+basicols+((N-1)*(i-1)))+(N-1)))]
pander(style_table1(selec), missing = "-")
} else { if(i<nfig){
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):((i+basicols+((N-1)*(i-1)))+(N-1)))]
pander(style_table1(selec), missing = "-")
} else {
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):dim(data)[2])]
pander(style_table1(selec), missing = "-")
}
}
}
```
\
*Average Percentage Error (APE)*
```{r average_percentage_error_all}
# AVERAGE PERCENTAGE ERROR TABLE - Advanced readers ###############################
data=ape_tab_all
nstagers=length(unique(reader_data$'Reader code'))
ncols=dim(data[,!colnames(data) %in% c("all")])[2]
basicols=ncols-nstagers
Z=8
nfig=ceiling((dim(data)[2]-basicols)/Z)
N=min(Z,ncols)
for(i in 1:nfig)
{
if(i==1){
# Table caption
set.caption('**Table X:** Average Percentage Error (APE) table represents the APE per
modal age and reader, the APE of all advanced readers
combined per modal age and a weighted mean of the APE per reader.')
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):((i+basicols+((N-1)*(i-1)))+(N-1)))]
pander(style_table1(selec), missing = "-")
} else { if(i<nfig){
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):((i+basicols+((N-1)*(i-1)))+(N-1)))]
pander(style_table1(selec), missing = "-")
} else {
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):dim(data)[2])]
pander(style_table1(selec), missing = "-")
}
}
}
```
\
*Relative bias*
<!-- Relative bias text -->
The relative bias is the difference between the mean age (per modal age per
reader) and modal age. As for the previous tables, a combined bias for all
readers and weighted means are calculated.
```{r rb}
# RELATIVE BIAS TABLE - All readers ###########################################
data=rel_bias_tab_all
nstagers=length(unique(reader_data$'Reader code'))
ncols=dim(data[,!colnames(data) %in% c("all")])[2]
basicols=ncols-nstagers
Z=8
nfig=ceiling((dim(data)[2]-basicols)/Z)
N=min(Z,ncols)
for(i in 1:nfig)
{
if(i==1){
# Table caption
set.caption('**Table X:** The relative bias (as the difference between the mean and modal age) per
modal age and reader is presented, as well as the weighted mean relative bias per reader and the relative bias per modal age for all
readers combined.')
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):((i+basicols+((N-1)*(i-1)))+(N-1)))]
pander(style_table1(selec), missing = "-")
} else { if(i<nfig){
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):((i+basicols+((N-1)*(i-1)))+(N-1)))]
pander(style_table1(selec), missing = "-")
} else {
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):dim(data)[2])]
pander(style_table1(selec), missing = "-")
}
}
}
```
```{r bias_plots_all, fig.width = 5, fig.height = 4, fig.cap = cap_in}
# BIAS PLOTS - All readers ####################################################
# Figure Caption
cap_in <- '**Figure X:**: Age bias plot for all readers. Mean age
recorded +/- 2 stdev of each reader and all readers combined are
plotted against modal age. The estimated mean age corresponds to
modal age, if the estimated mean age is on the 1:1 equilibrium
line (solid line). Relative bias is the age difference between
estimated mean age and modal age.'
# Output figure
plot_bias_all(ad_long_all, sel_readers="All readers")
```
\
*Inter-reader bias test*
```{r bias_table}
# INTER READER BIAS TEST - All readers ########################################
# Table caption
set.caption('**Table X:** Inter reader bias test. The Inter-reader bias test
gives probability of bias between readers and with modal age.
- = no sign of bias (p>0.05), * = possibility of bias
(0.01<p<0.05), * * = certainty of bias (p<0.01) , / = diagonal of the table (no bias) ')
# Output table
pander(style_table3(bias_tab_all), missing = ".", style = "simple")
```
\
*Growth analysis*
```{r growth_analysis, fig.width = 8, fig.height = 4, fig.cap = cap_in}
# GROWTH ANALYSIS - All readers ###############################################
# Figure caption
cap_in <- '**Figure X:** Plot of average distance from the centre to the winter
rings for all readers. 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 figure
plot_growth(dist, ad_long_all, stratif="no_stratification")
```
<!--------------------------------------------->
<!--------- Start with stratification --------->
<!--------------------------------------------->
```{r set_strata_all}
# initialise strata loop
istrata <- 0
group <- "all"
print_strata <- function() length(params$strata) >= istrata
```
<!-- first strata -->
```{r strata_plus_one}
istrata <- istrata + 1
```
\newpage
```{r conditional_text_Ia, eval= print_strata()}
asis_output("***Samples split by strata***")
```
```{r results_by_strata_and_reader_title, eval = print_strata()}
stratum <- params$strata[istrata]
# Section title
asis_output(paste0("**Comparison results by reader on strata: ", stratum, "**"))
```
<!-- Select data by strata -->
```{r select_data_by_strata, eval = print_strata()}
ad_long_all_by_strata=ad_long_all[ad_long_all[["strata"]]==stratum,]
```
```{r conditional_text_heading_section_I, eval= print_strata()}
```
<!-- Total number of samples (NSample), number (CountMM) and percentage of multimodal cases (PercMM) text -->
```{r summary_multiple_modes_all_by_strata, eval = print_strata()}
summary_multiple_modes_all <-
c(NSample = length(unique(ad_long_all_by_strata$SampleID)),
PercMM_traditional=unique(ifelse(eval(parse(text=paste0(vsname("multimode_cases_tab_traditional"),"$NModes_trad")))=="zero", paste(0,"%"), paste(round((nrow(eval(parse(text=vsname("multimode_cases_tab_traditional"))))/length(unique(ad_long_all_by_strata$SampleID)))*100, digits=0),"%"))),
PercMM_linear_weight=unique(ifelse(eval(parse(text=paste0(vsname("multimode_cases_tab_linear"),"$NModes_linear")))=="zero", paste(0,"%"), paste(round((nrow(eval(parse(text=vsname("multimode_cases_tab_linear"))))/length(unique(ad_long_all$SampleID)))*100, digits=0),"%"))),
PercMM_negexp_weight=unique(ifelse(eval(parse(text=paste0(vsname("multimode_cases_tab_negexp"),"$NModes_negexp")))=="zero", paste(0,"%"), paste(round((nrow(eval(parse(text=vsname("multimode_cases_tab_negexp"))))/length(unique(ad_long_all$SampleID)))*100, digits=0),"%"))),
PercMM_multistage=unique(ifelse(eval(parse(text=paste0(vsname("multimode_cases_tab_multistage"),"$NModes_multistage")))=="zero", paste(0,"%"), paste(round((nrow(eval(parse(text=vsname("multimode_cases_tab_multistage"))))/length(unique(ad_long_all$SampleID)))*100, digits=0),"%"))))
# Table caption
set.caption(paste('**Table X:** Strata', str_remove(unique(ad_long_all[["strata"]])[istrata], "Strata_"), '.Total number of samples (NSample) and 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_all), missing="")
```
```{r conditional_text_heading_section_II, eval= print_strata()}
```
<!-- Total number of samples (NSample), number (CountMM) and percentage of multimodal cases (PercMM), PA, CV and APE text -->
```{r summary_statistics_all_by_strata, eval = print_strata()}
summary_statistics_all <-
c(NSample = length(unique(ad_long_all_by_strata$SampleID)),
CV = eval(parse(text=vsname("cv_tab")))[nrow(eval(parse(text=vsname("cv_tab")))), "all"],
PA = eval(parse(text=vsname("pa_tab")))[nrow(eval(parse(text=vsname("pa_tab")))), "total"],
APE = eval(parse(text=vsname("ape_tab")))[nrow(eval(parse(text=vsname("ape_tab")))), "all"])
# Table caption
set.caption(paste('**Table X:** Strata', stratum, '.Summary of statistics; Total number of samples (NSample), coefficient of variance (CV), percentage of agreement (PA) and average percentage error (APE) for all ages and readers'))
# Output table
pander(style_table0(summary_statistics_all), missing="")
```
```{r conditional_text_I, eval= print_strata()}
asis_output(paste0("In this exchange event ", summary_statistics_all[1], " otolith fish individuals were aged. Of those, ", summary_multiple_modes_all[2], "when the traditional approach (all readers equally weighted) is used to define the mode. The percentage of multiple mode cases is reduced to ", summary_multiple_modes_all[5], ". The complete list of cases with multiple modes is presented in table X in the annex 3 section, where the ageing from each of the readers participating in the exchange event is presented. When all the otolith samples are considered (both single and multimodal cases) the weighted average percentage agreement based on modal ages for all readers is ", summary_statistics_all[3], ", with the weighted average CV of ", summary_statistics_all[2], " and APE of ", summary_statistics_all[4], "."))
```
\
```{r conditional_text_heading_section_III, eval= print_strata()}
```
```{r cv_table_by_strata, eval = print_strata()}
# CV TABLE - All readers ######################################################
data=eval(parse(text=vsname("cv_tab")))
nstagers=length(unique(reader_data$'Reader code'))
ncols=dim(data[,!colnames(data) %in% c("all")])[2]
basicols=ncols-nstagers
Z=8
nfig=ceiling((dim(data)[2]-basicols)/Z)
N=min(Z,ncols)
for(i in 1:nfig)
{
if(i==1){
# Table caption
set.caption(paste('**Table X:** ', stratum, '.Coefficient of Variation (CV) table presents the CV
per modal age and reader, the CV of all readers combined per modal
age and a weighted mean of the CV per reader'))
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):((i+basicols+((N-1)*(i-1)))+(N-1)))]
pander(style_table1(selec), missing = "-")
} else { if(i<nfig){
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):((i+basicols+((N-1)*(i-1)))+(N-1)))]
pander(style_table1(selec), missing = "-")
} else {
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):dim(data)[2])]
pander(style_table1(selec), missing = "-")
}
}
}
```
\
```{r conditional_text_heading_section_IV, eval= print_strata()}
```
```{r conditional_text_II, eval= print_strata()}
# <!-- PA text -->
asis_output("The percentage agreement per reader per modal age tells how large part of the
readings that are equal to the modal age. The weighted mean including at the
bottom of the table is weighted according to number of age readings.")
```
```{r percentage_agreement_by_strata, eval = print_strata()}
# PERCENTAGE AGREEMENT TABLE - All readers ####################################
data=eval(parse(text=vsname("pa_tab")))
nstagers=length(unique(reader_data$'Reader code'))
ncols=dim(data[,!colnames(data) %in% c("total")])[2]
basicols=ncols-nstagers
Z=8
nfig=ceiling((dim(data)[2]-basicols)/Z)
N=min(Z,ncols)
for(i in 1:nfig)
{
if(i==1){
# Table caption
set.caption(paste('**Table X:** ', stratum, '.Percentage agreement (PA) table represents the PA per
modal age and reader, the PA of all readers combined per modal
age and a weighted mean of the PA per reader.'))
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):((i+basicols+((N-1)*(i-1)))+(N-1)))]
pander(style_table1(selec), missing = "-")
} else { if(i<nfig){
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):((i+basicols+((N-1)*(i-1)))+(N-1)))]
pander(style_table1(selec), missing = "-")
} else {
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):dim(data)[2])]
pander(style_table1(selec), missing = "-")
}
}
}
```
\
```{r conditional_text_heading_section_V, eval= print_strata()}
```
```{r average_percentage_error_all_by_strata, eval = print_strata()}
# AVERAGE PERCENTAGE ERROR TABLE - Advanced readers ###############################
data=eval(parse(text=vsname("ape_tab")))
nstagers=length(unique(reader_data$'Reader code'))
ncols=dim(data[,!colnames(data) %in% c("all")])[2]
basicols=ncols-nstagers
Z=8
nfig=ceiling((dim(data)[2]-basicols)/Z)
N=min(Z,ncols)
for(i in 1:nfig)
{
if(i==1){
# Table caption
set.caption(paste('**Table X:** ', stratum, '.Average Percentage Error (APE) table represents the APE per
modal age and reader, the APE of all advanced readers
combined per modal age and a weighted mean of the APE per reader.'))
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):((i+basicols+((N-1)*(i-1)))+(N-1)))]
pander(style_table1(selec), missing = "-")
} else { if(i<nfig){
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):((i+basicols+((N-1)*(i-1)))+(N-1)))]
pander(style_table1(selec), missing = "-")
} else {
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):dim(data)[2])]
pander(style_table1(selec), missing = "-")
}
}
}
```
\
```{r conditional_text_heading_section_VI, eval= print_strata()}
```
```{r conditional_text_III, eval= print_strata()}
# <!-- Relative bias text -->
asis_output("The relative bias is the difference between the mean age (per modal age per
reader) and modal age. As for the previous tables, a combined bias for all
readers and weighted means are calculated.")
```
```{r rb_by_strata, eval = print_strata()}
# RELATIVE BIAS TABLE - All readers ###########################################
data=eval(parse(text=vsname("rel_bias_tab")))
nstagers=length(unique(reader_data$'Reader code'))
ncols=dim(data[,!colnames(data) %in% c("all")])[2]
basicols=ncols-nstagers
Z=8
nfig=ceiling((dim(data)[2]-basicols)/Z)
N=min(Z,ncols)
for(i in 1:nfig)
{
if(i==1){
# Table caption
set.caption(paste('**Table X:** ', stratum, '. The relative bias (as the difference between the mean and modal age) per
modal age and reader is presented, as well as the weighted mean relative bias per reader and the relative bias per modal age for all
readers combined.'))
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):((i+basicols+((N-1)*(i-1)))+(N-1)))]
pander(style_table1(selec), missing = "-")
} else { if(i<nfig){
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):((i+basicols+((N-1)*(i-1)))+(N-1)))]
pander(style_table1(selec), missing = "-")
} else {
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):dim(data)[2])]
pander(style_table1(selec), missing = "-")
}
}
}
```
```{r bias_plots_all_by_strata, fig.width = 5, fig.height = 4, fig.cap = cap_in, eval = print_strata()}
# BIAS PLOTS - All readers by strata ####################################################
# Figure Caption
cap_in <- paste('**Figure X:** ', stratum, '.Age bias plot for all readers. Mean age recorded +/- 2 stdev of each reader and all readers combined are plotted against modal age. The estimated mean age corresponds to modal age, if the estimated mean age is on the 1:1 equilibrium line (solid line). Relative bias is the age difference between estimated mean age and modal age.')
# Output figure
plot_bias_all(ad_long_all_by_strata, sel_readers="All readers")
```
\
```{r conditional_text_heading_section_VII, eval= print_strata()}
```
```{r bias_table_by_strata, eval = print_strata()}
# INTER READER BIAS TEST - All readers ########################################
# Table caption
set.caption(paste('**Table X:** ', stratum, '.Inter reader bias test. The Inter-reader bias test
gives probability of bias between readers and with modal age.
- = no sign of bias (p>0.05), * = possibility of bias
(0.01<p<0.05), * * = certainty of bias (p<0.01) , / = diagonal of the table (no bias) '))
# Output table
pander(style_table3(bias_tab_all), missing = ".", style = "simple")
```
\
```{r conditional_text_heading_section_VIII, eval= print_strata()}
```
```{r growth_analysis_by_strata, fig.width = 8, fig.height = 4, fig.cap = cap_in, eval = print_strata()}
# GROWTH ANALYSIS - All readers ###############################################
# Figure caption
cap_in <- paste('**Figure X:** ', stratum, '.Plot of average distance from the centre to the winter rings for all readers. 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 figure
plot_growth(dist, ad_long_all_by_strata, stratif=stratum)
```
<!-- second strata -->
```{r ref.label= 'strata_plus_one'}
```
\
```{r ref.label= 'results_by_strata_and_reader_title', eval = print_strata()}
```
<!-- Select data by strata -->
```{r ref.label= 'select_data_by_strata', eval = print_strata()}
```
```{r conditional_text_heading_section_I, eval= print_strata()}
```
<!-- Total number of samples (NSample), number (CountMM) and percentage of multimodal cases (PercMM) text -->
```{r ref.label= 'summary_multiple_modes_all_by_strata', eval = print_strata()}
```
\
```{r conditional_text_heading_section_II, eval= print_strata()}
```
<!-- Total number of samples (NSample), number (CountMM) and percentage of multimodal cases (PercMM), PA, CV and APE text -->
```{r ref.label= 'summary_statistics_all_by_strata', eval = print_strata()}
```
\
```{r conditional_text_heading_section_III, eval= print_strata()}
```
```{r ref.label= 'cv_table_by_strata', eval = print_strata()}
```
\
```{r conditional_text_heading_section_IV, eval= print_strata()}
```
```{r ref.label= 'percentage_agreement_by_strata', eval = print_strata()}
```
\
```{r conditional_text_heading_section_V, eval= print_strata()}
```
```{r ref.label= 'average_percentage_error_all_by_strata', eval = print_strata()}
```
\
```{r conditional_text_heading_section_VI, eval= print_strata()}
```
```{r ref.label= 'rb_by_strata', eval = print_strata()}
```
```{r ref.label= 'bias_plots_all_by_strata', fig.width = 5, fig.height = 4, fig.cap = cap_in, eval = print_strata()}
```
\
```{r conditional_text_heading_section_VII, eval= print_strata()}
```
```{r ref.label= 'bias_table_by_strata', eval = print_strata()}
```
\
```{r conditional_text_heading_section_VIII, eval= print_strata()}
```
```{r ref.label= 'growth_analysis_by_strata', fig.width = 8, fig.height = 4, fig.cap = cap_in, eval = print_strata()}
```
<!-- third strata -->
```{r ref.label= 'strata_plus_one'}
```
\
```{r ref.label= 'results_by_strata_and_reader_title', eval = print_strata()}
```
<!-- Select data by strata -->
```{r ref.label= 'select_data_by_strata', eval = print_strata()}
```
```{r conditional_text_heading_section_I, eval= print_strata()}
```
<!-- Total number of samples (NSample), number (CountMM) and percentage of multimodal cases (PercMM) text -->
```{r ref.label= 'summary_multiple_modes_all_by_strata', eval = print_strata()}
```
\
```{r conditional_text_heading_section_II, eval= print_strata()}
```
<!-- Total number of samples (NSample), number (CountMM) and percentage of multimodal cases (PercMM), PA, CV and APE text -->
```{r ref.label= 'summary_statistics_all_by_strata', eval = print_strata()}
```
\
```{r conditional_text_heading_section_III, eval= print_strata()}
```
```{r ref.label= 'cv_table_by_strata', eval = print_strata()}
```
\
```{r conditional_text_heading_section_IV, eval= print_strata()}
```
```{r ref.label= 'percentage_agreement_by_strata', eval = print_strata()}
```
\
```{r conditional_text_heading_section_V, eval= print_strata()}
```
```{r ref.label= 'average_percentage_error_all_by_strata', eval = print_strata()}
```
\
```{r conditional_text_heading_section_VI, eval= print_strata()}
```
```{r ref.label= 'rb_by_strata', eval = print_strata()}
```
```{r ref.label= 'bias_plots_all_by_strata', fig.width = 5, fig.height = 4, fig.cap = cap_in, eval = print_strata()}
```
\
```{r conditional_text_heading_section_VII, eval= print_strata()}
```
```{r ref.label= 'bias_table_by_strata', eval = print_strata()}
```
\