The phytoclass package

library(phytoclass)

Introduction

The phytoclass package uses non-negative matrix factorization and simulated annealing to determine the biomass of different phytoplankton groups from pigment concentrations. The methodology is discussed in (Hayward, Pinkerton, and Gutierrez‐Rodriguez 2023) and is similar to the CHEMTAX method of Mackey et al. (1996).

For ease of use, most functions have default options. However the user also has the option to set their own parameters within the program, and instructions on how to do this are listed for each function.

It is important to highlight that naming conventions for phytoplankton groups and their pigments should be adhered to when using the default samples. For example, the user should ensure that pigment names in their sample matrix (S) match the same pigment names in the pigment – Chl a ratio matrix (F).

At present the use of DV Chl a with Prochlorococcus is not supported, however it will be in a future release.

The main function of the package is simulated_annealing() with an associated helper function Cluster()

Other helper functions covered in this document are:

  1. Matrix_checks
  2. Bounded_weights
  3. Steepest_Desc
  4. NNLS_MF

Main function: simulated_annealing()

This is the main function for the phytoclass package.

It takes in the inputs (listed below) and returns the updated pigment to Chl a ratios, the Chl a biomass of each phytoplankton group, error associated with each group, and a graph displaying the Chl a concentration for each group.

It is important that samples are clustered appropriately before using the function (see the Cluster function).

Arguments:

S = Sample matrix – a matrix of pigment samples. Ensure that Chl a is the final column

F = Pigment to Chl a matrix. If left blank default values will be used. Ensure that pigment columns are in the same order as S and column naming conventions match.

user_defined_min_max = If blank default values are used. To create different min_max values, follow the same structure as the phytoclass::min_max file. See the example below.

do_matrix_checks = this should only be set to true when using the default values. This will remove pigment columns that have column sums of 0. Set to FALSE if using customised names for pigments and phytoplankton groups.

niter = number of iterations. Default value is 500.

step = step ratio used. Default value is 0.009.

weight.upper.bound = the upper limit of the weights applied. Default value is 30.

When using the default values, the only argument required is the sample matrix. However, make sure that the pigment names match those in the built-in pigment to Chl matrix Fm.

For the examples that follow the argument niter equals one for processing speed, but should be set much higher to obtain convergence.

Cluster function

Prior to analysis using simulated annealing, pigment samples require clustering.

The Cluster function divides all pigment concentrations by the total Chl a concentration. Following this the data undergoes BoxCox transformation, and the data is hierarchically clustered using the Ward method based on the Manhattan distances between pigment samples. The DynamicTreeCut method of (Langfelder, Zhang, and Horvath 2008) is then used to prune the dendogram into reasonable clusters of specified size(s).

The function returns a list of the clusters and the cluster dendrogram.

An example, using the built-in sample data set Sm:

Cluster.result <- Cluster(Sm, 14)
#>  ..done.
# list of clusters
Cluster.result$cluster.list
#> [[1]]
#>       Per     X19but      Fuco        Neox        Pra        Viol     X19hex
#> 1  0.0000 0.03024000 0.0622500 0.005570000 0.01407000 0.007590000 0.08224000
#> 2  0.0000 0.01084000 0.0286400 0.001110000 0.00351000 0.001440000 0.01497000
#> 3  0.0000 0.01560000 0.2172000 0.006400000 0.00920000 0.000000000 0.01740000
#> 4  0.0000 0.01770000 0.2347000 0.007000000 0.01150000 0.000000000 0.01890000
#> 5  0.0000 0.02520000 0.2952000 0.009900000 0.01300000 0.000000000 0.02110000
#> 6  0.0102 0.02220000 0.2275000 0.007600000 0.01070000 0.000000000 0.01900000
#> 7  0.0000 0.01510000 0.1417000 0.004000000 0.00800000 0.002600000 0.02550000
#> 8  0.0000 0.04520000 0.4484000 0.003700000 0.00650000 0.000000000 0.13170000
#> 9  0.0000 0.05180000 0.6228000 0.004900000 0.00750000 0.004000000 0.13210000
#> 10 0.0000 0.02200000 0.1090000 0.004000000 0.00800000 0.003000000 0.04200000
#> 11 0.0000 0.04906269 0.5266418 0.017334346 0.03446357 0.000000000 0.12044287
#> 12 0.0000 0.02052662 0.2714934 0.017692288 0.01994758 0.000000000 0.03011548
#> 13 0.0000 0.02216177 0.1654257 0.012242414 0.01956286 0.000000000 0.02721049
#> 14 0.0000 0.01438545 0.2555594 0.020671983 0.04736366 0.011507712 0.02167651
#> 15 0.0000 0.02619187 0.6025477 0.038948613 0.04929322 0.034893958 0.10082727
#> 16 0.0000 0.02662521 0.2205439 0.024444776 0.06623835 0.027029275 0.04015983
#> 17 0.0000 0.06542364 0.6603459 0.044215705 0.11285620 0.064560275 0.13896777
#> 18 0.0000 0.05315834 0.2584586 0.016123905 0.04701666 0.011387548 0.08065818
#> 19 0.0000 0.06040911 0.4494852 0.027862628 0.07757631 0.025258248 0.10999693
#> 20 0.0000 0.07577285 0.3920489 0.017239170 0.05136883 0.020899111 0.12859331
#> 21 0.0000 0.06067605 0.4112795 0.021768249 0.07620416 0.022592896 0.08973832
#> 22 0.0000 0.04388275 0.6257830 0.012373717 0.03347165 0.013495185 0.12822965
#> 23 0.0000 0.03971444 0.4332551 0.014402749 0.02657611 0.010560487 0.09220387
#> 24 0.0000 0.03092146 0.1639481 0.013383240 0.01262176 0.008793182 0.05881285
#> 25 0.0000 0.02725515 0.1966991 0.009916299 0.01832477 0.009112193 0.05488214
#> 26 0.0000 0.01678833 0.1755048 0.008821737 0.02676049 0.006637964 0.02189435
#> 27 0.0000 0.02444961 0.1273596 0.007049435 0.01323978 0.004447137 0.02218985
#> 28 0.0000 0.01567523 0.1052905 0.006144340 0.01372236 0.006294480 0.02208074
#> 29 0.0000 0.03108003 0.0874373 0.011728700 0.02004430 0.005772257 0.04855466
#>           Allo         Zea Lut ChlcMGDG18 ChlcMGDG14      Chl_b     Tchla Clust
#> 1  0.001880000 0.002010000   0          0          0 0.08661000 0.4585100     1
#> 2  0.001440000 0.001910000   0          0          0 0.01473000 0.1457100     1
#> 3  0.005800000 0.003600000   0          0          0 0.05700000 0.6127000     1
#> 4  0.005400000 0.003800000   0          0          0 0.06190000 0.6207000     1
#> 5  0.001400000 0.007600000   0          0          0 0.05780000 0.5302000     1
#> 6  0.000000000 0.003000000   0          0          0 0.04530000 0.4057000     1
#> 7  0.000800000 0.001000000   0          0          0 0.03120000 0.2117000     1
#> 8  0.004400000 0.002300000   0          0          0 0.00930000 0.6885000     1
#> 9  0.059700000 0.003500000   0          0          0 0.01210000 1.0849000     1
#> 10 0.003000000 0.003000000   0          0          0 0.03200000 0.2060000     1
#> 11 0.029990012 0.039966194   0          0          0 0.15325050 1.0396607     1
#> 12 0.000000000 0.030828916   0          0          0 0.09243326 0.4812043     1
#> 13 0.000000000 0.017661542   0          0          0 0.08720595 0.3409079     1
#> 14 0.009032764 0.018938989   0          0          0 0.14213442 0.4892902     1
#> 15 0.031610292 0.036313122   0          0          0 0.16461333 1.3811642     1
#> 16 0.007170750 0.013507988   0          0          0 0.18532190 0.5711149     1
#> 17 0.016001053 0.028670688   0          0          0 0.41729467 1.7413395     1
#> 18 0.010093841 0.016835362   0          0          0 0.13198111 0.5776707     1
#> 19 0.019249598 0.020581908   0          0          0 0.26015615 1.0739310     1
#> 20 0.024550418 0.020066576   0          0          0 0.22391720 0.9909010     1
#> 21 0.016719215 0.019212773   0          0          0 0.23686078 0.9520484     1
#> 22 0.018189726 0.017601736   0          0          0 0.15579381 1.2494685     1
#> 23 0.014131906 0.012984478   0          0          0 0.12090732 0.9190665     1
#> 24 0.011139374 0.012782671   0          0          0 0.05213182 0.3486558     1
#> 25 0.013767971 0.012392348   0          0          0 0.08734698 0.4556423     1
#> 26 0.008302439 0.010946550   0          0          0 0.07005955 0.3497736     1
#> 27 0.005887899 0.010324368   0          0          0 0.03627212 0.2367185     1
#> 28 0.004908419 0.009914413   0          0          0 0.03735579 0.2117071     1
#> 29 0.009256850 0.009871839   0          0          0 0.09414383 0.3014690     1
# plot of clusters
plot(Cluster.result$cluster.plot)

Example without clustering

The example here uses the built-in sample matrix Sm.

set.seed("7683")
Results <- simulated_annealing(Sm, niter = 1)
Results$`condition number`
#> [1] 728.0411
Results$RMSE
#> [1] 0.02819993
Results$MAE
#>          Per       X19but         Fuco         Neox          Pra         Viol 
#> 8.532288e-05 1.029630e-05 4.746166e-03 4.346108e-03 3.364625e-03 2.253839e-03 
#>       X19hex         Allo          Zea        Chl_b        Tchla 
#> 2.883243e-04 1.750370e-04 7.460491e-05 7.255182e-03 6.520774e-02
Results$Error
#>                 Per        X19but          Fuco          Neox           Pra
#>  [1,] -4.522442e-04  2.998121e-05 -0.0138200899 -7.840801e-04 -0.0061179974
#>  [2,] -6.216036e-04  4.120877e-05 -0.0189955299 -3.067019e-04 -0.0007864679
#>  [3,] -5.332655e-04  3.535246e-05 -0.0162960147  2.472446e-03 -0.0044775819
#>  [4,] -4.648612e-04  3.081764e-05 -0.0142056529  2.503969e-03 -0.0035775433
#>  [5,] -1.111827e-04  7.370779e-06 -0.0033976227  5.620855e-03 -0.0019343731
#>  [6,] -3.887731e-05  2.577344e-06 -0.0011880485  5.380674e-03 -0.0014102286
#>  [7,]  0.000000e+00 -1.481838e-05  0.0068306578  3.359748e-03 -0.0003564754
#>  [8,]  0.000000e+00 -1.239137e-05  0.0057119070  1.898147e-03  0.0019983654
#>  [9,]  0.000000e+00 -6.424739e-06  0.0029615376  1.695727e-03  0.0014498199
#> [10,]  0.000000e+00 -1.403169e-05  0.0064680253  3.314125e-03 -0.0004392935
#> [11,]  0.000000e+00 -5.989623e-06  0.0027609674  2.862882e-03 -0.0018901051
#> [12,]  0.000000e+00 -5.165725e-06  0.0023811845  1.096601e-02 -0.0037115649
#> [13,]  0.000000e+00 -3.440096e-06  0.0015857411  8.055950e-03 -0.0035585943
#> [14,]  0.000000e+00 -1.123305e-05  0.0051779691  7.804847e-03  0.0054590882
#> [15,] -1.010735e-04  6.700599e-06 -0.0030886974  9.669789e-03  0.0025703235
#> [16,]  0.000000e+00 -4.939879e-06  0.0022770788  6.187837e-03  0.0102135493
#> [17,] -7.204535e-05  4.776196e-06 -0.0022016276  2.825672e-03  0.0026713678
#> [18,]  0.000000e+00 -8.860647e-06  0.0040843897  3.472132e-03  0.0062625846
#> [19,]  0.000000e+00 -2.472896e-06  0.0011399021  2.714729e-03  0.0027338804
#> [20,]  0.000000e+00 -1.852945e-06  0.0008541308 -4.167585e-05 -0.0016094239
#> [21,]  0.000000e+00 -3.466027e-06  0.0015976945  6.460336e-04  0.0045334465
#> [22,] -2.188674e-05  1.450966e-06 -0.0006688349  2.342643e-04 -0.0016432033
#> [23,] -5.732325e-05  3.800204e-06 -0.0017517363  2.974590e-03 -0.0018193671
#> [24,]  0.000000e+00 -1.079130e-05  0.0049743407  1.254368e-02 -0.0003315649
#> [25,]  0.000000e+00 -3.197543e-06  0.0014739346  3.631535e-03 -0.0025215078
#> [26,]  0.000000e+00 -5.441175e-06  0.0025081554  3.279447e-03  0.0073943172
#> [27,]  0.000000e+00 -8.340946e-06  0.0038448294  7.443059e-03  0.0043155685
#> [28,]  0.000000e+00 -8.806090e-06  0.0040592414  6.023247e-03  0.0063530778
#> [29,]  0.000000e+00 -2.892364e-06  0.0013332597  7.323287e-03 -0.0054334560
#>                Viol        X19hex          Allo           Zea         Chl_b
#>  [1,] -2.991785e-03 -8.395552e-04 -5.248057e-04 -6.019496e-04  0.0118460542
#>  [2,] -6.174530e-04 -1.153957e-03 -7.213385e-04 -2.414874e-04 -0.0002826714
#>  [3,] -3.719736e-03 -9.899649e-04 -6.188268e-04 -2.071689e-04  0.0068938258
#>  [4,] -4.002116e-03 -8.629777e-04 -5.394471e-04 -1.805944e-04  0.0055741998
#>  [5,] -4.044827e-03 -2.064018e-04 -1.290217e-04 -4.319348e-05  0.0020210463
#>  [6,] -4.096586e-03 -7.217263e-05 -4.511509e-05 -1.510349e-05  0.0014604394
#>  [7,] -1.885126e-06  4.149549e-04  2.593882e-04 -7.434065e-05 -0.0003949694
#>  [8,] -7.464511e-04  3.469920e-04  2.169046e-04  7.261464e-05 -0.0037816724
#>  [9,]  7.348941e-04  1.799101e-04  1.124618e-04  3.764960e-05 -0.0036888128
#> [10,] -4.075866e-05  3.929254e-04  2.456176e-04  8.222706e-05 -0.0002753353
#> [11,] -4.979837e-03  1.677257e-04  1.048453e-04  3.509978e-05  0.0046831916
#> [12,] -6.385044e-03  1.446543e-04  0.000000e+00  3.027165e-05  0.0041467486
#> [13,] -8.325314e-03  9.633202e-05  0.000000e+00  2.015930e-05  0.0063670271
#> [14,]  5.678401e-04  3.145559e-04  1.966288e-04  6.582677e-05 -0.0143182751
#> [15,]  1.336983e-03 -1.876350e-04 -1.172906e-04 -3.926616e-05 -0.0113128399
#> [16,]  4.803235e-03  1.383300e-04  8.647006e-05  2.894817e-05 -0.0247241794
#> [17,]  1.245298e-03 -1.337464e-04 -8.360487e-05 -2.798897e-05 -0.0074741412
#> [18,]  8.773357e-04  2.481222e-04  1.551011e-04  5.192425e-05 -0.0136479985
#> [19,]  1.315879e-03  6.924779e-05  4.328678e-05  1.449141e-05 -0.0071702762
#> [20,] -7.203085e-04  5.188750e-05  3.243486e-05  1.085844e-05  0.0034916023
#> [21,]  2.093974e-03  9.705818e-05  6.067104e-05  2.031126e-05 -0.0096961674
#> [22,] -7.499585e-04 -4.063098e-05 -2.539842e-05 -8.502801e-06  0.0032340526
#> [23,] -7.845869e-04 -1.064160e-04 -6.652064e-05 -2.226957e-05  0.0019007062
#> [24,]  1.897016e-04  3.021857e-04  1.888962e-04  6.323807e-05 -0.0059962848
#> [25,] -1.046001e-03  8.953990e-05  5.597137e-05  1.873792e-05  0.0033507415
#> [26,]  1.410100e-03  1.523677e-04  9.524499e-05  3.188581e-05 -0.0161049681
#> [27,]  2.173429e-03  2.335691e-04  1.460040e-04  4.887876e-05 -0.0129150333
#> [28,]  3.070484e-03  2.465944e-04  1.541461e-04  5.160454e-05 -0.0163412589
#> [29,] -2.289536e-03  8.099405e-05  5.062936e-05  1.694954e-05  0.0073057578
#>              Tchla
#>  [1,]  0.189874712
#>  [2,]  0.260980269
#>  [3,]  0.223891532
#>  [4,]  0.195171976
#>  [5,]  0.046680061
#>  [6,]  0.016322641
#>  [7,] -0.093846653
#>  [8,] -0.078476095
#>  [9,] -0.040688672
#> [10,] -0.088864432
#> [11,] -0.037933031
#> [12,] -0.032715180
#> [13,] -0.021786554
#> [14,] -0.071140303
#> [15,]  0.042435725
#> [16,] -0.031284868
#> [17,]  0.030248241
#> [18,] -0.056115578
#> [19,] -0.015661155
#> [20,] -0.011734934
#> [21,] -0.021950782
#> [22,]  0.009189147
#> [23,]  0.024067168
#> [24,] -0.068342646
#> [25,] -0.020250440
#> [26,] -0.034459637
#> [27,] -0.052824249
#> [28,] -0.055770064
#> [29,] -0.018317703

Results$`F matrix`
#>                      Per X19but   Fuco   Neox    Pra   Viol X19hex  Allo    Zea
#> Prasinophytes     0.0000 0.0000 0.0000 0.0718 0.2373 0.0621 0.0000 0.000 0.0297
#> Chlorophytes      0.0000 0.0000 0.0000 0.0418 0.0000 0.4047 0.0000 0.000 0.0103
#> Cryptophytes      0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.402 0.0000
#> Diatoms-2         0.0000 0.0000 0.7769 0.0000 0.0000 0.0000 0.0000 0.000 0.0000
#> Dinoflagellates-1 0.4665 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.000 0.0000
#> Haptophytes       0.0000 0.1387 0.0973 0.0000 0.0000 0.0000 0.5726 0.000 0.0000
#> Pelagophytes      0.0000 1.1648 0.9055 0.0000 0.0000 0.0000 0.0000 0.000 0.0000
#> Syn               0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.000 1.2008
#>                    Chl_b Tchla
#> Prasinophytes     0.8920     1
#> Chlorophytes      0.6174     1
#> Cryptophytes      0.0000     1
#> Diatoms-2         0.0000     1
#> Dinoflagellates-1 0.0000     1
#> Haptophytes       0.0000     1
#> Pelagophytes      0.0000     1
#> Syn               0.0000     1
Results$`Class abundances`
#>    Prasinophytes Chlorophytes Cryptophytes  Diatoms-2 Dinoflagellates-1
#> 1     0.11415345  0.017760362 8.210281e-03 0.09464098      0.0010566129
#> 2     0.02596671  0.002535096 6.660287e-03 0.05327371      0.0004995775
#> 3     0.08644760  0.000000000 2.425845e-02 0.43415727      0.0016497735
#> 4     0.09150323  0.000000000 2.133523e-02 0.43803319      0.0014148487
#> 5     0.06841045  0.000000000 4.141719e-03 0.39271201      0.0002503224
#> 6     0.05109922  0.000000000 8.693199e-05 0.28070172      0.0226109310
#> 7     0.02874819  0.000963134 1.425962e-03 0.13714426      0.0000000000
#> 8     0.01397285  0.000000000 8.867831e-03 0.45558900      0.0000000000
#> 9     0.01813906  0.003064060 1.377094e-01 0.69375518      0.0000000000
#> 10    0.02909102  0.001821201 6.067940e-03 0.09750384      0.0000000000
#> 11    0.15022669  0.000000000 6.901425e-02 0.58178234      0.0000000000
#> 12    0.09304273  0.000000000 0.000000e+00 0.30656949      0.0000000000
#> 13    0.08888919  0.000000000 0.000000e+00 0.18193124      0.0000000000
#> 14    0.15296582  0.000000000 1.910311e-02 0.26801862      0.0000000000
#> 15    0.19585190  0.054422260 8.585848e-02 0.82403425      0.0005781949
#> 16    0.21437060  0.016654663 1.651401e-02 0.23921925      0.0000000000
#> 17    0.46513088  0.087085634 4.294163e-02 0.84545970      0.0005388426
#> 18    0.14896006  0.000000000 2.206536e-02 0.24626376      0.0000000000
#> 19    0.29334798  0.008823141 4.622372e-02 0.50203773      0.0000000000
#> 20    0.22449402  0.019414622 5.954199e-02 0.42003254      0.0000000000
#> 21    0.27270519  0.002177163 3.956266e-02 0.44719765      0.0000000000
#> 22    0.15966551  0.013751518 4.617374e-02 0.77977476      0.0001096826
#> 23    0.13066475  0.010663096 3.706702e-02 0.54808753      0.0002164486
#> 24    0.04753960  0.011474616 2.401721e-02 0.15520283      0.0000000000
#> 25    0.08334978  0.011075382 3.283349e-02 0.21698830      0.0000000000
#> 26    0.08525731  0.000000000 1.917424e-02 0.19407363      0.0000000000
#> 27    0.04231253  0.001053833 1.304852e-02 0.12406303      0.0000000000
#> 28    0.04149765  0.004643577 1.081055e-02 0.10600086      0.0000000000
#> 29    0.09507180  0.002534130 2.211667e-02 0.07857270      0.0000000000
#>    Haptophytes Pelagophytes         Syn
#> 1   0.21004894  0.012639373 0.000000000
#> 2   0.04445565  0.010248827 0.002070137
#> 3   0.04890870  0.014588293 0.002689922
#> 4   0.04988337  0.016002411 0.002527718
#> 5   0.04063556  0.018789815 0.005260123
#> 6   0.03431373  0.015565380 0.001322075
#> 7   0.03697534  0.006443106 0.000000000
#> 8   0.19882409  0.010000516 0.001245711
#> 9   0.21414986  0.015902305 0.002180125
#> 10  0.06157777  0.008592416 0.001345809
#> 11  0.19541771  0.015982106 0.027237631
#> 12  0.04912996  0.010692079 0.021770069
#> 13  0.04539578  0.012816440 0.011875242
#> 14  0.03243077  0.006887679 0.009884176
#> 15  0.19139905  0.001523416 0.027496641
#> 16  0.06560214  0.013661036 0.005093240
#> 17  0.25822016  0.028809222 0.013153418
#> 18  0.12565300  0.025906675 0.008821836
#> 19  0.18607885  0.028150523 0.009269014
#> 20  0.21934822  0.037471166 0.010598432
#> 21  0.14981024  0.032063958 0.008531546
#> 22  0.22795899  0.011174393 0.010859876
#> 23  0.16878169  0.015564580 0.008021373
#> 24  0.08978395  0.012605268 0.008032291
#> 25  0.09208545  0.011550302 0.007759552
#> 26  0.03561157  0.009251359 0.006405479
#> 27  0.03476806  0.014792389 0.006680167
#> 28  0.03444581  0.007980578 0.006328068
#> 29  0.08163696  0.015995444 0.005541267
Results$Figure

Example with clustering

Clust1 <- Cluster(Sm, min_cluster_size = 14)$cluster.list[[1]]
#>  ..done.
# Remove the cluster column/label
Clust1$Clust <- NULL

set.seed("7683")
Results <- simulated_annealing(Clust1, niter = 1)
Results$`condition number`
#> [1] 728.0411
Results$RMSE
#> [1] 0.02819993
Results$MAE
#>          Per       X19but         Fuco         Neox          Pra         Viol 
#> 8.532288e-05 1.029630e-05 4.746166e-03 4.346108e-03 3.364625e-03 2.253839e-03 
#>       X19hex         Allo          Zea        Chl_b        Tchla 
#> 2.883243e-04 1.750370e-04 7.460491e-05 7.255182e-03 6.520774e-02
Results$Error
#>                 Per        X19but          Fuco          Neox           Pra
#>  [1,] -4.522442e-04  2.998121e-05 -0.0138200899 -7.840801e-04 -0.0061179974
#>  [2,] -6.216036e-04  4.120877e-05 -0.0189955299 -3.067019e-04 -0.0007864679
#>  [3,] -5.332655e-04  3.535246e-05 -0.0162960147  2.472446e-03 -0.0044775819
#>  [4,] -4.648612e-04  3.081764e-05 -0.0142056529  2.503969e-03 -0.0035775433
#>  [5,] -1.111827e-04  7.370779e-06 -0.0033976227  5.620855e-03 -0.0019343731
#>  [6,] -3.887731e-05  2.577344e-06 -0.0011880485  5.380674e-03 -0.0014102286
#>  [7,]  0.000000e+00 -1.481838e-05  0.0068306578  3.359748e-03 -0.0003564754
#>  [8,]  0.000000e+00 -1.239137e-05  0.0057119070  1.898147e-03  0.0019983654
#>  [9,]  0.000000e+00 -6.424739e-06  0.0029615376  1.695727e-03  0.0014498199
#> [10,]  0.000000e+00 -1.403169e-05  0.0064680253  3.314125e-03 -0.0004392935
#> [11,]  0.000000e+00 -5.989623e-06  0.0027609674  2.862882e-03 -0.0018901051
#> [12,]  0.000000e+00 -5.165725e-06  0.0023811845  1.096601e-02 -0.0037115649
#> [13,]  0.000000e+00 -3.440096e-06  0.0015857411  8.055950e-03 -0.0035585943
#> [14,]  0.000000e+00 -1.123305e-05  0.0051779691  7.804847e-03  0.0054590882
#> [15,] -1.010735e-04  6.700599e-06 -0.0030886974  9.669789e-03  0.0025703235
#> [16,]  0.000000e+00 -4.939879e-06  0.0022770788  6.187837e-03  0.0102135493
#> [17,] -7.204535e-05  4.776196e-06 -0.0022016276  2.825672e-03  0.0026713678
#> [18,]  0.000000e+00 -8.860647e-06  0.0040843897  3.472132e-03  0.0062625846
#> [19,]  0.000000e+00 -2.472896e-06  0.0011399021  2.714729e-03  0.0027338804
#> [20,]  0.000000e+00 -1.852945e-06  0.0008541308 -4.167585e-05 -0.0016094239
#> [21,]  0.000000e+00 -3.466027e-06  0.0015976945  6.460336e-04  0.0045334465
#> [22,] -2.188674e-05  1.450966e-06 -0.0006688349  2.342643e-04 -0.0016432033
#> [23,] -5.732325e-05  3.800204e-06 -0.0017517363  2.974590e-03 -0.0018193671
#> [24,]  0.000000e+00 -1.079130e-05  0.0049743407  1.254368e-02 -0.0003315649
#> [25,]  0.000000e+00 -3.197543e-06  0.0014739346  3.631535e-03 -0.0025215078
#> [26,]  0.000000e+00 -5.441175e-06  0.0025081554  3.279447e-03  0.0073943172
#> [27,]  0.000000e+00 -8.340946e-06  0.0038448294  7.443059e-03  0.0043155685
#> [28,]  0.000000e+00 -8.806090e-06  0.0040592414  6.023247e-03  0.0063530778
#> [29,]  0.000000e+00 -2.892364e-06  0.0013332597  7.323287e-03 -0.0054334560
#>                Viol        X19hex          Allo           Zea         Chl_b
#>  [1,] -2.991785e-03 -8.395552e-04 -5.248057e-04 -6.019496e-04  0.0118460542
#>  [2,] -6.174530e-04 -1.153957e-03 -7.213385e-04 -2.414874e-04 -0.0002826714
#>  [3,] -3.719736e-03 -9.899649e-04 -6.188268e-04 -2.071689e-04  0.0068938258
#>  [4,] -4.002116e-03 -8.629777e-04 -5.394471e-04 -1.805944e-04  0.0055741998
#>  [5,] -4.044827e-03 -2.064018e-04 -1.290217e-04 -4.319348e-05  0.0020210463
#>  [6,] -4.096586e-03 -7.217263e-05 -4.511509e-05 -1.510349e-05  0.0014604394
#>  [7,] -1.885126e-06  4.149549e-04  2.593882e-04 -7.434065e-05 -0.0003949694
#>  [8,] -7.464511e-04  3.469920e-04  2.169046e-04  7.261464e-05 -0.0037816724
#>  [9,]  7.348941e-04  1.799101e-04  1.124618e-04  3.764960e-05 -0.0036888128
#> [10,] -4.075866e-05  3.929254e-04  2.456176e-04  8.222706e-05 -0.0002753353
#> [11,] -4.979837e-03  1.677257e-04  1.048453e-04  3.509978e-05  0.0046831916
#> [12,] -6.385044e-03  1.446543e-04  0.000000e+00  3.027165e-05  0.0041467486
#> [13,] -8.325314e-03  9.633202e-05  0.000000e+00  2.015930e-05  0.0063670271
#> [14,]  5.678401e-04  3.145559e-04  1.966288e-04  6.582677e-05 -0.0143182751
#> [15,]  1.336983e-03 -1.876350e-04 -1.172906e-04 -3.926616e-05 -0.0113128399
#> [16,]  4.803235e-03  1.383300e-04  8.647006e-05  2.894817e-05 -0.0247241794
#> [17,]  1.245298e-03 -1.337464e-04 -8.360487e-05 -2.798897e-05 -0.0074741412
#> [18,]  8.773357e-04  2.481222e-04  1.551011e-04  5.192425e-05 -0.0136479985
#> [19,]  1.315879e-03  6.924779e-05  4.328678e-05  1.449141e-05 -0.0071702762
#> [20,] -7.203085e-04  5.188750e-05  3.243486e-05  1.085844e-05  0.0034916023
#> [21,]  2.093974e-03  9.705818e-05  6.067104e-05  2.031126e-05 -0.0096961674
#> [22,] -7.499585e-04 -4.063098e-05 -2.539842e-05 -8.502801e-06  0.0032340526
#> [23,] -7.845869e-04 -1.064160e-04 -6.652064e-05 -2.226957e-05  0.0019007062
#> [24,]  1.897016e-04  3.021857e-04  1.888962e-04  6.323807e-05 -0.0059962848
#> [25,] -1.046001e-03  8.953990e-05  5.597137e-05  1.873792e-05  0.0033507415
#> [26,]  1.410100e-03  1.523677e-04  9.524499e-05  3.188581e-05 -0.0161049681
#> [27,]  2.173429e-03  2.335691e-04  1.460040e-04  4.887876e-05 -0.0129150333
#> [28,]  3.070484e-03  2.465944e-04  1.541461e-04  5.160454e-05 -0.0163412589
#> [29,] -2.289536e-03  8.099405e-05  5.062936e-05  1.694954e-05  0.0073057578
#>              Tchla
#>  [1,]  0.189874712
#>  [2,]  0.260980269
#>  [3,]  0.223891532
#>  [4,]  0.195171976
#>  [5,]  0.046680061
#>  [6,]  0.016322641
#>  [7,] -0.093846653
#>  [8,] -0.078476095
#>  [9,] -0.040688672
#> [10,] -0.088864432
#> [11,] -0.037933031
#> [12,] -0.032715180
#> [13,] -0.021786554
#> [14,] -0.071140303
#> [15,]  0.042435725
#> [16,] -0.031284868
#> [17,]  0.030248241
#> [18,] -0.056115578
#> [19,] -0.015661155
#> [20,] -0.011734934
#> [21,] -0.021950782
#> [22,]  0.009189147
#> [23,]  0.024067168
#> [24,] -0.068342646
#> [25,] -0.020250440
#> [26,] -0.034459637
#> [27,] -0.052824249
#> [28,] -0.055770064
#> [29,] -0.018317703

Results$`F matrix`
#>                      Per X19but   Fuco   Neox    Pra   Viol X19hex  Allo    Zea
#> Prasinophytes     0.0000 0.0000 0.0000 0.0718 0.2373 0.0621 0.0000 0.000 0.0297
#> Chlorophytes      0.0000 0.0000 0.0000 0.0418 0.0000 0.4047 0.0000 0.000 0.0103
#> Cryptophytes      0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.402 0.0000
#> Diatoms-2         0.0000 0.0000 0.7769 0.0000 0.0000 0.0000 0.0000 0.000 0.0000
#> Dinoflagellates-1 0.4665 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.000 0.0000
#> Haptophytes       0.0000 0.1387 0.0973 0.0000 0.0000 0.0000 0.5726 0.000 0.0000
#> Pelagophytes      0.0000 1.1648 0.9055 0.0000 0.0000 0.0000 0.0000 0.000 0.0000
#> Syn               0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.000 1.2008
#>                    Chl_b Tchla
#> Prasinophytes     0.8920     1
#> Chlorophytes      0.6174     1
#> Cryptophytes      0.0000     1
#> Diatoms-2         0.0000     1
#> Dinoflagellates-1 0.0000     1
#> Haptophytes       0.0000     1
#> Pelagophytes      0.0000     1
#> Syn               0.0000     1
Results$`Class abundances`
#>    Prasinophytes Chlorophytes Cryptophytes  Diatoms-2 Dinoflagellates-1
#> 1     0.11415345  0.017760362 8.210281e-03 0.09464098      0.0010566129
#> 2     0.02596671  0.002535096 6.660287e-03 0.05327371      0.0004995775
#> 3     0.08644760  0.000000000 2.425845e-02 0.43415727      0.0016497735
#> 4     0.09150323  0.000000000 2.133523e-02 0.43803319      0.0014148487
#> 5     0.06841045  0.000000000 4.141719e-03 0.39271201      0.0002503224
#> 6     0.05109922  0.000000000 8.693199e-05 0.28070172      0.0226109310
#> 7     0.02874819  0.000963134 1.425962e-03 0.13714426      0.0000000000
#> 8     0.01397285  0.000000000 8.867831e-03 0.45558900      0.0000000000
#> 9     0.01813906  0.003064060 1.377094e-01 0.69375518      0.0000000000
#> 10    0.02909102  0.001821201 6.067940e-03 0.09750384      0.0000000000
#> 11    0.15022669  0.000000000 6.901425e-02 0.58178234      0.0000000000
#> 12    0.09304273  0.000000000 0.000000e+00 0.30656949      0.0000000000
#> 13    0.08888919  0.000000000 0.000000e+00 0.18193124      0.0000000000
#> 14    0.15296582  0.000000000 1.910311e-02 0.26801862      0.0000000000
#> 15    0.19585190  0.054422260 8.585848e-02 0.82403425      0.0005781949
#> 16    0.21437060  0.016654663 1.651401e-02 0.23921925      0.0000000000
#> 17    0.46513088  0.087085634 4.294163e-02 0.84545970      0.0005388426
#> 18    0.14896006  0.000000000 2.206536e-02 0.24626376      0.0000000000
#> 19    0.29334798  0.008823141 4.622372e-02 0.50203773      0.0000000000
#> 20    0.22449402  0.019414622 5.954199e-02 0.42003254      0.0000000000
#> 21    0.27270519  0.002177163 3.956266e-02 0.44719765      0.0000000000
#> 22    0.15966551  0.013751518 4.617374e-02 0.77977476      0.0001096826
#> 23    0.13066475  0.010663096 3.706702e-02 0.54808753      0.0002164486
#> 24    0.04753960  0.011474616 2.401721e-02 0.15520283      0.0000000000
#> 25    0.08334978  0.011075382 3.283349e-02 0.21698830      0.0000000000
#> 26    0.08525731  0.000000000 1.917424e-02 0.19407363      0.0000000000
#> 27    0.04231253  0.001053833 1.304852e-02 0.12406303      0.0000000000
#> 28    0.04149765  0.004643577 1.081055e-02 0.10600086      0.0000000000
#> 29    0.09507180  0.002534130 2.211667e-02 0.07857270      0.0000000000
#>    Haptophytes Pelagophytes         Syn
#> 1   0.21004894  0.012639373 0.000000000
#> 2   0.04445565  0.010248827 0.002070137
#> 3   0.04890870  0.014588293 0.002689922
#> 4   0.04988337  0.016002411 0.002527718
#> 5   0.04063556  0.018789815 0.005260123
#> 6   0.03431373  0.015565380 0.001322075
#> 7   0.03697534  0.006443106 0.000000000
#> 8   0.19882409  0.010000516 0.001245711
#> 9   0.21414986  0.015902305 0.002180125
#> 10  0.06157777  0.008592416 0.001345809
#> 11  0.19541771  0.015982106 0.027237631
#> 12  0.04912996  0.010692079 0.021770069
#> 13  0.04539578  0.012816440 0.011875242
#> 14  0.03243077  0.006887679 0.009884176
#> 15  0.19139905  0.001523416 0.027496641
#> 16  0.06560214  0.013661036 0.005093240
#> 17  0.25822016  0.028809222 0.013153418
#> 18  0.12565300  0.025906675 0.008821836
#> 19  0.18607885  0.028150523 0.009269014
#> 20  0.21934822  0.037471166 0.010598432
#> 21  0.14981024  0.032063958 0.008531546
#> 22  0.22795899  0.011174393 0.010859876
#> 23  0.16878169  0.015564580 0.008021373
#> 24  0.08978395  0.012605268 0.008032291
#> 25  0.09208545  0.011550302 0.007759552
#> 26  0.03561157  0.009251359 0.006405479
#> 27  0.03476806  0.014792389 0.006680167
#> 28  0.03444581  0.007980578 0.006328068
#> 29  0.08163696  0.015995444 0.005541267
Results$Figure

Example using non-default values

#Create Fm (F matrix). Alternatively, a .csv file can be uploaded.
#Create Fm (F matrix). Alternatively, a .csv file can be uploaded.
Fu <- data.frame(
  Per = c(0, 0, 0, 0, 1, 0, 0, 0),
  X19but = c(0, 0, 0, 0, 0, 1, 1, 0),
  Fuco = c(0, 0, 0, 1, 0, 1, 1, 0),
  Pra = c(1, 0, 0, 0, 0, 0, 0, 0),
  X19hex = c(0, 0, 0, 0, 0, 1, 0, 0),
  Allo = c(0, 0, 1, 0, 0, 0, 0, 0),
  Zea = c(1, 1, 0, 0, 0, 0, 0, 1),
  Chl_b = c(1, 1, 0, 0, 0, 0, 0, 0),
  Tchla = c(1, 1, 1, 1, 1, 1, 1, 1)
)

rownames(Fu) <- c(
  "Prasinophytes", "Chlorophytes", "Cryptophytes"
  , "Diatoms-2", "Dinoflagellates-1",
  "Haptophytes", "Pelagophytes", "Syn"
)

Min_max <- data.frame(
  Class = c(
    "Syn", "Chlorophytes", "Chlorophytes", "Prasinophytes", "Prasinophytes",
    "Prasinophytes", "Cryptophytes", "Diatoms-2", "Diatoms-2", "Pelagophytes",
    "Pelagophytes", "Pelagophytes", "Dinoflagellates-1", "Haptophytes",
    "Haptophytes", "Haptophytes", "Haptophytes", "Diatoms-2", "Cryptophytes",
    "Prasinophytes", "Chlorophytes", "Syn", "Dinoflagellates-1", "Pelagophytes"
  ),
  Pig_Abbrev = c(
    "Zea", "Zea", "Chl_b", "Pra", "Zea", "Chl_b", "Allo", "Chl_c3",
    "Fuco", "Chl_c3", "X19but", "Fuco", "Per", "X19but", "X19hex",
    "Fuco", "Tchla", "Tchla", "Tchla", "Tchla", "Tchla", "Tchla", "Tchla",
    "Tchla"
  ),
  min = as.numeric(c(
    0.0800, 0.0063, 0.1666, 0.0642, 0.0151, 0.4993, 0.2118, 0.0189,
    0.3315, 0.1471, 0.2457, 0.3092, 0.3421, 0.0819, 0.2107, 0.0090,
    1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000
  )),
  max = as.numeric(c(
    1.2123, 0.0722, 0.9254, 0.4369, 0.1396, 0.9072, 0.5479, 0.1840,
    0.9332, 0.2967, 1.0339, 1.2366, 0.8650, 0.2872, 1.3766, 0.4689,
    1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000
  ))
)
set.seed("7683")
Results <- simulated_annealing(
  S = Sm, 
  F = Fu,
  user_defined_min_max = Min_max,
  do_matrix_checks = TRUE,
  niter = 1,
  step = 0.01,
  weight.upper.bound = 30
)
set.seed("7683")
Results <- simulated_annealing(
  S = Sm, 
  F = Fu,
  user_defined_min_max = Min_max,
  do_matrix_checks = TRUE,
  niter = 1,
  step = 0.01,
  weight.upper.bound = 30
)
Results$`condition number`
#> [1] 1246.385
Results$RMSE
#> [1] 0.02172976
Results$MAE
#>          Per       X19but         Fuco          Pra       X19hex         Allo 
#> 5.760788e-05 2.969032e-05 3.341336e-03 2.608691e-03 1.264442e-04 1.467274e-04 
#>          Zea        Chl_b        Tchla 
#> 1.377911e-03 4.665555e-03 4.794013e-02
Results$Error
#>                 Per        X19but          Fuco           Pra        X19hex
#>  [1,] -1.540353e-04 -4.443987e-05 -5.001243e-03  2.387518e-03 -1.892591e-04
#>  [2,] -4.407218e-04 -1.271502e-04 -1.430942e-02  2.905187e-03 -5.415031e-04
#>  [3,] -2.789685e-04 -8.048366e-05 -9.057595e-03  2.016773e-03 -3.427612e-04
#>  [4,] -2.566387e-04 -7.404139e-05 -8.332585e-03  1.971743e-03 -3.153251e-04
#>  [5,] -6.912664e-05 -1.994334e-05 -2.244415e-03  4.556748e-04 -8.493406e-05
#>  [6,] -3.495682e-05 -1.008520e-05 -1.134983e-03  6.271547e-04 -4.295051e-05
#>  [7,]  0.000000e+00  3.199972e-05  3.601235e-03  4.125569e-04  1.362794e-04
#>  [8,]  0.000000e+00  7.954242e-06  8.951668e-04  2.019758e-03  3.387527e-05
#>  [9,]  0.000000e+00  1.592528e-06  1.792223e-04  1.446277e-03  6.782205e-06
#> [10,]  0.000000e+00  2.576880e-05  2.900009e-03 -4.195474e-04  1.097433e-04
#> [11,]  0.000000e+00  2.422799e-05  2.726607e-03 -5.535725e-04  1.031814e-04
#> [12,]  0.000000e+00  3.898821e-05  4.387716e-03 -8.908209e-04  1.660417e-04
#> [13,]  0.000000e+00  3.437586e-05  3.868644e-03 -7.854359e-04  1.463988e-04
#> [14,]  0.000000e+00  2.975730e-05  3.348873e-03  6.603140e-03  1.267294e-04
#> [15,] -1.863894e-04 -5.377415e-05 -6.051719e-03  1.505595e-03 -2.290116e-04
#> [16,] -2.192229e-06 -6.324676e-07 -7.117763e-05  1.112948e-02 -2.693533e-06
#> [17,] -1.352676e-04 -3.902530e-05 -4.391890e-03  1.844555e-03 -1.661997e-04
#> [18,]  0.000000e+00  1.660517e-05  1.868739e-03  6.898358e-03  7.071758e-05
#> [19,] -3.749984e-05 -1.081887e-05 -1.217551e-03  3.350522e-03 -4.607506e-05
#> [20,]  0.000000e+00  1.415749e-05  1.593278e-03 -8.877482e-05  6.029347e-05
#> [21,] -9.153627e-06 -2.640862e-06 -2.972014e-04  5.411871e-03 -1.124682e-05
#> [22,] -2.136934e-05 -6.165148e-06 -6.938230e-04  1.408642e-04 -2.625593e-05
#> [23,] -4.430863e-05 -1.278323e-05 -1.438619e-03  2.920773e-04 -5.444082e-05
#> [24,]  0.000000e+00  2.419299e-05  2.722668e-03 -5.527728e-04  1.030323e-04
#> [25,]  0.000000e+00  2.553948e-05  2.874202e-03 -5.835380e-04  1.087667e-04
#> [26,]  0.000000e+00  8.869575e-06  9.981780e-04  8.070696e-03  3.777346e-05
#> [27,]  0.000000e+00  2.948775e-05  3.318538e-03  5.160518e-03  1.255815e-04
#> [28,]  0.000000e+00  2.182335e-05  2.455990e-03  6.128883e-03  9.294058e-05
#> [29,]  0.000000e+00  4.369520e-05  4.917439e-03 -9.983685e-04  1.860877e-04
#>                Allo           Zea         Chl_b        Tchla
#>  [1,] -2.400743e-04 -6.818570e-03  2.371929e-05  0.071755809
#>  [2,] -6.868943e-04 -4.513605e-04 -7.234509e-03  0.205305833
#>  [3,] -4.347911e-04 -1.149024e-03 -4.248508e-03  0.129954705
#>  [4,] -3.999885e-04 -1.622101e-03 -3.691928e-03  0.119552557
#>  [5,] -1.077385e-04 -7.079531e-05 -1.134723e-03  0.032201955
#>  [6,] -5.448253e-05 -1.961634e-03  1.641019e-04  0.016284284
#>  [7,]  1.728698e-04 -4.950825e-03  3.566148e-03 -0.051669059
#>  [8,]  4.297063e-05  2.823614e-05 -3.824066e-03 -0.012843491
#>  [9,]  8.603197e-06  5.653189e-06 -2.789617e-03 -0.002571410
#> [10,]  1.392089e-04 -7.300278e-04  1.780952e-03 -0.041608161
#> [11,]  1.308851e-04  8.600506e-05  1.378509e-03 -0.039120259
#> [12,]  0.000000e+00  1.384012e-04  2.218326e-03 -0.062953169
#> [13,]  0.000000e+00  1.220282e-04  1.955896e-03 -0.055505746
#> [14,]  1.607557e-04  1.056331e-04 -1.245496e-02 -0.048048281
#> [15,] -2.905002e-04 -1.908887e-04 -3.597588e-03  0.086827618
#> [16,] -3.416735e-06 -7.188582e-03 -1.599866e-02  0.001021228
#> [17,] -2.108236e-04 -4.764176e-03 -4.480252e-04  0.063013059
#> [18,]  8.970494e-05  5.894541e-05 -1.319301e-02 -0.026811910
#> [19,] -5.844601e-05 -3.814780e-03 -3.685879e-03  0.017468928
#> [20,]  7.648201e-05 -1.089069e-03  1.242080e-03 -0.022859707
#> [21,] -1.426654e-05 -4.000149e-03 -7.419989e-03  0.004264126
#> [22,] -3.330554e-05 -2.188518e-05 -3.507807e-04  0.009954692
#> [23,] -6.905795e-05 -4.537820e-05 -7.273323e-04  0.020640730
#> [24,]  1.306961e-04  8.588080e-05  1.376517e-03 -0.039063743
#> [25,]  1.379701e-04  9.066061e-05  1.453129e-03 -0.041237884
#> [26,]  4.791547e-05  3.148541e-05 -1.556718e-02 -0.014321454
#> [27,]  1.592996e-04  1.046763e-04 -9.655891e-03 -0.047613044
#> [28,]  1.178947e-04  7.746901e-05 -1.163294e-02 -0.035237552
#> [29,]  2.360515e-04  1.551102e-04  2.486142e-03 -0.070553421

Results$`F matrix`
#>                      Per X19but   Fuco    Pra X19hex   Allo    Zea  Chl_b Tchla
#> Prasinophytes     0.0000 0.0000 0.0000 0.2279  0.000 0.0000 0.0919 0.8640     1
#> Chlorophytes      0.0000 0.0000 0.0000 0.0000  0.000 0.0000 0.0118 0.2268     1
#> Cryptophytes      0.0000 0.0000 0.0000 0.0000  0.000 0.3321 0.0000 0.0000     1
#> Diatoms-2         0.0000 0.0000 0.8419 0.0000  0.000 0.0000 0.0000 0.0000     1
#> Dinoflagellates-1 0.5176 0.0000 0.0000 0.0000  0.000 0.0000 0.0000 0.0000     1
#> Haptophytes       0.0000 0.1310 0.1053 0.0000  0.894 0.0000 0.0000 0.0000     1
#> Pelagophytes      0.0000 0.6849 0.5205 0.0000  0.000 0.0000 0.0000 0.0000     1
#> Syn               0.0000 0.0000 0.0000 0.0000  0.000 0.0000 0.5054 0.0000     1
Results$`Class abundances`
#>    Prasinophytes Chlorophytes Cryptophytes  Diatoms-2 Dinoflagellates-1
#> 1     0.06105833 0.1990376885 0.0070029011 0.05694234      2.482309e-04
#> 2     0.01828905 0.0350763698 0.0069735610 0.04052284      2.746169e-04
#> 3     0.04003214 0.1832299487 0.0233391511 0.31687606      6.315298e-04
#> 4     0.05174144 0.1584216877 0.0214629525 0.33514306      5.949039e-04
#> 5     0.05852206 0.0525924650 0.0048017729 0.35050118      1.348690e-04
#> 6     0.04628561 0.0289996797 0.0001257441 0.25875623      2.036438e-02
#> 7     0.03102206 0.0000000000 0.0019730073 0.13798702      0.000000e+00
#> 8     0.01627271 0.0000000000 0.0127580863 0.47748504      0.000000e+00
#> 9     0.02028450 0.0000000000 0.1788768956 0.68834971      0.000000e+00
#> 10    0.03304855 0.0009664837 0.0081552127 0.09931081      0.000000e+00
#> 11    0.14517490 0.0642408514 0.0832722198 0.53387535      0.000000e+00
#> 12    0.08117559 0.0451685318 0.0000000000 0.26589364      0.000000e+00
#> 13    0.07939196 0.0384453911 0.0000000000 0.15590970      0.000000e+00
#> 14    0.16292612 0.0000000000 0.0243302871 0.26087948      0.000000e+00
#> 15    0.23598080 0.0000000000 0.1144974301 0.83377275      1.014099e-03
#> 16    0.23590672 0.0000000000 0.0216475409 0.23819570      4.798564e-06
#> 17    0.53052134 0.0653254799 0.0567307653 0.83706307      9.394163e-04
#> 18    0.16187643 0.0000000000 0.0285198402 0.24256379      0.000000e+00
#> 19    0.32075065 0.0000000000 0.0603616163 0.49828819      1.553036e-04
#> 20    0.21661296 0.1104834137 0.0703885346 0.37615700      0.000000e+00
#> 21    0.29258255 0.0000000000 0.0508481651 0.43735952      3.321923e-05
#> 22    0.14814749 0.1387954008 0.0560138433 0.71755858      9.554773e-05
#> 23    0.11891731 0.1062375285 0.0445581140 0.49948575      1.474983e-04
#> 24    0.05295877 0.0077005651 0.0308795322 0.15235979      0.000000e+00
#> 25    0.07661799 0.0601020386 0.0381094140 0.19072492      0.000000e+00
#> 26    0.09081140 0.0000000000 0.0242271266 0.18713018      0.000000e+00
#> 27    0.04316930 0.0000000000 0.0159703163 0.11605087      0.000000e+00
#> 28    0.04569986 0.0000000000 0.0136732671 0.10235937      0.000000e+00
#> 29    0.07940435 0.0555712748 0.0240573205 0.06305842      0.000000e+00
#>    Haptophytes Pelagophytes         Syn
#> 1   0.10417599   0.03004452 0.000000000
#> 2   0.02454977   0.01838375 0.001640034
#> 3   0.02474948   0.02384169 0.000000000
#> 4   0.02644976   0.02688619 0.000000000
#> 5   0.02514533   0.03427030 0.004232025
#> 6   0.02194347   0.02922489 0.000000000
#> 7   0.02572588   0.01499203 0.000000000
#> 8   0.14368310   0.03689270 0.001408358
#> 9   0.14705969   0.04714670 0.003182514
#> 10  0.04321779   0.02130115 0.000000000
#> 11  0.12510901   0.04264135 0.045347038
#> 12  0.02981800   0.02091672 0.038231851
#> 13  0.02730204   0.02387892 0.015979875
#> 14  0.02195285   0.01488997 0.004311483
#> 15  0.13347029   0.01970454 0.042724278
#> 16  0.04501592   0.03034426 0.000000000
#> 17  0.17633325   0.07442616 0.000000000
#> 18  0.08546430   0.05722432 0.002022010
#> 19  0.12743977   0.06693543 0.000000000
#> 20  0.13765510   0.07960397 0.000000000
#> 21  0.10124657   0.06997838 0.000000000
#> 22  0.14614628   0.03732076 0.005390572
#> 23  0.10723226   0.03975156 0.002736478
#> 24  0.06098498   0.03021600 0.013556133
#> 25  0.05682837   0.02600165 0.007257886
#> 26  0.02379894   0.01928751 0.004518430
#> 27  0.02258920   0.02823695 0.010701883
#> 28  0.02304180   0.01696960 0.009963192
#> 29  0.04749637   0.03065805 0.001223182
Results$Figure

Helper functions

Matrix_checks

This function will perform checks on the F and S matrices. If the columns sum is 0 or very small it will be eliminated from both the S and F matrix. To use this function, naming for both pigments and phytoplankton classes must follow the same conventions as the default values. The output of this function will be new S and F matrices.

Arguments:

S = S matrix

F = F matrix

MC <- Matrix_checks(Sm, Fm)  
Snew <- MC$Snew
Fnew <- MC$Fnew  

Steep_Desc

This algorithm will perform the steepest descent algorithm without being bound by any limits. The results may show unrealistic pig:Chl a ratios for certain groups, although the error can often be very low.

Arguments:

F = F matrix

S = S matrix

num.loops = the number of loops/iterations to perform

MC <- Matrix_checks(Sm, Fm)  
Snew <- MC$Snew
Fnew <- MC$Fnew
SDRes <- Steepest_Desc(Fnew, Snew, num.loops = 10)

Bounded_weights

This function determines the weights to use for the S matrix, for which the default upper bound is 30 in the simulated_annealing() function call.

Arguments:

S = sample matrix

weight.upper.bound = maximum weights upper bound

Bounded_weights(Sm, weight.upper.bound = 30)
#>        Per     X19but       Fuco       Neox        Pra       Viol     X19hex 
#>  30.000000  30.000000   3.405156  30.000000  30.000000  30.000000  15.742517 
#>       Allo        Zea        Lut ChlcMGDG18 ChlcMGDG14      Chl_b      Tchla 
#>  30.000000  30.000000  30.000000  30.000000  30.000000   9.185585   1.000000

NNLS_MF

This performs non-negative least least squares matrix factorization between the S and F matrices. Ensure that Chl a is the final column and that the columns in S and F are in the same order. If the weights are left blank then no weights will be used.

Arguments:

Fn = F matrix

S = sample matrix

cm = weights for each column

MC <- Matrix_checks(Sm, Fm)  
Snew <- MC$Snew
Fnew <- MC$Fnew
cm <- Bounded_weights(Snew, weight.upper.bound = 30)

Results <- NNLS_MF(Fnew, Snew, cm)
Results$`F matrix`
#>                   Per X19but Fuco Neox Pra Viol X19hex Allo Zea Chl_b Tchla
#> Prasinophytes       0      0    0    1   1    1      0    0   1     1     1
#> Chlorophytes        0      0    0    1   0    1      0    0   1     1     1
#> Cryptophytes        0      0    0    0   0    0      0    1   0     0     1
#> Diatoms-2           0      0    1    0   0    0      0    0   0     0     1
#> Dinoflagellates-1   1      0    0    0   0    0      0    0   0     0     1
#> Haptophytes         0      1    1    0   0    0      1    0   0     0     1
#> Pelagophytes        0      1    1    0   0    0      0    0   0     0     1
#> Syn                 0      0    0    0   0    0      0    0   1     0     1
Results$RMSE
#> [1] 0.1127568
Results$`C matrix`
#>       Prasinophytes Chlorophytes Cryptophytes Diatoms-2 Dinoflagellates-1
#>  [1,]   0.088117948   0.00000000 0.0217204089 0.4901801      0.0037567947
#>  [2,]   0.055584649   0.00000000 0.0373938768 0.6222451      0.0027804911
#>  [3,]   0.023402989   0.00000000 0.0237891848 0.8898721      0.0015045577
#>  [4,]   0.025080760   0.00000000 0.0208394859 0.8879702      0.0013748370
#>  [5,]   0.027278768   0.00000000 0.0050338409 0.8891283      0.0007088272
#>  [6,]   0.024427004   0.00000000 0.0006420380 0.8482800      0.0403115206
#>  [7,]   0.029818901   0.00000000 0.0056863026 0.8501687      0.0004333909
#>  [8,]   0.006998486   0.00000000 0.0097623255 0.8482667      0.0004993785
#>  [9,]   0.007273723   0.00000000 0.0834778062 0.8126633      0.0005630781
#> [10,]   0.041423150   0.00000000 0.0248502005 0.7213906      0.0007292296
#> [11,]   0.033785036   0.00000000 0.0480895900 0.7854960      0.0007137484
#> [12,]   0.047211598   0.00000000 0.0005753971 0.8297532      0.0005753971
#> [13,]   0.065913285   0.00000000 0.0008208615 0.7888618      0.0008208615
#> [14,]   0.088836617   0.00000000 0.0299819886 0.8287089      0.0006540520
#> [15,]   0.058417376   0.00000000 0.0440282484 0.8389594      0.0009788646
#> [16,]   0.125844391   0.00000000 0.0258929304 0.7449531      0.0010843156
#> [17,]   0.085675844   0.00000000 0.0205483370 0.7943691      0.0012253888
#> [18,]   0.080155362   0.00000000 0.0327531006 0.6997688      0.0009135323
#> [19,]   0.077226096   0.00000000 0.0355593296 0.7586179      0.0010293554
#> [20,]   0.065007214   0.00000000 0.0509516342 0.7059805      0.0011235075
#> [21,]   0.078274256   0.00000000 0.0339483113 0.7547636      0.0009751164
#> [22,]   0.031530158   0.00000000 0.0263143309 0.8543388      0.0008336558
#> [23,]   0.037075351   0.00000000 0.0290232371 0.8314658      0.0009196788
#> [24,]   0.062767108   0.00151289 0.0562106906 0.6948740      0.0008153781
#> [25,]   0.058367609   0.00000000 0.0575224093 0.7466852      0.0009684633
#> [26,]   0.069420509   0.00000000 0.0401302883 0.8048198      0.0007330733
#> [27,]   0.060138593   0.00000000 0.0395615803 0.7292408      0.0006281012
#> [28,]   0.075116512   0.00000000 0.0391858968 0.7480381      0.0007317574
#> [29,]   0.109413008   0.00000000 0.0750124557 0.5374235      0.0015472772
#>       Haptophytes Pelagophytes          Syn
#>  [1,]  0.39622477   0.00000000 0.0000000000
#>  [2,]  0.28199589   0.00000000 0.0000000000
#>  [3,]  0.06143118   0.00000000 0.0000000000
#>  [4,]  0.06473471   0.00000000 0.0000000000
#>  [5,]  0.06518414   0.01266611 0.0000000000
#>  [6,]  0.07389414   0.01244533 0.0000000000
#>  [7,]  0.11389271   0.00000000 0.0000000000
#>  [8,]  0.13447311   0.00000000 0.0000000000
#>  [9,]  0.09602212   0.00000000 0.0000000000
#> [10,]  0.21160678   0.00000000 0.0000000000
#> [11,]  0.10185148   0.00000000 0.0300641351
#> [12,]  0.07127730   0.00000000 0.0506071021
#> [13,]  0.11859426   0.00000000 0.0249889572
#> [14,]  0.05181846   0.00000000 0.0000000000
#> [15,]  0.05761614   0.00000000 0.0000000000
#> [16,]  0.10222524   0.00000000 0.0000000000
#> [17,]  0.09818131   0.00000000 0.0000000000
#> [18,]  0.18640925   0.00000000 0.0000000000
#> [19,]  0.12756732   0.00000000 0.0000000000
#> [20,]  0.17693716   0.00000000 0.0000000000
#> [21,]  0.13203875   0.00000000 0.0000000000
#> [22,]  0.08698308   0.00000000 0.0000000000
#> [23,]  0.10151595   0.00000000 0.0000000000
#> [24,]  0.18371728   0.00000000 0.0001026917
#> [25,]  0.13645632   0.00000000 0.0000000000
#> [26,]  0.08489631   0.00000000 0.0000000000
#> [27,]  0.14672943   0.01494256 0.0087589477
#> [28,]  0.13363978   0.00000000 0.0032879586
#> [29,]  0.27660378   0.00000000 0.0000000000

References

Hayward, A., M. H. Pinkerton, and A. Gutierrez‐Rodriguez. 2023. phytoclass: A pigment‐based chemotaxonomic method to determine the biomass of phytoplankton classes.” Limnology and Oceanography: Methods 21 (4): 220–41. https://doi.org/10.1002/lom3.10541.
Langfelder, p., B. Zhang, and S. Horvath. 2008. Defining clusters from a hierarchical cluster tree: the Dynamic Tree Cut package for R.” Bioinformatics 24 (5): 719–20.
Mackey, M. D., D. J. Mackey, H. W. Higgins, and S. W. Wright. 1996. “CHEMTAX-a Program for Estimating Class Abundances from Chemical Markers: Application to HPLC Measurements of Phytoplankton.” Marine Ecology Progress Series 144: 265–83. https://doi.org/10.3354/meps144265.