needs_trend(endo_matrix, lag)
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.
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_matrixrumination happiness activity [1,] 7.563253 3.955886 0.03153804 [2,] 3.134757 3.599997 2.04195743 [3,] 8.469677 9.978168 1.82820799 [4,] 8.685723 9.511101 3.19173027 [5,] 4.746356 9.134525 6.08774629 [6,] 3.897745 6.290791 5.33832097 [7,] 9.741431 4.816141 7.11154118 [8,] 2.806437 7.580368 9.26994089 [9,] 2.622422 5.720105 8.44052915 [10,] 1.716269 1.221206 8.19813547 [11,] 6.888176 6.371219 11.60226960 [12,] 8.435747 4.646451 12.02034438 [13,] 3.409909 1.879437 12.31455284 [14,] 9.227284 5.354394 14.04604584 [15,] 1.200356 4.765088 16.67465608 [16,] 4.824085 5.862624 15.27962089 [17,] 8.846015 4.311734 17.93575406 [18,] 7.064466 6.627474 17.39469847 [19,] 7.295172 2.270534 20.31466549 [20,] 4.763936 8.866662 20.86540322 [21,] 9.544739 7.223964 20.20924721 [22,] 1.226333 8.592581 21.98189512 [23,] 9.437616 7.745544 22.09477124 [24,] 7.807233 5.844784 22.23125012 [25,] 1.069765 7.987607 24.45693885 [26,] 5.482966 2.320778 26.88949946 [27,] 6.060613 7.418077 28.38894553 [28,] 6.364208 6.719862 27.35397150 [29,] 2.245116 8.951398 30.76573125 [30,] 6.265093 6.536182 30.38675360 [31,] 5.152557 4.784206 31.34006130 [32,] 5.081075 1.219229 31.89724164 [33,] 5.455243 2.903531 31.16039854 [34,] 9.750120 8.045272 34.03251774 [35,] 9.053552 6.292695 34.96745189 [36,] 1.460191 4.100072 36.53940687 [37,] 8.454390 5.886841 37.41365531 [38,] 4.871801 5.462638 38.07587311 [39,] 8.202829 1.901544 39.88699246 [40,] 4.572514 1.232669 41.61007878autovarCore:::needs_trend(data_matrix, 1)[1] TRUE