| Title: | Metabolomics and Spectral Data Analysis and Mining |
|---|---|
| Description: | Provides methods for metabolomics and spectral data analysis, including data import, preprocessing, visualization, univariate and multivariate analysis, machine learning, feature selection, and pathway analysis. The package supports analytical workflows for different data types used in metabolomics and spectroscopy. Some optional functionality uses the suggested packages 'cyjShiny' and 'specmine.datasets'. The package 'specmine.datasets' is maintained separately at <https://github.com/PedroFontao/specmine.datasets>. |
| Authors: | Christopher Costa [aut], Marcelo Maraschin [aut], Miguel Rocha [aut], Sara Cardoso [aut], Telma Afonso [aut], Bruno Pereira [aut], Pedro Fontão [aut, cre], Rafael Moreira [aut], C. Beleites [cph], Jie Hao [cph] |
| Maintainer: | Pedro Fontão <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 4.0.0 |
| Built: | 2026-09-28 16:30:37 UTC |
| Source: | https://github.com/pedrofontao/specmine |
Aggregate samples according to an aggregate function like mean, median, etc. This can be used to merge replicates.
aggregate_samples(dataset, indexes, aggreg.fn = "mean", meta.to.remove = c())aggregate_samples(dataset, indexes, aggreg.fn = "mean", meta.to.remove = c())
dataset |
List representing the dataset from a metabolomics experiment. |
indexes |
Index vector with the samples that are going to be aggregated (e.g. c(1,1,2,2), this index vector will aggregate the first two samples and the last two samples). |
aggreg.fn |
Aggregation function (e.g. "mean", "median", etc). |
meta.to.remove |
Metadata variables to be removed. |
A dataset object in which samples have been aggregated according to 'indexes' and 'aggreg.fn', with updated 'data', 'metadata', and preserved dataset-level fields such as labels, type, and description.
data <- matrix( c(1, 2, 10, 12, 3, 4, 14, 16), nrow = 2, dimnames = list(c("x1", "x2"), c("s1", "s2", "s3", "s4")) ) metadata <- data.frame( class = factor(c("A", "A", "B", "B")), batch = c(1, 1, 2, 2), row.names = c("s1", "s2", "s3", "s4") ) dataset <- list( data = data, metadata = metadata, labels = list(), type = "example", description = "toy dataset" ) aggregate_samples(dataset, c(1, 1, 2, 2), "mean")data <- matrix( c(1, 2, 10, 12, 3, 4, 14, 16), nrow = 2, dimnames = list(c("x1", "x2"), c("s1", "s2", "s3", "s4")) ) metadata <- data.frame( class = factor(c("A", "A", "B", "B")), batch = c(1, 1, 2, 2), row.names = c("s1", "s2", "s3", "s4") ) dataset <- list( data = data, metadata = metadata, labels = list(), type = "example", description = "toy dataset" ) aggregate_samples(dataset, c(1, 1, 2, 2), "mean")
Applies adaptive iteratively reweighted penalized least squares (airPLS) baseline correction to Raman or surface-enhanced Raman spectroscopy (SERS) spectra.
airPLS_fast_dataset(dataset, lambda = 1e+05, max_iter = 50)airPLS_fast_dataset(dataset, lambda = 1e+05, max_iter = 50)
dataset |
A dataset list containing a numeric matrix in
|
lambda |
Positive numeric smoothing parameter. Larger values produce a smoother estimated baseline. |
max_iter |
Positive integer giving the maximum number of airPLS iterations. |
The dataset is expected to contain spectral variables or wavenumbers in rows and samples in columns. Each sample is baseline-corrected independently. Corrected spectra are shifted so that their minimum intensity is zero.
A dataset equivalent to dataset, with baseline-corrected
values stored in dataset$data. Details of the correction are stored
in dataset$baseline.
Zhang, Z.-M., Chen, S., and Liang, Y.-Z. (2010). Baseline correction using adaptive iteratively reweighted penalized least squares. Analyst, 135(5), 1138-1146. doi:10.1039/B922045C.
set.seed(123) dataset = list( data = matrix( rnorm(100, mean = 10, sd = 2), nrow = 10, dimnames = list( paste0("wavenumber", 1:10), paste0("sample", 1:10) ) ) ) corrected = airPLS_fast_dataset( dataset, lambda = 1e4, max_iter = 5 ) range(corrected$data)set.seed(123) dataset = list( data = matrix( rnorm(100, mean = 10, sd = 2), nrow = 10, dimnames = list( paste0("wavenumber", 1:10), paste0("sample", 1:10) ) ) ) corrected = airPLS_fast_dataset( dataset, lambda = 1e4, max_iter = 5 ) range(corrected$data)
Performs one-way ANOVA for all variables in a dataset.
aov_all_vars( dataset, column.class, doTukey = TRUE, write.file = FALSE, file.out = NULL )aov_all_vars( dataset, column.class, doTukey = TRUE, write.file = FALSE, file.out = NULL )
dataset |
Dataset to analyze. |
column.class |
Metadata column used to define groups. |
doTukey |
Logical. If TRUE, also performs TukeyHSD post-hoc test. |
write.file |
Logical. If TRUE, writes results to file. |
file.out |
Output file name. |
A data frame with ANOVA results for all variables.
datamatrix <- matrix( c(10, 11, 20, 21, 5, 6, 5, 6), nrow = 2, byrow = TRUE, dimnames = list(c("x1", "x2"), c("s1", "s2", "s3", "s4")) ) metadata <- data.frame( group = factor(c("A", "A", "B", "B")), row.names = c("s1", "s2", "s3", "s4") ) dataset <- list(data = datamatrix, metadata = metadata) aov_all_vars(dataset, "group", doTukey = FALSE)datamatrix <- matrix( c(10, 11, 20, 21, 5, 6, 5, 6), nrow = 2, byrow = TRUE, dimnames = list(c("x1", "x2"), c("s1", "s2", "s3", "s4")) ) metadata <- data.frame( group = factor(c("A", "A", "B", "B")), row.names = c("s1", "s2", "s3", "s4") ) dataset <- list(data = datamatrix, metadata = metadata) aov_all_vars(dataset, "group", doTukey = FALSE)
Performs one-way ANOVA for a single variable in a dataset.
aov_one_var(dataset, x.val, groups, doTukey = TRUE)aov_one_var(dataset, x.val, groups, doTukey = TRUE)
dataset |
Dataset to analyze. |
x.val |
Variable name or x value to test. |
groups |
Grouping factor. |
doTukey |
Logical. If TRUE, also performs TukeyHSD post-hoc test. |
A list with p-value, -log10(p), FDR, and optional Tukey results.
datamatrix <- matrix( c(10, 11, 20, 21, 5, 6, 5, 6), nrow = 2, byrow = TRUE, dimnames = list(c("x1", "x2"), c("s1", "s2", "s3", "s4")) ) metadata <- data.frame( group = factor(c("A", "A", "B", "B")), row.names = c("s1", "s2", "s3", "s4") ) dataset <- list(data = datamatrix, metadata = metadata) aov_one_var(dataset, "x1", metadata$group, doTukey = FALSE)datamatrix <- matrix( c(10, 11, 20, 21, 5, 6, 5, 6), nrow = 2, byrow = TRUE, dimnames = list(c("x1", "x2"), c("s1", "s2", "s3", "s4")) ) metadata <- data.frame( group = factor(c("A", "A", "B", "B")), row.names = c("s1", "s2", "s3", "s4") ) dataset <- list(data = datamatrix, metadata = metadata) aov_one_var(dataset, "x1", metadata$group, doTukey = FALSE)
Applies a function to the variables of samples belonging to a given group.
apply_by_group(dataset, fn.to.apply, metadata.var, var.value)apply_by_group(dataset, fn.to.apply, metadata.var, var.value)
dataset |
Dataset to analyze. |
fn.to.apply |
Function to apply. |
metadata.var |
Metadata variable used to define the group. |
var.value |
Value or values of the metadata variable to select. |
A named vector or matrix, depending on the output of 'fn.to.apply', containing the values obtained by applying the function to each variable across the samples belonging to the selected group.
data <- matrix( c(1, 2, 3, 4, 5, 6), nrow = 2, dimnames = list(c("x1", "x2"), c("s1", "s2", "s3")) ) metadata <- data.frame( group = c("control", "control", "case"), row.names = c("s1", "s2", "s3") ) dataset <- list(data = data, metadata = metadata) apply_by_group(dataset, mean, "group", "control")data <- matrix( c(1, 2, 3, 4, 5, 6), nrow = 2, dimnames = list(c("x1", "x2"), c("s1", "s2", "s3")) ) metadata <- data.frame( group = c("control", "control", "case"), row.names = c("s1", "s2", "s3") ) dataset <- list(data = data, metadata = metadata) apply_by_group(dataset, mean, "group", "control")
Applies a function to groups defined by a metadata variable.
apply_by_groups( dataset, metadata.var, fn.to.apply = "mean", variables = NULL, variable.bounds = NULL )apply_by_groups( dataset, metadata.var, fn.to.apply = "mean", variables = NULL, variable.bounds = NULL )
dataset |
Dataset to analyze. |
metadata.var |
Metadata variable used to define groups. |
fn.to.apply |
Function to apply. |
variables |
Variables to include. |
variable.bounds |
Optional numeric bounds for variables. |
A matrix-like object with one row per selected variable and one column per group defined by 'metadata.var'. Each cell contains the result of applying 'fn.to.apply' to the values of that variable within the corresponding group.
data <- matrix( c(1, 2, 3, 4, 5, 6), nrow = 2, dimnames = list(c("x1", "x2"), c("s1", "s2", "s3")) ) metadata <- data.frame( group = c("control", "control", "case"), row.names = c("s1", "s2", "s3") ) dataset <- list(data = data, metadata = metadata) apply_by_groups(dataset, "group", mean)data <- matrix( c(1, 2, 3, 4, 5, 6), nrow = 2, dimnames = list(c("x1", "x2"), c("s1", "s2", "s3")) ) metadata <- data.frame( group = c("control", "control", "case"), row.names = c("s1", "s2", "s3") ) dataset <- list(data = data, metadata = metadata) apply_by_groups(dataset, "group", mean)
Get kegg codes from hmdb codes:
convert_hmdb_to_kegg(hmdb_codes)convert_hmdb_to_kegg(hmdb_codes)
hmdb_codes |
Character vector of HMDB identifiers. |
A named character vector with the KEGG compound identifiers
corresponding to the input HMDB codes. The vector values are KEGG compound
codes prefixed with "cpd:", and the element names are the matched
compound names.
## Not run: convert_hmdb_to_kegg(c("HMDB0000122")) ## End(Not run)## Not run: convert_hmdb_to_kegg(c("HMDB0000122")) ## End(Not run)
Convert KEGGPathway object to graph object
convert_keggpathway_2_reactiongraph(pathObj)convert_keggpathway_2_reactiongraph(pathObj)
pathObj |
TODO. |
A graph object representing the reactions in the input
KEGGPathway object. The returned object is suitable for graph-based
inspection or for use in downstream visualization functions.
## Not run: path <- get_MetabolitePath("hsa00010") graph <- convert_keggpathway_2_reactiongraph(path) class(graph) ## End(Not run)## Not run: path <- get_MetabolitePath("hsa00010") graph <- convert_keggpathway_2_reactiongraph(path) class(graph) ## End(Not run)
Get kegg codes from spcmnm codes:
convert_multiple_spcmnm_to_kegg(spcmnm_codes)convert_multiple_spcmnm_to_kegg(spcmnm_codes)
spcmnm_codes |
Character vector of SPCMNM identifiers. |
A named character vector with the KEGG compound identifiers
corresponding to the input SPCMNM codes. The vector values are KEGG compound
codes prefixed with "cpd:", and the element names are the matched
compound names.
## Not run: convert_multiple_spcmnm_to_kegg(c("SPCM00001")) ## End(Not run)## Not run: convert_multiple_spcmnm_to_kegg(c("SPCM00001")) ## End(Not run)
Returns the total number of missing values in the dataset.
count_missing_values(dataset)count_missing_values(dataset)
dataset |
Dataset to inspect. |
A single numeric value giving the total count of 'NA' entries present in 'dataset$data'.
data <- matrix( c(1, NA, 3, 4), nrow = 2, dimnames = list(c("x1", "x2"), c("s1", "s2")) ) metadata <- data.frame(class = c("A", "B"), row.names = c("s1", "s2")) dataset <- list(data = data, metadata = metadata) count_missing_values(dataset)data <- matrix( c(1, NA, 3, 4), nrow = 2, dimnames = list(c("x1", "x2"), c("s1", "s2")) ) metadata <- data.frame(class = c("A", "B"), row.names = c("s1", "s2")) dataset <- list(data = data, metadata = metadata) count_missing_values(dataset)
Returns the number of missing values per sample.
count_missing_values_per_sample(dataset, remove.zero = TRUE)count_missing_values_per_sample(dataset, remove.zero = TRUE)
dataset |
Dataset to inspect. |
remove.zero |
If TRUE, removes zero counts. |
A named numeric vector giving the number of missing values for each sample in 'dataset$data'. If 'remove.zero' is 'TRUE', only samples with at least one missing value are returned.
data <- matrix( c(1, NA, 3, 4, 5, NA), nrow = 2, dimnames = list(c("x1", "x2"), c("s1", "s2", "s3")) ) metadata <- data.frame(class = c("A", "B", "A"), row.names = c("s1", "s2", "s3")) dataset <- list(data = data, metadata = metadata) count_missing_values_per_sample(dataset)data <- matrix( c(1, NA, 3, 4, 5, NA), nrow = 2, dimnames = list(c("x1", "x2"), c("s1", "s2", "s3")) ) metadata <- data.frame(class = c("A", "B", "A"), row.names = c("s1", "s2", "s3")) dataset <- list(data = data, metadata = metadata) count_missing_values_per_sample(dataset)
Returns the number of missing values per variable.
count_missing_values_per_variable(dataset, remove.zero = TRUE)count_missing_values_per_variable(dataset, remove.zero = TRUE)
dataset |
Dataset to inspect. |
remove.zero |
If TRUE, removes zero counts. |
A named numeric vector giving the number of missing values for each variable in 'dataset$data'. If 'remove.zero' is 'TRUE', only variables with at least one missing value are returned.
data <- matrix( c(1, 2, NA, 4, 5, NA), nrow = 2, dimnames = list(c("x1", "x2"), c("s1", "s2", "s3")) ) metadata <- data.frame(class = c("A", "B", "A"), row.names = c("s1", "s2", "s3")) dataset <- list(data = data, metadata = metadata) count_missing_values_per_variable(dataset)data <- matrix( c(1, 2, NA, 4, 5, NA), nrow = 2, dimnames = list(c("x1", "x2"), c("s1", "s2", "s3")) ) metadata <- data.frame(class = c("A", "B", "A"), row.names = c("s1", "s2", "s3")) dataset <- list(data = data, metadata = metadata) count_missing_values_per_variable(dataset)
Creates a dataset from a numeric matrix.
create_dataset( datamatrix, type = "undefined", metadata = NULL, description = "", sample.names = NULL, x.axis.values = NULL, label.x = NULL, label.values = NULL, xSet = NULL )create_dataset( datamatrix, type = "undefined", metadata = NULL, description = "", sample.names = NULL, x.axis.values = NULL, label.x = NULL, label.values = NULL, xSet = NULL )
datamatrix |
Matrix with numerical data; rows are variables and columns are samples. |
type |
Type of data, such as "nmr-spectra", "nmr-peaks", "ir-spectra", "uvv-spectra", "concentrations", or "undefined". |
metadata |
Optional metadata as a data frame or matrix. |
description |
Dataset description. |
sample.names |
Optional sample names. |
x.axis.values |
Optional x-axis values. |
label.x |
Optional x-axis label. |
label.values |
Optional value label. |
xSet |
Optional xSet object. |
A list representing a specmine dataset. The returned object contains at least the elements
data, a numeric matrix with variables in rows and samples in columns; type, a character
string identifying the dataset type; description, a character string describing the dataset;
metadata, a data frame with one row per sample when available; labels, a list with axis
and value labels when provided; and xSet, an optional object associated with LC-MS processing.
This object is the standard input structure used by downstream specmine analysis functions.
datamatrix <- matrix( c(1.1, 2.2, 3.3, 4.4, 5.5, 6.6), nrow = 2, dimnames = list(NULL, NULL) ) metadata <- data.frame( class = c("A", "B", "A"), row.names = c("s1", "s2", "s3") ) create_dataset( datamatrix, type = "concentrations", metadata = metadata, sample.names = c("s1", "s2", "s3"), x.axis.values = c("v1", "v2"), label.x = "variable", label.values = "intensity" )datamatrix <- matrix( c(1.1, 2.2, 3.3, 4.4, 5.5, 6.6), nrow = 2, dimnames = list(NULL, NULL) ) metadata <- data.frame( class = c("A", "B", "A"), row.names = c("s1", "s2", "s3") ) create_dataset( datamatrix, type = "concentrations", metadata = metadata, sample.names = c("s1", "s2", "s3"), x.axis.values = c("v1", "v2"), label.x = "variable", label.values = "intensity" )
Creates the pathway, with reactions included in the nodes
create_pathway_with_reactions( path, path.name, identified_cpds, nodeNames = "kegg", nodeTooltip = FALSE, map.zoom = FALSE, map.layout = "preset", map.width = NULL, map.height = NULL )create_pathway_with_reactions( path, path.name, identified_cpds, nodeNames = "kegg", nodeTooltip = FALSE, map.zoom = FALSE, map.layout = "preset", map.width = NULL, map.height = NULL )
path |
TODO. |
path.name |
TODO. |
identified_cpds |
TODO. |
nodeNames |
TODO. |
nodeTooltip |
TODO. |
map.zoom |
TODO. |
map.layout |
TODO. |
map.width |
TODO. |
map.height |
TODO. |
A cyjShiny widget representing the pathway with reactions
included in the nodes. The widget contains the pathway graph ready for
interactive visualization, with identified compounds highlighted when they
are present in the pathway.
## Not run: path <- get_MetabolitePath("hsa00010") create_pathway_with_reactions( path = path, path.name = "hsa00010", identified_cpds = c("cpd:C00031", "cpd:C00022") ) ## End(Not run)## Not run: path <- get_MetabolitePath("hsa00010") create_pathway_with_reactions( path = path, path.name = "hsa00010", identified_cpds = c("cpd:C00031", "cpd:C00022") ) ## End(Not run)
Merges equivalent peaks across samples, extracts intensities, and creates a dataset object in standard package format.
dataset_from_peaks( sample.list, metadata = NULL, description = "", type = "nmr-peaks" )dataset_from_peaks( sample.list, metadata = NULL, description = "", type = "nmr-peaks" )
sample.list |
A named list of peak tables, one per sample. |
metadata |
Optional sample metadata. |
description |
Character string with a dataset description. |
type |
Character string describing the dataset type. |
A dataset object created from the input peak lists.
sample.list <- list( s1 = data.frame(ppm = c(1.0, 2.0), int = c(10, 20)), s2 = data.frame(ppm = c(1.0, 3.0), int = c(15, 30)) ) metadata <- data.frame(class = c("A", "B"), row.names = c("s1", "s2")) dataset <- dataset_from_peaks(sample.list, metadata = metadata) class(dataset)sample.list <- list( s1 = data.frame(ppm = c(1.0, 2.0), int = c(10, 20)), s2 = data.frame(ppm = c(1.0, 3.0), int = c(15, 30)) ) metadata <- data.frame(class = c("A", "B"), row.names = c("s1", "s2")) dataset <- dataset_from_peaks(sample.list, metadata = metadata) class(dataset)
Performs feature selection using univariate filters.
filter_feature_selection( datamat, samples.class, functions = caret::rfSBF, method = "cv", repeats = 5 )filter_feature_selection( datamat, samples.class, functions = caret::rfSBF, method = "cv", repeats = 5 )
datamat |
Data matrix with features in rows and samples in columns. |
samples.class |
Sample class labels. |
functions |
Caret SBF functions list. |
method |
Resampling method passed to |
repeats |
Number of repeats for resampling. |
An sbf object.
datamat <- matrix( rnorm(20), nrow = 4, dimnames = list(paste0("x", 1:4), paste0("s", 1:5)) ) classes <- factor(c("A", "A", "B", "B", "A")) filter_feature_selection(datamat, classes, caret::rfSBF)datamat <- matrix( rnorm(20), nrow = 4, dimnames = list(paste0("x", 1:4), paste0("s", 1:5)) ) classes <- factor(c("A", "A", "B", "B", "A")) filter_feature_selection(datamat, classes, caret::rfSBF)
Performs a flat pattern filter over the dataset.
flat_pattern_filter( dataset, filter.function = "iqr", by.percent = TRUE, by.threshold = FALSE, red.value = 0 )flat_pattern_filter( dataset, filter.function = "iqr", by.percent = TRUE, by.threshold = FALSE, red.value = 0 )
dataset |
A dataset object to filter. |
filter.function |
Filtering function to use. One of '"iqr"', '"rsd"', '"rnsd"', '"sd"', '"mad"', '"mean"', or '"median"'. |
by.percent |
Logical. If 'TRUE', the number of variables to filter will be defined as a percentage of the number of variables in the dataset; percentage is given by 'red.value'. |
by.threshold |
Logical. If 'TRUE', filtering selects variables where the filtering function is above or equal to a threshold. |
red.value |
Reduction value. If 'by.percent = TRUE', this is the percentage of variables to remove, or '"auto"' for automatic calculation. If 'by.threshold = TRUE', this is the minimum value needed to keep the variable. |
A dataset object with the same overall structure as the input, where 'dataset$data' has been filtered according to the selected flat-pattern criterion. Variables failing the selection rule are removed, the remaining dataset components are preserved, and 'dataset$description' is updated to record the filtering step.
if (requireNamespace("specmine.datasets", quietly = TRUE)) { data(propolis, package = "specmine.datasets") propolis_proc = missingvalues_imputation(propolis) propolis_proc = flat_pattern_filter(propolis_proc, "iqr", by.percent = TRUE, red.value = 75) }if (requireNamespace("specmine.datasets", quietly = TRUE)) { data(propolis, package = "specmine.datasets") propolis_proc = missingvalues_imputation(propolis) propolis_proc = flat_pattern_filter(propolis_proc, "iqr", by.percent = TRUE, red.value = 75) }
Returns compound names associated with KEGG compound identifiers.
get_cpd_names(kegg_codes)get_cpd_names(kegg_codes)
kegg_codes |
Character vector of KEGG compound identifiers. |
A named character vector in which the values are KEGG compound
identifiers and the names are the corresponding compound names. Each element
of the returned vector represents one KEGG compound code matched to its
primary compound name.
## Not run: get_cpd_names(c("C00031", "C00022")) ## End(Not run)## Not run: get_cpd_names(c("C00031", "C00022")) ## End(Not run)
Downloads files and metadata for every assay in a public MetaboLights study.
get_metabolights_study(studyID, directory, verbose = TRUE)get_metabolights_study(studyID, directory, verbose = TRUE)
studyID |
Character string with the MetaboLights study identifier. |
directory |
Output directory where study files and metadata will be written. |
verbose |
Logical indicating whether progress messages should be shown. |
Invisibly returns a list with one entry per assay containing downloaded files,
metadata, and sample-file mappings.
## Not run: tmpdir <- tempdir() get_metabolights_study("MTBLS1", directory = tmpdir, verbose = FALSE) ## End(Not run)## Not run: tmpdir <- tempdir() get_metabolights_study("MTBLS1", directory = tmpdir, verbose = FALSE) ## End(Not run)
Downloads the data files associated with one assay of a MetaboLights study.
get_metabolights_study_files_assay(studyID, assay, directory, verbose = TRUE)get_metabolights_study_files_assay(studyID, assay, directory, verbose = TRUE)
studyID |
Character string with the MetaboLights study identifier. |
assay |
Numeric or character index selecting the assay in the study. |
directory |
Output directory where assay files will be downloaded. |
verbose |
Logical indicating whether progress messages should be shown. |
Invisibly returns a character vector with downloaded file paths.
## Not run: tmpdir <- tempdir() get_metabolights_study_files_assay("MTBLS1", assay = 1, directory = tmpdir, verbose = FALSE) ## End(Not run)## Not run: tmpdir <- tempdir() get_metabolights_study_files_assay("MTBLS1", assay = 1, directory = tmpdir, verbose = FALSE) ## End(Not run)
Returns the metadata associated with the samples in one assay of a MetaboLights study and can optionally save it as a CSV file.
get_metabolights_study_metadata_assay(studyID, assay, directory = NULL)get_metabolights_study_metadata_assay(studyID, assay, directory = NULL)
studyID |
Character string with the MetaboLights study identifier. |
assay |
Numeric or character index selecting the assay in the study. |
directory |
Optional output directory where the metadata CSV will be written. |
Invisibly returns a data.frame with sample metadata for the selected assay.
## Not run: md <- get_metabolights_study_metadata_assay("MTBLS1", assay = 1) head(md) ## End(Not run)## Not run: md <- get_metabolights_study_metadata_assay("MTBLS1", assay = 1) head(md) ## End(Not run)
Returns the sample-to-file mapping for one assay in a MetaboLights study and can optionally save it as a CSV file.
get_metabolights_study_samples_files(studyID, assay, directory = NULL)get_metabolights_study_samples_files(studyID, assay, directory = NULL)
studyID |
Character string with the MetaboLights study identifier. |
assay |
Numeric or character index selecting the assay in the study. |
directory |
Optional output directory where |
Invisibly returns a two-column object with samples and corresponding files.
## Not run: get_metabolights_study_samples_files("MTBLS1", assay = 1) ## End(Not run)## Not run: get_metabolights_study_samples_files("MTBLS1", assay = 1) ## End(Not run)
Returns an object of KEGGPathway of the pathway especified in pathcode
get_MetabolitePath(pathcode)get_MetabolitePath(pathcode)
pathcode |
TODO. |
A KEGGPathway object corresponding to the pathway specified by
pathcode. This object contains the parsed KEGG pathway structure and
can be used as input to downstream graph conversion and visualization
functions.
## Not run: path <- get_MetabolitePath("hsa00010") class(path) ## End(Not run)## Not run: path <- get_MetabolitePath("hsa00010") class(path) ## End(Not run)
Get vector with paths numbers that occur in the given organism, named with the full path name:
get_metabPaths_org(org_code)get_metabPaths_org(org_code)
org_code |
TODO. |
A named character vector with the pathway identifiers
available for the specified organism, where each value is an organism-specific
pathway code and each name is the corresponding KEGG pathway name.
## Not run: head(get_metabPaths_org("hsa")) ## End(Not run)## Not run: head(get_metabPaths_org("hsa")) ## End(Not run)
Get code, t number, full name and phylogeny of all organisms in KEGG:
get_OrganismsCodes()get_OrganismsCodes()
A data.frame with the KEGG T number, organism code, species
names, and phylogeny for all organisms available in KEGG. Each row
represents one organism and the columns are Tnumber,
organismCode, speciesNames, and phylogeny.
## Not run: head(get_OrganismsCodes()) ## End(Not run)## Not run: head(get_OrganismsCodes()) ## End(Not run)
Get only the paths of the organism that contain given compounds:
get_paths_with_cpds_org(organism_code, compounds, full.result = TRUE)get_paths_with_cpds_org(organism_code, compounds, full.result = TRUE)
organism_code |
TODO. |
compounds |
TODO. |
full.result |
TODO. |
A data.frame with the pathways containing the input compounds.
Each row represents one matched pathway. When full.result = TRUE, the
returned data frame includes the columns pathways, ratio,
compounds, and compounds_names; otherwise it contains only
pathways and ratio. Row names correspond to pathway names.
## Not run: cpds <- c(glucose = "cpd:C00031", pyruvate = "cpd:C00022") head(get_paths_with_cpds_org("hsa", cpds, full.result = FALSE)) ## End(Not run)## Not run: cpds <- c(glucose = "cpd:C00031", pyruvate = "cpd:C00022") head(get_paths_with_cpds_org("hsa", cpds, full.result = FALSE)) ## End(Not run)
Returns the x-axis label associated with the dataset.
get_x_label(dataset)get_x_label(dataset)
dataset |
Dataset object. |
A character string giving the label of the x axis stored in 'dataset$labels$x'. If no x-axis label has been defined, the function returns an empty string.
datamatrix <- matrix( c(1, 2, 3, 4), nrow = 2, dimnames = list(c("10.5", "11.0"), c("s1", "s2")) ) metadata <- data.frame(class = c("A", "B"), row.names = c("s1", "s2")) dataset <- create_dataset( datamatrix, type = "concentrations", metadata = metadata, label.x = "ppm", label.values = "intensity" ) get_x_label(dataset)datamatrix <- matrix( c(1, 2, 3, 4), nrow = 2, dimnames = list(c("10.5", "11.0"), c("s1", "s2")) ) metadata <- data.frame(class = c("A", "B"), row.names = c("s1", "s2")) dataset <- create_dataset( datamatrix, type = "concentrations", metadata = metadata, label.x = "ppm", label.values = "intensity" ) get_x_label(dataset)
Returns the x values of a dataset as text.
get_x_values_as_text(dataset)get_x_values_as_text(dataset)
dataset |
Dataset object. |
A character vector containing the variable identifiers stored in 'rownames(dataset$data)'. Each element corresponds to one row of the data matrix and represents the x-axis value or variable label associated with that feature.
datamatrix <- matrix( c(1, 2, 3, 4), nrow = 2, dimnames = list(c("10.5", "11.0"), c("s1", "s2")) ) metadata <- data.frame(class = c("A", "B"), row.names = c("s1", "s2")) dataset <- create_dataset( datamatrix, type = "concentrations", metadata = metadata ) get_x_values_as_text(dataset)datamatrix <- matrix( c(1, 2, 3, 4), nrow = 2, dimnames = list(c("10.5", "11.0"), c("s1", "s2")) ) metadata <- data.frame(class = c("A", "B"), row.names = c("s1", "s2")) dataset <- create_dataset( datamatrix, type = "concentrations", metadata = metadata ) get_x_values_as_text(dataset)
Performs Independent Component Analysis (ICA) on a specmine dataset using the FastICA algorithm.
ica_analysis_dataset( dataset, n_components = 2, alg.typ = "parallel", fun = "logcosh", maxit = 200, tol = 1e-04, scale = FALSE, seed = 42, write.file = FALSE, file.out = NULL, ... )ica_analysis_dataset( dataset, n_components = 2, alg.typ = "parallel", fun = "logcosh", maxit = 200, tol = 1e-04, scale = FALSE, seed = 42, write.file = FALSE, file.out = NULL, ... )
dataset |
Dataset to analyse. |
n_components |
Number of independent components to extract. |
alg.typ |
Algorithm used by FastICA. Supported values include
|
fun |
Contrast function used by FastICA. Supported values include
|
maxit |
Maximum number of iterations. |
tol |
Convergence tolerance. |
scale |
Logical indicating whether the data should be scaled before ICA. |
seed |
Random seed used for reproducibility. |
write.file |
Logical indicating whether the independent components should be written to a CSV file. |
file.out |
Output file prefix used when
|
... |
Additional arguments passed to |
A list containing:
embedding: the independent component scores;
S: the estimated source matrix;
A: the estimated mixing matrix;
K: the whitening matrix;
W: the estimated unmixing matrix;
loadings: the component loadings;
params: the analysis parameters.
if (requireNamespace("fastICA", quietly = TRUE)) { datamat <- matrix( rnorm(240), nrow = 8, dimnames = list( paste0("feature", 1:8), paste0("sample", 1:30) ) ) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), each = 15)) ) ) ica.result <- ica_analysis_dataset( dataset, n_components = 2, maxit = 100, seed = 42 ) dim(ica.result$embedding) }if (requireNamespace("fastICA", quietly = TRUE)) { datamat <- matrix( rnorm(240), nrow = 8, dimnames = list( paste0("feature", 1:8), paste0("sample", 1:30) ) ) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), each = 15)) ) ) ica.result <- ica_analysis_dataset( dataset, n_components = 2, maxit = 100, seed = 42 ) dim(ica.result$embedding) }
Creates a two-dimensional ICA plot coloured by k-means clusters.
ica_kmeans_plot2D( dataset, ica.result, num.clusters = 3, dims = c(1, 2), kmeans.result = NULL, use.embedding = TRUE, labels = FALSE, bw = FALSE, ellipses = FALSE, leg.pos = "right", xlim = NULL, ylim = NULL )ica_kmeans_plot2D( dataset, ica.result, num.clusters = 3, dims = c(1, 2), kmeans.result = NULL, use.embedding = TRUE, labels = FALSE, bw = FALSE, ellipses = FALSE, leg.pos = "right", xlim = NULL, ylim = NULL )
dataset |
Dataset to cluster. |
ica.result |
Result returned by |
num.clusters |
Number of k-means clusters. |
dims |
Two independent components to plot. |
kmeans.result |
Optional k-means result containing a |
use.embedding |
Logical indicating whether k-means should be applied
to the ICA embedding when |
labels |
Logical indicating whether sample labels should be displayed. |
bw |
Logical indicating whether a black-and-white plot should be used. |
ellipses |
Logical indicating whether group ellipses should be displayed. |
leg.pos |
Legend position. |
xlim |
Optional x-axis limits. |
ylim |
Optional y-axis limits. |
A ggplot object.
if (requireNamespace("fastICA", quietly = TRUE)) { datamat <- matrix(rnorm(240), nrow = 8) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), each = 15)) ) ) ica.result <- ica_analysis_dataset( dataset, n_components = 2, maxit = 100, seed = 42 ) kmeans.result <- list( cluster = rep(1:2, each = 15) ) ica_kmeans_plot2D( dataset, ica.result, num.clusters = 2, kmeans.result = kmeans.result ) }if (requireNamespace("fastICA", quietly = TRUE)) { datamat <- matrix(rnorm(240), nrow = 8) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), each = 15)) ) ) ica.result <- ica_analysis_dataset( dataset, n_components = 2, maxit = 100, seed = 42 ) kmeans.result <- list( cluster = rep(1:2, each = 15) ) ica_kmeans_plot2D( dataset, ica.result, num.clusters = 2, kmeans.result = kmeans.result ) }
Creates an interactive three-dimensional ICA plot coloured by k-means clusters.
ica_kmeans_plot3D( dataset, ica.result, num.clusters = 3, dims = c(1, 2, 3), kmeans.result = NULL, use.embedding = TRUE, title = "ICA 3D K-means Plot" )ica_kmeans_plot3D( dataset, ica.result, num.clusters = 3, dims = c(1, 2, 3), kmeans.result = NULL, use.embedding = TRUE, title = "ICA 3D K-means Plot" )
dataset |
Dataset to cluster. |
ica.result |
Result returned by |
num.clusters |
Number of k-means clusters. |
dims |
Three independent components to plot. |
kmeans.result |
Optional k-means result containing a |
use.embedding |
Logical indicating whether k-means should be applied
to the ICA embedding when |
title |
Plot title. |
A plotly htmlwidget.
if (requireNamespace("fastICA", quietly = TRUE) && requireNamespace("plotly", quietly = TRUE)) { datamat <- matrix(rnorm(240), nrow = 8) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), each = 15)) ) ) ica.result <- ica_analysis_dataset( dataset, n_components = 3, maxit = 100, seed = 42 ) kmeans.result <- list( cluster = rep(1:2, each = 15) ) ica_kmeans_plot3D( dataset, ica.result, num.clusters = 2, kmeans.result = kmeans.result ) }if (requireNamespace("fastICA", quietly = TRUE) && requireNamespace("plotly", quietly = TRUE)) { datamat <- matrix(rnorm(240), nrow = 8) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), each = 15)) ) ) ica.result <- ica_analysis_dataset( dataset, n_components = 3, maxit = 100, seed = 42 ) kmeans.result <- list( cluster = rep(1:2, each = 15) ) ica_kmeans_plot3D( dataset, ica.result, num.clusters = 2, kmeans.result = kmeans.result ) }
Creates a two-dimensional plot of the loadings associated with two independent components.
ica_loadingsplot(ica.result, dims = c(1, 2), top.n = NULL, labels = FALSE)ica_loadingsplot(ica.result, dims = c(1, 2), top.n = NULL, labels = FALSE)
ica.result |
Result returned by |
dims |
Two independent components whose loadings should be plotted. |
top.n |
Optional number of variables with the largest loading magnitude to display. |
labels |
Logical indicating whether variable labels should be displayed. |
A ggplot object.
if (requireNamespace("fastICA", quietly = TRUE)) { datamat <- matrix( rnorm(240), nrow = 8, dimnames = list( paste0("feature", 1:8), paste0("sample", 1:30) ) ) dataset <- list(data = datamat) ica.result <- ica_analysis_dataset( dataset, n_components = 2, maxit = 100, seed = 42 ) ica_loadingsplot( ica.result, dims = c(1, 2), labels = TRUE ) }if (requireNamespace("fastICA", quietly = TRUE)) { datamat <- matrix( rnorm(240), nrow = 8, dimnames = list( paste0("feature", 1:8), paste0("sample", 1:30) ) ) dataset <- list(data = datamat) ica.result <- ica_analysis_dataset( dataset, n_components = 2, maxit = 100, seed = 42 ) ica_loadingsplot( ica.result, dims = c(1, 2), labels = TRUE ) }
Creates a pairs plot for independent components coloured by k-means clusters.
ica_pairs_kmeans_plot( dataset, ica.result, num.clusters = 3, kmeans.result = NULL, use.embedding = TRUE, dims = 1:min(5, ncol(ica.result$embedding)) )ica_pairs_kmeans_plot( dataset, ica.result, num.clusters = 3, kmeans.result = NULL, use.embedding = TRUE, dims = 1:min(5, ncol(ica.result$embedding)) )
dataset |
Dataset to cluster. |
ica.result |
Result returned by |
num.clusters |
Number of k-means clusters. |
kmeans.result |
Optional k-means result containing a |
use.embedding |
Logical indicating whether k-means should be applied
to the ICA embedding when |
dims |
Independent components to include in the pairs plot. |
A GGally pairs plot object.
if (requireNamespace("fastICA", quietly = TRUE) && requireNamespace("GGally", quietly = TRUE)) { datamat <- matrix(rnorm(240), nrow = 8) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), each = 15)) ) ) ica.result <- ica_analysis_dataset( dataset, n_components = 3, maxit = 100, seed = 42 ) kmeans.result <- list( cluster = rep(1:2, each = 15) ) ica_pairs_kmeans_plot( dataset, ica.result, num.clusters = 2, kmeans.result = kmeans.result, dims = 1:3 ) }if (requireNamespace("fastICA", quietly = TRUE) && requireNamespace("GGally", quietly = TRUE)) { datamat <- matrix(rnorm(240), nrow = 8) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), each = 15)) ) ) ica.result <- ica_analysis_dataset( dataset, n_components = 3, maxit = 100, seed = 42 ) kmeans.result <- list( cluster = rep(1:2, each = 15) ) ica_pairs_kmeans_plot( dataset, ica.result, num.clusters = 2, kmeans.result = kmeans.result, dims = 1:3 ) }
Creates a pairs plot for selected independent components.
ica_pairs_plot( dataset, ica.result, column.class = NULL, dims = 1:min(5, ncol(ica.result$embedding)), ... )ica_pairs_plot( dataset, ica.result, column.class = NULL, dims = 1:min(5, ncol(ica.result$embedding)), ... )
dataset |
Dataset used to calculate the independent components. |
ica.result |
Result returned by |
column.class |
Optional metadata column used to colour samples. |
dims |
Independent components to include in the pairs plot. |
... |
Additional arguments passed to |
A GGally pairs plot object.
if (requireNamespace("fastICA", quietly = TRUE) && requireNamespace("GGally", quietly = TRUE)) { datamat <- matrix(rnorm(240), nrow = 8) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), each = 15)) ) ) ica.result <- ica_analysis_dataset( dataset, n_components = 3, maxit = 100, seed = 42 ) ica_pairs_plot( dataset, ica.result, column.class = "class", dims = 1:3 ) }if (requireNamespace("fastICA", quietly = TRUE) && requireNamespace("GGally", quietly = TRUE)) { datamat <- matrix(rnorm(240), nrow = 8) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), each = 15)) ) ) ica.result <- ica_analysis_dataset( dataset, n_components = 3, maxit = 100, seed = 42 ) ica_pairs_plot( dataset, ica.result, column.class = "class", dims = 1:3 ) }
Creates a two-dimensional scores plot from an ICA result.
ica_scoresplot2D( dataset, ica.result, column.class = NULL, dims = c(1, 2), labels = FALSE, ellipses = FALSE, bw = FALSE, palette = 2, leg.pos = "right", xlim = NULL, ylim = NULL )ica_scoresplot2D( dataset, ica.result, column.class = NULL, dims = c(1, 2), labels = FALSE, ellipses = FALSE, bw = FALSE, palette = 2, leg.pos = "right", xlim = NULL, ylim = NULL )
dataset |
Dataset used to calculate the independent components. |
ica.result |
Result returned by |
column.class |
Optional metadata column used to colour or group samples. |
dims |
Two independent components to plot. |
labels |
Logical indicating whether sample labels should be displayed. |
ellipses |
Logical indicating whether group ellipses should be displayed. |
bw |
Logical indicating whether a black-and-white plot should be used. |
palette |
RColorBrewer palette number. |
leg.pos |
Legend position. |
xlim |
Optional x-axis limits. |
ylim |
Optional y-axis limits. |
A ggplot object.
if (requireNamespace("fastICA", quietly = TRUE)) { datamat <- matrix(rnorm(240), nrow = 8) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), each = 15)) ) ) ica.result <- ica_analysis_dataset( dataset, n_components = 2, maxit = 100, seed = 42 ) ica_scoresplot2D( dataset, ica.result, column.class = "class" ) }if (requireNamespace("fastICA", quietly = TRUE)) { datamat <- matrix(rnorm(240), nrow = 8) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), each = 15)) ) ) ica.result <- ica_analysis_dataset( dataset, n_components = 2, maxit = 100, seed = 42 ) ica_scoresplot2D( dataset, ica.result, column.class = "class" ) }
Creates an interactive three-dimensional scores plot from an ICA result.
ica_scoresplot3D( dataset, ica.result, column.class = NULL, dims = c(1, 2, 3), title = "ICA 3D Scores Plot" )ica_scoresplot3D( dataset, ica.result, column.class = NULL, dims = c(1, 2, 3), title = "ICA 3D Scores Plot" )
dataset |
Dataset used to calculate the independent components. |
ica.result |
Result returned by |
column.class |
Optional metadata column used to colour samples. |
dims |
Three independent components to plot. |
title |
Plot title. |
A plotly htmlwidget.
if (requireNamespace("fastICA", quietly = TRUE) && requireNamespace("plotly", quietly = TRUE)) { datamat <- matrix(rnorm(240), nrow = 8) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), each = 15)) ) ) ica.result <- ica_analysis_dataset( dataset, n_components = 3, maxit = 100, seed = 42 ) ica_scoresplot3D( dataset, ica.result, column.class = "class" ) }if (requireNamespace("fastICA", quietly = TRUE) && requireNamespace("plotly", quietly = TRUE)) { datamat <- matrix(rnorm(240), nrow = 8) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), each = 15)) ) ) ica.result <- ica_analysis_dataset( dataset, n_components = 3, maxit = 100, seed = 42 ) ica_scoresplot3D( dataset, ica.result, column.class = "class" ) }
Replace missing values using k-nearest neighbors imputation.
impute_nas_knn(dataset, k = 10, ...)impute_nas_knn(dataset, k = 10, ...)
dataset |
A dataset object to modify. |
k |
Number of neighbors to use in the imputation procedure. |
... |
Additional arguments passed to 'impute::impute.knn()'. |
A dataset object with the same structure as the input, where missing values in 'dataset$data' have been imputed using the k-nearest neighbors method implemented in 'impute::impute.knn()'. The returned object preserves the remaining dataset components unchanged.
data <- matrix( c(1, 2, NA, 4, 2, 3, 4, 5, 3, NA, 5, 6, 4, 5, 6, 7), nrow = 4, byrow = TRUE, dimnames = list(c("x1", "x2", "x3", "x4"), c("s1", "s2", "s3", "s4")) ) dataset <- list(data = data) impute_nas_knn(dataset, k = 2)data <- matrix( c(1, 2, NA, 4, 2, 3, 4, 5, 3, NA, 5, 6, 4, 5, 6, 7), nrow = 4, byrow = TRUE, dimnames = list(c("x1", "x2", "x3", "x4"), c("s1", "s2", "s3", "s4")) ) dataset <- list(data = data) impute_nas_knn(dataset, k = 2)
Replace missing values in each variable by the mean of the observed values for that variable.
impute_nas_mean(dataset)impute_nas_mean(dataset)
dataset |
A dataset object to modify. |
A dataset object with the same structure as the input, where missing values in 'dataset$data' have been replaced by the mean of the corresponding variable calculated with 'na.rm = TRUE'.
data <- matrix( c(1, NA, 3, 4), nrow = 2, dimnames = list(c("x1", "x2"), c("s1", "s2")) ) dataset <- list(data = data) impute_nas_mean(dataset)data <- matrix( c(1, NA, 3, 4), nrow = 2, dimnames = list(c("x1", "x2"), c("s1", "s2")) ) dataset <- list(data = data) impute_nas_mean(dataset)
Replace missing values in each variable by the median of the observed values for that variable.
impute_nas_median(dataset)impute_nas_median(dataset)
dataset |
A dataset object to modify. |
A dataset object with the same structure as the input, where missing values in 'dataset$data' have been replaced by the median of the corresponding variable calculated with 'na.rm = TRUE'.
data <- matrix( c(1, NA, 5, 4), nrow = 2, dimnames = list(c("x1", "x2"), c("s1", "s2")) ) dataset <- list(data = data) impute_nas_median(dataset)data <- matrix( c(1, NA, 5, 4), nrow = 2, dimnames = list(c("x1", "x2"), c("s1", "s2")) ) dataset <- list(data = data) impute_nas_median(dataset)
Replace all 'NA' values in 'dataset$data' by a user-defined constant.
impute_nas_value(dataset, value)impute_nas_value(dataset, value)
dataset |
A dataset object to modify. |
value |
A numeric or character value used to replace missing entries. |
A dataset object with the same structure as the input, where all missing values in 'dataset$data' have been replaced by 'value'. Other components of the dataset are preserved unchanged.
data <- matrix( c(1, NA, 3, 4), nrow = 2, dimnames = list(c("x1", "x2"), c("s1", "s2")) ) dataset <- list(data = data) impute_nas_value(dataset, 0)data <- matrix( c(1, NA, 3, 4), nrow = 2, dimnames = list(c("x1", "x2"), c("s1", "s2")) ) dataset <- list(data = data) impute_nas_value(dataset, 0)
Merges data and metadata into a data frame.
merge_data_metadata( dataset, samples = NULL, metadata.vars = NULL, x.values = NULL, by.index = FALSE )merge_data_metadata( dataset, samples = NULL, metadata.vars = NULL, x.values = NULL, by.index = FALSE )
dataset |
Dataset to merge. |
samples |
Samples to keep. |
metadata.vars |
Metadata variables to keep. |
x.values |
X values to keep. |
by.index |
Logical. If TRUE, x.values are indexes. |
A 'data.frame' containing the selected data matrix, transposed so that samples are rows, combined with the selected metadata columns.
data <- matrix( 1:6, nrow = 2, dimnames = list(c("x1", "x2"), c("s1", "s2", "s3")) ) metadata <- data.frame( class = c("A", "B", "A"), batch = c(1, 1, 2), row.names = c("s1", "s2", "s3") ) dataset <- list(data = data, metadata = metadata) merge_data_metadata(dataset, metadata.vars = "class")data <- matrix( 1:6, nrow = 2, dimnames = list(c("x1", "x2"), c("s1", "s2", "s3")) ) metadata <- data.frame( class = c("A", "B", "A"), batch = c(1, 1, 2), row.names = c("s1", "s2", "s3") ) dataset <- list(data = data, metadata = metadata) merge_data_metadata(dataset, metadata.vars = "class")
Returns the identifiers of public studies available in MetaboLights.
metabolights_studies_list()metabolights_studies_list()
A character vector with public MetaboLights study identifiers.
## Not run: head(metabolights_studies_list()) ## End(Not run)## Not run: head(metabolights_studies_list()) ## End(Not run)
Impute missing values in a dataset using different methods.
missingvalues_imputation(dataset, method = "value", value = 5e-04, k = 5)missingvalues_imputation(dataset, method = "value", value = 5e-04, k = 5)
dataset |
A dataset object to process. |
method |
Imputation method: '"value"', '"mean"', '"median"', '"knn"', or '"linapprox"'. |
value |
If 'method = "value"', the value used to replace missing entries. |
k |
If 'method = "knn"', the number of neighbors used for imputation. |
A dataset object with the same overall structure as the input, in which missing values in 'dataset$data' have been imputed according to the selected method. The returned object preserves the dataset components and updates the description to record the imputation step.
data <- matrix( c(1, NA, 3, 4, 5, NA), nrow = 2, dimnames = list(c("x1", "x2"), c("s1", "s2", "s3")) ) dataset <- list(data = data, description = "toy dataset") missingvalues_imputation(dataset, method = "value", value = 0)data <- matrix( c(1, NA, 3, 4, 5, NA), nrow = 2, dimnames = list(c("x1", "x2"), c("s1", "s2", "s3")) ) dataset <- list(data = data, description = "toy dataset") missingvalues_imputation(dataset, method = "value", value = 0)
Compute overall and class-averaged performance metrics for multiclass classification models, including ROC AUC and log-loss when class probabilities are available.
multiClassSummary(data, lev = NULL, model = NULL)multiClassSummary(data, lev = NULL, model = NULL)
data |
A data frame containing at least the columns 'pred' and 'obs', plus one probability column per class when ROC or log-loss are needed. |
lev |
An optional character vector with the class levels. |
model |
An optional fitted model object passed by 'caret'. |
A named numeric vector with overall and class-averaged classification statistics.
data <- data.frame( pred = factor(c("A", "B", "A", "B"), levels = c("A", "B")), obs = factor(c("A", "B", "B", "B"), levels = c("A", "B")), A = c(0.8, 0.2, 0.7, 0.3), B = c(0.2, 0.8, 0.3, 0.7) ) multiClassSummary(data)data <- data.frame( pred = factor(c("A", "B", "A", "B"), levels = c("A", "B")), obs = factor(c("A", "B", "B", "B"), levels = c("A", "B")), A = c(0.8, 0.2, 0.7, 0.3), B = c(0.2, 0.8, 0.3, 0.7) ) multiClassSummary(data)
Creates the pathway wanted. If any of the given compounds is present in the pathway, it is coloured differently.
pathway_analysis( compounds, pathway, nodeNames = "kegg", nodeTooltip = FALSE, map.zoom = FALSE, map.layout = "preset", map.width = NULL, map.height = NULL, verbose = TRUE )pathway_analysis( compounds, pathway, nodeNames = "kegg", nodeTooltip = FALSE, map.zoom = FALSE, map.layout = "preset", map.width = NULL, map.height = NULL, verbose = TRUE )
compounds |
TODO. |
pathway |
TODO. |
nodeNames |
TODO. |
nodeTooltip |
TODO. |
map.zoom |
TODO. |
map.layout |
TODO. |
map.width |
TODO. |
map.height |
TODO. |
verbose |
Logical indicating whether progress messages should be shown. |
A cyjShiny widget representing the selected pathway with the
input compounds highlighted when present. The returned widget can be printed
or embedded in an interactive R session to inspect the pathway graph.
## Not run: pathway_analysis( compounds = c(glucose = "cpd:C00031", pyruvate = "cpd:C00022"), pathway = "hsa00010", verbose = FALSE ) ## End(Not run)## Not run: pathway_analysis( compounds = c(glucose = "cpd:C00031", pyruvate = "cpd:C00022"), pathway = "hsa00010", verbose = FALSE ) ## End(Not run)
Performs classical Principal Component Analysis (PCA) on a specmine
dataset using stats::prcomp().
pca_analysis_dataset( dataset, scale = TRUE, center = TRUE, write.file = FALSE, file.out = NULL, ... )pca_analysis_dataset( dataset, scale = TRUE, center = TRUE, write.file = FALSE, file.out = NULL, ... )
dataset |
Dataset to analyse. The numeric data matrix must be stored
in |
scale |
Logical indicating whether variables should be scaled before
PCA. The default is |
center |
Logical indicating whether variables should be centred before
PCA. The default is |
write.file |
Logical indicating whether the PCA scores and loadings should be written to CSV files. |
file.out |
Output file prefix used when
|
... |
Additional arguments passed to
|
The dataset is expected to contain variables in rows and samples in columns. The data matrix is transposed internally so that samples are treated as observations and variables as features.
An object of class prcomp. The returned object contains:
x: a matrix of PCA scores, with one row per sample;
rotation: a matrix of PCA loadings, with one row per
variable;
sdev: the standard deviations of the principal components;
center: the centring values used by the PCA;
scale: the scaling values used by the PCA when
scale = TRUE;
call: the matched function call.
The row names of x correspond to sample names when the columns of
dataset$data are named. The row names of rotation correspond
to variable names when the rows of dataset$data are named.
datamat <- matrix( rnorm(40), nrow = 4, ncol = 10, dimnames = list( paste0("feature", 1:4), paste0("sample", 1:10) ) ) dataset <- list(data = datamat) pca.result <- pca_analysis_dataset( dataset, scale = TRUE, center = TRUE ) dim(pca.result$x) dim(pca.result$rotation) file.prefix <- file.path(tempdir(), "pca_example") pca_analysis_dataset( dataset, write.file = TRUE, file.out = file.prefix ) file.exists(paste0(file.prefix, "_scores.csv")) file.exists(paste0(file.prefix, "_loadings.csv"))datamat <- matrix( rnorm(40), nrow = 4, ncol = 10, dimnames = list( paste0("feature", 1:4), paste0("sample", 1:10) ) ) dataset <- list(data = datamat) pca.result <- pca_analysis_dataset( dataset, scale = TRUE, center = TRUE ) dim(pca.result$x) dim(pca.result$rotation) file.prefix <- file.path(tempdir(), "pca_example") pca_analysis_dataset( dataset, write.file = TRUE, file.out = file.prefix ) file.exists(paste0(file.prefix, "_scores.csv")) file.exists(paste0(file.prefix, "_loadings.csv"))
Draws a PCA biplot for a prcomp or princomp result.
pca_biplot( dataset, pca.result, cex = 0.8, legend.cex = 0.8, x.colors = 1, inset = c(0, 0), legend.place = "topright", ... )pca_biplot( dataset, pca.result, cex = 0.8, legend.cex = 0.8, x.colors = 1, inset = c(0, 0), legend.place = "topright", ... )
dataset |
Dataset used in the PCA. |
pca.result |
PCA result object. |
cex |
Text expansion factor. |
legend.cex |
Legend text size. |
x.colors |
Colour vector or metadata column name. |
inset |
Legend inset. |
legend.place |
Legend position. |
... |
Additional arguments passed to the plotting method. |
No return value, called for its side effect of plotting.
datamat <- matrix( rnorm(20), nrow = 4, dimnames = list(paste0("x", 1:4), paste0("s", 1:5)) ) metadata <- data.frame(class = factor(c("A", "A", "B", "B", "A"))) dataset <- list(data = datamat, metadata = metadata) pca_res <- pca_analysis_dataset(dataset) pca_biplot(dataset, pca_res)datamat <- matrix( rnorm(20), nrow = 4, dimnames = list(paste0("x", 1:4), paste0("s", 1:5)) ) metadata <- data.frame(class = factor(c("A", "A", "B", "B", "A"))) dataset <- list(data = datamat, metadata = metadata) pca_res <- pca_analysis_dataset(dataset) pca_biplot(dataset, pca_res)
Creates an interactive 3D PCA biplot using rgl.
pca_biplot3D(dataset, pca.result, column.class = NULL, pcas = c(1, 2, 3))pca_biplot3D(dataset, pca.result, column.class = NULL, pcas = c(1, 2, 3))
dataset |
Dataset used in the PCA. |
pca.result |
PCA result object. |
column.class |
Optional metadata column used for colouring groups. |
pcas |
Principal components to plot. |
No return value, called for its side effect of plotting.
datamat <- matrix( rnorm(20), nrow = 4, dimnames = list(paste0("x", 1:4), paste0("s", 1:5)) ) metadata <- data.frame(class = factor(c("A", "A", "B", "B", "A"))) dataset <- list(data = datamat, metadata = metadata) pca_res <- pca_analysis_dataset(dataset) pca_biplot3D(dataset, pca_res, column.class = "class")datamat <- matrix( rnorm(20), nrow = 4, dimnames = list(paste0("x", 1:4), paste0("s", 1:5)) ) metadata <- data.frame(class = factor(c("A", "A", "B", "B", "A"))) dataset <- list(data = datamat, metadata = metadata) pca_res <- pca_analysis_dataset(dataset) pca_biplot3D(dataset, pca_res, column.class = "class")
Calculates the standard deviation, proportion of variance and cumulative proportion of variance explained by selected principal components.
pca_importance( pca.res, pcs = 1:length(pca.res$sdev), sd = TRUE, prop = TRUE, cumul = TRUE, min.cum = NULL )pca_importance( pca.res, pcs = 1:length(pca.res$sdev), sd = TRUE, prop = TRUE, cumul = TRUE, min.cum = NULL )
pca.res |
An object inheriting from class |
pcs |
Integer vector specifying the principal components to return. By default, all available components are returned. |
sd |
Logical indicating whether the standard deviation row should be returned. |
prop |
Logical indicating whether the proportion of variance row should be returned. |
cumul |
Logical indicating whether the cumulative proportion row should be returned. |
min.cum |
Optional numeric value between 0 and 1. When supplied, components are selected up to the first component whose cumulative proportion is greater than or equal to this value. |
The function accepts PCA results generated by
pca_analysis_dataset(), stats::prcomp() or
stats::princomp().
A numeric matrix with one row for each requested measure:
Standard deviation, Proportion of Variance and/or
Cumulative Proportion. Columns correspond to the selected principal
components.
For a prcomp object, the values are calculated from its
sdev component. For a princomp object, the same calculation
is applied to its sdev component.
datamat <- matrix( rnorm(40), nrow = 4, ncol = 10, dimnames = list( paste0("feature", 1:4), paste0("sample", 1:10) ) ) dataset <- list(data = datamat) pca.result <- pca_analysis_dataset(dataset) pca_importance( pca.result, pcs = 1:3, sd = TRUE, prop = TRUE, cumul = TRUE ) pca_importance( pca.result, min.cum = 0.90, sd = FALSE, prop = TRUE, cumul = TRUE )datamat <- matrix( rnorm(40), nrow = 4, ncol = 10, dimnames = list( paste0("feature", 1:4), paste0("sample", 1:10) ) ) dataset <- list(data = datamat) pca.result <- pca_analysis_dataset(dataset) pca_importance( pca.result, pcs = 1:3, sd = TRUE, prop = TRUE, cumul = TRUE ) pca_importance( pca.result, min.cum = 0.90, sd = FALSE, prop = TRUE, cumul = TRUE )
Plots PCA scores in 2D coloured by k-means cluster assignment.
pca_kmeans_plot2D( dataset, pca.result, num.clusters = 3, pcas = c(1, 2), kmeans.result = NULL, labels = FALSE, bw = FALSE, ellipses = FALSE, leg.pos = "right", xlim = NULL, ylim = NULL )pca_kmeans_plot2D( dataset, pca.result, num.clusters = 3, pcas = c(1, 2), kmeans.result = NULL, labels = FALSE, bw = FALSE, ellipses = FALSE, leg.pos = "right", xlim = NULL, ylim = NULL )
dataset |
Dataset used in the PCA. |
pca.result |
PCA result object. |
num.clusters |
Number of clusters. |
pcas |
Principal components to plot. |
kmeans.result |
Optional precomputed k-means result. |
labels |
Logical indicating whether sample labels should be shown. |
bw |
Logical indicating whether a black-and-white style should be used. |
ellipses |
Logical indicating whether cluster ellipses should be drawn. |
leg.pos |
Legend position. |
xlim |
Optional x-axis limits. |
ylim |
Optional y-axis limits. |
A ggplot object.
datamat <- matrix( rnorm(20), nrow = 4, dimnames = list(paste0("x", 1:4), paste0("s", 1:5)) ) metadata <- data.frame(class = factor(c("A", "A", "B", "B", "A"))) dataset <- list(data = datamat, metadata = metadata) pca_res <- pca_analysis_dataset(dataset) pca_kmeans_plot2D(dataset, pca_res, num.clusters = 2)datamat <- matrix( rnorm(20), nrow = 4, dimnames = list(paste0("x", 1:4), paste0("s", 1:5)) ) metadata <- data.frame(class = factor(c("A", "A", "B", "B", "A"))) dataset <- list(data = datamat, metadata = metadata) pca_res <- pca_analysis_dataset(dataset) pca_kmeans_plot2D(dataset, pca_res, num.clusters = 2)
Plots PCA scores in 3D coloured by k-means cluster assignment.
pca_kmeans_plot3D( dataset, pca.result, num.clusters = 3, pcas = c(1, 2, 3), kmeans.result = NULL, labels = FALSE, size = 1, ... )pca_kmeans_plot3D( dataset, pca.result, num.clusters = 3, pcas = c(1, 2, 3), kmeans.result = NULL, labels = FALSE, size = 1, ... )
dataset |
Dataset used in the PCA. |
pca.result |
PCA result object. |
num.clusters |
Number of clusters. |
pcas |
Principal components to plot. |
kmeans.result |
Optional precomputed k-means result. |
labels |
Logical indicating whether sample labels should be shown. |
size |
Point size. |
... |
Additional arguments passed to |
No return value, called for its side effect of plotting.
datamat <- matrix( rnorm(20), nrow = 4, dimnames = list(paste0("x", 1:4), paste0("s", 1:5)) ) metadata <- data.frame(class = factor(c("A", "A", "B", "B", "A"))) dataset <- list(data = datamat, metadata = metadata) pca_res <- pca_analysis_dataset(dataset) pca_kmeans_plot3D(dataset, pca_res, num.clusters = 2)datamat <- matrix( rnorm(20), nrow = 4, dimnames = list(paste0("x", 1:4), paste0("s", 1:5)) ) metadata <- data.frame(class = factor(c("A", "A", "B", "B", "A"))) dataset <- list(data = datamat, metadata = metadata) pca_res <- pca_analysis_dataset(dataset) pca_kmeans_plot3D(dataset, pca_res, num.clusters = 2)
Creates a pairs plot of PCA scores coloured by k-means cluster assignment.
pca_pairs_kmeans_plot( dataset, pca.result, num.clusters = 3, kmeans.result = NULL, pcas = c(1, 2, 3, 4, 5) )pca_pairs_kmeans_plot( dataset, pca.result, num.clusters = 3, kmeans.result = NULL, pcas = c(1, 2, 3, 4, 5) )
dataset |
Dataset used in the PCA. |
pca.result |
PCA result object. |
num.clusters |
Number of clusters. |
kmeans.result |
Optional precomputed k-means result. |
pcas |
Principal components to include. |
A ggmatrix object.
datamat <- matrix( rnorm(30), nrow = 6, dimnames = list(paste0("x", 1:6), paste0("s", 1:5)) ) metadata <- data.frame(class = factor(c("A", "A", "B", "B", "A"))) dataset <- list(data = datamat, metadata = metadata) pca_res <- pca_analysis_dataset(dataset) pca_pairs_kmeans_plot(dataset, pca_res, num.clusters = 2, pcas = 1:3)datamat <- matrix( rnorm(30), nrow = 6, dimnames = list(paste0("x", 1:6), paste0("s", 1:5)) ) metadata <- data.frame(class = factor(c("A", "A", "B", "B", "A"))) dataset <- list(data = datamat, metadata = metadata) pca_res <- pca_analysis_dataset(dataset) pca_pairs_kmeans_plot(dataset, pca_res, num.clusters = 2, pcas = 1:3)
Creates a pairs plot of PCA scores.
pca_pairs_plot( dataset, pca.result, column.class = NULL, pcas = c(1, 2, 3, 4, 5), ... )pca_pairs_plot( dataset, pca.result, column.class = NULL, pcas = c(1, 2, 3, 4, 5), ... )
dataset |
Dataset used in the PCA. |
pca.result |
PCA result object. |
column.class |
Optional metadata column used for colouring groups. |
pcas |
Principal components to include. |
... |
Additional arguments passed to |
A ggmatrix object.
datamat <- matrix( rnorm(30), nrow = 6, dimnames = list(paste0("x", 1:6), paste0("s", 1:5)) ) metadata <- data.frame(class = factor(c("A", "A", "B", "B", "A"))) dataset <- list(data = datamat, metadata = metadata) pca_res <- pca_analysis_dataset(dataset) pca_pairs_plot(dataset, pca_res, column.class = "class", pcas = 1:3)datamat <- matrix( rnorm(30), nrow = 6, dimnames = list(paste0("x", 1:6), paste0("s", 1:5)) ) metadata <- data.frame(class = factor(c("A", "A", "B", "B", "A"))) dataset <- list(data = datamat, metadata = metadata) pca_res <- pca_analysis_dataset(dataset) pca_pairs_plot(dataset, pca_res, column.class = "class", pcas = 1:3)
Performs robust Principal Component Analysis using
pcaPP::PCAgrid().
pca_robust( dataset, center = "median", scale = "mad", k = 10, write.file = FALSE, file.out = NULL, ... )pca_robust( dataset, center = "median", scale = "mad", k = 10, write.file = FALSE, file.out = NULL, ... )
dataset |
Dataset to analyse. The numeric data matrix must be stored
in |
center |
Method used to centre the data. Common choices are
|
scale |
Method used to scale the data. Common choices are
|
k |
Number of robust principal components to compute. |
write.file |
Logical indicating whether the robust PCA scores and loadings should be written to CSV files. |
file.out |
Output file prefix used when
|
... |
Additional arguments passed to
|
The dataset is expected to contain variables in rows and samples in columns. The data matrix is transposed internally so that samples are treated as observations and variables as features.
The object returned by pcaPP::PCAgrid().
Depending on the version of pcaPP, the result contains robust PCA
scores, loadings, component deviations and the centring and scaling
information used in the analysis. When scores are available, they can be
accessed with pca.result$scores; loadings can be accessed with
pca.result$loadings.
if (requireNamespace("pcaPP", quietly = TRUE)) { datamat <- matrix( rnorm(40), nrow = 4, ncol = 10, dimnames = list( paste0("feature", 1:4), paste0("sample", 1:10) ) ) dataset <- list(data = datamat) robust.result <- pca_robust( dataset, center = "median", scale = "mad", k = 2 ) is.list(robust.result) } if (requireNamespace("pcaPP", quietly = TRUE)) { datamat <- matrix( rnorm(40), nrow = 4, ncol = 10, dimnames = list( paste0("feature", 1:4), paste0("sample", 1:10) ) ) dataset <- list(data = datamat) file.prefix <- file.path(tempdir(), "robust_pca_example") pca_robust( dataset, k = 2, write.file = TRUE, file.out = file.prefix ) file.exists(paste0(file.prefix, "_scores.csv")) file.exists(paste0(file.prefix, "_loadings.csv")) }if (requireNamespace("pcaPP", quietly = TRUE)) { datamat <- matrix( rnorm(40), nrow = 4, ncol = 10, dimnames = list( paste0("feature", 1:4), paste0("sample", 1:10) ) ) dataset <- list(data = datamat) robust.result <- pca_robust( dataset, center = "median", scale = "mad", k = 2 ) is.list(robust.result) } if (requireNamespace("pcaPP", quietly = TRUE)) { datamat <- matrix( rnorm(40), nrow = 4, ncol = 10, dimnames = list( paste0("feature", 1:4), paste0("sample", 1:10) ) ) dataset <- list(data = datamat) file.prefix <- file.path(tempdir(), "robust_pca_example") pca_robust( dataset, k = 2, write.file = TRUE, file.out = file.prefix ) file.exists(paste0(file.prefix, "_scores.csv")) file.exists(paste0(file.prefix, "_loadings.csv")) }
Creates a two-dimensional PCA scores plot.
pca_scoresplot2D( dataset, pca.result, column.class = NULL, pcas = c(1, 2), labels = FALSE, ellipses = FALSE, bw = FALSE, pallette = 2, leg.pos = "right", xlim = NULL, ylim = NULL )pca_scoresplot2D( dataset, pca.result, column.class = NULL, pcas = c(1, 2), labels = FALSE, ellipses = FALSE, bw = FALSE, pallette = 2, leg.pos = "right", xlim = NULL, ylim = NULL )
dataset |
Dataset used in the PCA. Its data matrix must contain variables in rows and samples in columns. |
pca.result |
PCA result object of class |
column.class |
Optional metadata column used for colouring or grouping samples. |
pcas |
Integer vector of length two specifying the principal components to plot. |
labels |
Logical indicating whether sample labels should be shown. |
ellipses |
Logical indicating whether group ellipses should be drawn. |
bw |
Logical indicating whether a black-and-white style should be used. |
pallette |
RColorBrewer palette identifier. The argument name
|
leg.pos |
Legend position. |
xlim |
Optional numeric vector of length two defining the x-axis limits. |
ylim |
Optional numeric vector of length two defining the y-axis limits. |
The function accepts results from pca_analysis_dataset(),
stats::prcomp() or stats::princomp().
A ggplot object containing the PCA scores plot. The plotted
points represent samples, and their coordinates are the selected PCA
scores. When column.class is supplied, point colours or shapes
represent the corresponding metadata groups.
datamat <- matrix( rnorm(40), nrow = 4, ncol = 10, dimnames = list( paste0("feature", 1:4), paste0("sample", 1:10) ) ) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), each = 5)) ) ) pca.result <- pca_analysis_dataset(dataset) pca_scoresplot2D( dataset, pca.result, column.class = "class", pcas = c(1, 2), labels = TRUE )datamat <- matrix( rnorm(40), nrow = 4, ncol = 10, dimnames = list( paste0("feature", 1:4), paste0("sample", 1:10) ) ) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), each = 5)) ) ) pca.result <- pca_analysis_dataset(dataset) pca_scoresplot2D( dataset, pca.result, column.class = "class", pcas = c(1, 2), labels = TRUE )
Creates an interactive three-dimensional scores plot from a PCA result.
pca_scoresplot3D( dataset, pca.result, column.class = NULL, pcas = c(1, 2, 3), title = "PCA 3D Scores Plot" )pca_scoresplot3D( dataset, pca.result, column.class = NULL, pcas = c(1, 2, 3), title = "PCA 3D Scores Plot" )
dataset |
Dataset used to calculate the PCA. |
pca.result |
Result returned by |
column.class |
Optional metadata column used to colour samples. |
pcas |
Integer vector of length three specifying the principal components to plot. |
title |
Plot title. |
A plotly htmlwidget.
if (requireNamespace("plotly", quietly = TRUE)) { datamat <- matrix( rnorm(40), nrow = 5, ncol = 8 ) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), length.out = 8)) ) ) result <- pca_analysis_dataset(dataset) pca_scoresplot3D( dataset, result, column.class = "class", pcas = c(1, 2, 3) ) }if (requireNamespace("plotly", quietly = TRUE)) { datamat <- matrix( rnorm(40), nrow = 5, ncol = 8 ) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), length.out = 8)) ) ) result <- pca_analysis_dataset(dataset) pca_scoresplot3D( dataset, result, column.class = "class", pcas = c(1, 2, 3) ) }
Creates an interactive three-dimensional PCA scores plot using
rgl.
pca_scoresplot3D_rgl( dataset, pca.result, column.class = NULL, pcas = c(1, 2, 3), size = 1, labels = FALSE )pca_scoresplot3D_rgl( dataset, pca.result, column.class = NULL, pcas = c(1, 2, 3), size = 1, labels = FALSE )
dataset |
Dataset used in the PCA. Its data matrix must contain variables in rows and samples in columns. |
pca.result |
PCA result object of class |
column.class |
Optional metadata column used for colouring sample groups. |
pcas |
Integer vector of length three specifying the principal components to plot. |
size |
Numeric point size passed to |
labels |
Logical indicating whether sample labels should be shown. |
Samples are represented as points in the selected principal component
space. When column.class is supplied, point colours represent the
corresponding metadata groups.
Invisibly returns the object produced by
rgl::plot3d(); the three-dimensional plot is also drawn as a side
effect.
if (requireNamespace("rgl", quietly = TRUE)) { options(rgl.useNULL = TRUE) datamat <- matrix( rnorm(40), nrow = 4, ncol = 10, dimnames = list( paste0("feature", 1:4), paste0("sample", 1:10) ) ) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), each = 5)) ) ) pca.result <- pca_analysis_dataset(dataset) pca_scoresplot3D_rgl( dataset, pca.result, column.class = "class", pcas = c(1, 2, 3), labels = TRUE ) }if (requireNamespace("rgl", quietly = TRUE)) { options(rgl.useNULL = TRUE) datamat <- matrix( rnorm(40), nrow = 4, ncol = 10, dimnames = list( paste0("feature", 1:4), paste0("sample", 1:10) ) ) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), each = 5)) ) ) pca.result <- pca_analysis_dataset(dataset) pca_scoresplot3D_rgl( dataset, pca.result, column.class = "class", pcas = c(1, 2, 3), labels = TRUE ) }
Draws a scree plot showing the individual and cumulative percentage of variance explained by the principal components.
pca_screeplot( pca.result, num.pcs = NULL, cex.leg = 0.8, leg.pos = "right", lab.text = c("individual percent", "cumulative percent"), fill.col = c("blue", "red"), ylab = "Percentage", xlab = "Principal components", ... )pca_screeplot( pca.result, num.pcs = NULL, cex.leg = 0.8, leg.pos = "right", lab.text = c("individual percent", "cumulative percent"), fill.col = c("blue", "red"), ylab = "Percentage", xlab = "Principal components", ... )
pca.result |
PCA result object inheriting from class |
num.pcs |
Optional number of principal components to display. If
|
cex.leg |
Numeric value controlling the legend text size. |
leg.pos |
Legend position accepted by |
lab.text |
Character vector of length two containing the labels for the individual and cumulative variance curves. |
fill.col |
Character or numeric vector of length two containing the colours for the individual and cumulative variance curves. |
ylab |
Y-axis label. |
xlab |
X-axis label. |
... |
Additional graphical parameters passed to
|
No return value; the scree plot is drawn as a side effect.
datamat <- matrix( rnorm(40), nrow = 4, ncol = 10, dimnames = list( paste0("feature", 1:4), paste0("sample", 1:10) ) ) dataset <- list(data = datamat) pca.result <- pca_analysis_dataset(dataset) pca_screeplot( pca.result, num.pcs = 4 )datamat <- matrix( rnorm(40), nrow = 4, ncol = 10, dimnames = list( paste0("feature", 1:4), paste0("sample", 1:10) ) ) dataset <- list(data = datamat) pca.result <- pca_analysis_dataset(dataset) pca_screeplot( pca.result, num.pcs = 4 )
Detects local maxima in each spectrum of a 2D NMR dataset and converts the detected peaks into a 1D specmine dataset suitable for downstream analysis.
peak_detection2d( specmine_2d_dataset, baseline_thresh = NULL, noiseFilt = 0, negatives = FALSE, verbose = TRUE )peak_detection2d( specmine_2d_dataset, baseline_thresh = NULL, noiseFilt = 0, negatives = FALSE, verbose = TRUE )
specmine_2d_dataset |
A specmine 2D dataset containing one numeric matrix per sample. |
baseline_thresh |
Optional numeric threshold used as the minimum intensity for peak detection.
If |
noiseFilt |
Integer noise filter level: |
negatives |
Logical indicating whether variables with negative ppm values should be kept. |
verbose |
Logical indicating whether progress messages should be shown. |
A specmine dataset object as a list. The data element is a numeric matrix where
rows correspond to detected 2D peak coordinates encoded as combined F1/F2 positions and columns
correspond to samples. Matrix entries contain peak intensities, with missing values indicating
that a given peak was not detected in a sample. The returned object also includes the original
sample metadata, the dataset description, the dataset type set to "nmr-peaks", and
labels describing the x-axis and data values. This output represents a reduced 1D peak table
derived from the input 2D NMR spectra.
m <- matrix(c(0, 5, 0, 0), nrow = 2) rownames(m) <- c("1.0", "1.1") colnames(m) <- c("2.0", "2.1") x <- list(data = list(s1 = m), metadata = data.frame(), description = "Toy") try(peak_detection2d(x, baseline_thresh = 1, negatives = TRUE, verbose = FALSE))m <- matrix(c(0, 5, 0, 0), nrow = 2) rownames(m) <- c("1.0", "1.1") colnames(m) <- c("2.0", "2.1") x <- list(data = list(s1 = m), metadata = data.frame(), description = "Toy") try(peak_detection2d(x, baseline_thresh = 1, negatives = TRUE, verbose = FALSE))
Groups peaks detected in multiple spectra into wavenumber bins defined by a tolerance. The resulting feature matrix can be used in downstream analyses such as PCA, clustering or classification.
raman_align_peaks( peak_results, tolerance = 4, reference_wavenumbers = NULL, feature_method = "max_height" )raman_align_peaks( peak_results, tolerance = 4, reference_wavenumbers = NULL, feature_method = "max_height" )
peak_results |
A non-empty list of peak-detection results, one per
sample. Each element must contain |
tolerance |
Positive numeric value defining the half-width, in wavenumbers, around each reference position. |
reference_wavenumbers |
Optional non-empty numeric vector of reference
wavenumbers. If |
feature_method |
Character string defining the feature summarised within
each bin. One of |
Missing peaks are represented by zero in the returned feature matrix.
Data frame with one row per reference wavenumber and one column per
sample. The first column, wavenumber, contains bin reference
positions.
wn = seq(400, 1800, by = 1) x1 = dnorm(wn, mean = 1000, sd = 20) + 0.01 * rnorm(length(wn)) x2 = dnorm(wn, mean = 1002, sd = 20) + 0.01 * rnorm(length(wn)) p1 = raman_find_peaks(x1, height = 0.01, distance = 5) p2 = raman_find_peaks(x2, height = 0.01, distance = 5) peak_results = list( list( sample_id = "sample1", wavenumbers = wn, peaks = p1$peaks, properties = p1$properties ), list( sample_id = "sample2", wavenumbers = wn, peaks = p2$peaks, properties = p2$properties ) ) features = raman_align_peaks( peak_results, tolerance = 4, feature_method = "max_height" ) head(features)wn = seq(400, 1800, by = 1) x1 = dnorm(wn, mean = 1000, sd = 20) + 0.01 * rnorm(length(wn)) x2 = dnorm(wn, mean = 1002, sd = 20) + 0.01 * rnorm(length(wn)) p1 = raman_find_peaks(x1, height = 0.01, distance = 5) p2 = raman_find_peaks(x2, height = 0.01, distance = 5) peak_results = list( list( sample_id = "sample1", wavenumbers = wn, peaks = p1$peaks, properties = p1$properties ), list( sample_id = "sample2", wavenumbers = wn, peaks = p2$peaks, properties = p2$properties ) ) features = raman_align_peaks( peak_results, tolerance = 4, feature_method = "max_height" ) head(features)
Restricts a Raman or surface-enhanced Raman spectroscopy (SERS) dataset to an inclusive wavenumber interval.
raman_crop_spectra(dataset, min_wn, max_wn)raman_crop_spectra(dataset, min_wn, max_wn)
dataset |
A dataset list containing a numeric matrix in
|
min_wn |
Single finite numeric value specifying the lower inclusive wavenumber limit. |
max_wn |
Single finite numeric value specifying the upper inclusive wavenumber limit. |
The dataset must contain wavenumbers in rows and samples in columns.
Wavenumbers are obtained from dataset$wavenumbers when available.
Otherwise, numeric row names in dataset$data are used.
A dataset equivalent to dataset, with dataset$data
restricted to wavenumbers between min_wn and max_wn.
The dataset$wavenumbers element is updated or created to match the
cropped data.
dataset = list( data = matrix( seq_len(30), nrow = 6, dimnames = list( as.character(seq(400, 900, by = 100)), paste0("sample", 1:5) ) ), wavenumbers = seq(400, 900, by = 100) ) cropped = raman_crop_spectra( dataset, min_wn = 500, max_wn = 800 ) cropped$wavenumbersdataset = list( data = matrix( seq_len(30), nrow = 6, dimnames = list( as.character(seq(400, 900, by = 100)), paste0("sample", 1:5) ) ), wavenumbers = seq(400, 900, by = 100) ) cropped = raman_crop_spectra( dataset, min_wn = 500, max_wn = 800 ) cropped$wavenumbers
Detects and replaces intensity spikes in Raman or surface-enhanced Raman spectroscopy (SERS) spectra using modified Z-scores based on the median absolute deviation (MAD).
raman_despike(dataset, ma = 10, threshold = 7)raman_despike(dataset, ma = 10, threshold = 7)
dataset |
A dataset list containing a numeric matrix in
|
ma |
Non-negative integer specifying the number of neighbouring points considered on each side of a detected spike. |
threshold |
Positive finite numeric value specifying the modified Z-score threshold used to identify spikes. |
The dataset must contain wavenumbers in rows and samples in columns. Each sample spectrum is processed independently. Detected spikes are replaced by the mean intensity of neighbouring non-spike points.
A dataset equivalent to dataset, with despiked spectra stored
in dataset$data. Information about the operation is stored in
dataset$despike.
dataset = list( data = matrix( c( 1, 1.1, 1.2, 20, 1.1, 1.2, 2, 2.1, 2.2, 30, 2.1, 2.2 ), nrow = 6, ncol = 2, dimnames = list( paste0("wavenumber", 1:6), paste0("sample", 1:2) ) ) ) despiked = raman_despike( dataset, ma = 1, threshold = 3 ) despiked$despike$n_spikesdataset = list( data = matrix( c( 1, 1.1, 1.2, 20, 1.1, 1.2, 2, 2.1, 2.2, 30, 2.1, 2.2 ), nrow = 6, ncol = 2, dimnames = list( paste0("wavenumber", 1:6), paste0("sample", 1:2) ) ) ) despiked = raman_despike( dataset, ma = 1, threshold = 3 ) despiked$despike$n_spikes
Finds local maxima in one-dimensional spectra according to peak properties such as height, threshold, distance, prominence, width and plateau size.
raman_find_peaks( x, height = NULL, threshold = NULL, distance = NULL, prominence = NULL, width = NULL, plateau_size = NULL, wlen = NULL, rel_height = 0.5 )raman_find_peaks( x, height = NULL, threshold = NULL, distance = NULL, prominence = NULL, width = NULL, plateau_size = NULL, wlen = NULL, rel_height = 0.5 )
x |
Numeric vector containing the signal intensity values. |
height |
Numeric value or length-two numeric vector specifying the
required height of peaks. A single value is interpreted as a minimum height.
A vector |
threshold |
Numeric value or length-two numeric vector specifying the required vertical distance to neighbouring samples. |
distance |
Positive integer specifying the minimum horizontal distance, in samples, between neighbouring peaks. |
prominence |
Numeric value or length-two numeric vector specifying the required prominence of peaks. |
width |
Numeric value or length-two numeric vector specifying the required width of peaks, in samples. |
plateau_size |
Numeric value or length-two numeric vector specifying the required size of the flat top of peaks, in samples. |
wlen |
Optional positive integer. It defines the maximum number of samples inspected on each side of a peak when calculating prominence. |
rel_height |
Numeric value between zero and one used for peak-width calculations. |
The interface and peak-property terminology are inspired by
scipy.signal.find_peaks(). Prominence and width calculations use an
R implementation tailored to Raman/SERS spectra and are not intended to
reproduce SciPy results exactly.
A list with two elements:
peaksInteger vector of one-based indices of peaks in
x satisfying the requested conditions.
propertiesData frame containing properties of the
returned peaks, including peak_index and peak_height.
Additional columns are included when the respective properties are
calculated.
x = c(0, 1, 0, 2, 1, 0, 3, 2, 0, 4, 1) res = raman_find_peaks( x, height = 1, distance = 2 ) res$peaks res$propertiesx = c(0, 1, 0, 2, 1, 0, 3, 2, 0, 4, 1) res = raman_find_peaks( x, height = 1, distance = 2 ) res$peaks res$properties
Normalizes Raman or surface-enhanced Raman spectroscopy (SERS) spectra using min-max normalization, L2 vector normalization, or normalization by the maximum intensity near a target silicon peak.
raman_normalize( dataset, method = "min-max", target_peak = 520, search_window = 20 )raman_normalize( dataset, method = "min-max", target_peak = 520, search_window = 20 )
dataset |
A dataset list containing a numeric matrix in
|
method |
Character string specifying the normalization method. One of
|
target_peak |
Single finite numeric value specifying the target
wavenumber of the silicon peak when |
search_window |
Positive finite numeric value specifying the half-width
of the wavenumber search interval around |
The dataset must contain wavenumbers in rows and samples in columns. Each sample spectrum is normalized independently.
A dataset equivalent to dataset, with normalized spectra
stored in dataset$data. Information about the selected
normalization method and its parameters is stored in
dataset$normalization.
dataset = list( data = matrix( c( 1, 2, 3, 4, 5, 2, 4, 6, 8, 10 ), nrow = 5, ncol = 2, dimnames = list( as.character(seq(500, 900, by = 100)), paste0("sample", 1:2) ) ), wavenumbers = seq(500, 900, by = 100) ) normalized = raman_normalize( dataset, method = "min-max" ) range(normalized$data[, 1])dataset = list( data = matrix( c( 1, 2, 3, 4, 5, 2, 4, 6, 8, 10 ), nrow = 5, ncol = 2, dimnames = list( as.character(seq(500, 900, by = 100)), paste0("sample", 1:2) ) ), wavenumbers = seq(500, 900, by = 100) ) normalized = raman_normalize( dataset, method = "min-max" ) range(normalized$data[, 1])
Normalizes a peak-feature matrix returned by raman_align_peaks().
raman_normalize_peak_features(features, method = "min-max")raman_normalize_peak_features(features, method = "min-max")
features |
Data frame with a numeric |
method |
Normalization method: |
With method = "min-max", normalization is carried out row-wise across
samples. Rows containing identical values for every sample are set to zero.
With method = "L2", normalization is performed column-wise for each
sample. Columns with zero L2 norm are retained as zero.
Data frame with the same structure as features, containing
normalized sample-feature values.
features = data.frame( wavenumber = c(1000, 1200, 1600), sample1 = c(1, 2, 3), sample2 = c(2, 4, 6) ) raman_normalize_peak_features(features, method = "L2")features = data.frame( wavenumber = c(1000, 1200, 1600), sample1 = c(1, 2, 3), sample2 = c(2, 4, 6) ) raman_normalize_peak_features(features, method = "L2")
Applies a Savitzky-Golay smoothing filter and computes the second derivative of Raman or surface-enhanced Raman spectroscopy (SERS) spectra.
raman_sgolay_derivative(dataset, window_size = 7, polynomial_order = 2)raman_sgolay_derivative(dataset, window_size = 7, polynomial_order = 2)
dataset |
A dataset list containing a numeric matrix in
|
window_size |
Odd positive integer specifying the size of the moving window (number of points). Must be less than or equal to the number of wavenumbers. |
polynomial_order |
Positive integer specifying the order of the
polynomial used for local fitting. Must be less than |
This function is a wrapper around savitzky_golay() specialized for
Raman/SERS datasets. It fixes the differentiation order to 2 and provides
argument names and validation tailored to spectroscopic workflows.
The dataset must contain wavenumbers in rows and samples in columns. Each sample spectrum is processed independently. The second derivative is computed using polynomial fitting within a moving window.
A dataset equivalent to dataset, with second derivative
spectra stored in dataset$data. The original wavenumbers are stored
in dataset$original_wavenumbers, when available. Information about
the transform is stored in dataset$derivative.
wavenumbers = seq(400, 1000, length.out = 21) dataset = list( data = cbind( sample1 = sin(seq(0, 2 * pi, length.out = 21)), sample2 = cos(seq(0, 2 * pi, length.out = 21)) ), wavenumbers = wavenumbers ) deriv2 = raman_sgolay_derivative( dataset, window_size = 7, polynomial_order = 2 ) dim(deriv2$data)wavenumbers = seq(400, 1000, length.out = 21) dataset = list( data = cbind( sample1 = sin(seq(0, 2 * pi, length.out = 21)), sample2 = cos(seq(0, 2 * pi, length.out = 21)) ), wavenumbers = wavenumbers ) deriv2 = raman_sgolay_derivative( dataset, window_size = 7, polynomial_order = 2 ) dim(deriv2$data)
Computes one-sided Fourier power spectra for each Raman or surface-enhanced Raman spectroscopy (SERS) sample.
raman_transform_fourier(dataset, remove_dc = FALSE)raman_transform_fourier(dataset, remove_dc = FALSE)
dataset |
A dataset list containing a numeric matrix in
|
remove_dc |
Logical value indicating whether the zero-frequency direct-current component should be excluded from the stored output. |
This function follows the specmine Raman workflow by preserving the
original spectrum in dataset$data. Fourier features are stored in
dataset$fourier$data; their normalized frequencies are stored in
dataset$fourier$frequencies.
The input data matrix must have wavenumbers in rows and samples in columns. Each sample is transformed independently.
The input dataset, with a fourier element containing:
dataMatrix of one-sided Fourier power features, with frequencies in rows and samples in columns.
frequenciesNumeric vector of normalized frequencies.
remove_dcLogical value indicating whether the DC component was removed.
n_wavenumbersNumber of original spectral variables.
wavenumbers = seq(400, 1000, length.out = 16) dataset = list( data = cbind( sample1 = sin(seq(0, 2 * pi, length.out = 16)), sample2 = cos(seq(0, 2 * pi, length.out = 16)) ), wavenumbers = wavenumbers ) transformed = raman_transform_fourier(dataset) dim(transformed$fourier$data)wavenumbers = seq(400, 1000, length.out = 16) dataset = list( data = cbind( sample1 = sin(seq(0, 2 * pi, length.out = 16)), sample2 = cos(seq(0, 2 * pi, length.out = 16)) ), wavenumbers = wavenumbers ) transformed = raman_transform_fourier(dataset) dim(transformed$fourier$data)
Computes a multilevel discrete Haar wavelet transform for each Raman or surface-enhanced Raman spectroscopy (SERS) sample.
raman_transform_wavelet(dataset, level = 1)raman_transform_wavelet(dataset, level = 1)
dataset |
A dataset list containing a numeric matrix in
|
level |
Positive integer specifying the number of Haar decomposition levels. |
This function preserves the original data in dataset$data, following
the specmine pipeline. Wavelet coefficients are stored in
dataset$wavelet$data.
The input data matrix must have wavenumbers in rows and samples in columns. If needed, each spectrum is extended by repeating its final intensity value until its length is a power of two.
The input dataset, with a wavelet element containing:
dataMatrix of Haar wavelet coefficients, with coefficients in rows and samples in columns.
filterThe character string "haar".
levelNumber of decomposition levels.
original_lengthNumber of original wavenumbers.
padded_lengthLength used after optional padding.
wavenumbers = seq(400, 1100, length.out = 8) dataset = list( data = cbind( sample1 = sin(seq(0, 2 * pi, length.out = 8)), sample2 = cos(seq(0, 2 * pi, length.out = 8)) ), wavenumbers = wavenumbers ) transformed = raman_transform_wavelet( dataset, level = 2 ) dim(transformed$wavelet$data)wavenumbers = seq(400, 1100, length.out = 8) dataset = list( data = cbind( sample1 = sin(seq(0, 2 * pi, length.out = 8)), sample2 = cos(seq(0, 2 * pi, length.out = 8)) ), wavenumbers = wavenumbers ) transformed = raman_transform_wavelet( dataset, level = 2 ) dim(transformed$wavelet$data)
Lists CSV files in a folder and reads them into a named list of data frames.
read_csvs_folder(foldername, verbose = TRUE, ...)read_csvs_folder(foldername, verbose = TRUE, ...)
foldername |
Path to the folder containing CSV files. |
verbose |
Logical; whether progress messages should be shown. |
... |
Additional arguments passed to |
A named list of data frames, one per CSV file found in the folder.
folder <- file.path(tempdir(), "peak_csvs") dir.create(folder, showWarnings = FALSE) utils::write.csv(data.frame(ppm = c(1, 2), int = c(10, 20)), file.path(folder, "sample1.csv"), row.names = FALSE) utils::write.csv(data.frame(ppm = c(1, 3), int = c(15, 30)), file.path(folder, "sample2.csv"), row.names = FALSE) read_csvs_folder(folder, verbose = FALSE)folder <- file.path(tempdir(), "peak_csvs") dir.create(folder, showWarnings = FALSE) utils::write.csv(data.frame(ppm = c(1, 2), int = c(10, 20)), file.path(folder, "sample1.csv"), row.names = FALSE) utils::write.csv(data.frame(ppm = c(1, 3), int = c(15, 30)), file.path(folder, "sample2.csv"), row.names = FALSE) read_csvs_folder(folder, verbose = FALSE)
Reads all .dx files in a folder using readJDX::readJDX().
read_data_dx(foldername, debug = 0, verbose = TRUE)read_data_dx(foldername, debug = 0, verbose = TRUE)
foldername |
Path to the folder containing JDX files. |
debug |
Debug level passed to |
verbose |
Logical; whether progress messages should be shown. |
A named list with one imported JDX object per file.
folder <- tempdir() ## Not run: read_data_dx(folder) ## End(Not run)folder <- tempdir() ## Not run: read_data_dx(folder) ## End(Not run)
Reads a dataset from a CSV file containing the data matrix and, optionally, a second CSV file containing metadata.
read_dataset_csv( filename.data, filename.meta = NULL, type = "undefined", description = "", label.x = NULL, label.values = NULL, sample.names = NULL, format = "row", header.col = TRUE, header.row = TRUE, sep = ",", header.col.meta = TRUE, header.row.meta = TRUE, sep.meta = "," )read_dataset_csv( filename.data, filename.meta = NULL, type = "undefined", description = "", label.x = NULL, label.values = NULL, sample.names = NULL, format = "row", header.col = TRUE, header.row = TRUE, sep = ",", header.col.meta = TRUE, header.row.meta = TRUE, sep.meta = "," )
filename.data |
Path to the CSV file containing the data matrix. |
filename.meta |
Optional path to the CSV file containing metadata. |
type |
Character string describing the dataset type. |
description |
Character string with a dataset description. |
label.x |
Optional x-axis label. |
label.values |
Optional value labels. |
sample.names |
Optional sample names. |
format |
Data layout format, either |
header.col |
Logical; whether the data file has a header row. |
header.row |
Logical; whether the data file has a row names column. |
sep |
Field separator used in the data file. |
header.col.meta |
Logical; whether the metadata file has a header row. |
header.row.meta |
Logical; whether the metadata file has a row names column. |
sep.meta |
Field separator used in the metadata file. |
An object of class dataset created from the input files.
This object contains the imported data matrix and, if provided, the sample
metadata, together with dataset-level information such as type,
description, labels, and sample names. The returned object is intended to
be used as input to downstream processing and analysis functions in the
package.
data_file <- tempfile(fileext = ".csv") meta_file <- tempfile(fileext = ".csv") data_in <- data.frame( x1 = c(1.1, 2.2, 3.3), x2 = c(4.4, 5.5, 6.6), row.names = c("s1", "s2", "s3") ) metadata_in <- data.frame( class = c("A", "B", "A"), row.names = c("s1", "s2", "s3") ) utils::write.csv(data_in, data_file) utils::write.csv(metadata_in, meta_file) dataset <- read_dataset_csv( filename.data = data_file, filename.meta = meta_file, format = "row", header.row = TRUE, header.row.meta = TRUE ) class(dataset)data_file <- tempfile(fileext = ".csv") meta_file <- tempfile(fileext = ".csv") data_in <- data.frame( x1 = c(1.1, 2.2, 3.3), x2 = c(4.4, 5.5, 6.6), row.names = c("s1", "s2", "s3") ) metadata_in <- data.frame( class = c("A", "B", "A"), row.names = c("s1", "s2", "s3") ) utils::write.csv(data_in, data_file) utils::write.csv(metadata_in, meta_file) dataset <- read_dataset_csv( filename.data = data_file, filename.meta = meta_file, format = "row", header.row = TRUE, header.row.meta = TRUE ) class(dataset)
Reads all JDX spectra files in a folder, combines their intensity values into a data matrix, and optionally attaches sample metadata.
read_dataset_dx( folder.data, filename.meta = NULL, type = "undefined", description = "", label.x = NULL, label.values = NULL, header.col.meta = TRUE, header.row.meta = TRUE, sep.meta = ",", verbose = TRUE )read_dataset_dx( folder.data, filename.meta = NULL, type = "undefined", description = "", label.x = NULL, label.values = NULL, header.col.meta = TRUE, header.row.meta = TRUE, sep.meta = ",", verbose = TRUE )
folder.data |
Path to the folder containing JDX files. |
filename.meta |
Optional metadata CSV file. |
type |
Character string describing the dataset type. |
description |
Character string with a dataset description. |
label.x |
Optional x-axis label. |
label.values |
Optional value labels. |
header.col.meta |
Logical; whether the metadata file has a header row. |
header.row.meta |
Logical; whether the metadata file has a row names column. |
sep.meta |
Field separator used in the metadata file. |
verbose |
Logical; whether progress messages should be shown. |
A dataset object created from the spectra found in folder.data
and the optional metadata file.
folder <- tempdir() meta_file <- tempfile(fileext = ".csv") metadata_in <- data.frame(sample = c("sample1", "sample2"), class = c("A", "B")) utils::write.csv(metadata_in, meta_file, row.names = FALSE) ## Not run: read_dataset_dx(folder, filename.meta = meta_file) ## End(Not run)folder <- tempdir() meta_file <- tempfile(fileext = ".csv") metadata_in <- data.frame(sample = c("sample1", "sample2"), class = c("A", "B")) utils::write.csv(metadata_in, meta_file, row.names = FALSE) ## Not run: read_dataset_dx(folder, filename.meta = meta_file) ## End(Not run)
Reads metadata from a CSV file and returns it as a data frame.
read_metadata(filename, header.col = TRUE, header.row = TRUE, sep = ",")read_metadata(filename, header.col = TRUE, header.row = TRUE, sep = ",")
filename |
Path to the metadata CSV file. |
header.col |
Logical; whether the metadata file has a header row. |
header.row |
Logical; whether the metadata file has a row names column. |
sep |
Field separator used in the metadata file. |
A data.frame containing the imported metadata. Rows usually
correspond to samples and columns correspond to metadata variables.
meta_file <- tempfile(fileext = ".csv") metadata_in <- data.frame( class = c("A", "B", "A"), batch = c("b1", "b1", "b2"), row.names = c("s1", "s2", "s3") ) utils::write.csv(metadata_in, meta_file) read_metadata(meta_file, header.row = TRUE)meta_file <- tempfile(fileext = ".csv") metadata_in <- data.frame( class = c("A", "B", "A"), batch = c("b1", "b1", "b2"), row.names = c("s1", "s2", "s3") ) utils::write.csv(metadata_in, meta_file) read_metadata(meta_file, header.row = TRUE)
Reads multiple CSV files, one per sample, and returns them as a named list.
read_multiple_csvs(filenames, ext = ".csv", verbose = TRUE, ...)read_multiple_csvs(filenames, ext = ".csv", verbose = TRUE, ...)
filenames |
Character vector with file names or file paths. |
ext |
File extension appended to each file name. |
verbose |
Logical; whether progress messages should be shown. |
... |
Additional arguments passed to |
A named list of data frames, one per input file.
f1 <- tempfile(fileext = ".csv") f2 <- tempfile(fileext = ".csv") utils::write.csv(data.frame(ppm = c(1, 2), int = c(10, 20)), f1, row.names = FALSE) utils::write.csv(data.frame(ppm = c(1, 3), int = c(15, 30)), f2, row.names = FALSE) read_multiple_csvs(c(f1, f2), ext = "", verbose = FALSE)f1 <- tempfile(fileext = ".csv") f2 <- tempfile(fileext = ".csv") utils::write.csv(data.frame(ppm = c(1, 2), int = c(10, 20)), f1, row.names = FALSE) utils::write.csv(data.frame(ppm = c(1, 3), int = c(15, 30)), f2, row.names = FALSE) read_multiple_csvs(c(f1, f2), ext = "", verbose = FALSE)
Import for Thermo Galactic's spc file format These functions allow to import .spc files. A detailed description of the .spc file format is available at
read_spc_nosubhdr( filename, keys.hdr2data = c("fexper", "fres", "fsource"), keys.hdr2log = c("fdate", "fpeakpt"), keys.log2data = FALSE, keys.log2log = TRUE, log.txt = TRUE, log.bin = FALSE, log.disk = FALSE, hdr = list(), nosubhdr = TRUE, no.object = FALSE )read_spc_nosubhdr( filename, keys.hdr2data = c("fexper", "fres", "fsource"), keys.hdr2log = c("fdate", "fpeakpt"), keys.log2data = FALSE, keys.log2log = TRUE, log.txt = TRUE, log.bin = FALSE, log.disk = FALSE, hdr = list(), nosubhdr = TRUE, no.object = FALSE )
filename |
The complete file name of the .spc file. |
keys.hdr2data, keys.hdr2log, keys.log2data, keys.log2log
|
character
vectors with the names of parameters in the .spc file's log block
(log2xxx) or header (hdr2xxx) that should go into the extra data
(yyy2data) or into the |
log.txt |
Should the text part of the .spc file's log block be read? |
log.bin, log.disk
|
Should the normal and on-disk binary parts of the .spc file's log block be read? |
hdr |
A list with fileheader fields that overwrite the settings of actual file's header. |
nosubhdr |
Boolean value to decide if the header should be read or not. |
no.object |
If |
A list with imported spectra information.
C. Beleites
Reference information for the SPC file format.
filename <- system.file("extdata", "toy.spc", package = "specmine") if (nzchar(filename)) { read_spc_nosubhdr(filename) }filename <- system.file("extdata", "toy.spc", package = "specmine") if (nzchar(filename)) { read_spc_nosubhdr(filename) }
Performs recursive feature elimination on a data matrix.
recursive_feature_elimination( datamat, samples.class, functions = caret::rfFuncs, method = "cv", repeats = 5, number = 10, subsets = 2^(2:4) )recursive_feature_elimination( datamat, samples.class, functions = caret::rfFuncs, method = "cv", repeats = 5, number = 10, subsets = 2^(2:4) )
datamat |
Data matrix with features in rows and samples in columns. |
samples.class |
Sample class labels. |
functions |
Caret RFE functions list. |
method |
Resampling method passed to |
repeats |
Number of repeats for resampling. |
number |
Number of resampling folds or iterations. |
subsets |
Subset sizes to evaluate. |
An rfe object.
if (requireNamespace("randomForest", quietly = TRUE)) { datamat <- matrix( rnorm(20), nrow = 4, dimnames = list(paste0("x", 1:4), paste0("s", 1:5)) ) classes <- factor(c("A", "A", "B", "B", "A")) recursive_feature_elimination(datamat, classes, caret::rfFuncs) }if (requireNamespace("randomForest", quietly = TRUE)) { datamat <- matrix( rnorm(20), nrow = 4, dimnames = list(paste0("x", 1:4), paste0("s", 1:5)) ) classes <- factor(c("A", "A", "B", "B", "A")) recursive_feature_elimination(datamat, classes, caret::rfFuncs) }
Removes selected samples, data variables, or metadata variables from a dataset.
remove_data( dataset, data.to.remove, type = "sample", by.index = FALSE, rebuild.factors = TRUE )remove_data( dataset, data.to.remove, type = "sample", by.index = FALSE, rebuild.factors = TRUE )
dataset |
Dataset to modify. |
data.to.remove |
Data to remove. |
type |
One of "sample", "data", or "metadata". |
by.index |
Logical. If TRUE, data.to.remove has indexes. |
rebuild.factors |
Logical. If TRUE, rebuild factors in metadata. |
A dataset object with the same overall structure as the input, where the requested samples, data variables, or metadata variables have been removed according to 'type'.
data <- matrix( 1:9, nrow = 3, dimnames = list(c("x1", "x2", "x3"), c("s1", "s2", "s3")) ) metadata <- data.frame(class = c("A", "B", "A"), row.names = c("s1", "s2", "s3")) dataset <- list(data = data, metadata = metadata) remove_data(dataset, "s2", type = "sample")data <- matrix( 1:9, nrow = 3, dimnames = list(c("x1", "x2", "x3"), c("s1", "s2", "s3")) ) metadata <- data.frame(class = c("A", "B", "A"), row.names = c("s1", "s2", "s3")) dataset <- list(data = data, metadata = metadata) remove_data(dataset, "s2", type = "sample")
Removes x variables from a dataset.
remove_data_variables(dataset, variables.to.remove, by.index = FALSE)remove_data_variables(dataset, variables.to.remove, by.index = FALSE)
dataset |
Dataset to modify. |
variables.to.remove |
Variables to remove. |
by.index |
Logical. If TRUE, variables.to.remove are indexes. |
A dataset object with the same structure as the input, where the selected rows of 'dataset$data' have been removed. If no matching variables are found, the input dataset is returned unchanged and a warning is issued.
data <- matrix( 1:9, nrow = 3, dimnames = list(c("10", "20", "30"), c("s1", "s2", "s3")) ) metadata <- data.frame(class = c("A", "B", "A"), row.names = c("s1", "s2", "s3")) dataset <- list(data = data, metadata = metadata) remove_data_variables(dataset, "20")data <- matrix( 1:9, nrow = 3, dimnames = list(c("10", "20", "30"), c("s1", "s2", "s3")) ) metadata <- data.frame(class = c("A", "B", "A"), row.names = c("s1", "s2", "s3")) dataset <- list(data = data, metadata = metadata) remove_data_variables(dataset, "20")
Removes metadata variables from a dataset.
remove_metadata_variables(dataset, variables.to.remove)remove_metadata_variables(dataset, variables.to.remove)
dataset |
Dataset to modify. |
variables.to.remove |
Metadata variables to remove. |
A dataset object with the same structure as the input, where the selected columns have been removed from 'dataset$metadata'. If no matching metadata fields are found, the dataset is returned unchanged and a warning is issued.
data <- matrix( 1:6, nrow = 2, dimnames = list(c("x1", "x2"), c("s1", "s2", "s3")) ) metadata <- data.frame( class = c("A", "B", "A"), batch = c(1, 1, 2), row.names = c("s1", "s2", "s3") ) dataset <- list(data = data, metadata = metadata) remove_metadata_variables(dataset, "batch")data <- matrix( 1:6, nrow = 2, dimnames = list(c("x1", "x2"), c("s1", "s2", "s3")) ) metadata <- data.frame( class = c("A", "B", "A"), batch = c(1, 1, 2), row.names = c("s1", "s2", "s3") ) dataset <- list(data = data, metadata = metadata) remove_metadata_variables(dataset, "batch")
Removes samples from a dataset.
remove_samples(dataset, samples.to.remove, rebuild.factors = TRUE)remove_samples(dataset, samples.to.remove, rebuild.factors = TRUE)
dataset |
Dataset to modify. |
samples.to.remove |
Samples to remove. |
rebuild.factors |
Logical. If TRUE, rebuild factors in metadata. |
A dataset object with the same structure as the input, with the selected samples removed from both 'dataset$data' and 'dataset$metadata'. If 'rebuild.factors' is 'TRUE', unused factor levels in metadata are dropped.
data <- matrix( 1:9, nrow = 3, dimnames = list(c("x1", "x2", "x3"), c("s1", "s2", "s3")) ) metadata <- data.frame( class = factor(c("A", "B", "A")), row.names = c("s1", "s2", "s3") ) dataset <- list(data = data, metadata = metadata) remove_samples(dataset, "s2")data <- matrix( 1:9, nrow = 3, dimnames = list(c("x1", "x2", "x3"), c("s1", "s2", "s3")) ) metadata <- data.frame( class = factor(c("A", "B", "A")), row.names = c("s1", "s2", "s3") ) dataset <- list(data = data, metadata = metadata) remove_samples(dataset, "s2")
Removes samples with NA in a given metadata variable.
remove_samples_by_na_metadata(dataset, metadata.var)remove_samples_by_na_metadata(dataset, metadata.var)
dataset |
Dataset to modify. |
metadata.var |
Metadata variable name. |
A dataset object with the same structure as the input, where samples with missing values in the selected metadata variable have been removed.
data <- matrix( 1:9, nrow = 3, dimnames = list(c("x1", "x2", "x3"), c("s1", "s2", "s3")) ) metadata <- data.frame( class = c("A", NA, "B"), row.names = c("s1", "s2", "s3") ) dataset <- list(data = data, metadata = metadata) remove_samples_by_na_metadata(dataset, "class")data <- matrix( 1:9, nrow = 3, dimnames = list(c("x1", "x2", "x3"), c("s1", "s2", "s3")) ) metadata <- data.frame( class = c("A", NA, "B"), row.names = c("s1", "s2", "s3") ) dataset <- list(data = data, metadata = metadata) remove_samples_by_na_metadata(dataset, "class")
Removes samples with too many missing values.
remove_samples_by_nas(dataset, max.nas = 0, by.percent = FALSE)remove_samples_by_nas(dataset, max.nas = 0, by.percent = FALSE)
dataset |
Dataset to modify. |
max.nas |
Maximum number of missing values allowed. |
by.percent |
Logical. If TRUE, max.nas is treated as a percentage. |
A dataset object with the same structure as the input, where samples whose number of missing values exceeds 'max.nas' have been removed from both 'dataset$data' and 'dataset$metadata'.
data <- matrix( c(1, NA, 3, 4, 5, NA, 7, 8, 9), nrow = 3, dimnames = list(c("x1", "x2", "x3"), c("s1", "s2", "s3")) ) metadata <- data.frame(class = c("A", "B", "A"), row.names = c("s1", "s2", "s3")) dataset <- list(data = data, metadata = metadata) remove_samples_by_nas(dataset, max.nas = 0)data <- matrix( c(1, NA, 3, 4, 5, NA, 7, 8, 9), nrow = 3, dimnames = list(c("x1", "x2", "x3"), c("s1", "s2", "s3")) ) metadata <- data.frame(class = c("A", "B", "A"), row.names = c("s1", "s2", "s3")) dataset <- list(data = data, metadata = metadata) remove_samples_by_nas(dataset, max.nas = 0)
Removes variables with too many missing values.
remove_variables_by_nas(dataset, max.nas = 0, by.percent = FALSE)remove_variables_by_nas(dataset, max.nas = 0, by.percent = FALSE)
dataset |
Dataset to modify. |
max.nas |
Maximum number of missing values allowed. |
by.percent |
Logical. If TRUE, max.nas is treated as a percentage. |
A dataset object with the same structure as the input, where variables whose number of missing values exceeds 'max.nas' have been removed from 'dataset$data'.
data <- matrix( c(1, 2, 3, NA, 5, NA, 7, 8, 9), nrow = 3, dimnames = list(c("x1", "x2", "x3"), c("s1", "s2", "s3")) ) metadata <- data.frame(class = c("A", "B", "A"), row.names = c("s1", "s2", "s3")) dataset <- list(data = data, metadata = metadata) remove_variables_by_nas(dataset, max.nas = 1)data <- matrix( c(1, 2, 3, NA, 5, NA, 7, 8, 9), nrow = 3, dimnames = list(c("x1", "x2", "x3"), c("s1", "s2", "s3")) ) metadata <- data.frame(class = c("A", "B", "A"), row.names = c("s1", "s2", "s3")) dataset <- list(data = data, metadata = metadata) remove_variables_by_nas(dataset, max.nas = 1)
Removes x values inside an interval.
remove_x_values_by_interval(dataset, min.value, max.value)remove_x_values_by_interval(dataset, min.value, max.value)
dataset |
Dataset to modify. |
min.value |
Minimum x value. |
max.value |
Maximum x value. |
A dataset object with the same structure as the input, where all variables with x values between 'min.value' and 'max.value', inclusive, have been removed from 'dataset$data'.
data <- matrix( 1:12, nrow = 4, dimnames = list(c("10", "20", "30", "40"), c("s1", "s2", "s3")) ) metadata <- data.frame(class = c("A", "B", "A"), row.names = c("s1", "s2", "s3")) dataset <- list(data = data, metadata = metadata) remove_x_values_by_interval(dataset, 15, 35)data <- matrix( 1:12, nrow = 4, dimnames = list(c("10", "20", "30", "40"), c("s1", "s2", "s3")) ) metadata <- data.frame(class = c("A", "B", "A"), row.names = c("s1", "s2", "s3")) dataset <- list(data = data, metadata = metadata) remove_x_values_by_interval(dataset, 15, 35)
Default options used in spectral data processing workflows.
data(spectra_options)data(spectra_options)
A list containing spectral processing options.
A named list of default options used by the package for spectral data processing. Each element stores a processing parameter or lookup table that controls analysis steps such as preprocessing, identification, or scoring.
data(spectra_options) names(spectra_options)data(spectra_options) names(spectra_options)
Selects samples and x values simultaneously.
subset_by_samples_and_xvalues( dataset, samples, variables = NULL, by.index = FALSE, variable.bounds = NULL, rebuild.factors = TRUE )subset_by_samples_and_xvalues( dataset, samples, variables = NULL, by.index = FALSE, variable.bounds = NULL, rebuild.factors = TRUE )
dataset |
Dataset to subset. |
samples |
Sample indexes. |
variables |
Variables to keep. |
by.index |
Logical. If TRUE, variables are interpreted as indexes. |
variable.bounds |
Optional numeric bounds for x values. |
rebuild.factors |
If TRUE, rebuild factors in metadata. |
A dataset object with the same overall structure as the input, containing only the selected samples and selected x values. The returned object includes the corresponding subset of 'dataset$data' and matching rows of 'dataset$metadata'; factor levels are rebuilt when 'rebuild.factors = TRUE'.
data <- matrix( 1:12, nrow = 4, dimnames = list(c("10", "20", "30", "40"), c("s1", "s2", "s3")) ) metadata <- data.frame( class = factor(c("A", "B", "A")), row.names = c("s1", "s2", "s3") ) dataset <- list(data = data, metadata = metadata) subset_by_samples_and_xvalues(dataset, samples = c(1, 3), variables = c("10", "30"))data <- matrix( 1:12, nrow = 4, dimnames = list(c("10", "20", "30", "40"), c("s1", "s2", "s3")) ) metadata <- data.frame( class = factor(c("A", "B", "A")), row.names = c("s1", "s2", "s3") ) dataset <- list(data = data, metadata = metadata) subset_by_samples_and_xvalues(dataset, samples = c(1, 3), variables = c("10", "30"))
Selects metadata variables to keep.
subset_metadata(dataset, variables)subset_metadata(dataset, variables)
dataset |
Dataset to subset. |
variables |
Metadata variables to keep. |
A dataset object with the same structure as the input, where 'dataset$metadata' contains only the selected metadata variables.
data <- matrix( 1:6, nrow = 2, dimnames = list(c("x1", "x2"), c("s1", "s2", "s3")) ) metadata <- data.frame( class = c("A", "B", "A"), batch = c(1, 1, 2), row.names = c("s1", "s2", "s3") ) dataset <- list(data = data, metadata = metadata) subset_metadata(dataset, "class")data <- matrix( 1:6, nrow = 2, dimnames = list(c("x1", "x2"), c("s1", "s2", "s3")) ) metadata <- data.frame( class = c("A", "B", "A"), batch = c(1, 1, 2), row.names = c("s1", "s2", "s3") ) dataset <- list(data = data, metadata = metadata) subset_metadata(dataset, "class")
Selects a random subset of samples from the dataset.
subset_random_samples(dataset, nsamples)subset_random_samples(dataset, nsamples)
dataset |
Dataset to subset. |
nsamples |
Number of samples to select. |
A dataset object with the same structure as the input, containing a random subset of 'nsamples' samples.
set.seed(123) data <- matrix( 1:12, nrow = 3, dimnames = list(c("x1", "x2", "x3"), c("s1", "s2", "s3", "s4")) ) metadata <- data.frame( class = factor(c("A", "A", "B", "B")), row.names = c("s1", "s2", "s3", "s4") ) dataset <- list(data = data, metadata = metadata) subset_random_samples(dataset, 2)set.seed(123) data <- matrix( 1:12, nrow = 3, dimnames = list(c("x1", "x2", "x3"), c("s1", "s2", "s3", "s4")) ) metadata <- data.frame( class = factor(c("A", "A", "B", "B")), row.names = c("s1", "s2", "s3", "s4") ) dataset <- list(data = data, metadata = metadata) subset_random_samples(dataset, 2)
Returns a dataset with a selected set of samples.
subset_samples(dataset, samples, rebuild.factors = TRUE)subset_samples(dataset, samples, rebuild.factors = TRUE)
dataset |
Dataset to subset. |
samples |
Vector with indexes or names of the samples to select. |
rebuild.factors |
If TRUE, rebuild factors in metadata. |
A dataset object with the same overall structure as the input, containing only the selected samples in both 'dataset$data' and 'dataset$metadata'. If 'rebuild.factors' is 'TRUE', unused factor levels in metadata are dropped.
data <- matrix( c(1, 2, 3, 4, 5, 6), nrow = 2, dimnames = list(c("x1", "x2"), c("s1", "s2", "s3")) ) metadata <- data.frame( class = factor(c("A", "B", "A")), row.names = c("s1", "s2", "s3") ) dataset <- list(data = data, metadata = metadata) subset_samples(dataset, c("s1", "s3"))data <- matrix( c(1, 2, 3, 4, 5, 6), nrow = 2, dimnames = list(c("x1", "x2"), c("s1", "s2", "s3")) ) metadata <- data.frame( class = factor(c("A", "B", "A")), row.names = c("s1", "s2", "s3") ) dataset <- list(data = data, metadata = metadata) subset_samples(dataset, c("s1", "s3"))
Selects a set of samples by the value of a metadata variable.
subset_samples_by_metadata_values(dataset, metadata.varname, values)subset_samples_by_metadata_values(dataset, metadata.varname, values)
dataset |
Dataset to subset. |
metadata.varname |
Metadata variable name. |
values |
Values to keep. |
A dataset object with the same structure as the input, containing only samples whose 'metadata.varname' value matches one of the requested 'values'.
data <- matrix( c(1, 2, 3, 4, 5, 6), nrow = 2, dimnames = list(c("x1", "x2"), c("s1", "s2", "s3")) ) metadata <- data.frame( class = factor(c("A", "B", "A")), row.names = c("s1", "s2", "s3") ) dataset <- list(data = data, metadata = metadata) subset_samples_by_metadata_values(dataset, "class", "A")data <- matrix( c(1, 2, 3, 4, 5, 6), nrow = 2, dimnames = list(c("x1", "x2"), c("s1", "s2", "s3")) ) metadata <- data.frame( class = factor(c("A", "B", "A")), row.names = c("s1", "s2", "s3") ) dataset <- list(data = data, metadata = metadata) subset_samples_by_metadata_values(dataset, "class", "A")
Selects rows of the dataset by x values or by row index.
subset_x_values(dataset, variables, by.index = FALSE)subset_x_values(dataset, variables, by.index = FALSE)
dataset |
Dataset to subset. |
variables |
Variables to keep. |
by.index |
Logical. If TRUE, variables are interpreted as row indexes. |
A dataset object with the same structure as the input, where 'dataset$data' contains only the selected variables or row indexes.
data <- matrix( 1:9, nrow = 3, dimnames = list(c("10", "20", "30"), c("s1", "s2", "s3")) ) metadata <- data.frame(group = c("A", "B", "A"), row.names = c("s1", "s2", "s3")) dataset <- list(data = data, metadata = metadata) subset_x_values(dataset, c("10", "30"))data <- matrix( 1:9, nrow = 3, dimnames = list(c("10", "20", "30"), c("s1", "s2", "s3")) ) metadata <- data.frame(group = c("A", "B", "A"), row.names = c("s1", "s2", "s3")) dataset <- list(data = data, metadata = metadata) subset_x_values(dataset, c("10", "30"))
Selects x values within a numeric interval.
subset_x_values_by_interval(dataset, min.value, max.value)subset_x_values_by_interval(dataset, min.value, max.value)
dataset |
Dataset to subset. |
min.value |
Minimum x value. |
max.value |
Maximum x value. |
A dataset object with the same structure as the input, where 'dataset$data' contains only variables whose x values fall between 'min.value' and 'max.value', inclusive.
data <- matrix( 1:12, nrow = 4, dimnames = list(c("10", "20", "30", "40"), c("s1", "s2", "s3")) ) metadata <- data.frame(group = c("A", "B", "A"), row.names = c("s1", "s2", "s3")) dataset <- list(data = data, metadata = metadata) subset_x_values_by_interval(dataset, 15, 35)data <- matrix( 1:12, nrow = 4, dimnames = list(c("10", "20", "30", "40"), c("s1", "s2", "s3")) ) metadata <- data.frame(group = c("A", "B", "A"), row.names = c("s1", "s2", "s3")) dataset <- list(data = data, metadata = metadata) subset_x_values_by_interval(dataset, 15, 35)
Keep the top rows of each variable-importance table produced during model comparison.
summary_var_importance(performances, number.rows)summary_var_importance(performances, number.rows)
performances |
A list returned by |
number.rows |
Number of rows to keep from each variable-importance table. |
A list of truncated variable-importance tables, one per model.
performances <- list( vips = list( rf = data.frame(Mean = c(0.9, 0.7, 0.4), row.names = c("v1", "v2", "v3")), svm = data.frame(Mean = c(0.8, 0.6, 0.5), row.names = c("v1", "v2", "v3")) ) ) summary_var_importance(performances, 2)performances <- list( vips = list( rf = data.frame(Mean = c(0.9, 0.7, 0.4), row.names = c("v1", "v2", "v3")), svm = data.frame(Mean = c(0.8, 0.6, 0.5), row.names = c("v1", "v2", "v3")) ) ) summary_var_importance(performances, 2)
Train a classification model from a dataset and use the fitted model to predict the class labels of new samples.
train_and_predict( dataset, new.samples, column.class, model, validation, num.folds = 10, num.repeats = 10, tunelength = 10, tunegrid = NULL, metric = NULL, summary.function = caret::defaultSummary )train_and_predict( dataset, new.samples, column.class, model, validation, num.folds = 10, num.repeats = 10, tunelength = 10, tunegrid = NULL, metric = NULL, summary.function = caret::defaultSummary )
dataset |
A dataset object containing data and metadata. |
new.samples |
A data frame or matrix with new samples to classify. |
column.class |
The metadata column containing the class labels. |
model |
A model name accepted by |
validation |
Validation method, such as |
num.folds |
Number of folds used in resampling. |
num.repeats |
Number of repeats used in repeated resampling. |
tunelength |
Number of tuning levels evaluated by |
tunegrid |
Optional data frame of tuning parameter combinations. |
metric |
Optional performance metric used for model selection. |
summary.function |
Summary function passed to
|
A list with two elements: train.result, the fitted training
object, and predictions.result, a data frame with predicted classes
for new.samples.
## Not run: datamat <- matrix( rnorm(24), nrow = 4, dimnames = list(paste0("v", 1:4), paste0("s", 1:6)) ) metadata <- data.frame(class = factor(c("A", "A", "A", "B", "B", "B"))) dataset <- list(data = datamat, metadata = metadata) new.samples <- datamat[, 1:2, drop = FALSE] train_and_predict(dataset, new.samples, "class", model = "rpart", validation = "cv") ## End(Not run)## Not run: datamat <- matrix( rnorm(24), nrow = 4, dimnames = list(paste0("v", 1:4), paste0("s", 1:6)) ) metadata <- data.frame(class = factor(c("A", "A", "A", "B", "B", "B"))) dataset <- list(data = datamat, metadata = metadata) new.samples <- datamat[, 1:2, drop = FALSE] train_and_predict(dataset, new.samples, "class", model = "rpart", validation = "cv") ## End(Not run)
Train a classifier from a dataset object using metadata or data-derived class
labels and a resampling strategy supported by caret.
train_classifier( dataset, column.class, model, validation, num.folds = 10, num.repeats = 10, tunelength = 10, tunegrid = NULL, metric = NULL, summary.function = caret::defaultSummary, class.in.metadata = TRUE )train_classifier( dataset, column.class, model, validation, num.folds = 10, num.repeats = 10, tunelength = 10, tunegrid = NULL, metric = NULL, summary.function = caret::defaultSummary, class.in.metadata = TRUE )
dataset |
A dataset object. |
column.class |
The metadata column containing the class labels. |
model |
A model name accepted by |
validation |
Validation method used in training. |
num.folds |
Number of folds used in resampling. |
num.repeats |
Number of repeats used in repeated resampling. |
tunelength |
Number of tuning levels evaluated by |
tunegrid |
Optional data frame of tuning parameter combinations. |
metric |
Optional performance metric used for model selection. |
summary.function |
Summary function passed to
|
class.in.metadata |
Logical; if |
A caret training object returned by caret::train().
## Not run: datamat <- matrix( rnorm(24), nrow = 4, dimnames = list(paste0("v", 1:4), paste0("s", 1:6)) ) metadata <- data.frame(class = factor(c("A", "A", "A", "B", "B", "B"))) dataset <- list(data = datamat, metadata = metadata) train_classifier(dataset, "class", model = "rpart", validation = "cv") ## End(Not run)## Not run: datamat <- matrix( rnorm(24), nrow = 4, dimnames = list(paste0("v", 1:4), paste0("s", 1:6)) ) metadata <- data.frame(class = factor(c("A", "A", "A", "B", "B", "B"))) dataset <- list(data = datamat, metadata = metadata) train_classifier(dataset, "class", model = "rpart", validation = "cv") ## End(Not run)
Train a set of models, collect their resampling performance, optionally compute variable importance, and store fitted models and tuning summaries.
train_models_performance( dataset, models, column.class, validation, num.folds = 10, num.repeats = 10, tunelength = 10, tunegrid = NULL, metric = NULL, summary.function = "default", class.in.metadata = TRUE, compute.varimp = TRUE )train_models_performance( dataset, models, column.class, validation, num.folds = 10, num.repeats = 10, tunelength = 10, tunegrid = NULL, metric = NULL, summary.function = "default", class.in.metadata = TRUE, compute.varimp = TRUE )
dataset |
A dataset object. |
models |
A character vector with model names accepted by |
column.class |
The metadata column containing the class labels. |
validation |
Validation method used in training. |
num.folds |
Number of folds used in resampling. |
num.repeats |
Number of repeats used in repeated resampling. |
tunelength |
Number of tuning levels evaluated by |
tunegrid |
Optional list of tuning grids, one per model. |
metric |
Optional performance metric used for model selection. |
summary.function |
Summary function, or |
class.in.metadata |
Logical; if |
compute.varimp |
Logical; if |
A list containing model performance, variable importance, full tuning results, best tuning settings, optional confusion matrices, and final fitted models.
## Not run: datamat <- matrix( rnorm(24), nrow = 4, dimnames = list(paste0("v", 1:4), paste0("s", 1:6)) ) metadata <- data.frame(class = factor(c("A", "A", "A", "B", "B", "B"))) dataset <- list(data = datamat, metadata = metadata) train_models_performance( dataset, models = c("rpart"), column.class = "class", validation = "cv", compute.varimp = FALSE ) ## End(Not run)## Not run: datamat <- matrix( rnorm(24), nrow = 4, dimnames = list(paste0("v", 1:4), paste0("s", 1:6)) ) metadata <- data.frame(class = factor(c("A", "A", "A", "B", "B", "B"))) dataset <- list(data = datamat, metadata = metadata) train_models_performance( dataset, models = c("rpart"), column.class = "class", validation = "cv", compute.varimp = FALSE ) ## End(Not run)
Performs t-distributed Stochastic Neighbor Embedding (t-SNE) dimensionality reduction on a specmine dataset.
tsne_analysis_dataset( dataset, n_components = 2, perplexity = 30, max_iter = 1000, theta = 0.5, eta = "auto", scale = FALSE, seed = 42, write.file = FALSE, file.out = NULL, ... )tsne_analysis_dataset( dataset, n_components = 2, perplexity = 30, max_iter = 1000, theta = 0.5, eta = "auto", scale = FALSE, seed = 42, write.file = FALSE, file.out = NULL, ... )
dataset |
Dataset to analyse. |
n_components |
Number of dimensions in the embedding. |
perplexity |
Perplexity parameter controlling the balance between local and global structure. It must be sufficiently small relative to the number of samples. |
max_iter |
Maximum number of optimization iterations. |
theta |
Speed-accuracy trade-off parameter. A value of zero performs exact t-SNE, whereas larger values are faster but approximate. |
eta |
Learning rate. The default value |
scale |
Logical indicating whether the data should be scaled before t-SNE. |
seed |
Random seed used for reproducibility. |
write.file |
Logical indicating whether the embedding should be written to a CSV file. |
file.out |
Output file prefix used when
|
... |
Additional arguments passed to |
A list containing the t-SNE embedding and the analysis parameters.
if (requireNamespace("Rtsne", quietly = TRUE)) { datamat <- matrix( rnorm(40), nrow = 5, dimnames = list( paste0("x", 1:5), paste0("s", 1:8) ) ) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), length.out = 8)) ) ) tsne.result <- tsne_analysis_dataset( dataset, n_components = 2, perplexity = 2, max_iter = 250, seed = 42 ) }if (requireNamespace("Rtsne", quietly = TRUE)) { datamat <- matrix( rnorm(40), nrow = 5, dimnames = list( paste0("x", 1:5), paste0("s", 1:8) ) ) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), length.out = 8)) ) ) tsne.result <- tsne_analysis_dataset( dataset, n_components = 2, perplexity = 2, max_iter = 250, seed = 42 ) }
Creates a two-dimensional t-SNE plot coloured by k-means clusters.
tsne_kmeans_plot2D( dataset, tsne.result, num.clusters = 3, dims = c(1, 2), kmeans.result = NULL, labels = FALSE, bw = FALSE, ellipses = FALSE, leg.pos = "right", xlim = NULL, ylim = NULL )tsne_kmeans_plot2D( dataset, tsne.result, num.clusters = 3, dims = c(1, 2), kmeans.result = NULL, labels = FALSE, bw = FALSE, ellipses = FALSE, leg.pos = "right", xlim = NULL, ylim = NULL )
dataset |
Dataset to cluster. |
tsne.result |
Result returned by |
num.clusters |
Number of k-means clusters. |
dims |
Two embedding dimensions to plot. |
kmeans.result |
Optional result returned by |
labels |
Logical indicating whether sample labels should be displayed. |
bw |
Logical indicating whether a black-and-white plot should be used. |
ellipses |
Logical indicating whether group ellipses should be displayed. |
leg.pos |
Legend position. |
xlim |
Optional x-axis limits. |
ylim |
Optional y-axis limits. |
A ggplot object.
if (requireNamespace("Rtsne", quietly = TRUE)) { datamat <- matrix( rnorm(40), nrow = 5, dimnames = list( paste0("x", 1:5), paste0("s", 1:8) ) ) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), length.out = 8)) ) ) tsne.result <- tsne_analysis_dataset( dataset, perplexity = 2, max_iter = 250, seed = 42 ) kmeans.result <- list( cluster = rep(1:2, each = 4) ) tsne_kmeans_plot2D( dataset, tsne.result, num.clusters = 2, kmeans.result = kmeans.result ) }if (requireNamespace("Rtsne", quietly = TRUE)) { datamat <- matrix( rnorm(40), nrow = 5, dimnames = list( paste0("x", 1:5), paste0("s", 1:8) ) ) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), length.out = 8)) ) ) tsne.result <- tsne_analysis_dataset( dataset, perplexity = 2, max_iter = 250, seed = 42 ) kmeans.result <- list( cluster = rep(1:2, each = 4) ) tsne_kmeans_plot2D( dataset, tsne.result, num.clusters = 2, kmeans.result = kmeans.result ) }
Creates an interactive three-dimensional t-SNE plot coloured by k-means clusters.
tsne_kmeans_plot3D( dataset, tsne.result, num.clusters = 3, dims = c(1, 2, 3), kmeans.result = NULL, title = "t-SNE 3D K-means Plot" )tsne_kmeans_plot3D( dataset, tsne.result, num.clusters = 3, dims = c(1, 2, 3), kmeans.result = NULL, title = "t-SNE 3D K-means Plot" )
dataset |
Dataset to cluster. |
tsne.result |
Result returned by |
num.clusters |
Number of k-means clusters. |
dims |
Three embedding dimensions to plot. |
kmeans.result |
Optional result returned by |
title |
Plot title. |
A plotly htmlwidget.
if (requireNamespace("Rtsne", quietly = TRUE) && requireNamespace("plotly", quietly = TRUE)) { datamat <- matrix( rnorm(40), nrow = 5, dimnames = list( paste0("x", 1:5), paste0("s", 1:8) ) ) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), length.out = 8)) ) ) tsne.result <- tsne_analysis_dataset( dataset, n_components = 3, perplexity = 2, max_iter = 250, seed = 42 ) kmeans.result <- list( cluster = rep(1:2, each = 4) ) tsne_kmeans_plot3D( dataset, tsne.result, num.clusters = 2, kmeans.result = kmeans.result ) }if (requireNamespace("Rtsne", quietly = TRUE) && requireNamespace("plotly", quietly = TRUE)) { datamat <- matrix( rnorm(40), nrow = 5, dimnames = list( paste0("x", 1:5), paste0("s", 1:8) ) ) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), length.out = 8)) ) ) tsne.result <- tsne_analysis_dataset( dataset, n_components = 3, perplexity = 2, max_iter = 250, seed = 42 ) kmeans.result <- list( cluster = rep(1:2, each = 4) ) tsne_kmeans_plot3D( dataset, tsne.result, num.clusters = 2, kmeans.result = kmeans.result ) }
Creates a pairs plot for t-SNE dimensions coloured by k-means clusters.
tsne_pairs_kmeans_plot( dataset, tsne.result, num.clusters = 3, kmeans.result = NULL, dims = 1:min(5, ncol(tsne.result$embedding)) )tsne_pairs_kmeans_plot( dataset, tsne.result, num.clusters = 3, kmeans.result = NULL, dims = 1:min(5, ncol(tsne.result$embedding)) )
dataset |
Dataset to cluster. |
tsne.result |
Result returned by |
num.clusters |
Number of k-means clusters. |
kmeans.result |
Optional result returned by |
dims |
Embedding dimensions to include in the pairs plot. |
A GGally pairs plot object.
if (requireNamespace("Rtsne", quietly = TRUE) && requireNamespace("GGally", quietly = TRUE)) { datamat <- matrix( rnorm(40), nrow = 5, dimnames = list( paste0("x", 1:5), paste0("s", 1:8) ) ) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), length.out = 8)) ) ) tsne.result <- tsne_analysis_dataset( dataset, n_components = 3, perplexity = 2, max_iter = 250, seed = 42 ) kmeans.result <- list( cluster = rep(1:2, each = 4) ) tsne_pairs_kmeans_plot( dataset, tsne.result, num.clusters = 2, kmeans.result = kmeans.result, dims = 1:3 ) }if (requireNamespace("Rtsne", quietly = TRUE) && requireNamespace("GGally", quietly = TRUE)) { datamat <- matrix( rnorm(40), nrow = 5, dimnames = list( paste0("x", 1:5), paste0("s", 1:8) ) ) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), length.out = 8)) ) ) tsne.result <- tsne_analysis_dataset( dataset, n_components = 3, perplexity = 2, max_iter = 250, seed = 42 ) kmeans.result <- list( cluster = rep(1:2, each = 4) ) tsne_pairs_kmeans_plot( dataset, tsne.result, num.clusters = 2, kmeans.result = kmeans.result, dims = 1:3 ) }
Creates a pairs plot for selected t-SNE dimensions.
tsne_pairs_plot( dataset, tsne.result, column.class = NULL, dims = 1:min(5, ncol(tsne.result$embedding)), ... )tsne_pairs_plot( dataset, tsne.result, column.class = NULL, dims = 1:min(5, ncol(tsne.result$embedding)), ... )
dataset |
Dataset used to calculate the embedding. |
tsne.result |
Result returned by |
column.class |
Optional metadata column used to colour samples. |
dims |
Embedding dimensions to include in the pairs plot. |
... |
Additional arguments passed to |
A GGally pairs plot object.
if (requireNamespace("Rtsne", quietly = TRUE) && requireNamespace("GGally", quietly = TRUE)) { datamat <- matrix( rnorm(40), nrow = 5, dimnames = list( paste0("x", 1:5), paste0("s", 1:8) ) ) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), length.out = 8)) ) ) tsne.result <- tsne_analysis_dataset( dataset, n_components = 3, perplexity = 2, max_iter = 250, seed = 42 ) tsne_pairs_plot( dataset, tsne.result, column.class = "class", dims = 1:3 ) }if (requireNamespace("Rtsne", quietly = TRUE) && requireNamespace("GGally", quietly = TRUE)) { datamat <- matrix( rnorm(40), nrow = 5, dimnames = list( paste0("x", 1:5), paste0("s", 1:8) ) ) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), length.out = 8)) ) ) tsne.result <- tsne_analysis_dataset( dataset, n_components = 3, perplexity = 2, max_iter = 250, seed = 42 ) tsne_pairs_plot( dataset, tsne.result, column.class = "class", dims = 1:3 ) }
Creates a two-dimensional scores plot from a t-SNE result.
tsne_scoresplot2D( dataset, tsne.result, column.class = NULL, dims = c(1, 2), labels = FALSE, ellipses = FALSE, bw = FALSE, pallette = 2, leg.pos = "right", xlim = NULL, ylim = NULL )tsne_scoresplot2D( dataset, tsne.result, column.class = NULL, dims = c(1, 2), labels = FALSE, ellipses = FALSE, bw = FALSE, pallette = 2, leg.pos = "right", xlim = NULL, ylim = NULL )
dataset |
Dataset used to calculate the embedding. |
tsne.result |
Result returned by |
column.class |
Optional metadata column used to colour or group samples. |
dims |
Two embedding dimensions to plot. |
labels |
Logical indicating whether sample labels should be displayed. |
ellipses |
Logical indicating whether group ellipses should be displayed. |
bw |
Logical indicating whether a black-and-white plot should be used. |
pallette |
RColorBrewer palette number. |
leg.pos |
Legend position. |
xlim |
Optional x-axis limits. |
ylim |
Optional y-axis limits. |
A ggplot object.
if (requireNamespace("Rtsne", quietly = TRUE)) { datamat <- matrix( rnorm(40), nrow = 5, dimnames = list( paste0("x", 1:5), paste0("s", 1:8) ) ) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), length.out = 8)) ) ) tsne.result <- tsne_analysis_dataset( dataset, perplexity = 2, max_iter = 250, seed = 42 ) tsne_scoresplot2D( dataset, tsne.result, column.class = "class" ) }if (requireNamespace("Rtsne", quietly = TRUE)) { datamat <- matrix( rnorm(40), nrow = 5, dimnames = list( paste0("x", 1:5), paste0("s", 1:8) ) ) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), length.out = 8)) ) ) tsne.result <- tsne_analysis_dataset( dataset, perplexity = 2, max_iter = 250, seed = 42 ) tsne_scoresplot2D( dataset, tsne.result, column.class = "class" ) }
Creates an interactive three-dimensional scores plot from a t-SNE result.
tsne_scoresplot3D( dataset, tsne.result, column.class = NULL, dims = c(1, 2, 3), title = "t-SNE 3D Scores Plot" )tsne_scoresplot3D( dataset, tsne.result, column.class = NULL, dims = c(1, 2, 3), title = "t-SNE 3D Scores Plot" )
dataset |
Dataset used to calculate the embedding. |
tsne.result |
Result returned by |
column.class |
Optional metadata column used to colour samples. |
dims |
Three embedding dimensions to plot. |
title |
Plot title. |
A plotly htmlwidget.
if (requireNamespace("Rtsne", quietly = TRUE) && requireNamespace("plotly", quietly = TRUE)) { datamat <- matrix( rnorm(40), nrow = 5, dimnames = list( paste0("x", 1:5), paste0("s", 1:8) ) ) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), length.out = 8)) ) ) tsne.result <- tsne_analysis_dataset( dataset, n_components = 3, perplexity = 2, max_iter = 250, seed = 42 ) tsne_scoresplot3D( dataset, tsne.result, column.class = "class" ) }if (requireNamespace("Rtsne", quietly = TRUE) && requireNamespace("plotly", quietly = TRUE)) { datamat <- matrix( rnorm(40), nrow = 5, dimnames = list( paste0("x", 1:5), paste0("s", 1:8) ) ) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), length.out = 8)) ) ) tsne.result <- tsne_analysis_dataset( dataset, n_components = 3, perplexity = 2, max_iter = 250, seed = 42 ) tsne_scoresplot3D( dataset, tsne.result, column.class = "class" ) }
Performs Uniform Manifold Approximation and Projection (UMAP) dimensionality reduction on a specmine dataset.
umap_analysis_dataset( dataset, n_components = 2, n_neighbors = 15, min_dist = 0.1, metric = "euclidean", scale = FALSE, ret_model = FALSE, seed = 42, write.file = FALSE, file.out = NULL, ... )umap_analysis_dataset( dataset, n_components = 2, n_neighbors = 15, min_dist = 0.1, metric = "euclidean", scale = FALSE, ret_model = FALSE, seed = 42, write.file = FALSE, file.out = NULL, ... )
dataset |
Dataset to analyse. |
n_components |
Number of dimensions in the embedding. |
n_neighbors |
Number of nearest neighbours. |
min_dist |
Minimum distance between points in the embedding. |
metric |
Distance metric passed to |
scale |
Logical indicating whether the data should be scaled. |
ret_model |
Logical indicating whether the UMAP model should be returned. |
seed |
Random seed used for reproducibility. |
write.file |
Logical indicating whether the embedding should be written to a CSV file. |
file.out |
Output file prefix used when |
... |
Additional arguments passed to |
A list containing the UMAP embedding and the analysis parameters.
When ret_model = TRUE, the fitted UMAP model is also returned.
if (requireNamespace("uwot", quietly = TRUE)) { datamat <- matrix( rnorm(40), nrow = 5, dimnames = list(paste0("x", 1:5), paste0("s", 1:8)) ) dataset <- list( data = datamat, metadata = data.frame(class = factor(rep(c("A", "B"), length.out = 8))) ) result <- umap_analysis_dataset( dataset, n_components = 2, n_neighbors = 3, seed = 42 ) }if (requireNamespace("uwot", quietly = TRUE)) { datamat <- matrix( rnorm(40), nrow = 5, dimnames = list(paste0("x", 1:5), paste0("s", 1:8)) ) dataset <- list( data = datamat, metadata = data.frame(class = factor(rep(c("A", "B"), length.out = 8))) ) result <- umap_analysis_dataset( dataset, n_components = 2, n_neighbors = 3, seed = 42 ) }
Creates a two-dimensional UMAP plot coloured by k-means clusters.
umap_kmeans_plot2D( dataset, umap.result, num.clusters = 3, dims = c(1, 2), kmeans.result = NULL, labels = FALSE, bw = FALSE, ellipses = FALSE, leg.pos = "right", xlim = NULL, ylim = NULL )umap_kmeans_plot2D( dataset, umap.result, num.clusters = 3, dims = c(1, 2), kmeans.result = NULL, labels = FALSE, bw = FALSE, ellipses = FALSE, leg.pos = "right", xlim = NULL, ylim = NULL )
dataset |
Dataset to cluster. |
umap.result |
Result returned by |
num.clusters |
Number of k-means clusters. |
dims |
Two embedding dimensions to plot. |
kmeans.result |
Optional result returned by |
labels |
Logical indicating whether sample labels should be displayed. |
bw |
Logical indicating whether a black-and-white plot should be used. |
ellipses |
Logical indicating whether group ellipses should be displayed. |
leg.pos |
Legend position. |
xlim |
Optional x-axis limits. |
ylim |
Optional y-axis limits. |
A ggplot object.
if (requireNamespace("uwot", quietly = TRUE)) { datamat <- matrix( rnorm(40), nrow = 5, dimnames = list( paste0("x", 1:5), paste0("s", 1:8) ) ) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), length.out = 8)) ) ) umap.result <- umap_analysis_dataset( dataset, n_components = 2, n_neighbors = 3, seed = 42 ) umap_kmeans_plot2D( dataset, umap.result, num.clusters = 2, dims = c(1, 2) ) }if (requireNamespace("uwot", quietly = TRUE)) { datamat <- matrix( rnorm(40), nrow = 5, dimnames = list( paste0("x", 1:5), paste0("s", 1:8) ) ) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), length.out = 8)) ) ) umap.result <- umap_analysis_dataset( dataset, n_components = 2, n_neighbors = 3, seed = 42 ) umap_kmeans_plot2D( dataset, umap.result, num.clusters = 2, dims = c(1, 2) ) }
Creates an interactive three-dimensional UMAP plot coloured by k-means clusters.
umap_kmeans_plot3D( dataset, umap.result, num.clusters = 3, dims = c(1, 2, 3), kmeans.result = NULL, title = "UMAP 3D K-means Plot" )umap_kmeans_plot3D( dataset, umap.result, num.clusters = 3, dims = c(1, 2, 3), kmeans.result = NULL, title = "UMAP 3D K-means Plot" )
dataset |
Dataset to cluster. |
umap.result |
Result returned by |
num.clusters |
Number of k-means clusters. |
dims |
Three embedding dimensions to plot. |
kmeans.result |
Optional result returned by |
title |
Plot title. |
A plotly htmlwidget.
if (requireNamespace("uwot", quietly = TRUE) && requireNamespace("plotly", quietly = TRUE)) { datamat <- matrix( rnorm(40), nrow = 5, dimnames = list( paste0("x", 1:5), paste0("s", 1:8) ) ) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), length.out = 8)) ) ) umap.result <- umap_analysis_dataset( dataset, n_components = 3, n_neighbors = 3, seed = 42 ) umap_kmeans_plot3D( dataset, umap.result, num.clusters = 2, dims = c(1, 2, 3) ) }if (requireNamespace("uwot", quietly = TRUE) && requireNamespace("plotly", quietly = TRUE)) { datamat <- matrix( rnorm(40), nrow = 5, dimnames = list( paste0("x", 1:5), paste0("s", 1:8) ) ) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), length.out = 8)) ) ) umap.result <- umap_analysis_dataset( dataset, n_components = 3, n_neighbors = 3, seed = 42 ) umap_kmeans_plot3D( dataset, umap.result, num.clusters = 2, dims = c(1, 2, 3) ) }
Creates a pairs plot for UMAP dimensions coloured by k-means clusters.
umap_pairs_kmeans_plot( dataset, umap.result, num.clusters = 3, kmeans.result = NULL, dims = 1:min(5, ncol(umap.result$embedding)) )umap_pairs_kmeans_plot( dataset, umap.result, num.clusters = 3, kmeans.result = NULL, dims = 1:min(5, ncol(umap.result$embedding)) )
dataset |
Dataset to cluster. |
umap.result |
Result returned by |
num.clusters |
Number of k-means clusters. |
kmeans.result |
Optional result returned by |
dims |
Embedding dimensions to include in the pairs plot. |
A GGally pairs plot object.
if (requireNamespace("uwot", quietly = TRUE) && requireNamespace("GGally", quietly = TRUE)) { datamat <- matrix( rnorm(40), nrow = 5, dimnames = list( paste0("x", 1:5), paste0("s", 1:8) ) ) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), length.out = 8)) ) ) umap.result <- umap_analysis_dataset( dataset, n_components = 3, n_neighbors = 3, seed = 42 ) umap_pairs_kmeans_plot( dataset, umap.result, num.clusters = 2, dims = 1:3 ) }if (requireNamespace("uwot", quietly = TRUE) && requireNamespace("GGally", quietly = TRUE)) { datamat <- matrix( rnorm(40), nrow = 5, dimnames = list( paste0("x", 1:5), paste0("s", 1:8) ) ) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), length.out = 8)) ) ) umap.result <- umap_analysis_dataset( dataset, n_components = 3, n_neighbors = 3, seed = 42 ) umap_pairs_kmeans_plot( dataset, umap.result, num.clusters = 2, dims = 1:3 ) }
Creates a pairs plot for selected UMAP dimensions.
umap_pairs_plot( dataset, umap.result, column.class = NULL, dims = 1:min(5, ncol(umap.result$embedding)), ... )umap_pairs_plot( dataset, umap.result, column.class = NULL, dims = 1:min(5, ncol(umap.result$embedding)), ... )
dataset |
Dataset used to calculate the embedding. |
umap.result |
Result returned by |
column.class |
Optional metadata column used to colour samples. |
dims |
Embedding dimensions to include in the pairs plot. |
... |
Additional arguments passed to |
A GGally pairs plot object.
if (requireNamespace("uwot", quietly = TRUE) && requireNamespace("GGally", quietly = TRUE)) { datamat <- matrix(rnorm(40), nrow = 5) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), length.out = 8)) ) ) result <- umap_analysis_dataset( dataset, n_components = 3, n_neighbors = 3 ) umap_pairs_plot( dataset, result, column.class = "class", dims = 1:3 ) }if (requireNamespace("uwot", quietly = TRUE) && requireNamespace("GGally", quietly = TRUE)) { datamat <- matrix(rnorm(40), nrow = 5) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), length.out = 8)) ) ) result <- umap_analysis_dataset( dataset, n_components = 3, n_neighbors = 3 ) umap_pairs_plot( dataset, result, column.class = "class", dims = 1:3 ) }
Creates a two-dimensional scores plot from a UMAP result.
umap_scoresplot2D( dataset, umap.result, column.class = NULL, dims = c(1, 2), labels = FALSE, ellipses = FALSE, bw = FALSE, pallette = 2, leg.pos = "right", xlim = NULL, ylim = NULL )umap_scoresplot2D( dataset, umap.result, column.class = NULL, dims = c(1, 2), labels = FALSE, ellipses = FALSE, bw = FALSE, pallette = 2, leg.pos = "right", xlim = NULL, ylim = NULL )
dataset |
Dataset used to calculate the embedding. |
umap.result |
Result returned by |
column.class |
Optional metadata column used to colour or group samples. |
dims |
Two embedding dimensions to plot. |
labels |
Logical indicating whether sample labels should be displayed. |
ellipses |
Logical indicating whether group ellipses should be displayed. |
bw |
Logical indicating whether a black-and-white plot should be used. |
pallette |
RColorBrewer palette number. |
leg.pos |
Legend position. |
xlim |
Optional x-axis limits. |
ylim |
Optional y-axis limits. |
A ggplot object.
if (requireNamespace("uwot", quietly = TRUE)) { datamat <- matrix(rnorm(40), nrow = 5) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), length.out = 8)) ) ) result <- umap_analysis_dataset(dataset, n_neighbors = 3) umap_scoresplot2D(dataset, result, column.class = "class") }if (requireNamespace("uwot", quietly = TRUE)) { datamat <- matrix(rnorm(40), nrow = 5) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), length.out = 8)) ) ) result <- umap_analysis_dataset(dataset, n_neighbors = 3) umap_scoresplot2D(dataset, result, column.class = "class") }
Creates an interactive three-dimensional scores plot from a UMAP result.
umap_scoresplot3D( dataset, umap.result, column.class = NULL, dims = c(1, 2, 3), title = "UMAP 3D Scores Plot" )umap_scoresplot3D( dataset, umap.result, column.class = NULL, dims = c(1, 2, 3), title = "UMAP 3D Scores Plot" )
dataset |
Dataset used to calculate the embedding. |
umap.result |
Result returned by |
column.class |
Optional metadata column used to colour samples. |
dims |
Three embedding dimensions to plot. |
title |
Plot title. |
A plotly htmlwidget.
if (requireNamespace("uwot", quietly = TRUE) && requireNamespace("plotly", quietly = TRUE)) { datamat <- matrix(rnorm(40), nrow = 5) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), length.out = 8)) ) ) result <- umap_analysis_dataset( dataset, n_components = 3, n_neighbors = 3 ) umap_scoresplot3D(dataset, result, column.class = "class") }if (requireNamespace("uwot", quietly = TRUE) && requireNamespace("plotly", quietly = TRUE)) { datamat <- matrix(rnorm(40), nrow = 5) dataset <- list( data = datamat, metadata = data.frame( class = factor(rep(c("A", "B"), length.out = 8)) ) ) result <- umap_analysis_dataset( dataset, n_components = 3, n_neighbors = 3 ) umap_scoresplot3D(dataset, result, column.class = "class") }