mc_rw: Random Walk Model Structure

View source: R/mc_rw.R

mc_rwR Documentation

Random Walk Model Structure

Description

Constructs the components of the matrix linear predictor associated with random walk (RW) models for longitudinal or time series data. The user may specify the order of the random walk process.

Usage

mc_rw(id, time, data, order = 1, proper = FALSE)

Arguments

id

A character string giving the name of the column in data that identifies subjects or clusters.

time

A character string giving the name of the column in data that indexes time or ordering within each subject.

data

A data frame containing the variables specified in id and time.

order

A positive integer specifying the order of the random walk model.

proper

Logical indicating whether a proper random walk specification should be used.

Details

This function builds sparse precision matrix components corresponding to random walk structures of a given order. It is primarily intended for longitudinal data indexed by a subject identifier and a time variable. For pure time series data, the same id value should be used for all observations. When proper = TRUE, the precision structure is decomposed into diagonal and off-diagonal components.

Value

If proper = FALSE, a list with a single component:

Z1

A sparse matrix of class dgCMatrix representing the random walk precision structure.

If proper = TRUE, a list with two components:

Z1

A sparse diagonal matrix of class dgCMatrix.

Z2

A sparse off-diagonal matrix of class dgCMatrix.

The matrices are ordered consistently with the original data.

Author(s)

Wagner Hugo Bonat, wbonat@ufpr.br

Source

Bonat, W. H. (2018). Multiple Response Variables Regression Models in R: The mcglm Package. Journal of Statistical Software, 84(4), 1–30.

See Also

mc_id, mc_dist, mc_car, mc_ma, mc_mixed, mc_compute_rho

Examples

id <- rep(1:2, each = 4)
time <- rep(1:4, 2)
data <- data.frame(id = id, time = time)
mc_rw(id = "id", time = "time", data = data, order = 1, proper = FALSE)
mc_rw(id = "id", time = "time", data = data, order = 1, proper = TRUE)
mc_rw(id = "id", time = "time", data = data, order = 2, proper = TRUE)


mcglm documentation built on Jan. 9, 2026, 1:07 a.m.