Title: | Tools for Constructing and Plotting Markov Random Fields in R for Graphical Data |
---|---|
Description: | Utility functions for using Markov Random Field smooths in Generalized Additive Models fitted with the 'mgcv' package. |
Authors: | Eric J. Pedersen [aut, cre], Gavin L. Simpson [aut], Valentin Lucet [ctb] |
Maintainer: | Eric J. Petersen <[email protected]> |
License: | GPL-3 |
Version: | 0.0-2 |
Built: | 2025-03-13 09:19:59 UTC |
Source: | https://github.com/gavinsimpson/MRFtools |
Convert a MRF penalty object to a matrix
## S3 method for class 'mrf_penalty' as.matrix(x, ...)
## S3 method for class 'mrf_penalty' as.matrix(x, ...)
x |
an object inheriting from class |
... |
arguments passed to other methods |
p <- mrf_penalty(1:10) as.matrix(p)
p <- mrf_penalty(1:10) as.matrix(p)
Extract configuration details of an MRF penalty
get_config(penalty)
get_config(penalty)
penalty |
an object of class |
An object of class "mrf_config"
, a list.
Extract MRF node labels from an MRF penalty
get_labels(penalty)
get_labels(penalty)
penalty |
an object of class |
Extract a fitted MRF
get_mrf(object, ...) ## S3 method for class 'bam' get_mrf(object, ...) ## S3 method for class 'gamm' get_mrf(object, ...) ## S3 method for class 'list' get_mrf(object, ...) ## S3 method for class 'gam' get_mrf(object, term, ...)
get_mrf(object, ...) ## S3 method for class 'bam' get_mrf(object, ...) ## S3 method for class 'gamm' get_mrf(object, ...) ## S3 method for class 'list' get_mrf(object, ...) ## S3 method for class 'gam' get_mrf(object, term, ...)
object |
An object from which to extract the fitted MRF. Currently only
for objects of classes |
... |
Arguments passed to other methods. |
term |
character; the MRF term to extract. Can be a partial match to a term, which is matched against the smooth label. |
A object representing the fitted MRF
Extract a MRF penalty matrix
get_penalty(penalty, ...) ## S3 method for class 'mrf_penalty' get_penalty(penalty, ...)
get_penalty(penalty, ...) ## S3 method for class 'mrf_penalty' get_penalty(penalty, ...)
penalty |
an R object from which to extract the MRF penalty matrix. |
... |
arguments passed to other methods. |
A penalty matrix of class "matrix"
.
Extract the type of MRF from the penalty
get_type(object) ## S3 method for class 'mrf_penalty' get_type(object) ## S3 method for class 'mrf_config' get_type(object)
get_type(object) ## S3 method for class 'mrf_penalty' get_type(object) ## S3 method for class 'mrf_config' get_type(object)
object |
an object of class |
A length 1 character vector containing the type of MRF penalty.
Markov Random Field Penalty
mrf_penalty(object, ...)
mrf_penalty(object, ...)
object |
an R object to create the MRF penalty from. |
... |
arguments passed to other methods. |
MRF penalty from a dendrogram
## S3 method for class 'dendrogram' mrf_penalty(object, node_labels = NULL, add_delta = FALSE, ...)
## S3 method for class 'dendrogram' mrf_penalty(object, node_labels = NULL, add_delta = FALSE, ...)
object |
an R object to create the MRF penalty from. |
node_labels |
character; a vector of alternative labels for the levels of the factor. |
add_delta |
numeric or logical; either the numeric value to add to the diagonal of the MRF penalty matrix, or a logical value indicating if such an adjustment should be made. The default is to not alter the diagonal of the penalty matrix. |
... |
arguments passed to other methods. |
Fully connected graph and random effect MRF penalties from a factor
## S3 method for class 'factor' mrf_penalty( object, type = c("full", "individual"), node_labels = NULL, add_delta = FALSE, ... )
## S3 method for class 'factor' mrf_penalty( object, type = c("full", "individual"), node_labels = NULL, add_delta = FALSE, ... )
object |
an R object to create the MRF penalty from. |
type |
character; one of |
node_labels |
character; a vector of alternative labels for the levels of the factor. |
add_delta |
numeric or logical; either the numeric value to add to the diagonal of the MRF penalty matrix, or a logical value indicating if such an adjustment should be made. The default is to not alter the diagonal of the penalty matrix. |
... |
arguments passed to other methods. |
# a factor fv <- factor(letters[1:10]) # create the MRF penalty for a fully connected graph p <- mrf_penalty(fv, type = "full") p as.matrix(p) # create the MRF penalty equivalent of random effects p <- mrf_penalty(fv, type = "individual") p as.matrix(p)
# a factor fv <- factor(letters[1:10]) # create the MRF penalty for a fully connected graph p <- mrf_penalty(fv, type = "full") p as.matrix(p) # create the MRF penalty equivalent of random effects p <- mrf_penalty(fv, type = "individual") p as.matrix(p)
MRF penalty from a hclust object
## S3 method for class 'hclust' mrf_penalty(object, ...)
## S3 method for class 'hclust' mrf_penalty(object, ...)
object |
an R object to create the MRF penalty from. |
... |
arguments passed to other methods. |
First-order random walk MRF penalty from a numeric vector
## S3 method for class 'numeric' mrf_penalty( object, type = c("linear", "cyclic"), node_labels = NULL, add_delta = FALSE, end_points = NULL, ... )
## S3 method for class 'numeric' mrf_penalty( object, type = c("linear", "cyclic"), node_labels = NULL, add_delta = FALSE, end_points = NULL, ... )
object |
an R object to create the MRF penalty from. |
type |
character; one of |
node_labels |
character; a vector of alternative labels for the levels of the factor. |
add_delta |
numeric or logical; either the numeric value to add to the diagonal of the MRF penalty matrix, or a logical value indicating if such an adjustment should be made. The default is to not alter the diagonal of the penalty matrix. |
end_points |
numeric; an optional vector of length 2 providing the end points of the period of cycle. |
... |
arguments passed to other methods. |
# linear p <- mrf_penalty(1:10) as.matrix(p) # cyclic p <- mrf_penalty(1:10, type = "cyclic") as.matrix(p) # cyclic with user end points p <- mrf_penalty(1:10, type = "cyclic", end_points = c(0,11)) as.matrix(p)
# linear p <- mrf_penalty(1:10) as.matrix(p) # cyclic p <- mrf_penalty(1:10, type = "cyclic") as.matrix(p) # cyclic with user end points p <- mrf_penalty(1:10, type = "cyclic", end_points = c(0,11)) as.matrix(p)
MRF penalty from a phylogeny
## S3 method for class 'phylo' mrf_penalty(object, node_labels = NULL, add_delta = FALSE, eps = 0, ...)
## S3 method for class 'phylo' mrf_penalty(object, node_labels = NULL, add_delta = FALSE, eps = 0, ...)
object |
an R object to create the MRF penalty from. |
node_labels |
character; a vector of alternative labels for the levels of the factor. |
add_delta |
numeric or logical; either the numeric value to add to the diagonal of the MRF penalty matrix, or a logical value indicating if such an adjustment should be made. The default is to not alter the diagonal of the penalty matrix. |
eps |
A value to add to the variance-covariance matrix diagonal to make it positive definite |
... |
arguments passed to other methods. |
MRF penalty from polygon or multi-polygon simple features
## S3 method for class 'sf' mrf_penalty(object, node_labels = NULL, buffer = NULL, add_delta = FALSE, ...)
## S3 method for class 'sf' mrf_penalty(object, node_labels = NULL, buffer = NULL, add_delta = FALSE, ...)
object |
an R object to create the MRF penalty from. |
node_labels |
character; a vector of alternative labels for the levels of the factor. |
buffer |
numeric; buffer distance for all or for individual elements
of the geometry. See argument |
add_delta |
numeric or logical; either the numeric value to add to the diagonal of the MRF penalty matrix, or a logical value indicating if such an adjustment should be made. The default is to not alter the diagonal of the penalty matrix. |
... |
arguments passed to other methods. |
MRF penalty from a SpatialPolygons
## S3 method for class 'SpatialPolygons' mrf_penalty(object, node_labels = NULL, buffer = NULL, add_delta = FALSE, ...)
## S3 method for class 'SpatialPolygons' mrf_penalty(object, node_labels = NULL, buffer = NULL, add_delta = FALSE, ...)
object |
an R object to create the MRF penalty from. |
node_labels |
character; a vector of alternative labels for the levels of the factor. |
buffer |
numeric; buffer distance for all or for individual elements
of the geometry. See argument |
add_delta |
numeric or logical; either the numeric value to add to the diagonal of the MRF penalty matrix, or a logical value indicating if such an adjustment should be made. The default is to not alter the diagonal of the penalty matrix. |
... |
arguments passed to other methods. |
MRF penalty from a SpatialPoylgonsDataFrame
## S3 method for class 'SpatialPolygonsDataFrame' mrf_penalty(object, node_labels = NULL, buffer = NULL, add_delta = FALSE, ...)
## S3 method for class 'SpatialPolygonsDataFrame' mrf_penalty(object, node_labels = NULL, buffer = NULL, add_delta = FALSE, ...)
object |
an R object to create the MRF penalty from. |
node_labels |
character; a vector of alternative labels for the levels of the factor. |
buffer |
numeric; buffer distance for all or for individual elements
of the geometry. See argument |
add_delta |
numeric or logical; either the numeric value to add to the diagonal of the MRF penalty matrix, or a logical value indicating if such an adjustment should be made. The default is to not alter the diagonal of the penalty matrix. |
... |
arguments passed to other methods. |