The function mc_ma helps to build the components of the matrix linear predictor associated with moving average models. This function is generaly used for the analysis of longitudinal and times series data. The user can specify the order of the moving average process.

mc_ma(id, time, data, order = 1)

Arguments

id

name of the column (string) containing the subject index. Note that this structure was designed to deal with longitudinal data. For times series data use the same id for all observations (one unit sample).

time

name of the column (string) containing the index indicating the time.

data

data set.

order

order of the moving average process.

Source

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

Value

A matrix of dgCMatrix class.

Details

This function was designed mainly to deal with longitudinal data, but can also be used for times series analysis. In that case, the id argument should contain only one index. It pretends a longitudinal data taken just for one individual or unit sample. This function is a simple call of the bandSparse function from the Matrix package.

See also

mc_id, mc_dist, mc_car, mc_rw and mc_mixed.

Examples

id <- rep(1:2, each = 4) time <- rep(1:4, 2) data <- data.frame("id" = id, "time" = time) mc_ma(id = "id", time = "time", data = data, order = 1)
#> $Z1 #> 8 x 8 sparse Matrix of class "nsCMatrix" #> #> [1,] . | . . . . . . #> [2,] | . | . . . . . #> [3,] . | . | . . . . #> [4,] . . | . . . . . #> [5,] . . . . . | . . #> [6,] . . . . | . | . #> [7,] . . . . . | . | #> [8,] . . . . . . | . #>
mc_ma(id = "id", time = "time", data = data, order = 2)
#> $Z1 #> 8 x 8 sparse Matrix of class "nsCMatrix" #> #> [1,] . . | . . . . . #> [2,] . . . | . . . . #> [3,] | . . . . . . . #> [4,] . | . . . . . . #> [5,] . . . . . . | . #> [6,] . . . . . . . | #> [7,] . . . . | . . . #> [8,] . . . . . | . . #>