Title: | Time Series Analysis Library |
---|---|
Description: | The library allows to perform a multivariate time series classification based on the use of Discrete Wavelet Transform for feature extraction, a step wise discriminant to select the most relevant features and finally, the use of a linear or quadratic discriminant for classification. Note that all these steps can be done separately which allows to implement new steps. Velasco, I., Sipols, A., de Blas, C. S., Pastor, L., & Bayona, S. (2023) <doi:10.1186/S12938-023-01079-X>. Percival, D. B., & Walden, A. T. (2000,ISBN:0521640687). Maharaj, E. A., & Alonso, A. M. (2014) <doi:10.1016/j.csda.2013.09.006>. |
Authors: | Iván Velasco [aut, cre, cph] |
Maintainer: | Iván Velasco <[email protected]> |
License: | Artistic-2.0 |
Version: | 0.1.3 |
Built: | 2024-10-01 06:51:12 UTC |
Source: | CRAN |
Print the available features for the MultiWaveAnalysis
and
StepDiscrim
availableFeatures()
availableFeatures()
A data.frame
containing the name of the characteristics and their
abbreviations for use in the code. For example, to use variances and
correlations, the vector c("Var", "Cor") will be used.
availableFeatures()
availableFeatures()
Print the available filters for the wave analysis
availableFilters()
availableFilters()
A data.frame
containing all supported filters
availableFilters()
availableFilters()
Select the DWT level of decomposition based on wavelet filter, data series length and a user choice
chooseLevel(choice, filter, N)
chooseLevel(choice, filter, N)
choice |
Valid values:
|
filter |
Wavelet transform filter name. To see the available filters use
the function |
N |
Number of observations. Must be a positive integer |
Number of level of decomposition based in selection criteria
Percival, D. B. and A. T. Walden (2000) Wavelet Methods for Time Series Analysis. Cambridge: Cambridge University Press.
lev <- chooseLevel("conservative", "haar", 8)
lev <- chooseLevel("conservative", "haar", 8)
This function allows to classify observations based on a pretrained model that could have been obtained in several ways (such as using the train model function). T
classify(data, ...)
classify(data, ...)
data |
The data to be classified. This data can be either the raw data , or a MultiWaveAnalysis object generated earlier. |
... |
Additional arguments |
A factor with predicted class of each observation
This function allows to classify observations based on a pretrained model that could have been obtained in several ways (such as using the train model function).
## S3 method for class 'array' classify(data, model, ...)
## S3 method for class 'array' classify(data, model, ...)
data |
Sample from the population (dim x length x cases) |
model |
pretrained discriminant model (lda or qda) |
... |
Additional arguments |
A factor with predicted class of each observation
load(system.file("extdata/ECGExample.rda",package = "TSEAL")) # We simulate that the second series has been obtained after Series1 <- ECGExample[, , 1:9] Series2 <- ECGExample[, , 10, drop = FALSE] # Training a discriminant model MWA <- MultiWaveAnalysis(Series1, "haar", features = c("var")) MWADiscrim <- StepDiscrim(MWA, c(rep(1, 5), rep(2, 4)), maxvars = 5, features = c("var")) model <- trainModel(MWADiscrim, c(rep(1, 5), rep(2, 4)), "linear") # Using the discriminant trained on new data prediction <- classify(Series2, model)
load(system.file("extdata/ECGExample.rda",package = "TSEAL")) # We simulate that the second series has been obtained after Series1 <- ECGExample[, , 1:9] Series2 <- ECGExample[, , 10, drop = FALSE] # Training a discriminant model MWA <- MultiWaveAnalysis(Series1, "haar", features = c("var")) MWADiscrim <- StepDiscrim(MWA, c(rep(1, 5), rep(2, 4)), maxvars = 5, features = c("var")) model <- trainModel(MWADiscrim, c(rep(1, 5), rep(2, 4)), "linear") # Using the discriminant trained on new data prediction <- classify(Series2, model)
This function allows to classify observations based on a pretrained model that could have been obtained in several ways (such as using the train model function).
## S3 method for class 'MultiWaveAnalysis' classify(data, model, ...)
## S3 method for class 'MultiWaveAnalysis' classify(data, model, ...)
data |
Data to be classified by the model. Remember that it must be an object of type MultiWaveAnalysis. Note that it should have the same variables selected as those used to generate the model. |
model |
pretrained discriminant model (lda or qda) |
... |
Additional arguments |
A factor with predicted class of each observation
load(system.file("extdata/ECGExample.rda",package = "TSEAL")) # We simulate that the second series has been obtained after Series1 <- ECGExample[, , 1:9] Series2 <- ECGExample[, , 10, drop = FALSE] # Training a discriminant model MWA <- MultiWaveAnalysis(Series1, "haar", features = c("var")) MWADiscrim <- StepDiscrim(MWA, c(rep(1, 5), rep(2, 4)), maxvars = 5, features = c("var")) model <- trainModel(MWADiscrim, c(rep(1, 5), rep(2, 4)), "linear") # Using the discriminant trained on new data MWA2 <- MultiWaveAnalysis(Series2, "haar", features = c("var")) MWA2Discrim <- SameDiscrim(MWA2, MWADiscrim) prediction <- classify(MWA2Discrim, model)
load(system.file("extdata/ECGExample.rda",package = "TSEAL")) # We simulate that the second series has been obtained after Series1 <- ECGExample[, , 1:9] Series2 <- ECGExample[, , 10, drop = FALSE] # Training a discriminant model MWA <- MultiWaveAnalysis(Series1, "haar", features = c("var")) MWADiscrim <- StepDiscrim(MWA, c(rep(1, 5), rep(2, 4)), maxvars = 5, features = c("var")) model <- trainModel(MWADiscrim, c(rep(1, 5), rep(2, 4)), "linear") # Using the discriminant trained on new data MWA2 <- MultiWaveAnalysis(Series2, "haar", features = c("var")) MWA2Discrim <- SameDiscrim(MWA2, MWADiscrim) prediction <- classify(MWA2Discrim, model)
This function permits to extract certain observations from a MultiWaveAnalysis
extractSubset(MWA, indices)
extractSubset(MWA, indices)
MWA |
MultiWaveAnalysis from which the desired observations will be extracted |
indices |
Indices that will indicate which observations will be extracted |
A list with two elements:
MWA: The MultiWaveAnalysis provided minus the extracted observations.
MWAExtracted: A new MultiWaveAnalysis with the extracted observations
load(system.file("extdata/ECGExample.rda",package = "TSEAL")) MWA <- MultiWaveAnalysis(ECGExample, "haar", features = "Var") aux <- extractSubset(MWA, c(1, 2, 3)) MWATrain <- aux[[1]] MWATest <- aux[[2]]
load(system.file("extdata/ECGExample.rda",package = "TSEAL")) MWA <- MultiWaveAnalysis(ECGExample, "haar", features = "Var") aux <- extractSubset(MWA, c(1, 2, 3)) MWATrain <- aux[[1]] MWATest <- aux[[2]]
This function allows to obtain in a single step the complete MultiWaveAnalysis and the selection of the most discriminating variables of the MultiWaveAnalysis.
generateStepDiscrim( series, labels, f, maxvars, VStep, lev = 0, features = c("Var", "Cor", "IQR", "PE", "DM"), nCores = 0 )
generateStepDiscrim( series, labels, f, maxvars, VStep, lev = 0, features = c("Var", "Cor", "IQR", "PE", "DM"), nCores = 0 )
series |
Sample from the population (dim x length x cases) |
labels |
Labeled vector that classify the observations |
f |
Selected filter for the MODWT (to see the available filters use the
function |
maxvars |
Maximum number of variables included by the StepDiscrim algorithm (Note that if you defined this, can not define VStep). Must be a positive integer |
VStep |
Minimum value of V above which all other variables are considered irrelevant and therefore will not be included. (Note that if you defined this, can not defined maxvars).Must be a positive number. For more information see StepDiscrim documentation. |
lev |
Determines the number of decomposition levels for MODWT (by default the optimum is calculated). Must be a positive integer, where 0 corresponds to the default behavior. |
features |
A list of characteristics that will be used for the
classification process. To see the available features see
|
nCores |
Determines the number of processes that will be used in the function, by default it uses all but one of the system cores. Must be a positive integer, where 0 corresponds to the default behavior |
A MultiWaveAnalysis with the most discriminant variables based on the features indicated.
load(system.file("extdata/ECGExample.rda",package = "TSEAL")) # The dataset has the first 5 elements of class 1 # and the last 5 of class 2. labels <- c(rep(1, 5), rep(2, 5)) MWADiscrim <- generateStepDiscrim(ECGExample, labels, "haar", features = c("Var"), maxvars = 5 ) # or using the VStep option MWADiscrim <- generateStepDiscrim(ECGExample, labels, "haar", features = c("Var", "Cor"), VStep = 0.7 )
load(system.file("extdata/ECGExample.rda",package = "TSEAL")) # The dataset has the first 5 elements of class 1 # and the last 5 of class 2. labels <- c(rep(1, 5), rep(2, 5)) MWADiscrim <- generateStepDiscrim(ECGExample, labels, "haar", features = c("Var"), maxvars = 5 ) # or using the VStep option MWADiscrim <- generateStepDiscrim(ECGExample, labels, "haar", features = c("Var", "Cor"), VStep = 0.7 )
This function performs the K-Fold Cross Validation (KFCV) process with different types of input parameters.
KFCV(data, ...)
KFCV(data, ...)
data |
Starting data to generate the validation. It can be either the raw data, or a previously generated MultiWaveAnalysis object. |
... |
Additional arguments |
Not return value, used as generic function
It generates and validates a discriminant model starting from the data. First , a MultiWaveAnalysis object is obtained according to the selected characteristics ,filter and levels. Then, the most important features are selected using a stepwise discriminant that allows to select a maximum number of variables (maxvars) or a minimum enhancement step (VStep). Finally, the model is trained using the subset of features and validated using K-Fold Cross Validation (KFCV).
## S3 method for class 'array' KFCV( data, labels, f, method, maxvars, VStep, k = 5L, lev = 0L, features = c("Var", "Cor", "IQR", "PE", "DM"), returnClassification = FALSE, nCores = 0, ... )
## S3 method for class 'array' KFCV( data, labels, f, method, maxvars, VStep, k = 5L, lev = 0L, features = c("Var", "Cor", "IQR", "PE", "DM"), returnClassification = FALSE, nCores = 0, ... )
data |
Sample from the population (dim x length x cases) |
labels |
Labeled vector that classify the observations |
f |
Selected filter for the MODWT (to see the available filters use the
function |
method |
Selected method for the discriminant. Valid values "linear" "quadratic" |
maxvars |
Maximum number of variables included by the StepDiscrim algorithm (Note that if you defined this, can not define VStep). Must be a positive integer greater than 0. |
VStep |
Minimum value of V above which all other variables are considered irrelevant and therefore will not be included. (Note that if you defined this, can not defined maxvars). Must be a positive number and greater than 0. For more information see StepDiscrim documentation |
k |
The number of folds in KFCV. Must be a positive integer lower or equal than the number of observations |
lev |
Determines the number of decomposition levels for MODWT (by default the optimum is calculated using the "conservative" strategy). Must be a positive integer (including 0 to auto-select the level) |
features |
A list of characteristics that will be used for the
classification process. To see the available features see
|
returnClassification |
Allows to select if the raw result classification is returned. |
nCores |
Determines the number of processes that will be used in the function, by default it uses all but one of the system cores. Must be a positive integer, where 0 corresponds to the default behavior. |
... |
Additional arguments |
if returnClassification is false return a object of class confusionMatrix
if returnClassification is true, it returns a list containing an object of the confusionMatrix class and a vector with the classification result.
load(system.file("extdata/ECGExample.rda",package = "TSEAL")) labels <- c(rep(1, 5), rep(2, 5)) CM <- KFCV(ECGExample, labels, "haar", "linear", maxvars = 5, features = c("Var"), returnClassification = FALSE ) # or with VStep CMV <- KFCV(ECGExample, labels, "haar", "linear", k = 5, VStep = 5, features = c("Var"), returnClassification = FALSE )
load(system.file("extdata/ECGExample.rda",package = "TSEAL")) labels <- c(rep(1, 5), rep(2, 5)) CM <- KFCV(ECGExample, labels, "haar", "linear", maxvars = 5, features = c("Var"), returnClassification = FALSE ) # or with VStep CMV <- KFCV(ECGExample, labels, "haar", "linear", k = 5, VStep = 5, features = c("Var"), returnClassification = FALSE )
Performs k-fold cross-validation where groups are chosen randomly. In case the value k is not divisor of the number of observations the last group will have nobs mod k observations.
## S3 method for class 'MultiWaveAnalysis' KFCV(data, labels, method, k = 5L, returnClassification = FALSE, ...)
## S3 method for class 'MultiWaveAnalysis' KFCV(data, labels, method, k = 5L, returnClassification = FALSE, ...)
data |
MultiWaveAnalysis (MWA) object obtained with MultiWaveAnalysis and
preferably obtained a subset of its characteristics
( |
labels |
labeled vector that classify the observations. |
method |
Selected method for discrimination. Valid options "linear" "quadratic" |
k |
the number of folds in KFCV. Must be a positive integer and lower or equal than the number of observations |
returnClassification |
Allows to select if the raw result classification is returned. |
... |
Additional arguments |
if returnClassification is false return a object of class confusionMatrix
if returnClassification is true, it returns a list containing an object of the confusionMatrix class and a vector with the classification result.
load(system.file("extdata/ECGExample.rda",package = "TSEAL")) MWA <- MultiWaveAnalysis(ECGExample, "haar", features = c("var")) MWADiscrim <- StepDiscrim(MWA, c(rep(1, 5), rep(2, 5)), 5, features = c("var")) CM <- KFCV(MWADiscrim, c(rep(1, 5), rep(2, 5)), "linear", 5, returnClassification = FALSE )
load(system.file("extdata/ECGExample.rda",package = "TSEAL")) MWA <- MultiWaveAnalysis(ECGExample, "haar", features = c("var")) MWADiscrim <- StepDiscrim(MWA, c(rep(1, 5), rep(2, 5)), 5, features = c("var")) CM <- KFCV(MWADiscrim, c(rep(1, 5), rep(2, 5)), "linear", 5, returnClassification = FALSE )
This function performs the Leave-One-Out Cross Validation (LOOCV) process with different types of input parameters.
LOOCV(data, ...)
LOOCV(data, ...)
data |
Starting data to generate the validation. It can be either the raw data, or a previously generated MultiWaveAnalysis object. |
... |
Additional arguments |
Not return value, used as generic function
It generates and validates a discriminant model starting from the data. First, a MultiWaveAnalysis object is obtained according to the selected characteristics, filter and levels. Then, the most important features are selected using a stepwise discriminant that allows to select a maximum number of variables (maxvars) or a minimum enhancement step (VStep). Finally, the model is trained using the subset of features and validated using Leave-One-Out Cross Validation (LOOCV).
## S3 method for class 'array' LOOCV( data, labels, f, method, maxvars, VStep, lev = 0, features = c("Var", "Cor", "IQR", "PE", "DM"), returnClassification = FALSE, nCores = 0, ... )
## S3 method for class 'array' LOOCV( data, labels, f, method, maxvars, VStep, lev = 0, features = c("Var", "Cor", "IQR", "PE", "DM"), returnClassification = FALSE, nCores = 0, ... )
data |
Sample from the population (dim x length x cases) |
labels |
Labeled vector that classify the observations |
f |
Selected filter for the MODWT (to see the available filters use the
function |
method |
Selected method for the discriminant. Valid values "linear" "quadratic" |
maxvars |
Maximum number of variables included by the StepDiscrim algorithm (Note that if you defined this, can not define VStep). Must be a positive integer greater than 0. |
VStep |
Minimum value of V above which all other variables are considered irrelevant and therefore will not be included. (Note that if you defined this, can not defined maxvars). Must be a positive number and greater than 0. For more information see StepDiscrim documentation |
lev |
Determines the number of decomposition levels for MODWT (by default the optimum is calculated using the "conservative" strategy). Must be a positive integer (including 0 to auto-select the level) |
features |
A list of characteristics that will be used for the
classification process. To see the available features see
|
returnClassification |
Allows to select if the raw result classification is returned. |
nCores |
Determines the number of processes that will be used in the function, by default it uses all but one of the system cores. Must be a positive integer, where 0 corresponds to the default behavior. |
... |
Additional arguments |
if returnClassification is false return a object of class confusionMatrix
if returnClassification is true, it returns a list containing an object of the confusionMatrix class and a vector with the classification result.
load(system.file("extdata/ECGExample.rda",package = "TSEAL")) labels <- c(rep(1, 5), rep(2, 5)) CM <- LOOCV(ECGExample, labels, "haar", "linear", maxvars = 5, features = c("Var"), returnClassification = FALSE ) # or with VStep CMV <- LOOCV(ECGExample, labels, "haar", "linear", VStep = 5, features = c("Var", "Cor"), returnClassification = FALSE )
load(system.file("extdata/ECGExample.rda",package = "TSEAL")) labels <- c(rep(1, 5), rep(2, 5)) CM <- LOOCV(ECGExample, labels, "haar", "linear", maxvars = 5, features = c("Var"), returnClassification = FALSE ) # or with VStep CMV <- LOOCV(ECGExample, labels, "haar", "linear", VStep = 5, features = c("Var", "Cor"), returnClassification = FALSE )
Performs a leave-one-cross-validation (LOOCV) method on a MultiWaveAnalysis
object. It is advisable to have selected a subset of all features
(StepDiscrim
,StepDiscrimV
)
## S3 method for class 'MultiWaveAnalysis' LOOCV(data, labels, method, returnClassification = FALSE, ...)
## S3 method for class 'MultiWaveAnalysis' LOOCV(data, labels, method, returnClassification = FALSE, ...)
data |
MultiWaveAnalysis object obtained with MultiWaveAnalysis function and
preferably obtained a subset of its characteristics
( |
labels |
Labeled vector that classify the observations. |
method |
Selected method for discrimination. Valid options "linear" "quadratic" |
returnClassification |
Allows to select if the raw result classification is returned. |
... |
Additional arguments |
if returnClassification is false return a object of class confusionMatrix
if returnClassification is true, it returns a list containing an object of the confusionMatrix class and a vector with the classification result.
load(system.file("extdata/ECGExample.rda",package = "TSEAL")) MWA <- MultiWaveAnalysis(ECGExample, "haar", features = c("var")) MWADiscrim <- StepDiscrim(MWA, c(rep(1, 5), rep(2, 5)), 5, features = c("var")) CM <- LOOCV(MWADiscrim, c(rep(1, 5), rep(2, 5)), "linear")
load(system.file("extdata/ECGExample.rda",package = "TSEAL")) MWA <- MultiWaveAnalysis(ECGExample, "haar", features = c("var")) MWADiscrim <- StepDiscrim(MWA, c(rep(1, 5), rep(2, 5)), 5, features = c("var")) CM <- LOOCV(MWADiscrim, c(rep(1, 5), rep(2, 5)), "linear")
Generates a multivariate analysis by calculating a series of features from the result of applying MODWT to the input data.
MultiWaveAnalysis( series, f, lev = 0, features = c("Var", "Cor", "IQR", "PE", "DM"), nCores = 0 )
MultiWaveAnalysis( series, f, lev = 0, features = c("Var", "Cor", "IQR", "PE", "DM"), nCores = 0 )
series |
Sample from the population (array of three dimensions [dim, length, cases] |
f |
Selected wavelet filter for the analysis. To see the available
filters use the function |
lev |
Wavelet decomposition level by default is selected using the
"conservative" strategy. See |
features |
It allows to select the characteristics to be calculated for
the analysis. To see the available features use the function
|
nCores |
Determines the number of processes that will be used in the function, by default it uses all but one of the system cores. Must be a positive integer, where 0 corresponds to the default behavior |
A multivariate analysis with the characteristics indicated in the
parameter features. This is an object of class MultiWaveAnalysis with
contains
* Features: A list with the computed features
* StepSelection: A selection with the most discriminant features
StepDiscrim
* Observations: Number of total observations
* NLevels: Number of levels selected for the decomposition process
* Filter: Filter used in the decomposition process
load(system.file("extdata/ECGExample.rda",package = "TSEAL")) MWA <- MultiWaveAnalysis(ECGExample, f = "haar", lev = 0, features = c("Var", "Cor"), nCores = 0 )
load(system.file("extdata/ECGExample.rda",package = "TSEAL")) MWA <- MultiWaveAnalysis(ECGExample, f = "haar", lev = 0, features = c("Var", "Cor"), nCores = 0 )
Allows to perform the same variable selection in a new MWA object starting from a MWA object with the variables already selected (it is advisable that the parameters of the MWA and of the selection are the same).
SameDiscrim(MWA, MWADiscrim)
SameDiscrim(MWA, MWADiscrim)
MWA |
MultiWaveAnalysis object on which variables are to be selected. |
MWADiscrim |
MultiWaveAnalysis object on which certain variables have been
previously selected, using |
An object of class MultiWaveAnalysis with the same variables selected as in the MWADiscrim object.
load(system.file("extdata/ECGExample.rda",package = "TSEAL")) # We simulate that the second series has been obtained after Series1 <- ECGExample[, , 1:9] Series2 <- ECGExample[, , 10, drop = FALSE] MWA <- MultiWaveAnalysis(Series1, "haar", features = c("var")) MWADiscrim <- StepDiscrim(MWA, c(rep(1, 5), rep(2, 4)), 5, features = c("var") ) MWA2 <- MultiWaveAnalysis(Series2, "haar", features = c("var")) MWA2Discrim <- SameDiscrim(MWA2, MWADiscrim) # At this point MWA2Discrim has the same variables that MWADiscrim # and can be used in a pretrained model with MWADiscrim
load(system.file("extdata/ECGExample.rda",package = "TSEAL")) # We simulate that the second series has been obtained after Series1 <- ECGExample[, , 1:9] Series2 <- ECGExample[, , 10, drop = FALSE] MWA <- MultiWaveAnalysis(Series1, "haar", features = c("var")) MWADiscrim <- StepDiscrim(MWA, c(rep(1, 5), rep(2, 4)), 5, features = c("var") ) MWA2 <- MultiWaveAnalysis(Series2, "haar", features = c("var")) MWA2Discrim <- SameDiscrim(MWA2, MWADiscrim) # At this point MWA2Discrim has the same variables that MWADiscrim # and can be used in a pretrained model with MWADiscrim
Stepwise discriminant analysis to determine the best subset of variables. Introduces variables so as to maximize at each step the Lawley-Hotelling trace (=Rao's V). This measure is proportional to the mean Mahalanobis distance.
StepDiscrim( MWA, labels, maxvars, features = c("Var", "Cor", "IQR", "PE", "DM"), nCores = 0 )
StepDiscrim( MWA, labels, maxvars, features = c("Var", "Cor", "IQR", "PE", "DM"), nCores = 0 )
MWA |
MultiWaveAnalysis object obtained with MultiWaveAnalysis function |
labels |
Labeled vector that classify the observations. |
maxvars |
The number of desired values. Must be a positive integer |
features |
A list of characteristics that will be used for the
classification process. To see the available features see
|
nCores |
Determines the number of processes that will be used in the function, by default it uses all but one of the system cores. Must be a positive integer, where 0 corresponds to the default behavior |
Based on StepDiscrim of R.E. Strauss
A MultiWaveAnalysis object with the maxvars most discriminant variables. This object contains: * Features: A list with the initial computed features * StepSelection: The maxvars most discriminant variables * Observations: Number of total observations * NLevels: Number of levels selected for the decomposition process * filter: Filter used in the decomposition process
load(system.file("extdata/ECGExample.rda",package = "TSEAL")) MWA <- MultiWaveAnalysis(ECGExample, "haar", features = c("var")) MWADiscrim <- StepDiscrim( MWA, c(rep(1, 5), rep(2, 5)), 5, c("Var") )
load(system.file("extdata/ECGExample.rda",package = "TSEAL")) MWA <- MultiWaveAnalysis(ECGExample, "haar", features = c("var")) MWADiscrim <- StepDiscrim( MWA, c(rep(1, 5), rep(2, 5)), 5, c("Var") )
Stepwise discriminant analysis to determine the best subset of variables. Introduces variables so as to maximize at each step the Lawley-Hotelling trace (=Rao's V). This measure is proportional to the mean Mahalanobis distance.The process ends when in one step the value of the Lawley-Hotelling trace is less than a given value.
StepDiscrimV( MWA, labels, VStep, features = c("Var", "Cor", "IQR", "PE", "DM"), nCores = 0 )
StepDiscrimV( MWA, labels, VStep, features = c("Var", "Cor", "IQR", "PE", "DM"), nCores = 0 )
MWA |
MultiWaveAnalysis object obtained with MultiWaveAnalysis function |
labels |
Labeled vector that classify the observations. |
VStep |
Determine the minimum value of V to continue adding new variables. Ex if an determinate step the maximum V is 0.2 but VStep is 0.3 the algorithm end. Must be greater than 0. |
features |
A list of characteristics that will be used for the
classification process. To see the available features see
|
nCores |
Determines the number of processes that will be used in the function, by default it uses all but one of the system cores. Must be a positive integer, where 0 corresponds to the default behavior |
Based on StepDiscrim of R.E. Strauss
A MultiWaveAnalysis object with the most discriminant variables. This Object contains: * Features: A list with the initial computed features * StepSelection: The most discriminant variables selected by this function * Observations: Number of total observations * NLevels: Number of levels selected for the decomposition process * filter: Filter used in the decomposition process
load(system.file("extdata/ECGExample.rda",package = "TSEAL")) MWA <- MultiWaveAnalysis(ECGExample, "haar", features = c("var")) MWADiscrim <- StepDiscrimV( MWA, c(rep(1, 5), rep(2, 5)), 0.1, c("Var") )
load(system.file("extdata/ECGExample.rda",package = "TSEAL")) MWA <- MultiWaveAnalysis(ECGExample, "haar", features = c("var")) MWADiscrim <- StepDiscrimV( MWA, c(rep(1, 5), rep(2, 5)), 0.1, c("Var") )
This function performs a test with a series of filters defined by the user, for the maximum number of variables determined. This function can be used to compare the performance of different filters with a different number of variables to be considered and the differences between a linear and a quadratic discriminant.
testFilters( series, labels, maxvars, filters = c("haar", "d4", "d6", "d8", "la8"), features = c("Var", "Cor", "IQR", "PE", "DM"), lev = 0 )
testFilters( series, labels, maxvars, filters = c("haar", "d4", "d6", "d8", "la8"), features = c("Var", "Cor", "IQR", "PE", "DM"), lev = 0 )
series |
Samples from the population (dim x length x cases) |
labels |
Labeled vector that classify the observations. |
maxvars |
maximum number of variables included by the StepDiscrim algorithm. Must be grater than 0 and, in normal cases, lesser than 100 |
filters |
Vector indicating the filters to be tested. To see the
available filters use the function |
features |
A list of characteristics that will be used for the
classification process. To see the available features see
|
lev |
Wavelet decomposition level, by default is selected using the
"conservative" strategy. See |
A list that each element contains:
CM: confusion matrix with a particular configuration using LOOCV
Classification: a vector with the raw classification result. "1" if the observation belongs to the population 1 and "2" if belongs to the population 2.
NVars: the total numbers of variables have been taken into account in the classification process
Method: type of classifier used.
Filter: filter used in the MultiWave analysis process
Features: vector containing the features taken into account
load(system.file("extdata/ECGExample.rda",package = "TSEAL")) # The dataset has the first 5 elements of class 1 # and the last 5 of class 2. labels <- c(rep(1, 5), rep(2, 5)) result <- testFilters(ECGExample, labels, features=c("var","cor"), filters= c("haar","d4"), maxvars = 3)
load(system.file("extdata/ECGExample.rda",package = "TSEAL")) # The dataset has the first 5 elements of class 1 # and the last 5 of class 2. labels <- c(rep(1, 5), rep(2, 5)) result <- testFilters(ECGExample, labels, features=c("var","cor"), filters= c("haar","d4"), maxvars = 3)
This function uses a pretrained linear discriminant to classify a set of test data. As output it returns a confusion matrix and optionally the raw classification result.
testModel(model, test, labels, returnClassification = FALSE, ...)
testModel(model, test, labels, returnClassification = FALSE, ...)
model |
Trained linear discriminant.
see |
test |
MultiWaveAnalysis class object to be used as test set. |
labels |
Vector that determines the class to which each of the observations provided in the test set belongs. |
returnClassification |
Allows to select if the raw result classification is returned. |
... |
Additional arguments |
if returnClassification is false return a object of class confusionMatrix
if returnClassification is true, it returns a list containing an object of the confusionMatrix class and a vector with the classification result.
load(system.file("extdata/ECGExample.rda",package = "TSEAL")) # The dataset has the first 5 elements of class 1 # and the last 5 of class 2. labels <- c(rep(1, 5), rep(2, 5)) MWA <- generateStepDiscrim(ECGExample, labels, "haar", maxvars = 5, features = c("var")) aux <- extractSubset(MWA, c(1, 2, 9, 10)) MWATest <- aux[[1]] MWATrain <- aux[[2]] ldaDiscriminant <- trainModel(MWATrain, labels[3:8], "linear") CM <- testModel(ldaDiscriminant, MWATest, labels[c(1, 2, 9, 10)])
load(system.file("extdata/ECGExample.rda",package = "TSEAL")) # The dataset has the first 5 elements of class 1 # and the last 5 of class 2. labels <- c(rep(1, 5), rep(2, 5)) MWA <- generateStepDiscrim(ECGExample, labels, "haar", maxvars = 5, features = c("var")) aux <- extractSubset(MWA, c(1, 2, 9, 10)) MWATest <- aux[[1]] MWATrain <- aux[[2]] ldaDiscriminant <- trainModel(MWATrain, labels[3:8], "linear") CM <- testModel(ldaDiscriminant, MWATest, labels[c(1, 2, 9, 10)])
This function allows training of a discriminant model using different inputs
trainModel(data, ...)
trainModel(data, ...)
data |
Starting data to generate a discriminator (linear or quadratic). This starting data can be either the raw data, or a MultiWaveAnalysis object generated earlier. |
... |
Additional arguments |
A trained discriminant model
It generates a discriminant model starting from the training data, which must be provided in 2 groups depending on their classification. The method first obtains the variances and correlations using MODWT, the f filter is applied with a number of levels lev. Then a subset of all the generated features will be obtained by means of a stepwise discriminant, which can be driven by a maximum number of features or by a minimum metric to be met. Finally, the selected discriminant model is trained with the subset obtained.
## S3 method for class 'array' trainModel( data, labels, f, method, maxvars, VStep, lev = 0, features = c("Var", "Cor", "IQR", "PE", "DM"), nCores = 0, ... )
## S3 method for class 'array' trainModel( data, labels, f, method, maxvars, VStep, lev = 0, features = c("Var", "Cor", "IQR", "PE", "DM"), nCores = 0, ... )
data |
Sample from the population (dim x length x cases) |
labels |
Labeled vector that classify the observations |
f |
Selected filter for the MODWT (to see the available filters use the function availableFilters) |
method |
Selected method for the discriminant. Valid values "linear" "quadratic" |
maxvars |
Maximum number of variables included by the StepDiscrim algorithm (Note that if you defined this, can not define VStep). Must be a positive integer greater than 0. |
VStep |
Minimum value of V above which all other variables are considered irrelevant and therefore will not be included. (Note that if you defined this, can not defined maxvars).Must be a positive number greater than 0. For more information see StepDiscrim documentation |
lev |
Determines the number of decomposition levels for MODWT (by default the optimum is calculated). Must be a positive integer |
features |
A list of characteristics that will be used for the
classification process. To see the available features
see |
nCores |
Determines the number of processes that will be used in the function, by default it uses all but one of the system cores. Must be a positive integer, where 0 corresponds to the default behavior. |
... |
Additional arguments |
A discriminant model object (lda or qda)
load(system.file("extdata/ECGExample.rda",package = "TSEAL")) # The dataset has the first 5 elements of class 1 and the last 5 of class 2. labels <- c(rep(1, 5), rep(2, 5)) model <- trainModel(ECGExample, labels, "d6", "linear", maxvars = 5, features = c("Var") ) # or using VStep modelV <- trainModel(ECGExample, labels, "d6", "linear", VStep = 14.5, features = c("Var") )
load(system.file("extdata/ECGExample.rda",package = "TSEAL")) # The dataset has the first 5 elements of class 1 and the last 5 of class 2. labels <- c(rep(1, 5), rep(2, 5)) model <- trainModel(ECGExample, labels, "d6", "linear", maxvars = 5, features = c("Var") ) # or using VStep modelV <- trainModel(ECGExample, labels, "d6", "linear", VStep = 14.5, features = c("Var") )
Generates a discriminant model from an already generated "MultiWaveAnalysis".
## S3 method for class 'MultiWaveAnalysis' trainModel(data, labels, method, ...)
## S3 method for class 'MultiWaveAnalysis' trainModel(data, labels, method, ...)
data |
A MultiWaveAnalysis object obtained with MultiWaveAnalysis function |
labels |
Labeled vector that classify the observations. |
method |
Selected method for discrimination. Valid options are "linear" and "quadratic" |
... |
Additional arguments |
A discriminant model based on selected method. It can be an object of the class lda or qda.
load(system.file("extdata/ECGExample.rda",package = "TSEAL")) MWA <- MultiWaveAnalysis(ECGExample, "d6", features = c("Var")) MWADiscrim <- StepDiscrim(MWA, c(rep(1, 5), rep(2, 5)), 5, features = c("Var") ) model <- trainModel(MWADiscrim, c(rep(1, 5), rep(2, 5)), "linear")
load(system.file("extdata/ECGExample.rda",package = "TSEAL")) MWA <- MultiWaveAnalysis(ECGExample, "d6", features = c("Var")) MWADiscrim <- StepDiscrim(MWA, c(rep(1, 5), rep(2, 5)), 5, features = c("Var") ) model <- trainModel(MWADiscrim, c(rep(1, 5), rep(2, 5)), "linear")