Query or set model label(s)
label.Rdlabel() extracts the model label(s) from x.
The replacement functions label<- and set_label() are used to set model label(s) in x.
n_model() returns the number of models included in an object x.
Usage
label(x, which)
label(x, which) <- value
set_label(x, value, which = seq_along(label(x)))
# S3 method for model
label(x, which)
# S3 method for multimodel
label(x, which)
# S3 method for cv
label(x, which)
# S3 method for performance
label(x, which)
n_model(x)Arguments
- x
Object of class “model”, “multimodel”, “cv” or “performance”.
- which
Optional integer index - allows querying or setting only a subset of the model labels. Must have the same length as
value. Default: All models inx.- value
Labels to be attributed to models.
Value
label() returns a character vector.
set_label() returns its input object x with modified labels.
n_model() returns an integer.
Details
These functions are generic and have methods for classes “model”, “multimodel”, “cv”, “performance”, “evaluation_log”.
n_model() just returns length(label(x)) and is thus available for any object having an appropriate label() method.
Examples
xvars <- names(iris)[-1]
forms <- lapply(xvars, reformulate, response = names(iris)[1])
model0 <- model(lm(Sepal.Length~1, iris), label = "intercept_only")
mm <- c(model0, multimodel(model0, formula = forms))
n_model(mm)
#> [1] 5
label(mm)
#> [1] "intercept_only" "intercept_only1" "intercept_only2" "intercept_only3"
#> [5] "intercept_only4"
label(mm, 2:5) <- xvars
label(mm)
#> [1] "intercept_only" "Sepal.Width" "Petal.Length" "Petal.Width"
#> [5] "Species"
mm
#> --- A “multimodel” object containing 5 models ---
#>
#> ‘intercept_only’:
#> model class: lm
#> formula: Sepal.Length ~ 1
#> data: data.frame [150 x 5],
#> input as: ‘data = iris’
#> call: lm(formula = Sepal.Length ~ 1, data = data)
#>
#> ‘Sepal.Width’:
#> model class: lm
#> formula: Sepal.Length ~ Sepal.Width
#> data: data.frame [150 x 5],
#> input as: ‘data = iris’
#> call: lm(formula = Sepal.Length ~ Sepal.Width, data = data)
#>
#> ‘Petal.Length’:
#> model class: lm
#> formula: Sepal.Length ~ Petal.Length
#> data: data.frame [150 x 5],
#> input as: ‘data = iris’
#> call: lm(formula = Sepal.Length ~ Petal.Length, data = data)
#>
#> and 2 models more, labelled:
#> ‘Petal.Width’, ‘Species’
#>
#>
#> Parameter table:
#> formula
#> intercept_only <unknown>
#> Sepal.Width Sepal.Length ~ Sepal.Width
#> Petal.Length Sepal.Length ~ Petal.Length
#> ... 2 rows omitted (nrow=5)
set_label(mm, paste0("model_number_", 1:5))
#> --- A “multimodel” object containing 5 models ---
#>
#> ‘model_number_1’:
#> model class: lm
#> formula: Sepal.Length ~ 1
#> data: data.frame [150 x 5],
#> input as: ‘data = iris’
#> call: lm(formula = Sepal.Length ~ 1, data = data)
#>
#> ‘model_number_2’:
#> model class: lm
#> formula: Sepal.Length ~ Sepal.Width
#> data: data.frame [150 x 5],
#> input as: ‘data = iris’
#> call: lm(formula = Sepal.Length ~ Sepal.Width, data = data)
#>
#> ‘model_number_3’:
#> model class: lm
#> formula: Sepal.Length ~ Petal.Length
#> data: data.frame [150 x 5],
#> input as: ‘data = iris’
#> call: lm(formula = Sepal.Length ~ Petal.Length, data = data)
#>
#> and 2 models more, labelled:
#> ‘model_number_4’, ‘model_number_5’
#>
#>
#> Parameter table:
#> formula
#> model_number_1 <unknown>
#> model_number_2 Sepal.Length ~ Sepal.Width
#> model_number_3 Sepal.Length ~ Petal.Length
#> ... 2 rows omitted (nrow=5)