-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport_full.Rmd
2501 lines (1717 loc) · 88.5 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
# maturity readings.
# The output is a .docx template that includes
# the results of the analysis and should be used as a standard for
# reporting of maturity staging 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 config$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 sex categorization and maturity staging’s
in the form of tables and graphical plots.
First, an overview of participating maturity stagers and the samples are presented.
Before each table or plot there is a short explanation of it. This text is
thought as a help to understand the tables/plot and can just be deleted in
the final output report. The document can be edited just like any other
.docx file. New text can be added, additional pictures can be included and
the tables 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.
In the first part of analysis some of the tables and plots from the
Guus Eltink Excel sheet 'Age Reading Comparisons' **(Eltink, A.T.G.W. 2000)** are presented, that can be used for "maturity staging comparisons". Since the sex categories and maturity stages are categorical in comparison to ages that are quantitative, some of the statistics presented in the report of the age exchange events cannot be calculated here, like the average percentage error or the coefficient of variation. The latter is being replaced by the coefficient of unlikeability (see below).
**Percentage Agreement**
The percentage agreement tells how large is the part of sex categorizations/maturity staging’s that are equal to the modal sex/maturity. The percentage agreement is estimated by modal sex or maturity and stager as the proportion (as percentage) of times that the lectures of that stager agreed with the resulting modal sex or maturity. This percentage is estimated as the number of times that a stager agreed with the modal sex or maturity divided by the total number of gonads analyzed by a stager for that modal maturity stage.
$$PA = { \frac{ {number \,of \,readings \,that \,agree \,with \,modal \,maturity}} {total \,number \,of \,readings \,by \,modal \,maturity} } \cdot {100 \%} $$
**Coefficient of unalikeability (CU)**
The concept of unalikeability (Kader and Perry, 2007) focuses on how often observations differ within a group. Specifically, for the sex/maturity staging events, the CU provides a measure of how alike, for each modal maturity stage, the stages decided by each stager were (or all stagers at once). The cu ranges between 0 and 1. The higher the cu value, the more unalike the data are.
The table presents the CU per modal maturity stage and stager. For the case of a finite number of observations (n), a finite number of categories (m) and a finite number of objects, k_i, within category i, will allow expression of the coefficient of unalikeablity as:
$$ u = {1 - ∑ p_i ^ 2} $$
where
$$ p_i = {k_i / n} $$
To the table is also added the CU of all stagers combined per modal maturity and
a weighted mean of the CU per stager.
**Maturity stage error matrix (MSEM)**
Maturity stage error matrices (AEM) were produced following the same procedures outlined
by WKSABCAL (2014) for calculating the "Age error matrix". MSEM shows the proportion of each modal
maturity stage mis-staged as other stages. The sum of each row is 1, which equals 100%.
The maturity data was analysed twice, the first time all stagers were included
and the second time only the “advanced” stagers were included. If a stager
is “advanced” then they are considered well trained and they provide maturity stages
for stock assessment or similar purposes. When the MSEM is compiled for
assessment purposes it uses only those stagers who provide maturity data for
the stock assessment in that specific area.
In this report the MSEM presented represents is in the transpose format.
The frequency bias table represents the MSEM in the format proposed by WKSABCAL (2014).
# Analysis of maturity staging calibration exercise (ToR?)
*Overview table*
<!-- Stock, Total number of samples (NSample), Preparation method, PA (sex and maturity), CU (sex and maturity), Number of readers (basic and advanced) text -->
```{r overview_statistics_all}
overview_statistics_all <-
c(Stock=unique(ad_long_all$stock),
NSample = length(unique(ad_long_all$SampleID)),
CU_sex = cu_tab_sex_all[nrow(cu_tab_sex_all), "Total"],
CU_mat = cu_tab_maturity_all[nrow(cu_tab_maturity_all), "Total"],
PA_sex = pa_tab_sex_all[nrow(pa_tab_sex_all), "Total"],
PA_mat = pa_tab_maturity_all[nrow(pa_tab_maturity_all), "Total"],
N_basic=length(unique(ad_long_all$reader))-length(unique(ad_long_adv$reader)),
N_adv=length(unique(ad_long_adv$reader)))
# Table caption
set.caption('**Table X:** Overview table: Stock; Total number of samples (NSample); coefficient of unalikeability (CU) for sex (CU_sex) and maturity (CU_maturity); percentage of agreement (PA) for sex (PA_sex) and for maturity (PA_maturity); number of basic readers (N_basic) and number of advanced readers (N_adv).')
# Output table
pander(style_table0(overview_statistics_all), missing="")
```
## Overview of samples and stagers
\br
```{r sample_overview}
# Table caption
set.caption(
paste(
'**Table X:** Overview of samples used for the exchange event number ',
config$event_id,
'. The number of samples (num) are shown by year, ices area, season (qtr). The range of maturity stages (mat_stages) and sex (sex_cat) assigned by the group or stagers participating in the event is also shown, as well as the range of modal maturity stages (modal_mat_stages) and modal sex (modal_sex_cat) decided for all samples.',
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 stagers participating in the event, with their overall expertise (Expertise), and their ranking position based in their experience (only valid if the experience weighting protocol has been applied). R01 EO is the Event Organizer.')
# Output table
pander(style_table0(filter(stager_data)))
```
## Results
Text?
### All stagers
Text?
#### All samples together
Text?
**Multimodal cases**
Those writing the report put TEXT here describing the results.
If there were available histological samples for all the fish individuals in the exchange event, no multiple modes are expected, however, if there were no histology samples for some of them, multiple maturity stage modes could be found. In the next table this information is presented for the sex category determination.
<!-- Total number of samples (NSample), number (CountMM) and percentage of multimodal cases (PercMM) text -->
```{r summary_multiple_modes_sex_all}
#histN=ad_long_all %>% subset(TypeAnnotation=="eventOrganizer") %>% select(FishID) %>% unique() %>% dim()
#allN=ad_long_all %>% select(FishID) %>% unique() %>% dim()
#perc_not_Hist=100-round(100*histN[1]/allN[1], 0)
histN=ad %>% subset(DoesSampleHaveHistologyImage=="Yes") %>% select(FishID) %>% unique() %>% dim()
allN=ad_long_all %>% select(FishID) %>% unique() %>% dim()
perc_not_Hist=100-round(100*histN[1]/allN[1], 0)
summary_multiple_modes_sex_all <-
c(NSample = length(unique(ad_long_all$FishID)),
Nhist=histN[1],
Perc_not_Hist=perc_not_Hist,
PercMM_traditional=unique(ifelse(multimode_cases_tab_traditional_Sex_all$NModes_trad=="zero", paste(0,"%"), paste(round((nrow(multimode_cases_tab_traditional_Sex_all)/length(unique(ad_long_all$SampleID)))*100, digits=0),"%"))),
PercMM_linear_weight=unique(ifelse(multimode_cases_tab_linear_Sex_all$NModes_linear=="zero", paste(0,"%"), paste(round((nrow(multimode_cases_tab_linear_Sex_all)/length(unique(ad_long_all$SampleID)))*100, digits=0),"%"))),
PercMM_negexp_weight=unique(ifelse(multimode_cases_tab_negexp_Sex_all$NModes_negexp=="zero", paste(0,"%"), paste(round((nrow(multimode_cases_tab_negexp_Sex_all)/length(unique(ad_long_all$SampleID)))*100, digits=0),"%"))),
PercMM_multistage=unique(ifelse(multimode_cases_tab_multistage_Sex_all$NModes_multistage=="zero", paste(0,"%"), paste(round((nrow(multimode_cases_tab_multistage_Sex_all)/length(unique(ad_long_all$SampleID)))*100, digits=0),"%"))))
# Table caption
set.caption('**Table X:** Summary of statistics for sex staging; Total number of fish individuals studied (NSample), number of fish individuals with histological samples (Nhist), percentage of fish individuals without histology (Perc_not_Hist). The percentage of cases (fish samples) with multiple modes depending on the approach to weight the experience of the stager which will be considered when defining the fish sex stage mode. PercMM_traditional shows the percentage of the total samples for which multiple modes are obtained when all the stagers 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 stagers 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_sex_all), missing="")
```
If there were available histological samples for all the fish individuals in the exchange event, no multiple modes are expected, however, if there were no histology samples for some of them, multiple maturity stage modes could be found. In the next table this information is presented for the maturity staging.
<!-- Total number of samples (NSample), number (CountMM) and percentage of multimodal cases (PercMM) text -->
```{r summary_multiple_modes_maturity_all}
histN=ad %>% subset(DoesSampleHaveHistologyImage=="Yes") %>% select(FishID) %>% unique() %>% dim()
allN=ad_long_all %>% select(FishID) %>% unique() %>% dim()
perc_not_Hist=100-round(100*histN[1]/allN[1], 0)
summary_multiple_modes_maturity_all <-
c(NSample = length(unique(ad_long_all$FishID)),
Nhist=histN[1],
Perc_not_Hist=perc_not_Hist,
PercMM_traditional=unique(ifelse(multimode_cases_tab_traditional_Maturity_all$NModes_trad=="zero", paste(0,"%"), paste(round((nrow(multimode_cases_tab_traditional_Maturity_all)/length(unique(ad_long_all$SampleID)))*100, digits=0),"%"))),
PercMM_linear_weight=unique(ifelse(multimode_cases_tab_linear_Maturity_all$NModes_linear=="zero", paste(0,"%"), paste(round((nrow(multimode_cases_tab_linear_Maturity_all)/length(unique(ad_long_all$SampleID)))*100, digits=0),"%"))),
PercMM_negexp_weight=unique(ifelse(multimode_cases_tab_negexp_Maturity_all$NModes_negexp=="zero", paste(0,"%"), paste(round((nrow(multimode_cases_tab_negexp_Maturity_all)/length(unique(ad_long_all$SampleID)))*100, digits=0),"%"))),
PercMM_multistage=unique(ifelse(multimode_cases_tab_multistage_Maturity_all$NModes_multistage=="zero", paste(0,"%"), paste(round((nrow(multimode_cases_tab_multistage_Maturity_all)/length(unique(ad_long_all$SampleID)))*100, digits=0),"%"))))
# Table caption
set.caption('**Table X:** Summary of statistics for maturity staging; Total number of fish individuals studied (NSample), number of fish individuals with histological samples (Nhist), percentage of fish individuals without histology (Perc_not_Hist). The percentage of cases (fish samples) with multiple modes depending on the approach to weight the experience of the stager which will be considered when defining the fish maturity stage mode. PercMM_traditional shows the percentage of the total samples for which multiple modes are obtained when all the stagers 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 stagers 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_maturity_all), missing="")
```
<!-- PA and CU text -->
```{r summary_statistics_sex_all}
summary_statistics_sex_all <-
c(NSample = length(unique(ad_long_all$FishID)),
CU = cu_tab_sex_all[nrow(cu_tab_sex_all), "Total"],
PA = pa_tab_sex_all[nrow(pa_tab_sex_all), "Total"])
summary_statistics_maturity_all <-
c(NSample = length(unique(ad_long_all$FishID)),
CU = cu_tab_maturity_all[nrow(cu_tab_maturity_all), "Total"],
PA = pa_tab_maturity_all[nrow(pa_tab_maturity_all), "Total"])
```
The average percentage agreement by modal sex category for all stagers was `r summary_statistics_sex_all[3]`, with a weighted average CU of `r summary_statistics_sex_all[2]`. Regarding the maturation staging, the percentage agreement by modal maturation stage was `r summary_statistics_maturity_all[3]`, and the weight average CU was `r summary_statistics_maturity_all[2]`.
**Sex categorization table**
Text?
```{r sex_composition_tab_all}
# Sex categorization TABLE - All stagers #################################################
data=sex_composition_tab_all
nstagers=length(unique(stager_data$'Reader code'))
ncols=dim(data[,!colnames(data) %in% c("Total")])[2]
basicols=ncols-nstagers
x<-max(ncol(data)-2, 1, na.rm = TRUE)
z=min(x,8)
#z=8
nfig=round((dim(data)[2]-basicols)/z)
N=min(z,ncols)
for(i in 1:nfig)
{
if(i==1){
# Table caption
set.caption('**Table X:** Sex categorization table: presents the
number of categorizations made per expert for each modal sex category.')
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):((i+basicols+((N-1)*(i-1)))+(N-1)))]
pander(style_table0(selec), missing = "-", style = "simple") #changed here to not appear the last column in bolt
} 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 = "-", style = "simple") #changed here to not appear the last column in bolt
} else {
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):dim(data)[2])]
pander(style_table0(selec), missing = "-", style = "simple") #changed here to not appear the last column in bolt
}
}
}
```
**Maturity staging table**
Text?
```{r num_read_maturity_all}
# maturity staging’s TABLE - All stagers #################################################
#data=num_read_tab_modal_matur_by_reader_all
data=maturity_composition_tab_all
nstagers=length(unique(stager_data$'Reader code'))
ncols=dim(data[,!colnames(data) %in% c("Total")])[2]
basicols=ncols-nstagers
x<-max(ncol(data)-2, 1, na.rm = TRUE)
z=min(x,8)
#z=8
nfig=round((dim(data)[2]-basicols)/z)
N=min(z,ncols)
for(i in 1:nfig)
{
if(i==1){
# Table caption
set.caption('**Table X:** Maturity staging table: presents the
number of staging’s made per expert stager for each modal maturity stage.')
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):((i+basicols+((N-1)*(i-1)))+(N-1)))]
pander(style_table0(selec), missing = "-", style = "simple") #changed here to not appear the last column in bolt
} 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_table0(selec), missing = "-", style = "simple") #changed here to not appear the last column in bolt
} else {
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):dim(data)[2])]
pander(style_table0(selec), missing = "-", style = "simple") #changed here to not appear the last column in bolt
}
}
}
```
**Coefficient of Unalikeability (CU) table by modal sex category**
Text?
```{r cu_sex_all_table}
# CU TABLE by modal sex category - All stagers #################################################
data=cu_tab_sex_all
nstagers=length(unique(stager_data$'Reader code'))
ncols=dim(data[,!colnames(data) %in% c("Total")])[2]
basicols=ncols-nstagers
x<-max(ncol(data)-2, 1, na.rm = TRUE)
z=max(x,8)
#z=8
nfig=round((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 unlikeability (CU) table by modal sex category: presents the
CU per modal sex category and stager, the CU of all stagers combined per sex category stage and a weighted mean of the CU
per stager.')
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):((i+basicols+((N-1)*(i-1)))+(N-1)))]
pander(style_table0(selec), missing = "-", style = "simple") #changed here to not appear the last column in bolt
} 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_table0(selec), missing = "-")
} else {
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):dim(data)[2])]
pander(style_table1(selec), missing = "-")
}
}
}
```
**Coefficient of Unalikeability (CU) table by modal maturity stage**
Text?
```{r cu_maturity_all_table}
# CU TABLE by modal maturity stages - All stagers #################################################
data=cu_tab_maturity_all
nstagers=length(unique(stager_data$'Reader code'))
ncols=dim(data[,!colnames(data) %in% c("Total")])[2]
basicols=ncols-nstagers
x<-max(ncol(data)-2, 1, na.rm = TRUE)
z=max(x,8)
#z=8
nfig=round((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 unlikeability (CU) table by modal maturity stage: presents the
CU per modal maturity stage and stager, the CU of all stagers combined per maturity stage and a weighted mean of the CU
per stager.')
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):((i+basicols+((N-1)*(i-1)))+(N-1)))]
pander(style_table0(selec), missing = "-", style = "simple") #changed here to not appear the last column in bolt
} 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 cu_tab_maturity_females_all}
# CU TABLE by modal maturity stages (Females) - All stagers #################################################
data=cu_tab_maturity_females_all
nstagers=length(unique(stager_data$'Reader code'))
ncols=dim(data[,!colnames(data) %in% c("Total")])[2]
basicols=ncols-nstagers
x<-max(ncol(data)-2, 1, na.rm = TRUE)
z=max(x,8)
#z=8
nfig=round((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 unlikeability (CU) table by modal maturity stage (only for females): presents the CU per modal maturity stage and stager, the CU of all stagers combined per maturity stage and a weighted mean of the CU per stager.')
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 cu_tab_maturity_males_all}
# CU TABLE by modal maturity stages (Males) - All stagers #################################################
data=cu_tab_maturity_males_all
nstagers=length(unique(stager_data$'Reader code'))
ncols=dim(data[,!colnames(data) %in% c("Total")])[2]
basicols=ncols-nstagers
x<-max(ncol(data)-2, 1, na.rm = TRUE)
z=max(x,8)
#z=8
nfig=round((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 unlikeability (CU) table by modal maturity stage (only for males): presents the CU per modal maturity stage and stager, the CU of all stagers combined per maturity stage and a weighted mean of the CU per stager.')
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 = "-")
}
}
}
```
**PA table by modal sex category**
<!-- PA text -->
The percentage agreement per stager and modal maturity stage represent the proportion of the total number of staging’s that are equal to the modal maturity stage. The weighted mean including at the bottom of the table is weighted according to number of maturity staging’s.
```{r percentage_agreement_sex_all}
# PERCENTAGE AGREEMENT TABLE by modal sex category - All stagers ####################################
data=pa_tab_sex_all
nstagers=length(unique(stager_data$'Reader code'))
ncols=dim(data[,!colnames(data) %in% c("Total")])[2]
basicols=ncols-nstagers
x<-max(ncol(data)-2, 1, na.rm = TRUE)
z=max(x,8)
#z=8
nfig=round((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: shows the PA per modal sex category and stager, the PA for all stagers combined and the weighted mean of the PA per stager.')
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 = "-")
}
}
}
```
**PA table by modal maturity stage**
Text?
```{r percentage_agreement_maturity_all}
# PERCENTAGE AGREEMENT TABLE by modal maturity stage - All stagers ####################################
data=pa_tab_maturity_all
nstagers=length(unique(stager_data$'Reader code'))
ncols=dim(data[,!colnames(data) %in% c("Total")])[2]
basicols=ncols-nstagers
x<-max(ncol(data)-2, 1, na.rm = TRUE)
z=max(x,8)
#z=8
nfig=round((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: shows the PA per modal maturity and stager, the PA for all stagers combined and the weighted mean of the PA per stager.')
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 percentage_agreement_maturity_females_all}
# PERCENTAGE AGREEMENT TABLE by modal maturity stage (females) - All stagers ####################################
data=pa_tab_maturity_females_all
nstagers=length(unique(stager_data$'Reader code'))
ncols=dim(data[,!colnames(data) %in% c("Total")])[2]
basicols=ncols-nstagers
x<-max(ncol(data)-2, 1, na.rm = TRUE)
z=max(x,8)
#z=8
nfig=round((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: shows the PA per modal maturity and stager (only females), the PA for all stagers combined and the weighted mean of the PA per stager.')
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):((i+basicols+((N-1)*(i-1)))+(N-1)))]
#pander(style_table0(selec), missing = "-", style = "simple") #changed here to not appear the last column in bolt
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_table0(selec), missing = "-", style = "simple") #changed here to not appear the last column in bolt
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 = "-", style = "simple") #changed here to not appear the last column in bolt
pander(style_table1(selec), missing = "-")
}
}
}
```
```{r percentage_agreement_maturity_males_all}
# PERCENTAGE AGREEMENT TABLE by modal maturity stage (males) - All stagers ####################################
data=pa_tab_maturity_males_all
nstagers=length(unique(stager_data$'Reader code'))
ncols=dim(data[,!colnames(data) %in% c("Total")])[2]
basicols=ncols-nstagers
x<-max(ncol(data)-2, 1, na.rm = TRUE)
z=max(x,8)
#z=8
nfig=round((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: shows the PA per modal maturity and stager (only males), the PA for all stagers combined and the weighted mean of the PA per stager.')
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):((i+basicols+((N-1)*(i-1)))+(N-1)))]
#pander(style_table0(selec), missing = "-", style = "simple") #changed here to not appear the last column in bolt
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_table0(selec), missing = "-", style = "simple") #changed here to not appear the last column in bolt
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 = "-", style = "simple") #changed here to not appear the last column in bolt
pander(style_table1(selec), missing = "-")
}
}
}
```
**General frequency bias table by modal sex category**
The frequency bias is shown by sex category for each modal sex category for all stagers together. This frequency distribution presented in the form of a table or a bubble plot may be used to explore the bias in the sex determination by the stagers participating in this event.
```{r general_freq_sex_all}
# frequency bias TABLE by sex category ###########################################
set.caption('**Table X:** General frequency bias table: represents the frequency per
modal sex category for all stagers combined. V1 in case some readers have samples without sex categorization.')
pander(style_table0(general_bias_freq_tab_sex_all), missing = "-", style = "simple") #changed here to not appear the last column in bolt
```
**General Frequency Bias plot by modal sex category**
Text?
```{r bias_plots_sex_all, fig.width = 5, fig.height = 4, fig.cap = cap_in}
# BIAS PLOT by modal sex category - All stagers ################################################
# Table caption
cap_in <- '**Figure X:** Sex categorization bias plot by modal sex category for all the stagers: presents the frequency per
modal sex category and sex category for all stager together. '
# Output figure
plot_general_freq_sex(ad_long_all, strata=NULL)
```
**General frequency bias table by modal maturity stage**
The frequency bias is shown by maturity stage for each modal maturity stage for all stagers together. This frequency distribution presented in the form of a table or a bubble plot may be used to explore the bias in the sex determination by the stagers participating in this event.
```{r general_freq_maturity_all}
# frequency bias TABLE by sex category ###########################################
set.caption('**Table X:** General frequency bias table: represents the frequency per
modal maturity stage for all stagers combined.')
pander(style_table0(general_bias_freq_tab_maturity_all), missing = "-", style = "simple") #changed here to not appear the last column in bolt
```
**General Frequency Bias plot by modal maturity stage**
Text?
```{r bias_plots_maturity_all, fig.width = 5, fig.height = 4, fig.cap = cap_in}
# BIAS PLOT by modal maturity stage - All stagers ################################################
# Table caption
cap_in <- '**Figure X:** Maturity staging bias plot by modal maturity stage for all stagers: presents the frequency per
modal maturity and maturity stage for all the stagers together. '
# Output figure
plot_general_freq_matur(ad_long_all, strata=NULL)
```
**General frequency bias table by modal maturity stage (only females)**
The frequency bias is shown by maturity stage for each modal maturity stage (only females) for all stagers together. This frequency distribution presented in the form of a table or a bubble plot may be used to explore the bias in the sex determination by the stagers participating in this event.
```{r general_freq_maturity_females_all}
# frequency bias TABLE by females category ###########################################
set.caption('**Table X:** General frequency bias table (only females): represents the frequency per
modal maturity stage for all stagers combined.')
pander(style_table0(general_bias_freq_tab_maturity_females_all), missing = "-", style = "simple") #changed here to not appear the last column in bolt
```
**General Frequency Bias plot by modal maturity stage (only females)**
Text?
```{r bias_plots_maturity_females_all, fig.width = 5, fig.height = 4, fig.cap = cap_in}
# BIAS PLOT by modal maturity stage (only females) - All stagers ################################################
# Table caption
cap_in <- '**Figure X:** Maturity staging bias plot by modal maturity (only females) stage for all stagers: presents the frequency per
modal maturity and maturity stage for all the stagers together. '
# Output figure
plot_general_freq_matur(ad_long_all[ad_long_all$Sex=="F",], strata=NULL)
```
**General frequency bias table by modal maturity stage (only males)**
The frequency bias is shown by maturity stage for each modal maturity stage (only males) for all stagers together. This frequency distribution presented in the form of a table or a bubble plot may be used to explore the bias in the sex determination by the stagers participating in this event.
```{r general_freq_maturity_males_all}
# frequency bias TABLE by males category ###########################################
set.caption('**Table X:** General frequency bias table (only males): represents the frequency per
modal maturity stage for all stagers combined.')
pander(style_table0(general_bias_freq_tab_maturity_males_all), missing = "-", style = "simple") #changed here to not appear the last column in bolt
```
**General Frequency Bias plot by modal maturity stage (only males)**
Text?
```{r bias_plots_maturity_males_all, fig.width = 5, fig.height = 4, fig.cap = cap_in}
# BIAS PLOT by modal maturity stage (only males) - All stagers ################################################
# Table caption
cap_in <- '**Figure X:** Maturity staging bias plot by modal maturity (only males) stage for all stagers: presents the frequency per
modal maturity and maturity stage for all the stagers together. '
# Output figure
plot_general_freq_matur(ad_long_all[ad_long_all$Sex=="M",], strata=NULL)
```
**Stager frequency bias table by modal sex category**
<!-- Frequency bias text -->
The frequency bias is shown by sex category for each modal sex category per stager. As for the previous tables, a combined frequency distribution for all stagers are calculated. This frequency distribution presented in the form of a table or a bubble plot may be used to explore the bias in the sex determination by the stagers participating in this event.
```{r freq_sex_all}
# frequency bias TABLE by sex category- per stagers ###########################################
data=stager_bias_freq_tab_sex_all
nstagers=length(unique(stager_data$'Reader code'))
ncols=dim(data[,!colnames(data) %in% c("Total")])[2]
basicols=ncols-nstagers
x<-max(ncol(data)-2, 1, na.rm = TRUE)
z=min(x,8)
#z=8
nfig=round((dim(data)[2]-basicols)/z)
N=min(z,ncols)
for(i in 1:nfig)
{
if(i==1){
# Table caption
set.caption('**Table X:** Frequency bias table: represents the frequency per
modal sex category per stager and the frequency distribution of all stagers combined
per modal sex category.')
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):((i+basicols+((N-1)*(i-1)))+(N-1)))]
pander(style_table0(selec), missing = "-", style = "simple") #changed here to not appear the last column in bolt
} 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_table0(selec), missing = "-", style = "simple") #changed here to not appear the last column in bolt
} else {
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):dim(data)[2])]
pander(style_table1(selec), missing = "-", style = "simple") #changed here to not appear the last column in bolt
}
}
}
```
**Stager frequency bias table by modal maturity stage**
<!-- Frequency bias text -->
The frequency bias is shown by maturity stages for each modal maturity stage per stager. As for the previous tables, a combined frequency distribution for all stagers are calculated. This frequency distribution presented in the form of a table or a bubble plot may be used to explore the bias in the maturity determination by the stagers participating in this event.
```{r freq_maturity_all}
# frequency bias TABLE by maturity stage - per stagers ###########################################
data=stager_bias_freq_tab_maturity_all
nstagers=length(unique(stager_data$'Reader code'))
ncols=dim(data[,!colnames(data) %in% c("Total")])[2]
basicols=ncols-nstagers
x<-max(ncol(data)-2, 1, na.rm = TRUE)
z=min(x,8)
#z=8
nfig=round((dim(data)[2]-basicols)/z)
N=min(z,ncols)
for(i in 1:nfig)
{
if(i==1){
# Table caption
set.caption('**Table X:** Frequency bias table: represents the frequency per
modal maturity stage per stager and the frequency distribution of all stagers combined
per modal maturity stage.')
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):((i+basicols+((N-1)*(i-1)))+(N-1)))]
pander(style_table0(selec), missing = "-", style = "simple") #changed here to not appear the last column in bolt
} 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_table0(selec), missing = "-", style = "simple") #changed here to not appear the last column in bolt
} else {
selec=data[,c(1:basicols, (i+basicols+((N-1)*(i-1))):dim(data)[2])]
pander(style_table1(selec), missing = "-", style = "simple") #changed here to not appear the last column in bolt
}
}
}
```
#### With samples split by strata
```{r set_strata_all}
# initialise strata loop
istrata <- 0
group <- "all"
print_strata <- function() length(params$strata) >= istrata
```
<!-- first strata -->
```{r strata_plus_one}
# second strata
istrata <- istrata + 1
```
```{r strata_title, eval = print_strata()}
stratum <- params$strata[istrata]
# Section title
asis_output(paste0("**Results by ", stratum, "**"))
```
```{r ar_sex_title, eval = print_strata()}
# title
asis_output(paste0("**Sex categorization by ", stratum, "**"))
```
```{r ar_sex_by, eval = print_strata()}
# NUMBER OF SEX CATEGORIZATION PER Strata - Advanced stagers #########################
# Table caption
set.caption(paste0('**Table X:** Number of sex categorization per ', stratum, ' for all the stagers.'))
# Output table
pander(style_table1(get(vsname("num_read_tab_modal_sex_by"))), missing = "-")
```
```{r ar_matur_title, eval = print_strata()}
# title
asis_output(paste0("**Maturity staging by ", stratum, "**"))
```
```{r ar_matur_by, eval = print_strata()}
# NUMBER OF MATURITY STAGING PER strata - Advanced stagers #########################
# Table caption
set.caption(paste0('**Table X:** Number of maturity staging’s per ', stratum, ' for all the stagers.'))
# Output table
pander(style_table1(get(vsname("num_read_tab_modal_matur_by"))), missing = "-")
```
```{r cu_sex_title, eval = print_strata()}
# title
asis_output(paste0("**Coefficient of Unalikeability by modal sex category per", stratum, "**"))
```
```{r cu_sex_by, eval = print_strata()}
# Table caption
set.caption(paste0('**Table X:** CU by modal sex category per ', stratum, '.'))
# Output table
pander(style_table2(get(vsname("cu_tab_sex_by"))), missing = "-")
```
```{r cu_matur_title, eval = print_strata()}
# title
asis_output(paste0("**Coefficient of Unalikeability by modal maturity stage per", stratum, "**"))
```
```{r cu_matur_by, eval = print_strata()}
# Table caption
set.caption(paste0('**Table X:** CU by modal maturity stage per ', stratum, '.'))
# Output table
pander(style_table2(get(vsname("cu_tab_maturity_by"))), missing = "-")
```
```{r pa_sex_title, eval = print_strata()}
# title
asis_output(paste0("**Percentage Agreement by sex category per ", stratum, "**"))
```
```{r pa_sex_by, eval = print_strata()}
# Section title
#asis_("## PA by sex category - Advanced stagers") # # #############################################
# Table caption
set.caption(paste0('**Table X:** Percentage Agreement by sex category per ', stratum, '.'))
# Output table
pander(style_table2(get(vsname("pa_tab_sex_by"))), missing = "-")