elasticNetGLMinterface {ClassifyR} | R Documentation

## An Interface for glmnet Package's glmnet Function

### Description

An elastic net GLM classifier uses a penalty which is a combination of a lasso penalty and a ridge penalty, scaled by a lambda value, to fit a sparse linear model to the data.

### Usage

      ## S4 method for signature 'matrix'
    elasticNetGLMtrainInterface(measurements, classes, ...)
      ## S4 method for signature 'DataFrame'
    elasticNetGLMtrainInterface(measurements, classes, lambda = NULL,
                                 ..., verbose = 3)
      ## S4 method for signature 'MultiAssayExperiment'
    elasticNetGLMtrainInterface(measurements, targets = names(measurements), ...)
      ## S4 method for signature 'multnet,matrix'
    elasticNetGLMpredictInterface(model, test, ...)
      ## S4 method for signature 'multnet,DataFrame'
    elasticNetGLMpredictInterface(model, test, classes = NULL, lambda, ..., verbose = 3)
      ## S4 method for signature 'multnet,MultiAssayExperiment'
    elasticNetGLMpredictInterface(model, test, targets = names(test), ...)

### Arguments

`measurements` | Either a `matrix`, `DataFrame` or `MultiAssayExperiment` containing the training data. For a `matrix`, the rows are features, and the columns are samples. If of type `DataFrame`, the data set is subset to only those features of type `integer`.
`classes` | Either a vector of class labels of class `factor` of the same length as the number of samples in `measurements` or if the measurements are of class `DataFrame` a character vector of length 1 containing the column name in `measurement` is also permitted. Not used if `measurements` is a `MultiAssayExperiment` object.
`lambda` | The lambda value passed directly to `glmnet` if the training function is used or passed as `s` to `predict.glmnet` if the prediction function is used.
`test` | An object of the same class as `measurements` with no samples in common with `measurements` and the same number of features as it.
`targets` | If `measurements` is a `MultiAssayExperiment`, the names of the data tables to be used. `"clinical"` is also a valid value and specifies that integer variables from the clinical data table will be used.
`...` | Variables not used by the `matrix` nor the `MultiAssayExperiment` method which are passed into and used by the `DataFrame` method (e.g. `verbose`) or, for the training function, options that are used by the `glmnet` function. For the testing function, this variable simply contains any parameters passed from the classification framework to it which aren't used by glmnet's `predict` fuction.
`model` | A trained elastic net GLM, as created by the `glmnet` function.
`verbose` | Default: 3. A number between 0 and 3 for the amount of progress messages to give. This function only prints progress messages if the value is 3.

### Details

If `measurements` is an object of class `MultiAssayExperiment`, the factor of sample classes must be stored in the DataFrame accessible by the `colData` function with column name `"class"`.

The value of the `"family"` parameter is fixed to `"multinomial"` so that classification with more than 2 classes is possible. During classifier training, if more than one lambda value is considered by specifying a vector of them as input, then the chosen value is determined based on classifier resubstitution performance. Leaving the default value of NULL, however, causes the `glmnet` function to determine a set of values to evaluate and then a single lambda value is chosen based on the fraction of (null) deviance explained by the fitted model.

### Value

For `elasticNetGLMtrainInterface`, an object of type `glmnet`. For `elasticNetGLMpredictInterface`, a factor vector of class predictions.

### Author(s)

Dario Strbenac

### Examples

      if(require(glmnet))
      {
        # Genes 76 to 100 have differential expression.
        genesMatrix <- sapply(1:25, function(sample) c(rnorm(100, 9, 2)))
        genesMatrix <- cbind(genesMatrix, sapply(1:25, function(sample)
                                          c(rnorm(75, 9, 2), rnorm(25, 14, 2))))
        classes <- factor(rep(c("Poor", "Good"), each = 25))
        colnames(genesMatrix) <- paste("Sample", 1:ncol(genesMatrix))
        rownames(genesMatrix) <- paste("Gene", 1:nrow(genesMatrix))

        resubstituteParams <- ResubstituteParams(nFeatures = seq(10, 100, 10),
                                                 performanceType = "balanced error",
                                                 better = "lower")

        # alpha is a user-specified tuning parameter.
        # lambda is automatically tuned, based on glmnet defaults, if not user-specified.
        trainParams <- TrainParams(elasticNetGLMtrainInterface,
                                   tuneParams = list(alpha = c(0, 0.5, 1)),
                                   resubstituteParams = resubstituteParams)
        predictParams <- PredictParams(elasticNetGLMpredictInterface,
                                       getClasses = function(result) result)
        classified <- runTests(genesMatrix, classes, "Example", "Differential Expression",
                               permutations = 5,
                               params = list(trainParams, predictParams))

        classified <- calcCVperformance(classified, "balanced error")
        head(tunedParameters(classified))
        performance(classified)
      }

[Package ClassifyR version 2.0.10 Index]