9.3

1.4 Formulas and named data🔗ℹ

The family procedures, such as elnet-fit and logistic-path, take a design matrix and a separate response, and their coefficients are known by position. Data usually arrives as a table of named columns instead, one of which is the response. The formula front end, which Fitting from named columns and Named data introduce, fits a model from such a table: a formula names the response and the predictors, and the fitted model keeps the names, so that its coefficients are keyed by name and it predicts from a new table by matching columns by name. The same three procedures fit every family: formula-fit at one λ, formula-path along a regularization path and formula-cv with cross-validation.

R’s glmnet itself has no formula interface; the R package glmnetUtils adds one, which this front end resembles (see Matching R).

    1.4.1 Tables

    1.4.2 Formulas

    1.4.3 A Gaussian fit

    1.4.4 The formula algebra

      1.4.4.1 Interactions and crossing

      1.4.4.2 Powers, and R’s x^2

      1.4.4.3 Removing terms

      1.4.4.4 The intercept

      1.4.4.5 Infix formulas

      1.4.4.6 The response on the right-hand side

      1.4.4.7 Predicting from new data

      1.4.4.8 From R’s syntax

    1.4.5 Transforms

      1.4.5.1 Squares, and R’s I()

      1.4.5.2 Names in a transform

      1.4.5.3 Values and new data

      1.4.5.4 Transforms as data

      1.4.5.5 From R’s transforms

    1.4.6 Categorical predictors

      1.4.6.1 Which columns are factors

      1.4.6.2 Levels and baselines

      1.4.6.3 Treatment contrasts

      1.4.6.4 Factors in interactions

      1.4.6.5 Transforms that make factors

      1.4.6.6 New data and levels

      1.4.6.7 Categorical responses

      1.4.6.8 From R’s factors

    1.4.7 A binomial fit

    1.4.8 A Cox fit

    1.4.9 Multinomial and multi-response fits

    1.4.10 Plots

    1.4.11 Matching R