Create a covariance matrix from a fitted model object.
covmatrix(object, newdata,...)## S3 method for class 'splm'covmatrix(object, newdata, cov_type,...)## S3 method for class 'spautor'covmatrix(object, newdata, cov_type,...)## S3 method for class 'spglm'covmatrix(object, newdata, cov_type,...)## S3 method for class 'spgautor'covmatrix(object, newdata, cov_type,...)
Arguments
object: A fitted model object (e.g., splm(), spautor(), spglm(), or spgautor()).
newdata: If omitted, the covariance matrix of the observed data is returned. If provided, newdata is a data frame or sf object that contains coordinate information required to construct the covariance between newdata and the observed data. If a data frame, newdata
must contain variables that represent coordinates having the same name as the coordinates from the observed data used to fit object. If an sf object, coordinates are obtained from the geometry of newdata.
...: Other arguments. Not used (needed for generic consistency).
cov_type: The type of covariance matrix returned. If newdata
is omitted or cov_type is "obs.obs", the n×n covariance matrix of the observed data is returned, where n is the sample size used to fit object. If newdata is provided and cov_type is "pred.obs"
(the default when newdata is provided), the m×n covariance matrix of the prediction and observed data is returned, where m is the number of elements in the prediction data. If newdata is provided and cov_type is "obs.pred", the n×m covariance matrix of the observed and prediction data is returned. If newdata is provided and cov_type is "pred.pred", the m×m covariance matrix of the prediction data is returned.
Returns
If newdata is omitted, the covariance matrix of the observed data, which has dimension n x n, where n is the sample size used to fit object. If newdata is provided, the covariance matrix between the unobserved (new) data and the observed data, which has dimension m x n, where m is the number of new observations and n is the sample size used to fit object.
Examples
spmod <- splm(z ~ water + tarp, data = caribou, spcov_type ="exponential", xcoord = x, ycoord = y
)covmatrix(spmod)