Getting started with limpidR

library(limpidR)

Load and validate

db <- load_limpid(quiet = TRUE)
check_database(db)
##                                   check status                                         detail
##                         required_tables   PASS                   All core tables are present.
##                          unique_Lake_ID   PASS   0 duplicate Lake_ID position (0 means none).
##                         unique_Event_ID   PASS  0 duplicate Event_ID position (0 means none).
##               event_to_lake_foreign_key   PASS               All events link to a known lake.
##            event_alignment_MP_Abundance   PASS                missing=0; extra=0; duplicate=0
##  event_alignment_Morphology_Composition   PASS                missing=0; extra=0; duplicate=0
##        event_alignment_Size_Composition   PASS                missing=0; extra=0; duplicate=0
##     event_alignment_Polymer_Composition   PASS                missing=0; extra=0; duplicate=0
##                  table:required_columns   PASS              All required columns are present.
##         table:unique_primary_identifier   PASS                 0 duplicate identifier row(s).
##            table:non_negative_abundance   PASS                  0 invalid abundance value(s).
##                  table:required_columns   PASS              All required columns are present.
##         table:unique_primary_identifier   PASS                 0 duplicate identifier row(s).
##                 table:percentage_bounds   PASS           0 component value(s) outside 0-100%.
##                table:percentage_closure   PASS   0 complete profile(s) outside 100 +/- 0.2 %.
##                  table:required_columns   PASS              All required columns are present.
##         table:unique_primary_identifier   PASS                 0 duplicate identifier row(s).
##                 table:percentage_bounds   PASS           0 component value(s) outside 0-100%.
##                table:percentage_closure   PASS   0 complete profile(s) outside 100 +/- 0.2 %.
##                  table:required_columns   PASS              All required columns are present.
##         table:unique_primary_identifier   PASS                 0 duplicate identifier row(s).
##                 table:percentage_bounds   PASS           0 component value(s) outside 0-100%.
##                table:percentage_closure   PASS   0 complete profile(s) outside 100 +/- 0.2 %.
##                       coordinate_ranges   PASS 0 lake coordinate row(s) outside valid ranges.
##                         abundance_units   PASS               Observed unit(s): particles L^-1
##                      method_foreign_key   PASS            All event Method_ID values resolve.
## 
## Summary:
## 
## PASS 
##   26

check_database() validates identifiers, cross-table event alignment, abundance ranges, composition closure, coordinates, abundance units and method links.

Descriptive analysis

head(summarise_abundance(db))
##                Lake_Name Season_Global n  mean sd median IQR se ci_low ci_high
## 1 Demo Reference Coastal       Monsoon 1 42.30 NA  42.30   0 NA     NA      NA
## 2 Demo Reference Coastal  Post-monsoon 1 37.40 NA  37.40   0 NA     NA      NA
## 3 Demo Reference Coastal   Pre-monsoon 1 34.20 NA  34.20   0 NA     NA      NA
## 4 Demo Reference Coastal        Winter 1 28.10 NA  28.10   0 NA     NA      NA
## 5    Demo Reference East       Monsoon 1 38.25 NA  38.25   0 NA     NA      NA
## 6    Demo Reference East  Post-monsoon 1 33.00 NA  33.00   0 NA     NA      NA
head(analyse_morphology(db))
##                Lake_Name Season_Global Fibres_pct Fragments_pct Films_pct Beads_pct
## 1 Demo Reference Coastal       Monsoon         36            28        18        18
## 2 Demo Reference Coastal  Post-monsoon         38            27        20        15
## 3 Demo Reference Coastal   Pre-monsoon         34            29        22        15
## 4 Demo Reference Coastal        Winter         32            30        20        18
## 5    Demo Reference East       Monsoon         44            31        22         3
## 6    Demo Reference East  Post-monsoon         46            30        18         6
##   dominant_component  shannon n_profiles
## 1             Fibres 1.341552          1
## 2             Fibres 1.327658          1
## 3             Fibres 1.343455          1
## 4             Fibres 1.356362          1
## 5             Fibres 1.162603          1
## 6             Fibres 1.195863          1
head(analyse_size_distribution(db))
##                Lake_Name Season_Global Fine_LT250_pct Intermediate_250_1000_pct
## 1 Demo Reference Coastal       Monsoon             74                        18
## 2 Demo Reference Coastal  Post-monsoon             78                        14
## 3 Demo Reference Coastal   Pre-monsoon             70                        22
## 4 Demo Reference Coastal        Winter             66                        26
## 5    Demo Reference East       Monsoon             71                        18
## 6    Demo Reference East  Post-monsoon             75                        14
##   Coarse_GT1000_pct dominant_component   shannon n_profiles
## 1                 8         Fine_LT250 0.7335398          1
## 2                 8         Fine_LT250 0.6711140          1
## 3                 8         Fine_LT250 0.7848389          1
## 4                 8         Fine_LT250 0.8265376          1
## 5                11         Fine_LT250 0.7946321          1
## 6                11         Fine_LT250 0.7338176          1
head(analyse_polymers(db))
##                Lake_Name Season_Global   PE_pct   PP_pct PET_PES_pct PA_Nylon_pct PS_EPS_pct
## 1 Demo Reference Coastal       Monsoon 25.00000 23.07692    18.26923     8.653846   12.50000
## 2 Demo Reference Coastal  Post-monsoon 25.74257 25.74257    14.85149     8.910891   13.86139
## 3 Demo Reference Coastal   Pre-monsoon 26.53061 22.44898    18.36735     9.183673   12.24490
## 4 Demo Reference Coastal        Winter 27.08333 20.83333    17.70833     9.375000   11.45833
## 5    Demo Reference East       Monsoon 24.50980 23.52941    17.64706     7.843137   12.74510
## 6    Demo Reference East  Post-monsoon 24.27184 25.24272    18.44660     7.766990   13.59223
##    PVC_pct OtherPolymer_pct dominant_component  shannon n_profiles
## 1 6.730769         5.769231                 PE 1.813435          1
## 2 4.950495         5.940595                 PE 1.787780          1
## 3 5.102041         6.122449                 PE 1.797908          1
## 4 7.291667         6.250001                 PE 1.821498          1
## 5 7.843137         5.882353                 PE 1.819700          1
## 6 4.854369         5.825243                 PP 1.785148          1

Modelling without random-row leakage

For a multisite database, random row splitting can place observations from the same lake in both training and testing sets. cross_validate_mp() therefore defaults to grouped validation by Lake_ID.

cv <- cross_validate_mp(
  db,
  MP_Mean ~ Season_Global + Lake_Type,
  method = "lognormal_lm",
  group = "Lake_ID"
)
cv$overall
##    n groups     RMSE      MAE      bias R2_predictive
## 1 24      6 4.820031 4.046157 0.0334341     0.3890025

Compositional data

Polymer, morphology and size profiles are compositional. limpidR provides closure checks, CLR transformation and Aitchison distance. Zero handling is explicit through the pseudocount argument.

pol <- db$Polymer_Composition
cols <- c("PE_pct", "PP_pct", "PET_PES_pct", "PA_Nylon_pct",
          "PS_EPS_pct", "PVC_pct", "OtherPolymer_pct")
head(clr_transform(pol, cols))
##   Polymer_ID Event_ID Lake_ID        Lake_Name   PE_pct   PP_pct PET_PES_pct PA_Nylon_pct
## 1     DPO001  DEVT001   DL001 Demo Urban North 23.59551 22.47191    19.10112     8.988764
## 2     DPO002  DEVT002   DL001 Demo Urban North 22.34043 23.40425    19.14894     8.510638
## 3     DPO003  DEVT003   DL001 Demo Urban North 21.21212 24.24242    19.19192     8.080808
## 4     DPO004  DEVT004   DL001 Demo Urban North 22.10526 27.36842    15.78947     8.421053
## 5     DPO005  DEVT005   DL002  Demo Urban West 23.65591 21.50538    19.35484     9.677419
## 6     DPO006  DEVT006   DL002  Demo Urban West 23.15789 23.15789    20.00000     9.473684
##   PS_EPS_pct  PVC_pct OtherPolymer_pct Polymer_Richness Polymer_Shannon Polymer_Profile_N
## 1   12.35955 6.741573         6.741572                7        1.831021                20
## 2   12.76596 7.446809         6.382979                7        1.832753                20
## 3   13.13131 8.080808         6.060607                7        1.832306                20
## 4   14.73684 5.263158         6.315789                7        1.799705                20
## 5   11.82796 7.526882         6.451613                7        1.839394                20
## 6   12.63158 5.263158         6.315789                7        1.813436                20
##   Sum_pct  Composition_Level                          QA_Note clr_PE_pct clr_PP_pct
## 1     100 Lake-event summary Synthetic deterministic example.  0.6253334  0.5765432
## 2     100 Lake-event summary Synthetic deterministic example.  0.5691004  0.6156204
## 3     100 Lake-event summary Synthetic deterministic example.  0.5184357  0.6519671
## 4     100 Lake-event summary Synthetic deterministic example.  0.5973274  0.8109015
## 5     100 Lake-event summary Synthetic deterministic example.  0.6181945  0.5228843
## 6     100 Lake-event summary Synthetic deterministic example.  0.6324921  0.6324921
##   clr_PET_PES_pct clr_PA_Nylon_pct clr_PS_EPS_pct clr_PVC_pct clr_OtherPolymer_pct
## 1       0.4140243       -0.3397476   -0.021293794  -0.6274296           -0.6274298
## 2       0.4149497       -0.3959806    0.009484544  -0.5295119           -0.6836626
## 3       0.4183522       -0.4466452    0.038862597  -0.4466452           -0.7343271
## 4       0.2608552       -0.3677535    0.191862262  -0.8377571           -0.6554357
## 5       0.4175238       -0.2756235   -0.074952722  -0.5269378           -0.6810885
## 6       0.4858886       -0.2613258    0.026356305  -0.8491124           -0.6667910
aitchison_distance(pol, cols)
##             1          2          3          4          5          6          7          8
## 2  0.14679749                                                                             
## 3  0.27620745 0.12947327                                                                  
## 4  0.41280836 0.43880166 0.49509046                                                       
## 5  0.15136557 0.18068087 0.27946108 0.53374085                                            
## 6  0.25972886 0.36080637 0.46796366 0.35026202 0.36243744                                 
## 7  0.27302731 0.24511804 0.28932239 0.35211542 0.30067036 0.41578410                      
## 8  0.39262977 0.44119536 0.51325485 0.11278717 0.50371990 0.27931220 0.35678535           
## 9  0.28385238 0.28443757 0.34502101 0.65089530 0.13254043 0.47253803 0.37919570 0.61534234
## 10 0.27333765 0.29804144 0.37237325 0.45547002 0.24447235 0.41623175 0.16435372 0.42506585
## 11 0.26640450 0.32160197 0.40907398 0.28936196 0.32323760 0.27298560 0.20121320 0.23171394
## 12 0.40080229 0.46677006 0.54901670 0.21486779 0.49690659 0.24212513 0.39067714 0.10210728
## 13 0.26657374 0.35853559 0.46298742 0.35557784 0.38797486 0.30774468 0.37661765 0.35392938
## 14 0.29783834 0.36506080 0.45453152 0.28650466 0.43276462 0.29003396 0.38741741 0.29786810
## 15 0.35505479 0.39847955 0.46976034 0.25120878 0.49208236 0.30886548 0.42362061 0.27714162
## 16 0.42274386 0.44778463 0.50183468 0.25328578 0.55761686 0.35186924 0.47458086 0.29033355
## 17 0.17951795 0.27110377 0.38251538 0.44026320 0.24093974 0.32542740 0.30496922 0.42025999
## 18 0.18313650 0.17805642 0.25792154 0.44361291 0.21800110 0.38456426 0.24436244 0.44465428
## 19 0.26420078 0.17315800 0.17679199 0.48148629 0.27290617 0.46666494 0.25712390 0.49876519
## 20 0.38782393 0.43785256 0.51023624 0.24935407 0.51547151 0.25730914 0.45893245 0.23456317
## 21 0.22265482 0.27964783 0.37546279 0.55080865 0.17160668 0.40478149 0.32288447 0.52083113
## 22 0.30180533 0.41556777 0.52801586 0.37296787 0.39717989 0.17031325 0.43005229 0.30538572
## 23 0.16998189 0.18106131 0.26781835 0.40013389 0.21326815 0.30142772 0.24603741 0.37913189
## 24 0.44232585 0.50502944 0.58412210 0.20928772 0.54595297 0.35551870 0.39113448 0.17484545
##             9         10         11         12         13         14         15         16
## 2                                                                                         
## 3                                                                                         
## 4                                                                                         
## 5                                                                                         
## 6                                                                                         
## 7                                                                                         
## 8                                                                                         
## 9                                                                                         
## 10 0.29212617                                                                             
## 11 0.41437690 0.20260482                                                                  
## 12 0.59950497 0.42287535 0.22060112                                                       
## 13 0.50698608 0.39973943 0.33044170 0.38040148                                            
## 14 0.55732828 0.44423224 0.33668783 0.33938452 0.11006593                                 
## 15 0.61714504 0.50352607 0.37257437 0.33106250 0.21129231 0.10123144                      
## 16 0.68106502 0.56926530 0.42525398 0.35051819 0.30501981 0.19496750 0.09373963           
## 17 0.34312011 0.27769570 0.28933446 0.42636933 0.17764461 0.25504987 0.34227995 0.42848655
## 18 0.31266877 0.26903697 0.31136943 0.46841699 0.26338148 0.29955830 0.36028574 0.43027972
## 19 0.34257939 0.32399680 0.37854181 0.53389388 0.37041008 0.38066777 0.41637023 0.46687298
## 20 0.63484700 0.52589222 0.36251324 0.26267921 0.28802504 0.19252441 0.12705840 0.12233810
## 21 0.22122208 0.24129935 0.33578359 0.51296558 0.32956230 0.40062573 0.47899904 0.55803282
## 22 0.50156782 0.41220037 0.28400743 0.26901107 0.22418651 0.23371019 0.28249632 0.34816737
## 23 0.31200919 0.26590865 0.25019252 0.38706222 0.27442227 0.28548565 0.32931241 0.38929871
## 24 0.65191033 0.43705225 0.27317349 0.20033502 0.31142275 0.27568920 0.28032233 0.31564828
##            17         18         19         20         21         22         23
## 2                                                                              
## 3                                                                              
## 4                                                                              
## 5                                                                              
## 6                                                                              
## 7                                                                              
## 8                                                                              
## 9                                                                              
## 10                                                                             
## 11                                                                             
## 12                                                                             
## 13                                                                             
## 14                                                                             
## 15                                                                             
## 16                                                                             
## 17                                                                             
## 18 0.14685449                                                                  
## 19 0.27637704 0.12958617                                                       
## 20 0.39374962 0.41945058 0.47532642                                            
## 21 0.15199749 0.17881427 0.27693816 0.51564415                                 
## 22 0.26152108 0.36021468 0.46623018 0.25139211 0.36303133                      
## 23 0.17571204 0.12121336 0.18789916 0.35224234 0.20787436 0.29274358           
## 24 0.39416429 0.44262936 0.51461275 0.26531206 0.50559161 0.28662716 0.39490071

Risk components

calculate_risk() intentionally does not ship a universal polymer-hazard weighting scheme. Supply the abundance reference and any polymer hazard values used in your study, and report them in the methods section.