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:
# 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.
Results$`condition number`
#> [1] 311.2721
Results$RMSE
#> [1] 0.03380027
Results$MAE
#> Per X19but Fuco Neox Viol X19hex
#> 7.037546e-05 3.200973e-05 5.719363e-03 8.815318e-03 1.386631e-02 2.382285e-04
#> Allo Zea Chl_b Tchla
#> 1.626395e-04 1.135648e-04 3.974469e-02 6.575059e-02
Results$Error
#> Per X19but Fuco Neox Viol
#> [1,] -4.447471e-04 -1.134710e-04 -2.027452e-02 0.003589306 -0.0175355909
#> [2,] -4.952833e-04 -1.263646e-04 -2.257829e-02 0.002683935 -0.0099116308
#> [3,] -3.922853e-04 -1.000861e-04 -1.788296e-02 0.005161085 -0.0117720565
#> [4,] -3.405666e-04 -8.689080e-05 -1.552528e-02 0.005464714 -0.0122792240
#> [5,] -3.151096e-05 -8.039581e-06 -1.436478e-03 0.008758521 -0.0117818619
#> [6,] 1.018898e-05 2.599575e-06 4.644810e-04 0.008584065 -0.0117759610
#> [7,] 0.000000e+00 5.427750e-05 9.698074e-03 0.006821760 -0.0108571634
#> [8,] 0.000000e+00 5.400886e-05 9.650074e-03 0.002588506 -0.0013053643
#> [9,] 0.000000e+00 3.640805e-05 6.505236e-03 0.002147936 -0.0003041764
#> [10,] 0.000000e+00 4.543370e-05 8.117901e-03 0.006847504 -0.0110621811
#> [11,] 0.000000e+00 2.224084e-05 3.973899e-03 0.006699444 -0.0145261276
#> [12,] 0.000000e+00 2.465484e-05 4.405223e-03 0.016031442 -0.0189657577
#> [13,] 0.000000e+00 7.858724e-06 1.404163e-03 0.014679711 -0.0246566546
#> [14,] 0.000000e+00 2.161536e-05 3.862141e-03 0.016157143 -0.0224335247
#> [15,] -7.298926e-05 -1.862219e-05 -3.327333e-03 0.013016791 -0.0072810489
#> [16,] -4.122598e-05 -1.051823e-05 -1.879353e-03 0.015454465 -0.0210167666
#> [17,] -1.127952e-04 -2.877812e-05 -5.141953e-03 0.008751977 -0.0159062881
#> [18,] 0.000000e+00 1.791855e-05 3.201611e-03 0.010082131 -0.0172309053
#> [19,] -2.003860e-05 -5.112569e-06 -9.134920e-04 0.009212121 -0.0185141142
#> [20,] -7.581600e-06 -1.934339e-06 -3.456195e-04 0.005087312 -0.0171190517
#> [21,] -5.775913e-06 -1.473643e-06 -2.633044e-04 0.007452954 -0.0187709429
#> [22,] 0.000000e+00 5.241695e-07 9.365638e-05 0.003163532 -0.0101696505
#> [23,] -3.069546e-05 -7.831518e-06 -1.399302e-03 0.006210314 -0.0110226502
#> [24,] 0.000000e+00 3.654059e-05 6.528918e-03 0.015987300 -0.0093002921
#> [25,] 0.000000e+00 7.494603e-06 1.339104e-03 0.007888634 -0.0143752872
#> [26,] 0.000000e+00 1.221034e-05 2.181691e-03 0.009569413 -0.0154758510
#> [27,] 0.000000e+00 3.660357e-05 6.540171e-03 0.011988831 -0.0106981209
#> [28,] 0.000000e+00 2.978846e-05 5.322475e-03 0.011010776 -0.0105201719
#> [29,] -3.520419e-05 -8.981855e-06 -1.604840e-03 0.014552606 -0.0255546310
#> X19hex Allo Zea Chl_b Tchla
#> [1,] -8.444938e-04 -5.992046e-04 -4.025746e-04 0.0517822197 0.233078611
#> [2,] -9.404529e-04 -6.672917e-04 -4.483188e-04 0.0278967435 0.259563134
#> [3,] -7.448783e-04 -5.285232e-04 -3.550874e-04 0.0331099899 0.205584938
#> [4,] -6.466740e-04 -4.588430e-04 -3.082729e-04 0.0348028952 0.178480738
#> [5,] -5.983358e-05 -4.245450e-05 -2.852298e-05 0.0331146167 0.016513950
#> [6,] 1.934701e-05 0.000000e+00 9.222821e-06 0.0333586881 -0.005339737
#> [7,] 4.039536e-04 2.866224e-04 1.925668e-04 0.0321458494 -0.111490389
#> [8,] 4.019542e-04 2.852038e-04 1.916137e-04 0.0038907056 -0.110938567
#> [9,] 2.709624e-04 1.922595e-04 1.291692e-04 0.0006235049 -0.074785087
#> [10,] 3.381347e-04 2.399211e-04 1.611906e-04 0.0326284463 -0.093324500
#> [11,] 1.655247e-04 1.174469e-04 7.890648e-05 0.0432298091 -0.045684486
#> [12,] 1.834906e-04 0.000000e+00 8.747093e-05 0.0530867374 -0.050643046
#> [13,] 5.848758e-05 0.000000e+00 2.788133e-05 0.0713715250 -0.016142456
#> [14,] 1.608697e-04 1.141439e-04 7.668740e-05 0.0639257562 -0.044399705
#> [15,] -1.385933e-04 -9.833791e-05 -6.606816e-05 0.0168046148 0.038251480
#> [16,] -7.828063e-05 -5.554347e-05 -3.731679e-05 0.0592129912 0.021605299
#> [17,] -2.141776e-04 -1.519682e-04 -1.020996e-04 0.0457799761 0.059112595
#> [18,] 1.333566e-04 9.462225e-05 6.357179e-05 0.0501714222 -0.036806162
#> [19,] -3.804966e-05 -2.699787e-05 -1.813847e-05 0.0542157231 0.010501630
#> [20,] -1.439608e-05 -1.021464e-05 -6.862686e-06 0.0517233730 0.003973289
#> [21,] -1.096741e-05 -7.781847e-06 -5.228221e-06 0.0558815554 0.003026983
#> [22,] 3.901066e-06 2.767974e-06 1.859659e-06 0.0306918123 -0.001076687
#> [23,] -5.828510e-05 -4.135578e-05 -2.778481e-05 0.0318685172 0.016086571
#> [24,] 2.719488e-04 1.929594e-04 1.296394e-04 0.0227971265 -0.075057340
#> [25,] 5.577765e-05 3.957664e-05 2.658950e-05 0.0419629458 -0.015394521
#> [26,] 9.087392e-05 6.447895e-05 4.332007e-05 0.0447624973 -0.025081022
#> [27,] 2.724175e-04 1.932919e-04 1.298629e-04 0.0290115200 -0.075186696
#> [28,] 2.216969e-04 1.573035e-04 1.056841e-04 0.0287720766 -0.061187900
#> [29,] -6.684634e-05 -4.743035e-05 -3.186600e-05 0.0739722833 0.018449458
Results$`F matrix`
#> Per X19but Fuco Neox Viol X19hex Allo Zea
#> Chlorophytes 0.0000 0.0000 0.0000 0.0558 0.3913 0.0000 0.0000 0.0386
#> Cryptophytes 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.4322 0.0000
#> Diatoms-2 0.0000 0.0000 0.6809 0.0000 0.0000 0.0000 0.0000 0.0000
#> Dinoflagellates-1 0.5823 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
#> Haptophytes 0.0000 0.0957 0.1020 0.0000 0.0000 0.6611 0.0000 0.0000
#> Pelagophytes 0.0000 0.9325 0.4027 0.0000 0.0000 0.0000 0.0000 0.0000
#> Syn 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.6433
#> Chl_b Tchla
#> Chlorophytes 0.9242962 1
#> Cryptophytes 0.0000000 1
#> Diatoms-2 0.0000000 1
#> Dinoflagellates-1 0.0000000 1
#> Haptophytes 0.0000000 1
#> Pelagophytes 0.0000000 1
#> Syn 0.0000000 1
Results$`Class abundances`
#> Chlorophytes Cryptophytes Diatoms-2 Dinoflagellates-1 Haptophytes
#> [1,] 0.083817834 0.008588806 0.13265700 8.999402e-04 0.20041427
#> [2,] 0.015283960 0.006053614 0.06666444 3.095410e-04 0.03784156
#> [3,] 0.041032908 0.021229138 0.48273263 9.188508e-04 0.03990177
#> [4,] 0.042219404 0.018756140 0.48942343 7.868760e-04 0.04096476
#> [5,] 0.029425087 0.003433835 0.42938948 5.288452e-05 0.03297645
#> [6,] 0.022069846 0.000000000 0.31391424 1.733484e-02 0.02844111
#> [7,] 0.015203578 0.001272798 0.15382861 0.000000e+00 0.03118578
#> [8,] 0.003661726 0.007655573 0.48839928 0.000000e+00 0.16331211
#> [9,] 0.010348749 0.120799082 0.74393311 0.000000e+00 0.17515328
#> [10,] 0.016486548 0.005625320 0.11361993 0.000000e+00 0.05311164
#> [11,] 0.067505071 0.063350518 0.65753321 0.000000e+00 0.16717274
#> [12,] 0.041631304 0.000000000 0.34162754 0.000000e+00 0.04119732
#> [13,] 0.041086601 0.000000000 0.21693806 0.000000e+00 0.03983093
#> [14,] 0.078750392 0.018949219 0.32843598 0.000000e+00 0.02988317
#> [15,] 0.143775017 0.078974815 0.92862904 3.247133e-04 0.16399961
#> [16,] 0.134697999 0.017472284 0.31809012 8.248762e-05 0.06356241
#> [17,] 0.329679870 0.042749564 1.04626067 6.897549e-04 0.23676988
#> [18,] 0.074531221 0.021516135 0.30697686 0.000000e+00 0.11341649
#> [19,] 0.164695407 0.045578817 0.62217731 7.187947e-05 0.16990335
#> [20,] 0.137312683 0.057283171 0.51525893 2.484862e-05 0.19604425
#> [21,] 0.146419797 0.038943643 0.55739364 1.826725e-05 0.13656627
#> [22,] 0.093167501 0.041989909 0.87192625 0.000000e+00 0.19357292
#> [23,] 0.075871939 0.033837703 0.62005197 8.996905e-05 0.14378729
#> [24,] 0.033995536 0.022124201 0.17949653 0.000000e+00 0.07705310
#> [25,] 0.053569477 0.030871825 0.25503247 0.000000e+00 0.08058271
#> [26,] 0.041425563 0.018235516 0.23095149 0.000000e+00 0.03151493
#> [27,] 0.021153818 0.011653713 0.14252780 0.000000e+00 0.02899738
#> [28,] 0.024403104 0.009992969 0.12349071 0.000000e+00 0.02966389
#> [29,] 0.055942739 0.022301711 0.10750461 3.761234e-05 0.07630449
#> Pelagophytes Syn
#> [1,] 0.031428134 0.000704017
#> [2,] 0.015326480 0.004230398
#> [3,] 0.020436725 0.006447972
#> [4,] 0.022245689 0.006303703
#> [5,] 0.024470846 0.010451422
#> [6,] 0.020656300 0.003283668
#> [7,] 0.009961661 0.000247576
#> [8,] 0.023075000 0.002396304
#> [9,] 0.030847394 0.003818389
#> [10,] 0.014322906 0.002833647
#> [11,] 0.031210153 0.052889036
#> [12,] 0.015771939 0.040976217
#> [13,] 0.018938957 0.024113349
#> [14,] 0.011075393 0.022196020
#> [15,] 0.013323834 0.052137164
#> [16,] 0.023300883 0.013908752
#> [17,] 0.054450955 0.030738786
#> [18,] 0.041434060 0.019795921
#> [19,] 0.048679783 0.022824405
#> [20,] 0.061764040 0.023213065
#> [21,] 0.051436621 0.021270160
#> [22,] 0.027100440 0.021711459
#> [23,] 0.029119311 0.016308302
#> [24,] 0.020882506 0.015103901
#> [25,] 0.020119463 0.015466325
#> [26,] 0.013937114 0.013708980
#> [27,] 0.019792044 0.012593760
#> [28,] 0.011936404 0.012220012
#> [29,] 0.026773842 0.012603965
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] 311.2721
Results$RMSE
#> [1] 0.03380027
Results$MAE
#> Per X19but Fuco Neox Viol X19hex
#> 7.037546e-05 3.200973e-05 5.719363e-03 8.815318e-03 1.386631e-02 2.382285e-04
#> Allo Zea Chl_b Tchla
#> 1.626395e-04 1.135648e-04 3.974469e-02 6.575059e-02
Results$Error
#> Per X19but Fuco Neox Viol
#> [1,] -4.447471e-04 -1.134710e-04 -2.027452e-02 0.003589306 -0.0175355909
#> [2,] -4.952833e-04 -1.263646e-04 -2.257829e-02 0.002683935 -0.0099116308
#> [3,] -3.922853e-04 -1.000861e-04 -1.788296e-02 0.005161085 -0.0117720565
#> [4,] -3.405666e-04 -8.689080e-05 -1.552528e-02 0.005464714 -0.0122792240
#> [5,] -3.151096e-05 -8.039581e-06 -1.436478e-03 0.008758521 -0.0117818619
#> [6,] 1.018898e-05 2.599575e-06 4.644810e-04 0.008584065 -0.0117759610
#> [7,] 0.000000e+00 5.427750e-05 9.698074e-03 0.006821760 -0.0108571634
#> [8,] 0.000000e+00 5.400886e-05 9.650074e-03 0.002588506 -0.0013053643
#> [9,] 0.000000e+00 3.640805e-05 6.505236e-03 0.002147936 -0.0003041764
#> [10,] 0.000000e+00 4.543370e-05 8.117901e-03 0.006847504 -0.0110621811
#> [11,] 0.000000e+00 2.224084e-05 3.973899e-03 0.006699444 -0.0145261276
#> [12,] 0.000000e+00 2.465484e-05 4.405223e-03 0.016031442 -0.0189657577
#> [13,] 0.000000e+00 7.858724e-06 1.404163e-03 0.014679711 -0.0246566546
#> [14,] 0.000000e+00 2.161536e-05 3.862141e-03 0.016157143 -0.0224335247
#> [15,] -7.298926e-05 -1.862219e-05 -3.327333e-03 0.013016791 -0.0072810489
#> [16,] -4.122598e-05 -1.051823e-05 -1.879353e-03 0.015454465 -0.0210167666
#> [17,] -1.127952e-04 -2.877812e-05 -5.141953e-03 0.008751977 -0.0159062881
#> [18,] 0.000000e+00 1.791855e-05 3.201611e-03 0.010082131 -0.0172309053
#> [19,] -2.003860e-05 -5.112569e-06 -9.134920e-04 0.009212121 -0.0185141142
#> [20,] -7.581600e-06 -1.934339e-06 -3.456195e-04 0.005087312 -0.0171190517
#> [21,] -5.775913e-06 -1.473643e-06 -2.633044e-04 0.007452954 -0.0187709429
#> [22,] 0.000000e+00 5.241695e-07 9.365638e-05 0.003163532 -0.0101696505
#> [23,] -3.069546e-05 -7.831518e-06 -1.399302e-03 0.006210314 -0.0110226502
#> [24,] 0.000000e+00 3.654059e-05 6.528918e-03 0.015987300 -0.0093002921
#> [25,] 0.000000e+00 7.494603e-06 1.339104e-03 0.007888634 -0.0143752872
#> [26,] 0.000000e+00 1.221034e-05 2.181691e-03 0.009569413 -0.0154758510
#> [27,] 0.000000e+00 3.660357e-05 6.540171e-03 0.011988831 -0.0106981209
#> [28,] 0.000000e+00 2.978846e-05 5.322475e-03 0.011010776 -0.0105201719
#> [29,] -3.520419e-05 -8.981855e-06 -1.604840e-03 0.014552606 -0.0255546310
#> X19hex Allo Zea Chl_b Tchla
#> [1,] -8.444938e-04 -5.992046e-04 -4.025746e-04 0.0517822197 0.233078611
#> [2,] -9.404529e-04 -6.672917e-04 -4.483188e-04 0.0278967435 0.259563134
#> [3,] -7.448783e-04 -5.285232e-04 -3.550874e-04 0.0331099899 0.205584938
#> [4,] -6.466740e-04 -4.588430e-04 -3.082729e-04 0.0348028952 0.178480738
#> [5,] -5.983358e-05 -4.245450e-05 -2.852298e-05 0.0331146167 0.016513950
#> [6,] 1.934701e-05 0.000000e+00 9.222821e-06 0.0333586881 -0.005339737
#> [7,] 4.039536e-04 2.866224e-04 1.925668e-04 0.0321458494 -0.111490389
#> [8,] 4.019542e-04 2.852038e-04 1.916137e-04 0.0038907056 -0.110938567
#> [9,] 2.709624e-04 1.922595e-04 1.291692e-04 0.0006235049 -0.074785087
#> [10,] 3.381347e-04 2.399211e-04 1.611906e-04 0.0326284463 -0.093324500
#> [11,] 1.655247e-04 1.174469e-04 7.890648e-05 0.0432298091 -0.045684486
#> [12,] 1.834906e-04 0.000000e+00 8.747093e-05 0.0530867374 -0.050643046
#> [13,] 5.848758e-05 0.000000e+00 2.788133e-05 0.0713715250 -0.016142456
#> [14,] 1.608697e-04 1.141439e-04 7.668740e-05 0.0639257562 -0.044399705
#> [15,] -1.385933e-04 -9.833791e-05 -6.606816e-05 0.0168046148 0.038251480
#> [16,] -7.828063e-05 -5.554347e-05 -3.731679e-05 0.0592129912 0.021605299
#> [17,] -2.141776e-04 -1.519682e-04 -1.020996e-04 0.0457799761 0.059112595
#> [18,] 1.333566e-04 9.462225e-05 6.357179e-05 0.0501714222 -0.036806162
#> [19,] -3.804966e-05 -2.699787e-05 -1.813847e-05 0.0542157231 0.010501630
#> [20,] -1.439608e-05 -1.021464e-05 -6.862686e-06 0.0517233730 0.003973289
#> [21,] -1.096741e-05 -7.781847e-06 -5.228221e-06 0.0558815554 0.003026983
#> [22,] 3.901066e-06 2.767974e-06 1.859659e-06 0.0306918123 -0.001076687
#> [23,] -5.828510e-05 -4.135578e-05 -2.778481e-05 0.0318685172 0.016086571
#> [24,] 2.719488e-04 1.929594e-04 1.296394e-04 0.0227971265 -0.075057340
#> [25,] 5.577765e-05 3.957664e-05 2.658950e-05 0.0419629458 -0.015394521
#> [26,] 9.087392e-05 6.447895e-05 4.332007e-05 0.0447624973 -0.025081022
#> [27,] 2.724175e-04 1.932919e-04 1.298629e-04 0.0290115200 -0.075186696
#> [28,] 2.216969e-04 1.573035e-04 1.056841e-04 0.0287720766 -0.061187900
#> [29,] -6.684634e-05 -4.743035e-05 -3.186600e-05 0.0739722833 0.018449458
Results$`F matrix`
#> Per X19but Fuco Neox Viol X19hex Allo Zea
#> Chlorophytes 0.0000 0.0000 0.0000 0.0558 0.3913 0.0000 0.0000 0.0386
#> Cryptophytes 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.4322 0.0000
#> Diatoms-2 0.0000 0.0000 0.6809 0.0000 0.0000 0.0000 0.0000 0.0000
#> Dinoflagellates-1 0.5823 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
#> Haptophytes 0.0000 0.0957 0.1020 0.0000 0.0000 0.6611 0.0000 0.0000
#> Pelagophytes 0.0000 0.9325 0.4027 0.0000 0.0000 0.0000 0.0000 0.0000
#> Syn 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.6433
#> Chl_b Tchla
#> Chlorophytes 0.9242962 1
#> Cryptophytes 0.0000000 1
#> Diatoms-2 0.0000000 1
#> Dinoflagellates-1 0.0000000 1
#> Haptophytes 0.0000000 1
#> Pelagophytes 0.0000000 1
#> Syn 0.0000000 1
Results$`Class abundances`
#> Chlorophytes Cryptophytes Diatoms-2 Dinoflagellates-1 Haptophytes
#> [1,] 0.083817834 0.008588806 0.13265700 8.999402e-04 0.20041427
#> [2,] 0.015283960 0.006053614 0.06666444 3.095410e-04 0.03784156
#> [3,] 0.041032908 0.021229138 0.48273263 9.188508e-04 0.03990177
#> [4,] 0.042219404 0.018756140 0.48942343 7.868760e-04 0.04096476
#> [5,] 0.029425087 0.003433835 0.42938948 5.288452e-05 0.03297645
#> [6,] 0.022069846 0.000000000 0.31391424 1.733484e-02 0.02844111
#> [7,] 0.015203578 0.001272798 0.15382861 0.000000e+00 0.03118578
#> [8,] 0.003661726 0.007655573 0.48839928 0.000000e+00 0.16331211
#> [9,] 0.010348749 0.120799082 0.74393311 0.000000e+00 0.17515328
#> [10,] 0.016486548 0.005625320 0.11361993 0.000000e+00 0.05311164
#> [11,] 0.067505071 0.063350518 0.65753321 0.000000e+00 0.16717274
#> [12,] 0.041631304 0.000000000 0.34162754 0.000000e+00 0.04119732
#> [13,] 0.041086601 0.000000000 0.21693806 0.000000e+00 0.03983093
#> [14,] 0.078750392 0.018949219 0.32843598 0.000000e+00 0.02988317
#> [15,] 0.143775017 0.078974815 0.92862904 3.247133e-04 0.16399961
#> [16,] 0.134697999 0.017472284 0.31809012 8.248762e-05 0.06356241
#> [17,] 0.329679870 0.042749564 1.04626067 6.897549e-04 0.23676988
#> [18,] 0.074531221 0.021516135 0.30697686 0.000000e+00 0.11341649
#> [19,] 0.164695407 0.045578817 0.62217731 7.187947e-05 0.16990335
#> [20,] 0.137312683 0.057283171 0.51525893 2.484862e-05 0.19604425
#> [21,] 0.146419797 0.038943643 0.55739364 1.826725e-05 0.13656627
#> [22,] 0.093167501 0.041989909 0.87192625 0.000000e+00 0.19357292
#> [23,] 0.075871939 0.033837703 0.62005197 8.996905e-05 0.14378729
#> [24,] 0.033995536 0.022124201 0.17949653 0.000000e+00 0.07705310
#> [25,] 0.053569477 0.030871825 0.25503247 0.000000e+00 0.08058271
#> [26,] 0.041425563 0.018235516 0.23095149 0.000000e+00 0.03151493
#> [27,] 0.021153818 0.011653713 0.14252780 0.000000e+00 0.02899738
#> [28,] 0.024403104 0.009992969 0.12349071 0.000000e+00 0.02966389
#> [29,] 0.055942739 0.022301711 0.10750461 3.761234e-05 0.07630449
#> Pelagophytes Syn
#> [1,] 0.031428134 0.000704017
#> [2,] 0.015326480 0.004230398
#> [3,] 0.020436725 0.006447972
#> [4,] 0.022245689 0.006303703
#> [5,] 0.024470846 0.010451422
#> [6,] 0.020656300 0.003283668
#> [7,] 0.009961661 0.000247576
#> [8,] 0.023075000 0.002396304
#> [9,] 0.030847394 0.003818389
#> [10,] 0.014322906 0.002833647
#> [11,] 0.031210153 0.052889036
#> [12,] 0.015771939 0.040976217
#> [13,] 0.018938957 0.024113349
#> [14,] 0.011075393 0.022196020
#> [15,] 0.013323834 0.052137164
#> [16,] 0.023300883 0.013908752
#> [17,] 0.054450955 0.030738786
#> [18,] 0.041434060 0.019795921
#> [19,] 0.048679783 0.022824405
#> [20,] 0.061764040 0.023213065
#> [21,] 0.051436621 0.021270160
#> [22,] 0.027100440 0.021711459
#> [23,] 0.029119311 0.016308302
#> [24,] 0.020882506 0.015103901
#> [25,] 0.020119463 0.015466325
#> [26,] 0.013937114 0.013708980
#> [27,] 0.019792044 0.012593760
#> [28,] 0.011936404 0.012220012
#> [29,] 0.026773842 0.012603965
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] 405.1108
Results$RMSE
#> [1] 0.03213964
Results$MAE
#> Per X19but Fuco X19hex Allo Zea
#> 8.593235e-05 3.986809e-05 5.116936e-03 2.627275e-04 1.701731e-04 3.828607e-04
#> Chl_b Tchla
#> 6.910666e-04 6.511825e-02
Results$Error
#> Per X19but Fuco X19hex Allo
#> [1,] -4.576254e-04 -3.611475e-05 -0.0147481960 -7.449756e-04 -5.155498e-04
#> [2,] -6.371388e-04 -5.028154e-05 -0.0205334951 -1.037208e-03 -7.177853e-04
#> [3,] -5.153685e-04 -4.067171e-05 -0.0166091215 -8.389766e-04 -5.806018e-04
#> [4,] -4.482757e-04 -3.537689e-05 -0.0144468769 -7.297551e-04 -5.050166e-04
#> [5,] -9.218266e-05 -7.274846e-06 -0.0029708318 -1.500656e-04 -1.038508e-04
#> [6,] -1.737557e-05 -1.371240e-06 -0.0005599739 -2.828596e-05 -1.957490e-05
#> [7,] 0.000000e+00 1.852282e-05 0.0075641707 3.820890e-04 2.644192e-04
#> [8,] 0.000000e+00 1.102914e-05 0.0045039734 2.275092e-04 1.574445e-04
#> [9,] 0.000000e+00 4.779704e-06 0.0019518896 9.859580e-05 6.823182e-05
#> [10,] 0.000000e+00 1.665493e-05 0.0068013811 3.435582e-04 2.377545e-04
#> [11,] 0.000000e+00 8.323306e-06 0.0033989917 1.716933e-04 1.188179e-04
#> [12,] 0.000000e+00 9.180511e-06 0.0037490491 1.893757e-04 0.000000e+00
#> [13,] 0.000000e+00 8.490581e-06 0.0034673021 1.751438e-04 0.000000e+00
#> [14,] 0.000000e+00 1.474899e-05 0.0060230511 3.042424e-04 2.105466e-04
#> [15,] -1.518476e-04 -8.047843e-04 -0.0048936922 3.706105e-04 -1.710678e-04
#> [16,] 0.000000e+00 4.059826e-06 0.0016579126 8.374614e-05 5.795532e-05
#> [17,] -8.964540e-05 -7.074611e-06 -0.0028890618 -1.459352e-04 -1.009924e-04
#> [18,] 0.000000e+00 1.033598e-05 0.0042209092 2.132108e-04 1.475495e-04
#> [19,] 0.000000e+00 3.351191e-06 0.0013685271 6.912841e-05 4.783933e-05
#> [20,] 0.000000e+00 3.990045e-06 0.0016294162 8.230670e-05 5.695918e-05
#> [21,] 0.000000e+00 4.776118e-06 0.0019504253 9.852183e-05 6.818063e-05
#> [22,] -2.382720e-05 -1.880388e-06 -0.0007678950 -3.878868e-05 -2.684315e-05
#> [23,] -5.875128e-05 -4.636517e-06 -0.0018934164 -9.564215e-05 -6.618778e-05
#> [24,] 0.000000e+00 1.135580e-05 0.0046373735 2.342476e-04 1.621078e-04
#> [25,] 0.000000e+00 4.799334e-06 0.0019599061 9.900074e-05 6.851205e-05
#> [26,] 0.000000e+00 5.806026e-06 0.0023710091 1.197668e-04 8.288290e-05
#> [27,] 0.000000e+00 1.006099e-05 0.0041086109 2.075383e-04 1.436239e-04
#> [28,] 0.000000e+00 8.816084e-06 0.0036002276 1.818583e-04 1.258524e-04
#> [29,] 0.000000e+00 7.626559e-06 0.0031144610 1.573208e-04 1.088716e-04
#> Zea Chl_b Tchla
#> [1,] -5.567856e-03 9.448815e-04 0.187685895
#> [2,] -2.607023e-04 -2.799179e-03 0.261309749
#> [3,] -5.822210e-04 -2.060230e-03 0.211368078
#> [4,] -6.908480e-04 -1.690724e-03 0.183851301
#> [5,] -3.771899e-05 -4.049914e-04 0.037806876
#> [6,] -2.472877e-04 5.558496e-05 0.007126242
#> [7,] -2.616751e-03 2.521214e-03 -0.096261818
#> [8,] 5.718443e-05 6.139932e-04 -0.057317673
#> [9,] 2.478205e-05 2.660866e-04 -0.024839794
#> [10,] 8.635334e-05 9.271817e-04 -0.086554539
#> [11,] 4.315510e-05 4.633592e-04 -0.043255650
#> [12,] 4.759958e-05 5.110799e-04 -0.047710488
#> [13,] 4.402240e-05 4.726715e-04 -0.044124970
#> [14,] 7.647131e-05 8.210777e-04 -0.076649492
#> [15,] -6.213248e-05 -6.671206e-04 0.062277244
#> [16,] 2.104959e-05 2.260109e-04 -0.021098635
#> [17,] -2.353361e-04 -2.847293e-04 0.036766270
#> [18,] 5.359053e-05 5.754051e-04 -0.053715392
#> [19,] 1.737542e-05 1.865611e-04 -0.017415909
#> [20,] 2.068779e-05 2.221262e-04 -0.020735990
#> [21,] 2.476346e-05 2.658870e-04 -0.024821160
#> [22,] -9.749533e-06 -1.046814e-04 0.009772250
#> [23,] -2.403965e-05 -2.581154e-04 0.024095663
#> [24,] 5.887814e-05 6.321786e-04 -0.059015326
#> [25,] 2.488383e-05 2.671794e-04 -0.024941812
#> [26,] 3.010338e-05 3.232220e-04 -0.030173519
#> [27,] 5.216474e-05 5.600963e-04 -0.052286280
#> [28,] 4.571008e-05 4.907922e-04 -0.045816583
#> [29,] 3.954257e-05 4.245713e-04 -0.039634706
Results$`F matrix`
#> Per X19but Fuco X19hex Allo Zea Chl_b Tchla
#> Chlorophytes 0.0000 0.0000 0.0000 0.0000 0.0000 0.0542 0.7711 1
#> Cryptophytes 0.0000 0.0000 0.0000 0.0000 0.4045 0.0000 0.0000 1
#> Diatoms-2 0.0000 0.0000 0.7832 0.0000 0.0000 0.0000 0.0000 1
#> Dinoflagellates-1 0.4557 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 1
#> Haptophytes 0.0000 0.1989 0.0421 0.7081 0.0000 0.0000 0.0000 1
#> Pelagophytes 0.0000 0.5419 0.7097 0.0000 0.0000 0.0000 0.0000 1
#> Syn 0.0000 0.0000 0.0000 0.0000 0.0000 1.1137 0.0000 1
Results$`Class abundances`
#> Chlorophytes Cryptophytes Diatoms-2 Dinoflagellates-1 Haptophytes
#> [1,] 0.15834313 7.915004e-03 0.10671096 0.0010327571 0.16611583
#> [2,] 0.03268850 6.485539e-03 0.04950397 0.0005013540 0.03526144
#> [3,] 0.11245503 2.306784e-02 0.40923776 0.0015468979 0.03778836
#> [4,] 0.11526962 2.036048e-02 0.41344038 0.0013255485 0.03873310
#> [5,] 0.08086218 3.967525e-03 0.37155416 0.0002034634 0.03214836
#> [6,] 0.05945988 3.592965e-05 0.26477368 0.0227033661 0.02721196
#> [7,] 0.03271381 1.422441e-03 0.13527590 0.0000000000 0.02996369
#> [8,] 0.00990526 9.327424e-03 0.48713224 0.0000000000 0.16706800
#> [9,] 0.01436618 1.409120e-01 0.72307445 0.0000000000 0.17825420
#> [10,] 0.03488547 6.102282e-03 0.09807421 0.0000000000 0.05029853
#> [11,] 0.18267632 6.802136e-02 0.58178479 0.0000000000 0.15683505
#> [12,] 0.10922336 0.000000e+00 0.29279194 0.0000000000 0.03872451
#> [13,] 0.10381203 0.000000e+00 0.16758525 0.0000000000 0.03525017
#> [14,] 0.15954498 1.900438e-02 0.26404124 0.0000000000 0.02628729
#> [15,] 0.24096607 8.848702e-02 0.86811862 0.0008730669 0.15784230
#> [16,] 0.23094102 1.690997e-02 0.24112274 0.0000000000 0.05444792
#> [17,] 0.57986330 4.311662e-02 0.85532601 0.0006453507 0.21052407
#> [18,] 0.15413764 2.221069e-02 0.24137928 0.0000000000 0.10277944
#> [19,] 0.32634875 4.586969e-02 0.49662473 0.0000000000 0.15028700
#> [20,] 0.27901617 5.817271e-02 0.40487353 0.0000000000 0.17460654
#> [21,] 0.29291343 3.920581e-02 0.43427253 0.0000000000 0.12085353
#> [22,] 0.20595137 4.592113e-02 0.79221858 0.0001191545 0.18444218
#> [23,] 0.16437932 3.677767e-02 0.55064414 0.0002198483 0.13626485
#> [24,] 0.06014461 2.445825e-02 0.15851616 0.0000000000 0.07430100
#> [25,] 0.10797016 3.238989e-02 0.21505374 0.0000000000 0.07395476
#> [26,] 0.08575036 1.930349e-02 0.19182321 0.0000000000 0.02916573
#> [27,] 0.04236822 1.305577e-02 0.11612727 0.0000000000 0.02830543
#> [28,] 0.04428572 1.103602e-02 0.10571588 0.0000000000 0.02856313
#> [29,] 0.11311736 2.111309e-02 0.07101563 0.0000000000 0.06357787
#> Pelagophytes Syn
#> [1,] 0.01839232 0.0000000000
#> [2,] 0.01995823 0.0013109662
#> [3,] 0.02860410 0.0000000000
#> [4,] 0.03157088 0.0000000000
#> [5,] 0.03805200 0.0034123091
#> [6,] 0.03151519 0.0000000000
#> [7,] 0.01232416 0.0000000000
#> [8,] 0.01375126 0.0013158172
#> [9,] 0.02602696 0.0022662147
#> [10,] 0.01607266 0.0005668512
#> [11,] 0.02612216 0.0242210487
#> [12,] 0.02046392 0.0200005810
#> [13,] 0.02472735 0.0095330995
#> [14,] 0.01343317 0.0069791289
#> [15,] 0.00000000 0.0248771162
#> [16,] 0.02728174 0.0004115478
#> [17,] 0.05186412 0.0000000000
#> [18,] 0.05103358 0.0061300652
#> [19,] 0.05281138 0.0019894089
#> [20,] 0.07049965 0.0037323916
#> [21,] 0.06261262 0.0021904816
#> [22,] 0.01473264 0.0060834235
#> [23,] 0.02656354 0.0042171241
#> [24,] 0.02389951 0.0073362476
#> [25,] 0.02091277 0.0053609420
#> [26,] 0.01861606 0.0051147374
#> [27,] 0.03053354 0.0063282991
#> [28,] 0.01609522 0.0060111126
#> [29,] 0.02993508 0.0027099260