View source: R/utils_covstruct.R
numFactor | R Documentation |
Create a factor with numeric interpretable factor levels.
numFactor(x, ...)
parseNumLevels(levels)
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. |
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.
Factor with specialized coding of levels.
## 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 )) )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.