The function mc_dist
helps to build the components
of the matrix linear predictor using matrices based on distances.
This function is generaly used for the analysis of longitudinal and
spatial data. The idea is to use the inverse of some measure of distance
as for example the Euclidean distance to model the covariance structure
within response variables. The model can also use the inverse of
distance squared or high order power.
mc_dist(id, time, data, method = "euclidean")
id | name of the column (string) containing the subject index.
For spatial data use the same |
---|---|
time | name of the column (string) containing the index indicating the time. For spatial data use the same index for all observations. |
data | data set. |
method | distance measure to be used. |
Bonat, W. H. (2018). Multiple Response Variables Regression Models in R: The mcglm Package. Journal of Statistical Software, 84(4):1--30.
A matrix of dgCMatrix class.
The distance measure must be one of "euclidean"
,
"maximum"
, "manhattan"
, "canberra"
,
"binary"
or "minkowski"
. This function is a customize
call of the dist
function.
dist
, mc_id
,
mc_conditional_test
, mc_car
, mc_ma
,
mc_rw
and mc_mixed
.
id <- rep(1:2, each = 4) time <- rep(1:4, 2) data <- data.frame("id" = id, "time" = time) mc_dist(id = "id", time = "time", data = data)#> $Z1 #> 8 x 8 sparse Matrix of class "dsCMatrix" #> #> [1,] . 1.0 0.5 0.3333333 . . . . #> [2,] 1.0000000 . 1.0 0.5000000 . . . . #> [3,] 0.5000000 1.0 . 1.0000000 . . . . #> [4,] 0.3333333 0.5 1.0 . . . . . #> [5,] . . . . . 1.0 0.5 0.3333333 #> [6,] . . . . 1.0000000 . 1.0 0.5000000 #> [7,] . . . . 0.5000000 1.0 . 1.0000000 #> [8,] . . . . 0.3333333 0.5 1.0 . #>mc_dist(id = "id", time = "time", data = data, method = "canberra")#> $Z1 #> 8 x 8 sparse Matrix of class "dsCMatrix" #> #> [1,] . 3 2 1.666667 . . . . #> [2,] 3.000000 . 5 3.000000 . . . . #> [3,] 2.000000 5 . 7.000000 . . . . #> [4,] 1.666667 3 7 . . . . . #> [5,] . . . . . 3 2 1.666667 #> [6,] . . . . 3.000000 . 5 3.000000 #> [7,] . . . . 2.000000 5 . 7.000000 #> [8,] . . . . 1.666667 3 7 . #>