cov_grid_2d: Grid of covariate values over two covariates

View source: R/utility.R

cov_grid_2dR Documentation

Grid of covariate values over two covariates

Description

The two-dimensional counterpart of cov_grid, used by HMM$plot_2d(). Both var and var2 are varied over a regular n_grid by n_grid lattice spanning their ranges in the data, and every other covariate is held at one value, as in cov_grid: the one given in covs, otherwise the mean of a numeric covariate or the first level of a factor.

Usage

cov_grid_2d(
  var,
  var2,
  data = NULL,
  obj = NULL,
  covs = NULL,
  formulas,
  n_grid = 40,
  padding = 0
)

Arguments

var

Name of the first covariate, on the x axis

var2

Name of the second covariate, on the y axis

data

Data frame of covariate values

obj

HMM model object, used to find the covariates if data is not given

covs

Optional named list of values for the other covariates

formulas

List of model formulas

n_grid

Number of points along each axis, so the grid has n_grid^2 rows

padding

Numeric vector of length 1 or 2 giving the amount to pad the 'var' and 'var2' ranges beyond the data. A single value is recycled to both axes, and a length-2 vector is interpreted as (padding in var, padding in var2). Defaults to 0.

Details

The lattice is regular because that is what ggplot2::geom_raster() needs, and var varies fastest, so that the result can be reshaped into a matrix column by column.

Value

Data frame with n_grid^2 rows and one column for each covariate


hmmTMB documentation built on Nov. 10, 2026, 5:09 p.m.