This function uses the Phillips-Perron Unit Root Test to determine whether a trend is required for a VAR model based on the given matrix of endogenous variables and the given lag. All variables are assessed individually. This function returns TRUE if any of the endogenous variables requires a trend.

needs_trend(endo_matrix, lag)

Arguments

endo_matrix

The matrix of endogenous variables in the model.

lag

An integer specifying the lag length of the model.

Value

A boolean indicating whether a trend is required for the specified VAR model.

Examples

data_matrix <- matrix(nrow = 40, ncol = 3) data_matrix[, ] <- runif(ncol(data_matrix) * nrow(data_matrix), 1, 10) data_matrix[, 3] <- (1:40) + rnorm(40) colnames(data_matrix) <- c('rumination', 'happiness', 'activity') data_matrix
#> rumination happiness activity #> [1,] 1.376607 7.576788 0.9658679 #> [2,] 4.104180 5.405683 2.2890512 #> [3,] 4.653367 2.918088 2.6367062 #> [4,] 8.861427 3.858456 1.9277599 #> [5,] 7.827266 3.559249 5.4478037 #> [6,] 9.824326 3.140841 8.3124198 #> [7,] 9.078313 9.312347 6.4284201 #> [8,] 4.169284 9.828676 7.4502292 #> [9,] 4.643521 3.344837 8.7905521 #> [10,] 7.828343 1.863046 8.5533376 #> [11,] 8.723764 7.964175 12.0260927 #> [12,] 4.884577 5.246152 9.8888272 #> [13,] 6.313301 3.716265 12.9162245 #> [14,] 1.483759 6.565983 13.4085945 #> [15,] 4.100249 3.706877 14.6142465 #> [16,] 9.339583 4.038872 15.0828058 #> [17,] 3.884411 7.715522 17.0782287 #> [18,] 9.793345 6.049213 16.0528071 #> [19,] 4.093596 4.802838 18.9046242 #> [20,] 8.344552 5.961970 21.7608835 #> [21,] 3.233721 3.477101 21.7059263 #> [22,] 4.326233 3.074382 21.4692476 #> [23,] 6.545027 2.314286 22.5069997 #> [24,] 5.753101 8.303210 24.4648510 #> [25,] 9.262846 6.526481 25.0271032 #> [26,] 4.260964 3.470033 26.8020278 #> [27,] 3.072297 8.962592 26.8942499 #> [28,] 9.844650 1.711047 27.9398879 #> [29,] 5.104155 1.953161 29.5379528 #> [30,] 2.325197 3.393589 30.7433091 #> [31,] 5.188691 1.196736 31.6922445 #> [32,] 8.212359 2.352380 31.5279780 #> [33,] 5.824039 2.478815 34.1796343 #> [34,] 3.281784 3.376451 33.5417210 #> [35,] 4.768168 2.231092 35.5629477 #> [36,] 9.363040 8.368167 37.7903331 #> [37,] 3.366422 8.366003 36.8837483 #> [38,] 7.687430 9.371758 39.2527537 #> [39,] 6.735215 1.802189 38.7260074 #> [40,] 7.775409 6.347375 40.7505286
autovarCore:::needs_trend(data_matrix, 1)
#> [1] TRUE