-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.tex
1727 lines (1520 loc) · 118 KB
/
README.tex
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
% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
]{article}
\usepackage{amsmath,amssymb}
\usepackage{iftex}
\ifPDFTeX
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
\usepackage{unicode-math} % this also loads fontspec
\defaultfontfeatures{Scale=MatchLowercase}
\defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
\usepackage{lmodern}
\ifPDFTeX\else
% xetex/luatex font selection
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
\usepackage[]{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
\KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\usepackage[margin=1in]{geometry}
\usepackage{color}
\usepackage{fancyvrb}
\newcommand{\VerbBar}{|}
\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\usepackage{framed}
\definecolor{shadecolor}{RGB}{248,248,248}
\newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{0.94,0.16,0.16}{#1}}
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\BuiltInTok}[1]{#1}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.64,0.00,0.00}{\textbf{#1}}}
\newcommand{\ExtensionTok}[1]{#1}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\ImportTok}[1]{#1}
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\NormalTok}[1]{#1}
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\RegionMarkerTok}[1]{#1}
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}}
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\usepackage{graphicx}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
% Set default figure placement to htbp
\makeatletter
\def\fps@figure{htbp}
\makeatother
\usepackage{svg}
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering
\ifLuaTeX
\usepackage{selnolig} % disable illegal ligatures
\fi
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\urlstyle{same}
\hypersetup{
pdftitle={fingR A support for Sediment Source Fingerprinting studies},
pdfauthor={Thomas Chalaux-Clergue},
hidelinks,
pdfcreator={LaTeX via pandoc}}
\title{fingR A support for Sediment Source Fingerprinting studies}
\author{Thomas Chalaux-Clergue}
\date{}
\begin{document}
\maketitle
\hypertarget{fingr}{%
\section{\texorpdfstring{fingR }{fingR }}\label{fingr}}
\includegraphics{https://img.shields.io/github/r-package/v/tchalauxclergue/fingR?logo=github}
\includegraphics{https://img.shields.io/github/release-date/tchalauxclergue/fingR?color=blue}
\href{https://doi.org/10.5281/zenodo.10044404}{\includesvg{https://zenodo.org/badge/DOI/10.5281/zenodo.1402028.svg}}
\href{http://www.repostatus.org/\#active}{\includegraphics{https://img.shields.io/github/downloads/tchalauxclergue/fingR/total?style=flat}
\includesvg{http://www.repostatus.org/badges/latest/active.svg}}
\hypertarget{overview}{%
\subsection{Overview}\label{overview}}
\texttt{fingR} is a comprehensive package designed to support Sediment
Source Fingerprinting studies. It provides essentials tools including:
dataset characterisation, tracer selection from analysed properties
through the Three-step method, model source contributions modelling with
the Bayesian Mixing Model (BMM), and assessment of modelling predictions
prediction though the use of virtual mixtures, supporting BMM and
\href{http://brianstock.github.io/MixSIAR/index.html}{MixSIAR} models.
The \texttt{fingR} package is available in this
\href{https://github.com/tchalauxclergue/fingR}{Github} repository and
archived on \href{https://zenodo.org/records/10796375}{Zenodo}.
\hypertarget{table-of-content}{%
\subsubsection{Table of content}\label{table-of-content}}
\begin{itemize}
\tightlist
\item
\protect\hyperlink{installation}{Installation}
\item
\protect\hyperlink{usage}{Usage}
\begin{itemize}
\tightlist
\item
\protect\hyperlink{data-preparation}{Data preparation}
\item
\protect\hyperlink{tracer-selection}{Tracer selection}
\begin{itemize}
\tightlist
\item
\protect\hyperlink{1-assessment-of-conservative-behaviour}{1.
Assessment of conservative behaviour}
\item
\protect\hyperlink{2-discriminant-power}{2. Discriminant power}
\item
\protect\hyperlink{selected-tracers}{Selected tracers}
\item
\protect\hyperlink{3-discriminant-function-analysis-dfa-stepwise-selection}{3.
Discriminant Function Analysis (DFA) stepwise selection}
\end{itemize}
\item
\protect\hyperlink{source-contribution-modelling}{Source
contribution modelling}
\begin{itemize}
\tightlist
\item
\protect\hyperlink{virtual-mixtures}{Virtual mixtures}
\item
\protect\hyperlink{un-mixing-models}{Un-mixing models}
\begin{itemize}
\tightlist
\item
\protect\hyperlink{bayesian-mean-model-bmm}{Bayesian Mean Model
(BMM)}
\begin{itemize}
\tightlist
\item
\protect\hyperlink{run-bmm-model-with-or-without_isotopic-ratio}{Run
BMM model with or without isotopic ratio}
\item
\protect\hyperlink{modelling-accuracy-statistics}{Modelling
accuarcy statistics}
\end{itemize}
\item
\protect\hyperlink{mixsiar}{MixSIAR}
\begin{itemize}
\tightlist
\item
\protect\hyperlink{generate-data-for-mixsiar}{Generate data
for MixSIAR}
\item
\protect\hyperlink{load-mixture-source-and-discrimination-data}{Load
mixture, source and discrimination data}
\item
\protect\hyperlink{write-jags-model-file}{Write JAGS model
file}
\item
\protect\hyperlink{run-mixsiar-model}{Run MixSIAR model}
\item
\protect\hyperlink{modelling-accuracy-statistics-1}{Modelling
accuracy statistics}
\end{itemize}
\end{itemize}
\end{itemize}
\end{itemize}
\item
\protect\hyperlink{future-updates}{Future updates}
\item
\protect\hyperlink{getting-help}{Getting help}
\item
\protect\hyperlink{citation}{Citation}
\item
\protect\hyperlink{references}{References}
\end{itemize}
\hypertarget{installation}{%
\subsection{Installation}\label{installation}}
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\#install.packages(devtools)}
\FunctionTok{library}\NormalTok{(devtools)}
\CommentTok{\# Install the lastest version from GitHub}
\NormalTok{devtools}\SpecialCharTok{::}\FunctionTok{install\_github}\NormalTok{(}\StringTok{"https://github.com/tchalauxclergue/fingR/releases/tag/2.0.0"}\NormalTok{, }\AttributeTok{ref =} \StringTok{"master"}\NormalTok{, }\AttributeTok{force =}\NormalTok{ T)}
\CommentTok{\# Alternatively, from the downloaded .tar.gz file}
\NormalTok{devtools}\SpecialCharTok{::}\FunctionTok{install\_local}\NormalTok{(}\StringTok{"path\_to\_file/fingR\_2.0.0.tar.gz"}\NormalTok{, }\AttributeTok{repos =} \ConstantTok{NULL}\NormalTok{) }\CommentTok{\# \textquotesingle{}path\_to\_file\textquotesingle{} should be modified accordingly to your working environment}
\end{Highlighting}
\end{Shaded}
\hypertarget{usage}{%
\subsection{Usage}\label{usage}}
\hypertarget{data-preparation}{%
\subsubsection{Data preparation}\label{data-preparation}}
To illustrate the usage of the package, we are using the database of the
sediment core sampled in the Mano Dam reservoir (Fukushima, Japan) and
associated soil samples. The \textbf{38} sediment core layer are used as
target, and \textbf{68} soil samples as potential sources. The potential
source include three classes: undecontaminated cropland (n =
\textbf{24}), remediated cropland (n = \textbf{22}), forest (n =
\textbf{24}), and subsoil (mainly granite saprolite; n = \textbf{24}).
All samples were sieved to 63 microns and analysed for organic matter,
elemental geochemistry and diffuse reflectance spectrocolourimetry for
sediment source fingerprinting.
The dataset, along with detailed measurement protocols, is available for
download on Zenodo at
\href{https://zenodo.org/doi/10.5281/zenodo.7081093}{Chalaux-Clergue et
al., 2024 (Version 2)}.
\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{library}\NormalTok{(fingR)}
\CommentTok{\# Get the dir to data and metadata files within the R package}
\NormalTok{data.dr }\OtherTok{\textless{}{-}} \FunctionTok{system.file}\NormalTok{(}\StringTok{"extdata"}\NormalTok{, }\StringTok{"TCC\_MDD\_20210608\_data\_ChalauxClergue\_et\_al\_v240319.csv"}\NormalTok{, }\AttributeTok{package =} \StringTok{"fingR"}\NormalTok{)}
\NormalTok{metadata.dr }\OtherTok{\textless{}{-}} \FunctionTok{system.file}\NormalTok{(}\StringTok{"extdata"}\NormalTok{, }\StringTok{"TCC\_MDD\_20210608\_metadata\_ChalauxClergue\_et\_al\_v240319.csv"}\NormalTok{, }\AttributeTok{package =} \StringTok{"fingR"}\NormalTok{)}
\CommentTok{\# Load the csv files of data and metadata {-} replace the dir with your file direction}
\NormalTok{db.data }\OtherTok{\textless{}{-}} \FunctionTok{read.csv}\NormalTok{(data.dr, }\AttributeTok{sep =} \StringTok{";"}\NormalTok{, }\AttributeTok{fileEncoding =} \StringTok{"latin1"}\NormalTok{, }\AttributeTok{na =} \StringTok{""}\NormalTok{)}
\NormalTok{db.metadata }\OtherTok{\textless{}{-}} \FunctionTok{read.csv}\NormalTok{(metadata.dr, }\AttributeTok{sep =} \StringTok{";"}\NormalTok{, }\AttributeTok{fileEncoding =} \StringTok{"latin1"}\NormalTok{, }\AttributeTok{na =} \StringTok{""}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
Verify the different samples classes
\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{table}\NormalTok{(db.metadata}\SpecialCharTok{$}\NormalTok{Class\_decontamination)}
\CommentTok{\#\textgreater{} }
\CommentTok{\#\textgreater{} Forest Remediated Subsoil Target }
\CommentTok{\#\textgreater{} 24 10 10 38 }
\CommentTok{\#\textgreater{} Undecontaminated }
\CommentTok{\#\textgreater{} 24}
\end{Highlighting}
\end{Shaded}
We join the metadata (general information) and the data (analyses) so
that all the information is on a single dataframe. Both dataframes are
joined by common variables, here IGSN and Sample\_name. In addition,
only the analyses performed on the sample fraction below 63 microns are
kept.
\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{library}\NormalTok{(dplyr)}
\CommentTok{\# Create a single dataframe with metadata and data information}
\NormalTok{database }\OtherTok{\textless{}{-}}\NormalTok{ dplyr}\SpecialCharTok{::}\FunctionTok{left\_join}\NormalTok{(db.metadata, db.data, }\AttributeTok{by =} \FunctionTok{join\_by}\NormalTok{(IGSN, Sample\_name)) }\SpecialCharTok{\%\textgreater{}\%} \CommentTok{\# Joining metadata and data data frame}
\NormalTok{ dplyr}\SpecialCharTok{::}\FunctionTok{filter}\NormalTok{(Sample\_size }\SpecialCharTok{==} \StringTok{"\textless{} 63 µm"}\NormalTok{) }\SpecialCharTok{\%\textgreater{}\%} \CommentTok{\# select sample fraction on which analyses were performed}
\NormalTok{ dplyr}\SpecialCharTok{::}\FunctionTok{filter}\NormalTok{(Class\_decontamination }\SpecialCharTok{!=} \StringTok{"Remediated"}\NormalTok{) }\CommentTok{\# to simplify the example remediated cropland are removed}
\end{Highlighting}
\end{Shaded}
\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{table}\NormalTok{(database}\SpecialCharTok{$}\NormalTok{Class\_decontamination)}
\CommentTok{\#\textgreater{} }
\CommentTok{\#\textgreater{} Forest Subsoil Target Undecontaminated }
\CommentTok{\#\textgreater{} 24 10 38 24}
\end{Highlighting}
\end{Shaded}
Among the analysed properties, 31 properties from organic matter and
elemental geochemistry analyses were selected as potential tracers.
Together with the properties, their measurement uncertainties are
selected.
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\# colnames(database)}
\CommentTok{\# Select the names/colnames of the properties}
\NormalTok{prop.values }\OtherTok{\textless{}{-}}\NormalTok{ database }\SpecialCharTok{\%\textgreater{}\%}\NormalTok{ dplyr}\SpecialCharTok{::}\FunctionTok{select}\NormalTok{(TOC\_PrC, TN\_PrC,}\CommentTok{\# organic matter properties}
\NormalTok{ EDXRF\_Al\_mg.kg}\FloatTok{.1}\SpecialCharTok{:}\NormalTok{EDXRF\_Zr\_mg.kg}\FloatTok{.1}\NormalTok{) }\SpecialCharTok{\%\textgreater{}\%}\NormalTok{ names }\CommentTok{\# elemental geochemistry}
\CommentTok{\# Select the names/colnames of the property measurement uncertainties/errors}
\NormalTok{prop.uncertainties }\OtherTok{\textless{}{-}}\NormalTok{ database }\SpecialCharTok{\%\textgreater{}\%}\NormalTok{ dplyr}\SpecialCharTok{::}\FunctionTok{select}\NormalTok{(TOC\_SD, TN\_SD, }\CommentTok{\# organic matter}
\NormalTok{ EDXRF\_Al\_RMSE}\SpecialCharTok{:}\NormalTok{EDXRF\_Zr\_RMSE) }\SpecialCharTok{\%\textgreater{}\%}\NormalTok{ names }\CommentTok{\# elemental geochemistry}
\FunctionTok{names}\NormalTok{(prop.uncertainties) }\OtherTok{\textless{}{-}}\NormalTok{ prop.values }\CommentTok{\# Add property names to property uncertainty for easier selection}
\end{Highlighting}
\end{Shaded}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{prop.values}
\CommentTok{\#\textgreater{} [1] "TOC\_PrC" "TN\_PrC" "EDXRF\_Al\_mg.kg.1" "EDXRF\_Ca\_mg.kg.1"}
\CommentTok{\#\textgreater{} [5] "EDXRF\_Co\_mg.kg.1" "EDXRF\_Cr\_mg.kg.1" "EDXRF\_Cu\_mg.kg.1" "EDXRF\_Fe\_mg.kg.1"}
\CommentTok{\#\textgreater{} [9] "EDXRF\_K\_mg.kg.1" "EDXRF\_Mg\_mg.kg.1" "EDXRF\_Mn\_mg.kg.1" "EDXRF\_Ni\_mg.kg.1"}
\CommentTok{\#\textgreater{} [13] "EDXRF\_Pb\_mg.kg.1" "EDXRF\_Rb\_mg.kg.1" "EDXRF\_Si\_mg.kg.1" "EDXRF\_Sr\_mg.kg.1"}
\CommentTok{\#\textgreater{} [17] "EDXRF\_Ti\_mg.kg.1" "EDXRF\_Zn\_mg.kg.1" "EDXRF\_Zr\_mg.kg.1"}
\FunctionTok{unname}\NormalTok{(prop.uncertainties)}
\CommentTok{\#\textgreater{} [1] "TOC\_SD" "TN\_SD" "EDXRF\_Al\_RMSE" "EDXRF\_Ca\_RMSE"}
\CommentTok{\#\textgreater{} [5] "EDXRF\_Co\_RMSE" "EDXRF\_Cr\_RMSE" "EDXRF\_Cu\_RMSE" "EDXRF\_Fe\_RMSE"}
\CommentTok{\#\textgreater{} [9] "EDXRF\_K\_RMSE" "EDXRF\_Mg\_RMSE" "EDXRF\_Mn\_RMSE" "EDXRF\_Ni\_RMSE"}
\CommentTok{\#\textgreater{} [13] "EDXRF\_Pb\_RMSE" "EDXRF\_Rb\_RMSE" "EDXRF\_Si\_RMSE" "EDXRF\_Sr\_RMSE"}
\CommentTok{\#\textgreater{} [17] "EDXRF\_Ti\_RMSE" "EDXRF\_Zn\_RMSE" "EDXRF\_Zr\_RMSE"}
\end{Highlighting}
\end{Shaded}
First, we use \texttt{data.watcher} to check that the selected
properties meet the quality criteria, particularly in terms of their
measurement uncertainty. Several criteria are evaluated (e.g.~presence
of some negative values or high uncertainty) and presented as indicators
to consider the use of a property.
\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{library}\NormalTok{(fingR)}
\NormalTok{fingR}\SpecialCharTok{::}\FunctionTok{data.watcher}\NormalTok{(}\AttributeTok{data =}\NormalTok{ database, }\AttributeTok{properties =}\NormalTok{ prop.values, }\AttributeTok{prop.uncer =}\NormalTok{ prop.uncertainties)}
\CommentTok{\#\textgreater{} }
\CommentTok{\#\textgreater{} Following column(s) contain(s) some negative values: EDXRF\_Cr\_mg.kg.1.}
\CommentTok{\#\textgreater{} Following column(s) have a measurement uncertainty that makes some values to be virtually impossible: EDXRF\_Co\_mg.kg.1, EDXRF\_Cr\_mg.kg.1, EDXRF\_Cu\_mg.kg.1, EDXRF\_Ni\_mg.kg.1.}
\CommentTok{\#\textgreater{} Following column(s) have a relative measurement uncertainty above 5\% (up to {-} number): EDXRF\_Co\_mg.kg.1 (max:753\% {-} n:26), EDXRF\_Cr\_mg.kg.1 (max:211\% {-} n:38), EDXRF\_Ni\_mg.kg.1 (max:105\% {-} n:96), EDXRF\_Cu\_mg.kg.1 (max:103\% {-} n:52), EDXRF\_Rb\_mg.kg.1 (max:89\% {-} n:93), TN\_PrC (max:45\% {-} n:91), EDXRF\_Pb\_mg.kg.1 (max:38\% {-} n:91), EDXRF\_Zn\_mg.kg.1 (max:34\% {-} n:96), EDXRF\_Sr\_mg.kg.1 (max:15\% {-} n:46), TOC\_PrC (max:14\% {-} n:95), EDXRF\_Zr\_mg.kg.1 (max:7\% {-} n:2).}
\end{Highlighting}
\end{Shaded}
According to \texttt{data.watcher} results: Co, Cr, Cu, Ni, and Rb have
too high measurement uncertainty and in addition Cr has some negative
values among the samples. These properties will be removed from
following study.
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\# Remove Co, Cr, Cu, Ni and Rb from the vector of properties}
\NormalTok{prop.values }\OtherTok{\textless{}{-}}\NormalTok{ prop.values[}\SpecialCharTok{!}\NormalTok{prop.values }\SpecialCharTok{\%in\%} \FunctionTok{c}\NormalTok{(}\StringTok{"EDXRF\_Co\_mg.kg.1"}\NormalTok{, }\StringTok{"EDXRF\_Cr\_mg.kg.1"}\NormalTok{, }\StringTok{"EDXRF\_Cu\_mg.kg.1"}\NormalTok{, }\StringTok{"EDXRF\_Ni\_mg.kg.1"}\NormalTok{, }\StringTok{"EDXRF\_Rb\_mg.kg.1"}\NormalTok{)]}
\CommentTok{\# Keep uncertainties associated to the new vector of properties}
\NormalTok{prop.uncertainties }\OtherTok{\textless{}{-}}\NormalTok{ prop.uncertainties[prop.values]}
\end{Highlighting}
\end{Shaded}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{prop.values}
\CommentTok{\#\textgreater{} [1] "TOC\_PrC" "TN\_PrC" "EDXRF\_Al\_mg.kg.1" "EDXRF\_Ca\_mg.kg.1"}
\CommentTok{\#\textgreater{} [5] "EDXRF\_Fe\_mg.kg.1" "EDXRF\_K\_mg.kg.1" "EDXRF\_Mg\_mg.kg.1" "EDXRF\_Mn\_mg.kg.1"}
\CommentTok{\#\textgreater{} [9] "EDXRF\_Pb\_mg.kg.1" "EDXRF\_Si\_mg.kg.1" "EDXRF\_Sr\_mg.kg.1" "EDXRF\_Ti\_mg.kg.1"}
\CommentTok{\#\textgreater{} [13] "EDXRF\_Zn\_mg.kg.1" "EDXRF\_Zr\_mg.kg.1"}
\end{Highlighting}
\end{Shaded}
\hypertarget{tracer-selection}{%
\subsubsection{Tracer selection}\label{tracer-selection}}
\hypertarget{assessment-of-conservative-behaviour}{%
\subsubsection{1. Assessment of conservative
behaviour}\label{assessment-of-conservative-behaviour}}
In the three-step method, the conservative behaviour is assessed by
range tests (RT), also known as bracket tests. To be considered to have
a conservative behaviour, all target samples values should lye within
the range of the potential source classes. The range of the potential
source classes is defined as the highest and lowest source class value
of a certain criterion.
Various criteria for range tests are documented in the literature,
including minimum-maximum (\textbf{MM}), minimum-maximum plus/minus 10\%
(\textbf{MMe}) -to account for measurement error- , boxplot
\textbf{whiskers} -as threshold to identify extreme values-, boxplot
\textbf{hinge} -50\% of the population-, \textbf{mean}, mean plus/minus
one standard deviation (\textbf{mean.sd}) and median. The \textbf{mean}
and \textbf{mean.sd} criteria are performed on log-transformed values,
assuming a Normal distribution of the samples.
By default, the function applies all these criteria, though their
effectiveness in identifying conservative characteristics may vary.
Among these, the \textbf{mean.sd} criterion is mathematically the most
robust.
The \texttt{range.test} function returns a list containing two data
frames - \emph{results.df}: A summary overview of the range test
results. - \emph{results.RT}: Detailed results for each target sample's
range test for each property.
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{rt.results }\OtherTok{\textless{}{-}}\NormalTok{ fingR}\SpecialCharTok{::}\FunctionTok{range.tests}\NormalTok{(}\AttributeTok{data =}\NormalTok{ database, }\CommentTok{\# Dataset containing source and mixture information}
\AttributeTok{class =} \StringTok{"Class\_decontamination"}\NormalTok{, }\CommentTok{\# Column containing the classification or grouping of sources and mixtures}
\AttributeTok{mixture =} \StringTok{"Target"}\NormalTok{, }\CommentTok{\# Identifier for mixtures within the class variable}
\AttributeTok{properties =}\NormalTok{ prop.values, }\CommentTok{\# Properties to be tested for conservativeness}
\AttributeTok{sample.id =} \StringTok{"Sample\_name"}\NormalTok{, }\CommentTok{\# Identifier for individual samples}
\AttributeTok{criteria =} \FunctionTok{c}\NormalTok{(}\StringTok{"mean.sd"}\NormalTok{) }\CommentTok{\# Criteria for conducting range tests (options: "MM", "MMe", "whiskers", "hinge", "mean", "mean.sd", "median", or "all")}
\CommentTok{\# MM.error = c(0.1), \# Optional: Set the minimum{-}maximum plus/minus error as 10\%}
\CommentTok{\# save.dir = dir.example, \# Optional: Directory path for saving the results}
\CommentTok{\# note = "example" \# Optional: Additional note to append to the file name}
\NormalTok{ )}
\end{Highlighting}
\end{Shaded}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{rt.results}\SpecialCharTok{$}\NormalTok{results.df[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{5}\NormalTok{]}
\CommentTok{\#\textgreater{} Property n\_source n\_mixture NAs RT\_mean.sd\_single}
\CommentTok{\#\textgreater{} 1 TOC\_PrC 58 38 0 TRUE}
\CommentTok{\#\textgreater{} 2 TN\_PrC 58 38 0 TRUE}
\CommentTok{\#\textgreater{} 3 EDXRF\_Al\_mg.kg.1 58 38 0 TRUE}
\CommentTok{\#\textgreater{} 4 EDXRF\_Ca\_mg.kg.1 58 38 0 FALSE}
\CommentTok{\#\textgreater{} 5 EDXRF\_Fe\_mg.kg.1 58 38 0 FALSE}
\CommentTok{\#\textgreater{} 6 EDXRF\_K\_mg.kg.1 58 38 0 FALSE}
\CommentTok{\#\textgreater{} 7 EDXRF\_Mg\_mg.kg.1 58 38 0 FALSE}
\CommentTok{\#\textgreater{} 8 EDXRF\_Mn\_mg.kg.1 58 38 0 FALSE}
\CommentTok{\#\textgreater{} 9 EDXRF\_Pb\_mg.kg.1 58 38 0 FALSE}
\CommentTok{\#\textgreater{} 10 EDXRF\_Si\_mg.kg.1 58 38 0 FALSE}
\CommentTok{\#\textgreater{} 11 EDXRF\_Sr\_mg.kg.1 58 38 0 FALSE}
\CommentTok{\#\textgreater{} 12 EDXRF\_Ti\_mg.kg.1 58 38 0 TRUE}
\CommentTok{\#\textgreater{} 13 EDXRF\_Zn\_mg.kg.1 58 38 0 FALSE}
\CommentTok{\#\textgreater{} 14 EDXRF\_Zr\_mg.kg.1 58 38 0 FALSE}
\end{Highlighting}
\end{Shaded}
The \texttt{is.conservative} function returns a list of vector of
conservative properties based on the results of range tests. If multiple
criteria are used, a vector is generated for each criterion.
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{prop.cons }\OtherTok{\textless{}{-}}\NormalTok{ fingR}\SpecialCharTok{::}\FunctionTok{is.conservative}\NormalTok{(}\AttributeTok{data =}\NormalTok{ rt.results}\SpecialCharTok{$}\NormalTok{results.df, }\CommentTok{\# Data frame containing the results of range tests, typically generated by fingR::range.tests}
\CommentTok{\# property = "Property", \# Optional: Column containing the names of properties being tested for conservativeness}
\CommentTok{\# test.format = "RT", \# Optional: Indicates the common pattern in column test names (default: "RT")}
\CommentTok{\# position = 2, \# Optional: Position of the test name in the column name (default: 2)}
\CommentTok{\# separator = "\_", \# Optional: Character used to split test names in the column (default: "\_")}
\CommentTok{\# note = "example" \# Optional: Additional note to append to the file name}
\NormalTok{ )}
\end{Highlighting}
\end{Shaded}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{prop.cons}
\CommentTok{\#\textgreater{} $mean.sd}
\CommentTok{\#\textgreater{} [1] "TOC\_PrC" "TN\_PrC" "EDXRF\_Al\_mg.kg.1" "EDXRF\_Ti\_mg.kg.1"}
\end{Highlighting}
\end{Shaded}
\hypertarget{discriminant-power}{%
\subsubsection{2. Discriminant power}\label{discriminant-power}}
Inthe three-step method, the capacity of a property to discriminate
among source groups is commonly assessed using a Kruskal-Wallis H-test.
The \emph{discriminant.test} function arguments are very similar to
\emph{range.tests}. As an alternative Kolmogov-Smirnov two-samples tests
can be used. It provides more detailled results as source groups are
compared to each other.
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{KS.results }\OtherTok{\textless{}{-}}\NormalTok{ fingR}\SpecialCharTok{::}\FunctionTok{discriminant.test}\NormalTok{(}\AttributeTok{data =}\NormalTok{ database, }\CommentTok{\# Dataset containing source and mixture information}
\AttributeTok{class =} \StringTok{"Class\_decontamination"}\NormalTok{, }\CommentTok{\# Column containing the classification or grouping of sources and mixtures}
\AttributeTok{mixture =} \StringTok{"Target"}\NormalTok{, }\CommentTok{\# Identifier for mixtures within the class variable}
\AttributeTok{test =} \StringTok{"KS"}\NormalTok{, }\CommentTok{\# Type of test performed, Kruskal{-}Wallis (KW) or Kolmogorov{-}smirnov (KS)}
\AttributeTok{properties =}\NormalTok{ prop.values, }\CommentTok{\# Properties to be tested for conservativeness}
\AttributeTok{p.level =}\NormalTok{ .}\DecValTok{01}\NormalTok{, }\CommentTok{\# Optional: p{-}value significance level (default = 0.05)}
\CommentTok{\# save.discrim.tests = T, \# Optional: If two{-}samples tests should be saved}
\CommentTok{\# save.dir = dir.example, \# Optional: Directory path for saving the results}
\CommentTok{\# note = "example" \# Optional: Additional note to append to the file name}
\NormalTok{ )}
\end{Highlighting}
\end{Shaded}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{KS.results[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{5}\NormalTok{,]}
\CommentTok{\#\textgreater{} Property n.diff.groups Kolmogorov.Smirnov\_discriminant}
\CommentTok{\#\textgreater{} 1 TOC\_PrC 3 TRUE}
\CommentTok{\#\textgreater{} 2 TN\_PrC 3 TRUE}
\CommentTok{\#\textgreater{} 3 EDXRF\_Al\_mg.kg.1 3 TRUE}
\CommentTok{\#\textgreater{} 4 EDXRF\_Ca\_mg.kg.1 1 TRUE}
\CommentTok{\#\textgreater{} 5 EDXRF\_Fe\_mg.kg.1 0 FALSE}
\end{Highlighting}
\end{Shaded}
Properties that get a Kruskal-Wallis p-value bellow 0.05
(\textbf{p.value = 0.05}), are selected as discriminant properties. The
function \emph{is.discriminant} list them. The function automatically
recognise data.frame produced by \emph{discriminant.test} but it is
possible to set it for other data.frame format.
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{prop.discrim }\OtherTok{\textless{}{-}}\NormalTok{ fingR}\SpecialCharTok{::}\FunctionTok{is.discriminant}\NormalTok{(KS.results, }\CommentTok{\# data.frame from discriminant.test or any df with the same organisation.}
\CommentTok{\# property = "Property", \# Optional: Column containing the names of properties being tested for conservativeness}
\CommentTok{\# test.format = "Kruskal.Wallis\_p.value", \# Optional: Indicates the common pattern in column test names (default: "RT")}
\CommentTok{\# position = 1, \# Optional: Position of the test name in the column name (default: 1)}
\CommentTok{\# separator = "\_", \# Optional: Character used to split test names in the column (default: "\_")}
\CommentTok{\# p.level = 0.05, \# Optional: p{-}value significance level (default = 0.05)}
\CommentTok{\# note = "example" \# Optional: Additional note to append to the file name}
\NormalTok{ )}
\end{Highlighting}
\end{Shaded}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{prop.discrim}
\CommentTok{\#\textgreater{} $Kolmogorov.Smirnov}
\CommentTok{\#\textgreater{} [1] "TOC\_PrC" "TN\_PrC" "EDXRF\_Al\_mg.kg.1" "EDXRF\_Ca\_mg.kg.1"}
\CommentTok{\#\textgreater{} [5] "EDXRF\_K\_mg.kg.1" "EDXRF\_Pb\_mg.kg.1" "EDXRF\_Si\_mg.kg.1" "EDXRF\_Sr\_mg.kg.1"}
\CommentTok{\#\textgreater{} [9] "EDXRF\_Zn\_mg.kg.1" "EDXRF\_Zr\_mg.kg.1"}
\end{Highlighting}
\end{Shaded}
\hypertarget{selected-tracers}{%
\paragraph{Selected tracers}\label{selected-tracers}}
Tracers are conservative and discriminant properties.
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{tracers }\OtherTok{\textless{}{-}}\NormalTok{ fingR}\SpecialCharTok{::}\FunctionTok{selected.tracers}\NormalTok{(}\AttributeTok{cons =}\NormalTok{ prop.cons, }\CommentTok{\# character vector of conservative properties}
\AttributeTok{discrim =}\NormalTok{ prop.discrim) }\CommentTok{\# character Vector of discriminant properties}
\end{Highlighting}
\end{Shaded}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{tracers }
\CommentTok{\#\textgreater{} $mean.sd\_Kolmogorov.Smirnov}
\CommentTok{\#\textgreater{} [1] "TOC\_PrC" "TN\_PrC" "EDXRF\_Al\_mg.kg.1"}
\end{Highlighting}
\end{Shaded}
Tracer selection are labelled by \texttt{selected.tracers} accordingly
to the range test criteria (e.g.~mean.sd, hinge\ldots) and discriminant
test (i.e.~Kruskal.Wallis or Kolmogorov.Smirnov). However, sometimes
this label is to long for file labelling therefore, you may replace it
accondingly.
\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{names}\NormalTok{(tracers) }\OtherTok{\textless{}{-}} \StringTok{"msd\_KS"} \CommentTok{\# replace tracers names with the new name}
\end{Highlighting}
\end{Shaded}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{tracers}
\CommentTok{\#\textgreater{} $msd\_KS}
\CommentTok{\#\textgreater{} [1] "TOC\_PrC" "TN\_PrC" "EDXRF\_Al\_mg.kg.1"}
\end{Highlighting}
\end{Shaded}
\hypertarget{discriminant-function-analysis-dfa-stepwise-selection}{%
\subsubsection{3. Discriminant Function Analysis (DFA) stepwise
selection}\label{discriminant-function-analysis-dfa-stepwise-selection}}
The conventional three-step method apply a DFA forward stepwise
selection on the selected tracers. This DFA stepwise selection aims to
retain tracers that maximize source discrimination. However, this step
has faced criticism. Observing the results for a large selection of
tracers can be insightful. However, it is not useful for small selection
of tracers, as it is the case here.
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{tracers.SW }\OtherTok{\textless{}{-}}\NormalTok{ fingR}\SpecialCharTok{::}\FunctionTok{stepwise.selection}\NormalTok{(}\AttributeTok{data =}\NormalTok{ database, }\CommentTok{\# Dataset containing source and mixture information}
\AttributeTok{class =} \StringTok{"Class\_decontamination"}\NormalTok{, }\CommentTok{\# Column containing the classification or grouping of source and mixtures}
\AttributeTok{tracers =}\NormalTok{ tracers}\SpecialCharTok{$}\NormalTok{msd\_KS, }\CommentTok{\# Character vector containing tracers to consider}
\AttributeTok{target =} \StringTok{"Target"} \CommentTok{\# Identifier for target samples within the "class" column}
\CommentTok{\# save.dir = dir.example, \# Optional: Directory path for saving the results}
\CommentTok{\# note = "example" \# Optional: Additional note to append to the file name}
\NormalTok{ )}
\end{Highlighting}
\end{Shaded}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{tracers.SW}
\CommentTok{\#\textgreater{} [1] "EDXRF\_Al\_mg.kg.1" "TOC\_PrC" "TN\_PrC"}
\end{Highlighting}
\end{Shaded}
The DFA stepwise selection did not removed any of the selected tracers.
If the DFA selects different tracers, examining the modelling results
for both sets can provide useful insights.
Both tracer selections could joint like following:
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\# Joining two tracers vector in a list}
\NormalTok{all.tracers }\OtherTok{\textless{}{-}} \FunctionTok{list}\NormalTok{(}\StringTok{"msd\_KS"} \OtherTok{=}\NormalTok{ tracers}\SpecialCharTok{$}\NormalTok{msd\_KS, }\StringTok{"msd\_KS\_DFA"} \OtherTok{=}\NormalTok{ tracers.SW)}
\end{Highlighting}
\end{Shaded}
\hypertarget{source-contribution-modelling}{%
\subsection{Source contribution
modelling}\label{source-contribution-modelling}}
\hypertarget{virtual-mixtures}{%
\paragraph{Virtual mixtures}\label{virtual-mixtures}}
To evaluate the accuracy of un-mixing models, virtual mixtures are used.
These virtual mixtures, serving as target samples with known
contributions, allow for the calculation of modelling accuracy metrics.
The \texttt{VM.contrib.generator} generate virtual mixture contributions
from the \texttt{min} to the \texttt{max} contribution set with a
specified \texttt{step}. Contribution could be set as percentage
(\texttt{min\ =\ 0,\ max\ =\ 100}) or as a ratios
(\texttt{min\ =\ 0,\ max\ =\ 1}). Smaller \texttt{step} result in a
higher number of virtual mixtures, such as 231 virtual mixtures for a
5\% step and 5151 virtual mixtures for a 1\% step. Alternatively,
virtual mixtures can be generated within \texttt{VM.builder}.
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\# Generate virtual mixture source contributions}
\NormalTok{VM.contrib }\OtherTok{\textless{}{-}}\NormalTok{ fingR}\SpecialCharTok{::}\FunctionTok{VM.contrib.generator}\NormalTok{(}\AttributeTok{n.sources =} \DecValTok{3}\NormalTok{, }\CommentTok{\# Number of source levels}
\AttributeTok{min =} \DecValTok{0}\NormalTok{, }\CommentTok{\# Minimum contribution (here percentage)}
\AttributeTok{max =} \DecValTok{100}\NormalTok{, }\CommentTok{\# Maximum contribution (here percentage)}
\AttributeTok{step =} \DecValTok{5}\NormalTok{, }\CommentTok{\# Step between two contribution levels (here percentage)}
\AttributeTok{sources.class =} \FunctionTok{c}\NormalTok{(}\StringTok{"Forest"}\NormalTok{, }\StringTok{"Subsoil"}\NormalTok{, }\StringTok{"Undecontaminated"}\NormalTok{), }\CommentTok{\# Optional: Classification of sources}
\AttributeTok{save.dir =}\NormalTok{ dir.example, }\CommentTok{\# Optional: Directory path for saving the results}
\CommentTok{\# note = "example" \# Optional: Additional note to append to the file name}
\CommentTok{\# VM.name = "Sample\_name", \# Optional: Name of the column containing virtual mixture labels}
\CommentTok{\# fileEncoding = "latin1", \# Optional: File encoding, important if special character are used in source levels}
\CommentTok{\# return = TRUE, \# Optional: Whether the function should return the result}
\CommentTok{\# save = TRUE \# Optional: Whether the function should save the result}
\NormalTok{ )}
\end{Highlighting}
\end{Shaded}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{VM.contrib[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{5}\NormalTok{,]}
\CommentTok{\#\textgreater{} Sample\_name Forest Subsoil Undecontaminated}
\CommentTok{\#\textgreater{} 1 VM{-}001 0 0 100}
\CommentTok{\#\textgreater{} 2 VM{-}002 0 5 95}
\CommentTok{\#\textgreater{} 3 VM{-}003 0 10 90}
\CommentTok{\#\textgreater{} 4 VM{-}004 0 15 85}
\CommentTok{\#\textgreater{} 5 VM{-}005 0 20 80}
\end{Highlighting}
\end{Shaded}
Next, virtual mixture properties are calculated as simple proportional
mixture of source signature (i.e.~mean values). This approach is a
simple mass balance approach. The \texttt{VM.builder} function saves and
returns a list containing three \emph{data.frame} objects: one with the
\texttt{\$property} values, the other with the \texttt{\$uncertainty}
values (with corresponding labels when given in \texttt{\$uncertainty}
if not simply ``\_SD'' is added at the end of the tracer label), and the
last one \texttt{\$full} where property and uncertainty were join.
To run un-mixing models, source and target information should be within
the same data frame. Source informations are added at the end of all the
\emph{data.frame} created.
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{VM }\OtherTok{\textless{}{-}} \FunctionTok{VM.builder}\NormalTok{(}\AttributeTok{data =}\NormalTok{ database, }\CommentTok{\# Dataset containing source samples}
\AttributeTok{material =} \StringTok{"Material"}\NormalTok{, }\CommentTok{\# Column indicating the difference between source and target}
\AttributeTok{source.name =} \StringTok{"Source"}\NormalTok{, }\CommentTok{\# Identifier for source samples within the material column}
\AttributeTok{class =} \StringTok{"Class\_decontamination"}\NormalTok{, }\CommentTok{\# Column containing the classification or grouping of sources and mixtures}
\AttributeTok{tracers =}\NormalTok{ tracers}\SpecialCharTok{$}\NormalTok{msd\_KS, }\CommentTok{\# Character vector containing tracers to consider}
\AttributeTok{uncertainty =} \FunctionTok{unname}\NormalTok{(prop.uncertainties[tracers}\SpecialCharTok{$}\NormalTok{msd\_KS]), }\CommentTok{\# Character vector containing tracers uncertainty labels}
\AttributeTok{contributions =}\NormalTok{ VM.contrib, }\CommentTok{\# Virtual mixture contributions}
\AttributeTok{VM.name =} \StringTok{"Sample\_name"}\NormalTok{, }\CommentTok{\# Column with virtual mixture labels in the \textquotesingle{}contribution\textquotesingle{} (i.e. VM.contribution)}
\AttributeTok{add.sources =} \ConstantTok{TRUE}\NormalTok{, }\CommentTok{\# Add source information at the end of the VM data frames}
\AttributeTok{save.dir =}\NormalTok{ dir.example, }\CommentTok{\# Optional: Directory path for saving the results}
\CommentTok{\# note = "example" \# Optional: Additional note to append to the file name}
\NormalTok{ )}
\end{Highlighting}
\end{Shaded}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{VM}\SpecialCharTok{$}\NormalTok{full[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{5}\NormalTok{,]}
\CommentTok{\#\textgreater{} Sample\_name Class\_decontamination TOC\_PrC TN\_PrC EDXRF\_Al\_mg.kg.1 TOC\_SD}
\CommentTok{\#\textgreater{} 1 VM{-}001 Virtual Mixture 5.16 0.42 84858.53 4.75}
\CommentTok{\#\textgreater{} 2 VM{-}002 Virtual Mixture 4.97 0.40 86004.71 4.75}
\CommentTok{\#\textgreater{} 3 VM{-}003 Virtual Mixture 4.78 0.39 87150.90 4.75}
\CommentTok{\#\textgreater{} 4 VM{-}004 Virtual Mixture 4.60 0.38 88297.08 4.75}
\CommentTok{\#\textgreater{} 5 VM{-}005 Virtual Mixture 4.41 0.36 89443.26 4.75}
\CommentTok{\#\textgreater{} TN\_SD EDXRF\_Al\_RMSE}
\CommentTok{\#\textgreater{} 1 0.28 17840.72}
\CommentTok{\#\textgreater{} 2 0.28 17840.72}
\CommentTok{\#\textgreater{} 3 0.28 17840.72}
\CommentTok{\#\textgreater{} 4 0.28 17840.72}
\CommentTok{\#\textgreater{} 5 0.28 17840.72}
\end{Highlighting}
\end{Shaded}
Here an example of sets to generate virtual mixture with the
\texttt{VM.builder} function without previously running the
\texttt{VM.contrib.generator} function.
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{VM }\OtherTok{\textless{}{-}} \FunctionTok{VM.builder}\NormalTok{(}\AttributeTok{data =}\NormalTok{ database, }\CommentTok{\# Dataset containing source samples}
\AttributeTok{material =} \StringTok{"Material"}\NormalTok{, }\CommentTok{\# Column indicating the difference between source and target}
\AttributeTok{source.name =} \StringTok{"Source"}\NormalTok{, }\CommentTok{\# Identifier for source samples within the material column}
\AttributeTok{class =} \StringTok{"Class\_decontamination"}\NormalTok{, }\CommentTok{\# Column containing the classification or grouping of sources and mixtures}
\AttributeTok{tracers =}\NormalTok{ tracers}\SpecialCharTok{$}\NormalTok{msd\_KS, }\CommentTok{\# Character vector containing tracers to consider}
\AttributeTok{uncertainty =} \FunctionTok{unname}\NormalTok{(prop.uncertainties[tracers}\SpecialCharTok{$}\NormalTok{msd\_KS]), }\CommentTok{\# Character vector containing tracers uncertainty labels}
\AttributeTok{VM.range =} \FunctionTok{c}\NormalTok{(}\DecValTok{0}\NormalTok{, }\DecValTok{100}\NormalTok{), }\CommentTok{\# Minimum and maximum contribution (here percentage)}
\AttributeTok{VM.step =} \DecValTok{5}\NormalTok{, }\CommentTok{\# Step between two contribution levels (here percentage)}
\AttributeTok{VM.name =} \StringTok{"Sample\_name"}\NormalTok{, }\CommentTok{\# Column with virtual mixture labels in the \textquotesingle{}contribution\textquotesingle{} (i.e. VM.contribution)}
\AttributeTok{add.sources =} \ConstantTok{TRUE}\NormalTok{, }\CommentTok{\# Add source information at the end of the VM data frames}
\AttributeTok{save.dir =}\NormalTok{ dir.example, }\CommentTok{\# Optional: Directory path for saving the results}
\CommentTok{\# note = "example" \# Optional: Additional note to append to the file name}
\NormalTok{ )}
\end{Highlighting}
\end{Shaded}
\hypertarget{un-mixing-models}{%
\subsubsection{Un-mixing models}\label{un-mixing-models}}
Create a folder where all modelling results will be saved
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\# Create new folder to save tracer modelling results}
\FunctionTok{dir.create}\NormalTok{(}\FunctionTok{file.path}\NormalTok{(dir.example, }\StringTok{"Modelling/"}\NormalTok{), }\AttributeTok{showWarnings =} \ConstantTok{FALSE}\NormalTok{)}
\NormalTok{dir.modelling }\OtherTok{\textless{}{-}} \FunctionTok{paste0}\NormalTok{(dir.example, }\StringTok{"Modelling/"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\hypertarget{bayesian-mean-model-bmm}{%
\subsubsection{Bayesian Mean Model
(BMM)}\label{bayesian-mean-model-bmm}}
Create a folder specific from BMM modelling results.
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\# Create new folder to save BMM modelling results}
\FunctionTok{dir.create}\NormalTok{(}\FunctionTok{file.path}\NormalTok{(dir.modelling, }\StringTok{"BMM/"}\NormalTok{), }\AttributeTok{showWarnings =} \ConstantTok{FALSE}\NormalTok{)}
\NormalTok{dir.mod.BMM }\OtherTok{\textless{}{-}} \FunctionTok{paste0}\NormalTok{(dir.modelling, }\StringTok{"BMM/"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\hypertarget{run-bmm-model-with-or-without-isotopic-ratio}{%
\paragraph{Run BMM model with or without isotopic
ratio}\label{run-bmm-model-with-or-without-isotopic-ratio}}
Run BMM models for actual sediment samples (\emph{mix}) and virtual
mixtures (\emph{VM}). The BMM model performs a Bayesian un-mixing with a
Monte-Carlo chain, the prediction is corrected using the sum of squared
relative error of each tracer. Without isotopic ratio within the
tracers, there is no need to take any precautions when setting up the
model.
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\# Run BMM model for sediment samples}
\NormalTok{BMM.mix }\OtherTok{\textless{}{-}}\NormalTok{ fingR}\SpecialCharTok{::}\FunctionTok{run.BMM}\NormalTok{(}\AttributeTok{data =}\NormalTok{ database, }\CommentTok{\# Dataset containing source and target samples}
\AttributeTok{class =} \StringTok{"Class\_decontamination"}\NormalTok{, }\CommentTok{\# Column containing the classification or grouping of sources and mixtures}
\AttributeTok{mixture =} \StringTok{"Target"}\NormalTok{, }\CommentTok{\# Column name identifying the target samples}
\AttributeTok{sample.id =} \StringTok{"Sample\_name"}\NormalTok{, }\CommentTok{\# Column name for sample identifiers}
\AttributeTok{tracers =}\NormalTok{ tracers}\SpecialCharTok{$}\NormalTok{msd\_KS, }\CommentTok{\# Character vector containing tracers to consider}
\AttributeTok{uncertainty =} \FunctionTok{unname}\NormalTok{(prop.uncertainties[tracers}\SpecialCharTok{$}\NormalTok{msd\_KS]), }\CommentTok{\# Optional: Character vector containing uncertainty of the tracers}
\AttributeTok{n.iter =} \DecValTok{30}\NormalTok{, }\CommentTok{\# Number of iterations for the model (30 for test version {-} 2500 or 5000 iterations are recommended) \textquotesingle{}prop.uncertainties\textquotesingle{}}
\AttributeTok{save.dir =}\NormalTok{ dir.mod.BMM, }\CommentTok{\# Optional: Directory path for saving the results {-} \textquotesingle{}BMM\_previsions.CSV\textquotesingle{}}
\CommentTok{\#note = "example" \# Optional: Additional note to append to the file name}
\NormalTok{ )}
\end{Highlighting}
\end{Shaded}
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\# Run BMM model for virtual mixtures}
\NormalTok{BMM.VM }\OtherTok{\textless{}{-}}\NormalTok{ fingR}\SpecialCharTok{::}\FunctionTok{run.BMM}\NormalTok{(}\AttributeTok{data =}\NormalTok{ VM}\SpecialCharTok{$}\NormalTok{full, }\CommentTok{\# Dataset containing source and target samples}
\AttributeTok{class =} \StringTok{"Class\_decontamination"}\NormalTok{, }\CommentTok{\# Column containing the classification or grouping of sources and mixtures}
\AttributeTok{mixture =} \StringTok{"Virtual Mixture"}\NormalTok{, }\CommentTok{\# Column name identifying the target samples}
\AttributeTok{sample.id =} \StringTok{"Sample\_name"}\NormalTok{, }\CommentTok{\# Column name for sample identifiers}
\AttributeTok{tracers =}\NormalTok{ tracers}\SpecialCharTok{$}\NormalTok{msd\_KS, }\CommentTok{\# Character vector containing tracers to consider}
\AttributeTok{uncertainty =} \FunctionTok{unname}\NormalTok{(prop.uncertainties[tracers}\SpecialCharTok{$}\NormalTok{msd\_KS]), }\CommentTok{\# Optional: Character vector containing uncertainty of the tracers}
\AttributeTok{n.iter =} \DecValTok{30}\NormalTok{, }\CommentTok{\# Number of iterations for the model (30 for test version {-} 2500 or 5000 iterations are recommended)}
\AttributeTok{save.dir =}\NormalTok{ dir.mod.BMM, }\CommentTok{\# Optional: Directory path for saving the results {-} \textquotesingle{}BMM\_previsions\_VM.CSV\textquotesingle{}}
\AttributeTok{note =} \StringTok{"VM"} \CommentTok{\# Optional: Additional note to append to the file name}
\NormalTok{ )}
\end{Highlighting}
\end{Shaded}
When dealing with isotopic ratios, which are non-linear properties,
errors should be calculated considering relative property content (see
\href{https://doi.org/10.1002/hyp.10311}{Laceby et al.~(2015)} for
further details). For example, the delta 13C ratio indicates the
isotopic ratio of 12C to 13C in organic matter, the \texttt{run.BMM}
function should be configured in this way:
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\# Run BMM model for sediment samples}
\NormalTok{BMM.iso }\OtherTok{\textless{}{-}}\NormalTok{ fingR}\SpecialCharTok{::}\FunctionTok{run.BMM}\NormalTok{(}\AttributeTok{data =}\NormalTok{ database, }\CommentTok{\# Dataset containing source and target samples}
\AttributeTok{class =} \StringTok{"Class\_decontamination"}\NormalTok{, }\CommentTok{\# Column containing the classification or grouping of sources and mixtures}
\AttributeTok{mixture =} \StringTok{"Target"}\NormalTok{, }\CommentTok{\# Column name identifying the target samples}
\AttributeTok{sample.id =} \StringTok{"Sample\_name"}\NormalTok{, }\CommentTok{\# Column name for sample identifiers}
\AttributeTok{tracers =}\NormalTok{ tracers}\SpecialCharTok{$}\NormalTok{msd\_KS, }\CommentTok{\# Character vector containing tracers to consider}
\AttributeTok{uncertainty =} \FunctionTok{unname}\NormalTok{(prop.uncertainties[tracers}\SpecialCharTok{$}\NormalTok{msd\_KS]), }\CommentTok{\# Optional: Character vector containing uncertainty of the tracers}
\AttributeTok{isotope.ratio =} \FunctionTok{c}\NormalTok{(}\StringTok{"d13C\_PrM"}\NormalTok{), }\CommentTok{\# Optional: Character vector containing isotopic ratios}
\AttributeTok{isotope.prop =} \FunctionTok{c}\NormalTok{(}\StringTok{"TOC\_PrC"}\NormalTok{), }\CommentTok{\# Optional: Character vector containing isotopic ratios respective properties}
\AttributeTok{isotopes.unc =} \FunctionTok{c}\NormalTok{(}\StringTok{"d13C\_SD"}\NormalTok{), }\CommentTok{\# Optional: Character vecotr containing uncertainty of the isotopic ratios}
\AttributeTok{n.iter =} \DecValTok{30}\NormalTok{, }\CommentTok{\# Number of iterations for the model (30 for test version {-} 2500 or 5000 iterations are recommended) \textquotesingle{}prop.uncertainties\textquotesingle{}}
\AttributeTok{save.dir =}\NormalTok{ dir.mod.BMM, }\CommentTok{\# Optional: Directory path for saving the results {-} \textquotesingle{}BMM\_previsions.CSV\textquotesingle{}}
\CommentTok{\#note = "example" \# Optional: Additional note to append to the file name}
\NormalTok{ )}
\end{Highlighting}
\end{Shaded}
After running the models, we extract the prediction information from the
iteration previsions. The \texttt{BMM.summary} function provides a
summary of the predictions, including the mean, standard deviation, and
various quantiles (2.5, 5, 25, 50, 75, 95, 97.5\%) for each mixture
(sediment sample or virtual mixture). From this summary, the
\texttt{BMM.pred} function extracts the `Median' and/or `Mean' for each
mixture. Finally, the \texttt{ensure.total} function ensures that the
total predicted contribution from all sources sums to 1 or 100\%.
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\# For sediment samples}
\DocumentationTok{\#\# Summarise BMM model previsions}
\NormalTok{BMM.summary.mix }\OtherTok{\textless{}{-}}\NormalTok{ fingR}\SpecialCharTok{::}\FunctionTok{BMM.summary}\NormalTok{(}\AttributeTok{pred =}\NormalTok{ BMM.mix, }\CommentTok{\# Predicted contributions from BMM}
\CommentTok{\#sample.id = "mix.names", \# Column name for sample identifier}
\CommentTok{\#source = "source", \# Column name for source identifier}
\CommentTok{\#value = "value", \# Column name for prediction value identifier}
\AttributeTok{save.dir =}\NormalTok{ dir.mod.BMM, }\CommentTok{\# Optional: Directory path for saving the results}
\CommentTok{\#note = "example" \# Optional: Additional note to append to the file name}
\NormalTok{ )}
\DocumentationTok{\#\# Extracts the median value of the previsions}
\NormalTok{BMM.preds.mix }\OtherTok{\textless{}{-}}\NormalTok{ fingR}\SpecialCharTok{::}\FunctionTok{BMM.pred}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BMM.summary.mix, }\CommentTok{\# Summary statistics of the predicted contribution by BMM, data from fingR::BMM.summary.mix}
\AttributeTok{stats =} \StringTok{"Median"}\NormalTok{, }\CommentTok{\# The summary statistics for source contribution, Could be Mean or Median}
\CommentTok{\#sample.id = "mix.names", \# Column name for sample identifier}
\CommentTok{\#source = "source", \# Column name for prediction value identifier}
\AttributeTok{save.dir =}\NormalTok{ dir.mod.BMM, }\CommentTok{\# Optional: Directory path for saving the results}
\CommentTok{\#note = "example" \# Optional: Additional note to append to the file name}
\NormalTok{ )}
\DocumentationTok{\#\# Ensure that the total predicted contribution sums to 1 or 100\%}
\NormalTok{BMM.preds.mixE }\OtherTok{\textless{}{-}}\NormalTok{ fingR}\SpecialCharTok{::}\FunctionTok{ensure.total}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BMM.preds.mix, }\CommentTok{\# Predicted source contribution for each sample, data from fingR::BMM.pre}
\AttributeTok{sample.name =} \StringTok{"mix.names"}\NormalTok{, }\CommentTok{\# Column name for sample identifier}
\AttributeTok{path =}\NormalTok{ dir.mod.BMM, }\CommentTok{\# Optional: Directory path for saving the results}
\CommentTok{\#note = "example" \# Optional: Additional note to append to the file name}
\NormalTok{ )}
\end{Highlighting}
\end{Shaded}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{BMM.preds.mixE[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{5}\NormalTok{,]}
\CommentTok{\#\textgreater{} mix.names Median\_Forest Median\_Subsoil Median\_Undecontaminated total}
\CommentTok{\#\textgreater{} 1 ManoDd\_2106\_00{-}01 0.001 0.807 0.192 1}
\CommentTok{\#\textgreater{} 2 ManoDd\_2106\_01{-}02 0.001 0.974 0.025 1}
\CommentTok{\#\textgreater{} 3 ManoDd\_2106\_02{-}03 0.031 0.755 0.214 1}
\CommentTok{\#\textgreater{} 4 ManoDd\_2106\_03{-}04 0.020 0.728 0.252 1}
\CommentTok{\#\textgreater{} 5 ManoDd\_2106\_04{-}05 0.010 0.820 0.170 1}
\end{Highlighting}
\end{Shaded}
Same code for virtual mixtures:
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\# For virtual mixtures}
\DocumentationTok{\#\# Summarise BMM model previsions}
\NormalTok{BMM.summary.VM }\OtherTok{\textless{}{-}}\NormalTok{ fingR}\SpecialCharTok{::}\FunctionTok{BMM.summary}\NormalTok{(}\AttributeTok{pred =}\NormalTok{ BMM.VM, }\CommentTok{\# Predicted contributions from BMM}
\CommentTok{\#sample.id = "mix.names", \# Column name for sample identifier}
\CommentTok{\#source = "source", \# Column name for source identifier}
\CommentTok{\#value = "value", \# Column name for prediction value identifier}
\AttributeTok{save.dir =}\NormalTok{ dir.mod.BMM, }\CommentTok{\# Optional: Directory path for saving the results}
\AttributeTok{note =} \StringTok{"VM"} \CommentTok{\# Optional: Additional note to append to the file name}
\NormalTok{ )}
\DocumentationTok{\#\# Extracts the median value of the previsions}
\NormalTok{BMM.preds.VM }\OtherTok{\textless{}{-}}\NormalTok{ fingR}\SpecialCharTok{::}\FunctionTok{BMM.pred}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BMM.summary.VM, }\CommentTok{\# Summary statistics of the predicted contribution by BMM, data from fingR::BMM.summary.mix}
\AttributeTok{stats =} \StringTok{"Median"}\NormalTok{, }\CommentTok{\# The summary statistics for source contribution, Could be Mean or Median}
\CommentTok{\#sample.id = "mix.names", \# Column name for sample identifier}
\CommentTok{\#source = "source", \# Column name for prediction value identifier}
\AttributeTok{save.dir =}\NormalTok{ dir.mod.BMM, }\CommentTok{\# Optional: Directory path for saving the results}
\AttributeTok{note =} \StringTok{"VM"} \CommentTok{\# Optional: Additional note to append to the file name}
\NormalTok{ )}
\DocumentationTok{\#\# Ensure that the total predicted contribution sums to 1 or 100\%}
\NormalTok{BMM.preds.VME }\OtherTok{\textless{}{-}}\NormalTok{ fingR}\SpecialCharTok{::}\FunctionTok{ensure.total}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BMM.preds.VM, }\CommentTok{\# Predicted source contribution for each sample, data from fingR::BMM.pre}
\AttributeTok{sample.name =} \StringTok{"mix.names"}\NormalTok{, }\CommentTok{\# Column name for sample identifier}
\AttributeTok{path =}\NormalTok{ dir.mod.BMM, }\CommentTok{\# Optional: Directory path for saving the results}
\AttributeTok{note =} \StringTok{"VM"} \CommentTok{\# Optional: Additional note to append to the file name}
\NormalTok{ )}
\end{Highlighting}
\end{Shaded}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{BMM.preds.VME[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{5}\NormalTok{,]}
\CommentTok{\#\textgreater{} mix.names Median\_Forest Median\_Subsoil Median\_Undecontaminated total}
\CommentTok{\#\textgreater{} 1 VM{-}001 0.001 0.677 0.322 1}
\CommentTok{\#\textgreater{} 2 VM{-}002 0.035 0.763 0.202 1}
\CommentTok{\#\textgreater{} 3 VM{-}003 0.030 0.969 0.001 1}
\CommentTok{\#\textgreater{} 4 VM{-}004 0.174 0.825 0.001 1}
\CommentTok{\#\textgreater{} 5 VM{-}005 0.001 0.896 0.103 1}
\end{Highlighting}
\end{Shaded}
\hypertarget{modelling-accuracy-statistics}{%
\paragraph{Modelling accuracy
statistics}\label{modelling-accuracy-statistics}}
The modelling accuracy of BMM model is evaluate with the virtual
mixtures. These virtual mixtures, serving as target samples with known
contributions (\emph{VM.contrib}), allow for the calculation of
modelling accuracy metrics based on their prediction.
The \texttt{eval.groups} function calculates several common modelling
accuracy metrics: ME, RMSE, squared Pearson's correlation coefficient
(r2), and Nash-Sutcliffe Modelling Efficiency Coefficient (NSE).
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{BMM.stats }\OtherTok{\textless{}{-}}\NormalTok{ fingR}\SpecialCharTok{::}\FunctionTok{eval.groups}\NormalTok{(}\AttributeTok{df.obs =}\NormalTok{ VM.contrib, }\CommentTok{\# Theoretical contribution}
\AttributeTok{df.pred =}\NormalTok{ BMM.preds.VME }\SpecialCharTok{\%\textgreater{}\%}\NormalTok{ dplyr}\SpecialCharTok{::}\FunctionTok{select}\NormalTok{(}\SpecialCharTok{{-}}\NormalTok{total), }\CommentTok{\# Predicted contribution (remove the $total column from ensured data.frame)}
\AttributeTok{by =} \FunctionTok{c}\NormalTok{(}\StringTok{"Sample\_name"} \OtherTok{=} \StringTok{"mix.names"}\NormalTok{), }\CommentTok{\# Column where mixtures labels are specified (for \textasciigrave{}dplyr::left\_join\textasciigrave{} function)}
\AttributeTok{path =}\NormalTok{ dir.mod.BMM, }\CommentTok{\# Optional: Directory path for saving the results}
\CommentTok{\#note = "example" \# Optional: Additional note to append to the file name}
\NormalTok{ )}
\end{Highlighting}
\end{Shaded}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{BMM.stats}
\CommentTok{\#\textgreater{} Type Source ME RMSE r2 NSE}
\CommentTok{\#\textgreater{} 1 Median Forest {-}0.17 0.24 0.57 0.10}
\CommentTok{\#\textgreater{} 2 Median Subsoil 0.41 0.48 0.38 {-}2.58}
\CommentTok{\#\textgreater{} 3 Median Undecontaminated {-}0.24 0.37 0.02 {-}1.18}
\end{Highlighting}
\end{Shaded}
The \texttt{CRPS} functions calculate the continuous ranking probability
score and returns a list contraining two \emph{data.frame} objects; one
with the \texttt{\$samples} CRPS values per source class group (saved as
\emph{CRPS.csv}), the other is \texttt{\$mean} with the mean of the CRPS
per source class groups (saved as \emph{CRPS\_mean.csv}).
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\# Calculate prediction CRPS values}
\NormalTok{BMM.CRPS }\OtherTok{\textless{}{-}}\NormalTok{ fingR}\SpecialCharTok{::}\FunctionTok{CRPS}\NormalTok{(}\AttributeTok{obs =}\NormalTok{ VM.contrib, }\CommentTok{\# Observed contributions}