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.260839 5.828456 1.734189 #> [2,] 3.156103 3.584209 0.945442 #> [3,] 4.989236 8.226470 3.030425 #> [4,] 8.145947 2.307373 3.379408 #> [5,] 9.353689 8.825268 4.806498 #> [6,] 5.328310 6.730871 6.393607 #> [7,] 8.728623 8.165150 6.966774 #> [8,] 9.315332 2.602407 7.471277 #> [9,] 7.694059 1.770745 12.071007 #> [10,] 7.969362 3.634218 8.575276 #> [11,] 5.059006 6.177261 11.330701 #> [12,] 8.240180 8.538302 10.240521 #> [13,] 2.586318 9.775416 11.983616 #> [14,] 7.437169 3.654475 15.036862 #> [15,] 9.417796 2.891047 15.034712 #> [16,] 3.164030 7.525298 14.306309 #> [17,] 5.224547 6.379133 16.625918 #> [18,] 2.445269 4.031261 16.741638 #> [19,] 4.201919 7.247918 18.391894 #> [20,] 9.681328 4.292316 18.631292 #> [21,] 7.550379 3.790154 20.057837 #> [22,] 2.284494 8.251861 22.739858 #> [23,] 9.429282 2.651511 23.022094 #> [24,] 5.312350 3.429896 24.548883 #> [25,] 5.207661 8.599224 23.649302 #> [26,] 4.034139 2.101044 25.355532 #> [27,] 9.310651 9.542231 28.047845 #> [28,] 3.547561 9.702133 27.678607 #> [29,] 8.601458 2.840843 29.034326 #> [30,] 6.418320 3.054149 31.063948 #> [31,] 3.244032 1.869226 29.412392 #> [32,] 7.062817 7.608737 30.416538 #> [33,] 4.658472 3.827600 33.110531 #> [34,] 6.730185 6.420634 34.246299 #> [35,] 7.240879 4.816384 35.057150 #> [36,] 5.041686 8.947319 34.916697 #> [37,] 1.051658 2.028668 37.216301 #> [38,] 9.180131 3.753878 37.176314 #> [39,] 3.175794 1.540223 37.499220 #> [40,] 2.132192 9.959741 41.226567
autovarCore:::needs_trend(data_matrix, 1)
#> [1] TRUE