numFactor function

Factor with numeric interpretable levels.

Factor with numeric interpretable levels.

Create a factor with numeric interpretable factor levels.

numFactor(x, ...) parseNumLevels(levels)

Arguments

  • x: Vector, matrix or data.frame that constitute the coordinates.
  • ...: Additional vectors, matrices or data.frames that constitute the coordinates.
  • levels: Character vector to parse into numeric values.

Returns

Factor with specialized coding of levels.

Details

Some glmmTMB covariance structures require extra information, such as temporal or spatial coordinates. numFactor allows to associate such extra information as part of a factor via the factor levels. The original numeric coordinates are recoverable without loss of precision using the function parseNumLevels. Factor levels are sorted coordinate wise from left to right: first coordinate is fastest running.

Examples

## 1D example numFactor(sample(1:5,20,TRUE)) ## 2D example coords <- cbind( sample(1:5,20,TRUE), sample(1:5,20,TRUE) ) (f <- numFactor(coords)) parseNumLevels(levels(f)) ## Sorted ## Used as part of a model.matrix model.matrix( ~f ) ## parseNumLevels( colnames(model.matrix( ~f )) ) ## Error: 'Failed to parse numeric levels: (Intercept)' parseNumLevels( colnames(model.matrix( ~ f-1 )) )
  • Maintainer: Mollie Brooks
  • License: AGPL-3
  • Last published: 2025-04-02