Learn R Programming

glmmTMB (version 1.1.10)

numFactor: Factor with numeric interpretable levels.

Description

Create a factor with numeric interpretable factor levels.

Usage

numFactor(x, ...)

parseNumLevels(levels)

Value

Factor with specialized coding of 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.

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

Run this code
## 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 )) )

Run the code above in your browser using DataLab