Title: Estimate Chla Concentrations of Phytoplankton Groups
Version: 2.3.1
Description: Determine the chlorophyll a (Chl a) concentrations of different phytoplankton groups based on their pigment biomarkers. The method uses non-negative matrix factorisation and simulated annealing to minimise error between the observed and estimated values of pigment concentrations (Hayward et al. (2023) <doi:10.1002/lom3.10541>). The approach is similar to the widely used 'CHEMTAX' program (Mackey et al. 1996) <doi:10.3354/meps144265>, but is more straightforward, accurate, and not reliant on initial guesses for the pigment to Chl a ratios for phytoplankton groups.
Imports: bestNormalize, dynamicTreeCut, ggplot2, RcppML, stats, tidyr, progress
License: MIT + file LICENSE
Encoding: UTF-8
RoxygenNote: 7.3.2
Depends: R (≥ 3.8)
LazyData: true
Suggests: knitr, rmarkdown, testthat (≥ 3.0.0), quarto, here
VignetteBuilder: knitr
URL: https://github.com/phytoclass/phytoclass/
BugReports: https://github.com/phytoclass/phytoclass/issues/
Config/testthat/edition: 3
NeedsCompilation: no
Packaged: 2026-01-30 14:44:01 UTC; tylar
Author: Alexander Hayward [aut, cre, cph], Tylar Murray [aut], Sebastian Di Geronimo [aut], Mohd Aasim Maqsood Khan [aut], Andy McKenzie [aut]
Maintainer: Alexander Hayward <phytoclass@outlook.com>
Repository: CRAN
Date/Publication: 2026-01-30 15:20:03 UTC

Add weights to the data, bound at a maximum.

Description

Add weights to the data, bound at a maximum.

Usage

Bounded_weights(S, weight.upper.bound = 30)

Arguments

S

Sample data matrix – a matrix of pigment samples

weight.upper.bound

Upper bound for weights (default is 30)

Value

A vector with upper bounds for weights

Examples

Bounded_weights(Sm, weight.upper.bound = 30)


Cluster things

Description

Cluster things

Usage

Cluster(
  Data,
  minSamplesPerCluster,
  row_ids = NULL,
  dist_method = "euclidean",
  hclust_method = "ward.D2"
)

Arguments

Data

S (sample) matrix

minSamplesPerCluster

the minimum number of samples required for a cluster

row_ids

A vector of custom row names to be added to dendrogram

dist_method

Distance metric to be used in stats::dist. This should be one of "euclidean", "maximum", "manhattan", "canberra", "binary" or "minkowski".

hclust_method

Cluster method to be used in stats::hclust. This should be one of "ward.D", "ward.D2", "single", "complete", "average" (= UPGMA), "mcquitty" (= WPGMA), "median" (= WPGMC) or "centroid" (= UPGMC).

Value

A named list of length two. The first element "cluster.list" is a list of clusters, and the second element "cluster.plot" the cluster analysis object (dendogram) that can be plotted.

Examples

Cluster.result <- Cluster(Sm, 14)
Cluster.result$cluster.list
plot(Cluster.result$cluster.plot)

Calculate the mean condition number for randomized F matrices

Description

Performs multiple simulations with randomized F matrices within given bounds to assess the numerical stability of the system.

Usage

Condition_test(S, Fn, min.val = NULL, max.val = NULL)

Arguments

S

Sample matrix of pigment measurements

Fn

Initial F matrix of pigment ratios

min.val

Optional vector of minimum values for each non-zero pigment ratio

max.val

Optional vector of maximum values for each non-zero pigment ratio

Value

Numeric value representing the mean condition number from 1000 simulations

Examples

# Create sample matrices
Fmat <- as.matrix(phytoclass::Fm)
S <- as.matrix(phytoclass::Sm)
min_max <- phytoclass::min_max
min.val <- min_max[[3]]
max.val <- min_max[[4]]
# Use only non-chla columns for Fmat and S, as in simulated_annealing
Fmat_sub <- Fmat[, -ncol(Fmat)]
S_sub <- S[, -ncol(S)]
# Calculate mean condition number
cond <- phytoclass:::Condition_test(S_sub, Fmat_sub, min.val, max.val)

Conduit between minimise_elements function and Fac_F_R of steepest descent algorithm.

Description

Conduit between minimise_elements function and Fac_F_R of steepest descent algorithm.

Usage

Conduit(Fmat, place, S, cm, c_num = c(1, 2, 3))

Arguments

Fmat

A matrix of contribution values for each pigment and taxa pair

place

Indices of elements to be modified

S

Matrix of pigment sample measurements

cm

Vector of weights for each column

c_num

A numeric value (1, 2, or 3) to select which scaler values to use

Value

A list containing three elements: 1: The modified F matrix 2: Number of iterations or modifications made 3: The original F matrix before modifications

Examples

Fmat <- as.matrix(phytoclass::Fm)
S <- as.matrix(phytoclass::Sm)
S_weights <- as.numeric(phytoclass:::Bounded_weights(S))
place <- which(Fmat[, seq(ncol(Fmat) - 2)] > 0)

# Get F_initial from NNLS_MF as done in Steepest_Descent
F_initial <- phytoclass::NNLS_MF(Fmat, S, S_weights)

result <- phytoclass:::Conduit(F_initial[[1]], place, S, S_weights, c_num = 3)

Sets the default minimum and maximum values for phytoplankton groups pigment ratios. To use this function, pigment and phytoplankton group names will need to fit the naming criteria of phytoclass.

Description

Sets the default minimum and maximum values for phytoplankton groups pigment ratios. To use this function, pigment and phytoplankton group names will need to fit the naming criteria of phytoclass.

Usage

Default_min_max(min_max, Fmat)

Arguments

min_max

A data.frame with 4 columns for class, pigment, min and max values

Fmat

F matrix with phytoplankton groups as rows and pigments as columns

Value

A list containing two elements: 1: Vector of minimum values for each non-zero pigment ratio 2: Vector of maximum values for each non-zero pigment ratio

Examples

# Create a sample F matrix
Fmat <- phytoclass::Fm

# Create min_max data frame
min_max <- phytoclass::min_max
result <- phytoclass:::Default_min_max(min_max, Fmat)

Part of the steepest descent algorithm that works to reduce error given the S and F matrices.

Description

Part of the steepest descent algorithm that works to reduce error given the S and F matrices.

Usage

Fac_F_RR(Fmat, vary, S, cm, fac_rr = c(1, 2, 3), place = NULL)

Arguments

Fmat

A list containing ⁠F matrix⁠, RMSE and ⁠C matrix⁠

vary

Indices of non-zero elements to vary in the optimization

S

A matrix of samples (rows) and pigments (columns)

cm

A vector of bounded weights for each pigment

fac_rr

A numeric value (1, 2, or 3) to select which scaler values to use: 1: (0.99, 1.01), 2: (0.98, 1.02), 3: (0.97, 1.03)

place

A vector of all the indices of non-zero pigment ratios

Value

A list containing two elements: 1: Updated F matrix after optimization 2: Vector of indices

Examples

 # Setup based on Minimise_elements_comb usage
 Fmat <- as.matrix(phytoclass::Fm)
 S <- as.matrix(phytoclass::Sm)
 cm <- as.numeric(phytoclass:::Bounded_weights(S))
 place <- which(Fmat[, seq(ncol(Fmat) - 2)] > 0)

 # Get F.new from Conduit as done in Minimise_elements_comb
 f <- phytoclass:::Conduit(Fmat, place, S, cm, c_num = 3)
 F.new <- f[[1]]

 # Set place1 as done in Minimise_elements_comb
 place1 <- place # place1 = place when c1_num != 1

 # Run Fac_F_RR
 result <- phytoclass:::Fac_F_RR(F.new, vary = place, place = place1, S, cm, fac_rr = 3)

Fm data

Description

Fm data

Usage

Fm

Format

Fm

A data frame with 9 rows and 15 columns:

chl_c1

XX

Per

XX

X19but

XX

...

Source

XX


Fp data

Description

Fp data

Usage

Fp

Format

Fp

A data frame with 9 rows and 15 columns:

chl_c1

XX

Per

XX

X19but

XX

...

Source

XX


Remove any column values that average 0. Further to this, also remove phytoplankton groups from the F matrix if their diagnostic pigment isn’t present.

Description

Remove any column values that average 0. Further to this, also remove phytoplankton groups from the F matrix if their diagnostic pigment isn’t present.

Usage

Matrix_checks(S, Fmat)

Arguments

S

Sample data matrix – a matrix of pigment samples

Fmat

Pigment to Chl a matrix

Value

Named list with new S and Fmat matrices

Examples

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


Part of the steepest descent algorithm

Description

Part of the steepest descent algorithm

Usage

Minimise_elements_comb(Fmat, place, S, cm, c1_num = c(1, 2, 3))

Arguments

Fmat

The F matrix

place

A vector of indices indicating which elements to adjust

S

A matrix of samples (rows) and pigments (columns)

cm

A vector of bounded weights for each pigment

c1_num

A numeric vector (1, 2, or 3) indicating which scaler values to use

Value

A list containing the F matrix with updated ratios, the RMSE of new estimates, and an updated C matrix of estimated group contribution.

Examples

 Fmat <- as.matrix(phytoclass::Fm)
 S <- as.matrix(phytoclass::Sm)
 S_weights <- as.numeric(phytoclass:::Bounded_weights(S))
 place <- which(Fmat[, seq(ncol(Fmat) - 2)] > 0)

 # Get F_initial from NNLS_MF as done in Steepest_Descent
 F_initial <- phytoclass::NNLS_MF(Fmat, S, S_weights)

 # Run Minimise_elements_comb with c1_num = 3 (as in Steepest_Descent)
 result <- phytoclass:::Minimise_elements_comb(
   F_initial[[1]], place, S, S_weights, c1_num = 3
 )

Performs the non-negative matrix factorisation for given phytoplankton pigments and pigment ratios, to attain an estimate of phytoplankton class abundances.

Description

Performs the non-negative matrix factorisation for given phytoplankton pigments and pigment ratios, to attain an estimate of phytoplankton class abundances.

Usage

NNLS_MF(Fn, S, S_weights = NULL)

Arguments

Fn

Pigment to Chl a matrix

S

Sample data matrix – a matrix of pigment samples

S_weights

Weights for each column

Value

A list containing

  1. The F matrix (pigment: Chl a) ratios

  2. The root mean square error (RMSE)

  3. The C matrix (class abundances for each group)

Examples

 Fmat <- as.matrix(phytoclass::Fm)
 S <- as.matrix(phytoclass::Sm)
 S_weights <- as.numeric(phytoclass:::Bounded_weights(S))
 place <- which(Fmat[, seq(ncol(Fmat) - 2)] > 0)
 num.loops <- 2
 # Run Steepest_Descent
 result <- phytoclass:::Steepest_Descent(Fmat, place, S, S_weights, num.loops)


Perform matrix factorisation for phytoplankton pigments and pigments ratios

Description

Performs the non-negative matrix factorisation for given phytoplankton pigments and pigment ratios, to attain an estimate of phytoplankton class abundances.

Usage

NNLS_MF_Final(Fn, S, S_Chl, S_weights, S_dvChl = NULL)

Arguments

Fn

F matrix with pigment ratios for each phytoplankton class

S

Sample data matrix of pigment measurements

S_Chl

Vector of chlorophyll a concentrations for each sample

S_weights

Vector of weights for each pigment

S_dvChl

Optional vector of divinyl chlorophyll concentrations for Prochlorococcus

Details

Unlike NNLS_ML(), it also removes any weighting and normalisation, and also multiplies relative abundances by chlorophyll values to determine the biomass of phytoplankton groups.

Value

A list containing the following elements:

F matrix

The normalized F matrix of pigment ratios

RMSE

Root mean square error of the fit

condition number

Condition number of Fn %*% t(S)

Class abundances

Data frame of phytoplankton class abundances

Figure

Plot of the results

MAE

Mean absolute error for each pigment

Error

Residual error matrix

Examples

 Fmat <- as.matrix(phytoclass::Fm)
 S <- as.matrix(phytoclass::Sm)
 S_weights <- as.numeric(phytoclass:::Bounded_weights(S))
 S_Chl <- S[, ncol(S)]
 # Run NNLS_MF_Final
 result <- phytoclass:::NNLS_MF_Final(Fmat, S, S_Chl, S_weights)

This function normalises each column in F to row sum

Description

This function normalises each column in F to row sum

Usage

Normalise_F(Fmat)

Arguments

Fmat

A matrix or data.frame with the last column containing non-zeros

Value

A list consisting of two components: - a matrix of pigment ratios normalized to row sums - a vector of row sums


Normalise matrix to row sum

Description

This function normalises each column in S to row sum

Usage

Normalise_S(S)

Arguments

S

A matrix or data.frame to be normalized

Value

A matrix

Examples

# Create a sample matrix
S <- as.matrix(phytoclass::Sm)
normalized <- phytoclass:::Normalise_S(S)


Normalize F matrix specifically for Prochlorococcus pigments

Description

Normalizes pigment ratios differently for Prochlorococcus vs other groups, using divinyl chlorophyll a for Prochlorococcus and chlorophyll a for others.

Usage

Prochloro_Normalise_F(Fmat)

Arguments

Fmat

Matrix with pigment ratios, where the last column is chlorophyll a and second-to-last column is divinyl chlorophyll a

Value

A list containing: 1: Normalized matrix where each row is scaled by its biomass marker 2: Vector of row sums from the scaled matrix

Examples

# Create sample F matrix with Prochlorococcus
Fmat <- as.matrix(phytoclass::Fp)
result <- phytoclass:::Prochloro_Normalise_F(Fmat)

Selects a random neighbour for a subset of non-zero pigments that are outside the min and max bounds for the simulated annealing algorithm, specifically handling Prochlorococcus pigments.

Description

Selects a random neighbour for a subset of non-zero pigments that are outside the min and max bounds for the simulated annealing algorithm, specifically handling Prochlorococcus pigments.

Usage

Prochloro_Random_Neighbour(
  f_new,
  Temp,
  chlv,
  chlvp,
  N,
  place,
  S,
  S_weights,
  minF,
  maxF
)

Arguments

f_new

F matrix of pigment ratios

Temp

Temperature of the annealing

chlv

Chlorophyll-a column

chlvp

Dvchla column

N

Indexs of pigment ratios to be changed

place

Indexes in F matrix where values are non-zero

S

S matrix of samples

S_weights

Weights for NNLS algorithm

minF

Minimum bounds for each phytoplankton group and pigments

maxF

Maximum bounds for each phytoplankton group and pigments

Value

A list containing:

F matrix

The new F matrix with randomly modified values

RMSE

Root mean square error of the new solution

C matrix

The concentration matrix from NNLS

Examples

 Fmat <- as.matrix(phytoclass::Fp)
 S <- as.matrix(phytoclass::Sp)
 S_weights <- as.numeric(phytoclass:::Bounded_weights(S))
 place <- which(Fmat[, seq(ncol(Fmat) - 2)] > 0)

 # Get min_max from package data
 min_max_mat <- phytoclass:::Default_min_max(phytoclass::min_max, Fmat[, -ncol(Fmat)])

 # Get bounds using Prochloro_Wrangling as in simulated_annealing_Prochloro
 f_c <- Fmat
 W0 <- phytoclass:::Prochloro_Wrangling(f_c, min_max_mat[[1]], min_max_mat[[2]])
 minF <- W0[[1]]
 maxF <- W0[[2]]

 # Extract chlv and chlvp from the matrix
 chlv <- f_c[, ncol(f_c)] # Chl a (Tchla)
 chlvp <- f_c[, ncol(f_c) - 1] # dvChl a

 Temp <- 0.5
 N <- place

 # Run Prochloro_Random_Neighbour
 result <- phytoclass:::Prochloro_Random_Neighbour(
   f_c, Temp, chlv, chlvp, N, place, S, S_weights, minF, maxF
 )

Prochloro Wrangling

Description

Prochloro Wrangling

Usage

Prochloro_Wrangling(Fl, min.val, max.val)

Arguments

Fl

Initial F matrix (i.e. pigment ratio matrix)

min.val

A vector of minimum values for each non-zero pigment ratio

max.val

A vector of maximum values for each non-zero pigment ratio

Value

A list containing vectorized min/max bounds and current values for Prochlorococcus-aware normalization


Select a random neighbour when the previous random neighbour is beyond the minimum or maximum value. Part of the simulated annealing algorithm.

Description

Select a random neighbour when the previous random neighbour is beyond the minimum or maximum value. Part of the simulated annealing algorithm.

Usage

Random_neighbour(f_new, Temp, chlv, N, place, S, S_weights, minF, maxF)

Arguments

f_new

Current F matrix of pigment ratios

Temp

Current temperature in the annealing process

chlv

Chlorophyll-a column to append to the matrix

N

Indices of pigment ratios to be modified

place

Vector of indices where values are non-zero in the F matrix

S

Matrix of samples (rows) and pigments (columns)

S_weights

Vector of weights for each pigment in NNLS

minF

Minimum bounds for each pigment ratio

maxF

Maximum bounds for each pigment ratio

Value

A list containing:

F matrix

The new F matrix with randomly modified values

RMSE

Root mean square error of the new solution

C matrix

The concentration matrix from NNLS

Examples

 # Setup based on simulated_annealing usage
 Fmat <- as.matrix(phytoclass::Fm)
 S <- as.matrix(phytoclass::Sm)
 S_weights <- as.numeric(phytoclass:::Bounded_weights(S))
 place <- which(Fmat[, seq(ncol(Fmat) - 2)] > 0)
 min_max <- phytoclass::min_max
 minF <- min_max[[3]][seq_along(place)]
 maxF <- min_max[[4]][seq_along(place)]
 chlv <- rep(1, nrow(Fmat)) # typical usage in simulated_annealing
 Temp <- 0.5
 N <- place
 # Run Random_neighbour
 result <- phytoclass:::Random_neighbour(Fmat, Temp, chlv, N, place, S, S_weights, minF, maxF)

Randomise value by applying scaling factors within specified bounds. Small values (< 0.001) are set to 0.001 to avoid numerical issues.

Description

Randomise value by applying scaling factors within specified bounds. Small values (< 0.001) are set to 0.001 to avoid numerical issues.

Usage

Randomise_elements(x, min.scaler, max.scaler)

Arguments

x

The element value to randomize

min.scaler

Minimum scaling factor to apply (e.g., 0.99 for 1% decrease)

max.scaler

Maximum scaling factor to apply (e.g., 1.01 for 1% increase)

Value

A numeric value between xmin.scaler and xmax.scaler, rounded to 4 decimals

Examples

# Randomize a single value
x <- 0.5
new_value <- phytoclass:::Randomise_elements(x, 0.99, 1.01)  # +/- 1% change

# Handle small values
small_x <- 0.0005
new_small <- phytoclass:::Randomise_elements(small_x, 0.99, 1.01)  # will use 0.001

Select the new F matrix element with lowest error in the steepest descent algorithm. Randomly modifies a single element and checks if the modification reduces the error.

Description

Select the new F matrix element with lowest error in the steepest descent algorithm. Randomly modifies a single element and checks if the modification reduces the error.

Usage

Replace_Rand(Fmat, i, S, cm, min.scaler, max.scaler)

Arguments

Fmat

A list containing the F matrix, RMSE, and other components

i

The index of the element to modify in the F matrix

S

Sample data matrix - matrix of pigment samples

cm

A vector of bounded weights for each pigment

min.scaler

Minimum scaling factor to apply (e.g., 0.99 for 1% decrease)

max.scaler

Maximum scaling factor to apply (e.g., 1.01 for 1% increase)

Value

A list containing:

F matrix

The modified F matrix

RMSE

Root mean square error of the new solution

C matrix

The concentration matrix

Improved

Logical indicating if the modification reduced error

Examples

 # Setup based on Fac_F_RR usage
 Fmat <- as.matrix(phytoclass::Fm)
 S <- as.matrix(phytoclass::Sm)
 cm <- as.numeric(phytoclass:::Bounded_weights(S))

 # Get Fmat as a list from NNLS_MF (as used in Fac_F_RR)
 Fmat_list <- phytoclass::NNLS_MF(Fmat, S, cm)

 # Test with a single index
 i <- 1 # first non-zero element to modify
 min.scaler <- 0.99
 max.scaler <- 1.01

 # Run Replace_Rand
 result <- phytoclass:::Replace_Rand(Fmat_list, i, S, cm, min.scaler, max.scaler)

Apply the steepest descent algorithm to optimize pigment ratios in phytoplankton classification. Loosely wraps Seepest_Descent function.

Description

Apply the steepest descent algorithm to optimize pigment ratios in phytoplankton classification. Loosely wraps Seepest_Descent function.

Usage

SAALS(Ft, min.value, max.value, place, S, cm, num.loops)

Arguments

Ft

Initial F matrix containing pigment ratios

min.value

UNUSED?

max.value

UNUSED?

place

Vector of indices where F matrix has non-zero values

S

Matrix of sample measurements

cm

Vector of bounded weights for each pigment

num.loops

Maximum number of iterations for the steepest descent

Value

A list containing: 1: The optimized F matrix 2: Final RMSE value

Examples

 Fmat <- as.matrix(phytoclass::Fm)
 S <- as.matrix(phytoclass::Sm)
 S_weights <- as.numeric(phytoclass:::Bounded_weights(S))
 place <- which(Fmat[, seq(ncol(Fmat) - 2)] > 0)
 num.loops <- 2
 # Run SAALS
 result <- phytoclass:::SAALS(Fmat, NULL, NULL, place, S, S_weights, num.loops)

Sm data

Description

Sm data

Usage

Sm

Format

Sm

A data frame with 29 rows and 15 columns:

chl_c1

XX

Per

XX

X19but

XX

...

Source

XX


Sp data

Description

Sp data

Usage

Sp

Format

Sp

A data frame with 29 rows and 15 columns:

chl_c1

XX

Per

XX

X19but

XX

...

Source

XX


Stand-alone version of steepest descent algorithm. This is similar to the CHEMTAX steepest descent algorithm. It is not required to use this function, and as results are not bound by minimum and maximum, results may be unrealistic.

Description

Stand-alone version of steepest descent algorithm. This is similar to the CHEMTAX steepest descent algorithm. It is not required to use this function, and as results are not bound by minimum and maximum, results may be unrealistic.

Usage

Steepest_Desc(Fmat, S, num.loops)

Arguments

Fmat

Pigment to Chl a matrix

S

Sample data matrix – a matrix of pigment samples

num.loops

Number of loops/iterations to perform (no default)

Value

A list containing

  1. The F matrix (pigment: Chl a) ratios

  2. RMSE (Root Mean Square Error)

  3. Condition number

  4. class abundances

  5. Figure (plot of results)

  6. MAE (Mean Absolute Error)

Examples

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


Performs the steepest descent algorithm for a set number of iterations to optimize the F matrix of pigment ratios.

Description

Performs the steepest descent algorithm for a set number of iterations to optimize the F matrix of pigment ratios.

Usage

Steepest_Descent(Fmat, place, S, S_weights, num.loops)

Arguments

Fmat

Initial F matrix containing pigment ratios

place

Vector of indices where F matrix has non-zero values

S

Matrix of sample measurements (rows) and pigments (columns)

S_weights

Vector of weights for each pigment in NNLS optimization

num.loops

Maximum number of iterations to perform optimization

Value

A list containing: 1: The optimized F matrix 2: Final RMSE value 3: The C matrix (class abundances for each group)

Examples

 Fmat <- as.matrix(phytoclass::Fm)
 S <- as.matrix(phytoclass::Sm)
 S_weights <- as.numeric(phytoclass:::Bounded_weights(S))
 place <- which(Fmat[, seq(ncol(Fmat) - 2)] > 0)
 num.loops <- 2
 # Run Steepest_Descent
 result <- phytoclass:::Steepest_Descent(Fmat, place, S, S_weights, num.loops)

Apply weights to F/S matrices by diagonal multiplication

Description

Apply weights to F/S matrices by diagonal multiplication

Usage

Weight_error(S, cm)

Arguments

S

Matrix to be weighted

cm

Vector of weights to be applied to columns of S

Value

A matrix with weighted columns (S %*% diag(cm))

Examples

# Create sample matrix and weights
S <- as.matrix(phytoclass::Sm)
Fmat <- as.matrix(phytoclass::Fm)
S_weights <- as.numeric(phytoclass:::Bounded_weights(S))
weighted <- phytoclass:::Weight_error(Fmat, S_weights)

Wrangle data to vectors

Description

Converts data-types and selects data for randomisation in the simulated annealing algorithm

Usage

Wrangling(Fl, min.val, max.val)

Arguments

Fl

A matrix of the initial F matrix (i.e. pigment ratio matrix)

min.val

A vector of the minimum values for each non-zero pigment ratios

max.val

A vector of the maximum values for each non-zero pigment ratios

Value

A list containing following components:
- A vector Fmin with the minimum pigment ratio values
- A vector Fmax with the maximum pigment ratio values
- A vector SE with the current pigment ratio values
- A vector chlv with the pigment ratio values for the last column in Fl

Convergence Figure

Description

A figure to show the pigment ratios for each phytoplankton group for each iteration.

Usage

convergence_figure(fm_iter, niter = NULL)

Arguments

fm_iter

A data.frame with columns of iter, phyto, pigment and ratio

niter

Optional: the number of iterations on the x axis. If NULL, will extract from the iter column of fm_iter.

Value

A figure with each pigment ratio per iteration per group

Examples

# ADD_EXAMPLES_HERE

min_max data

Description

min_max data

Usage

min_max

Format

min_max

A data frame with 51 rows and 4 columns:

class

XX

Pig_Abbrev

XX

min

XX

max

max

...

Source

XX


Phytoplankton Class Abundance Figure

Description

This function plots the class abundances as output by simulated_annealing.

Usage

phyto_figure(c_matrix)

Arguments

c_matrix

C matrix of class abundance concentrations

Value

A stacked line plot with sample number on x axis, chl a concentrations on y axis, and phytoplankton groups as colors

Examples

# ADD_EXAMPLES_HERE

This is the main phytoclass algorithm. It performs simulated annealing algorithm for S and F matrices. See the examples (Fm, Sm) for how to set up matrices, and the vignette for more detailed instructions. Different pigments and phytoplankton groups may be used.

Description

This is the main phytoclass algorithm. It performs simulated annealing algorithm for S and F matrices. See the examples (Fm, Sm) for how to set up matrices, and the vignette for more detailed instructions. Different pigments and phytoplankton groups may be used.

Usage

simulated_annealing(
  S,
  Fmat = NULL,
  user_defined_min_max = NULL,
  do_matrix_checks = TRUE,
  niter = 500,
  step = 0.009,
  weight.upper.bound = 30,
  verbose = TRUE,
  seed = NULL,
  check_converge = 100,
  alt_pro_name = NULL
)

Arguments

S

Sample data matrix – a matrix of pigment samples

Fmat

Pigment to Chl a matrix

user_defined_min_max

data frame with some format as min_max built-in data

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 is 500)

step

Step ratio used (default is 0.009)

weight.upper.bound

Upper limit of the weights applied (default value is 30).

verbose

Logical value. Output error and temperature at each iteration. Default value of TRUE

seed

Set number to reproduce the same results

check_converge

TRUE/FALSE/integer; set the number of F matrices to for convergence checking

alt_pro_name

Optional: additional alternate versions of divinyl-chlorophyll-a spellings used to detect prochlorococcus (Default: "dvchl", "dvchla", "dv_chla")

Value

A list containing

  1. Fmat matrix

  2. RMSE (Root Mean Square Error)

  3. condition number

  4. Class abundances

  5. Figure (plot of results)

  6. MAE (Mean Absolute Error)

  7. Error

  8. F_mat_iter

  9. converge_plot

Examples

# Using the built-in matrices Sm and Fm
set.seed(5326)
sa.example <- simulated_annealing(Sm, Fm, niter = 5)
sa.example$Figure

Perform simulated annealing algorithm for samples with divinyl chlorophyll and prochlorococcus. Chlorophyll must be the final column of both S and F matrices, with Divinyl Chlorophyll a the 2nd to last column. See how the example Sp and Fp matrices are organised.

Description

Perform simulated annealing algorithm for samples with divinyl chlorophyll and prochlorococcus. Chlorophyll must be the final column of both S and F matrices, with Divinyl Chlorophyll a the 2nd to last column. See how the example Sp and Fp matrices are organised.

Usage

simulated_annealing_Prochloro(
  S,
  Fmat = NULL,
  user_defined_min_max = NULL,
  do_matrix_checks = TRUE,
  niter = 500,
  step = 0.009,
  weight.upper.bound = 30,
  verbose = TRUE,
  seed = NULL,
  check_converge = 100
)

Arguments

S

Sample data matrix – a matrix of pigment samples

Fmat

Pigment to Chl a matrix

user_defined_min_max

data frame with some format as min_max built-in data

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 is 500)

step

Step ratio used (default is 0.009)

weight.upper.bound

Upper limit of the weights applied (default value is 30).

verbose

Logical value. Output error and temperature at each iteration. Default value of TRUE

seed

Set seed number to reproduce the same results

check_converge

TRUE/FALSE/integer; set the number of F matrices to for convergence checking

Value

A list containing

  1. Fmat matrix

  2. RMSE (Root Mean Square Error)

  3. condition number

  4. Class abundances

  5. Figure (plot of results)

  6. MAE (Mean Absolute Error)

  7. Error

Examples

# Using the built-in matrices Sp and Fp.
set.seed(5326)
sa.example <- simulated_annealing_Prochloro(Sp, Fp, niter = 1)
sa.example$Figure

Vectorise a matrix and keep non-zero elements

Description

Turn each non-zero element of the F-matrix into a vector

Usage

vectorise(Fmat)

Arguments

Fmat

A matrix to vectorise

Value

A vector of non-zero pigment elements