We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Function:
util_doubledifflog_ts <- function(.time_series){ time_series <- .time_series f <- stats::frequency(time_series) min_x <- min(time_series) # Diff of Log diff_order <- 1 while ( (min_x > 0) & (ts_adf_test(diff(diff(log(time_series), diff_order)))$p_value >= 0.05 & (diff_order <= f)) ){ diff_order <- diff_order + 1 } if (diff_order <= f){ rlang::inform( message = paste0("Double Differencing of order " , diff_order , " made the time series stationary"), use_cli_format = TRUE ) # Return stationary_ts <- diff(diff(log(time_series), diff_order)) return( list( stationary_ts = stationary_ts, ndiffs = diff_order, adf_stats = ts_adf_test(stationary_ts), trans_type = "double_diff_log", ret = TRUE ) ) } else { rlang::inform( message = "Could not stationarize data.", use_cli_format = TRUE ) return(list(ret = FALSE)) } }
Examples:
> util_doubledifflog_ts(x) Double Differencing of order 1 made the time series stationary $stationary_ts Jan Feb Mar Apr May Jun 1949 0.0599315450 -0.1351068163 -0.0410323405 0.1735060916 1950 -0.1520462214 0.1171022747 0.0211282048 -0.1559630954 -0.0334759292 0.2525936098 1951 -0.1703526544 -0.0011897681 0.1372467045 -0.2591816057 0.1417776255 -0.0194552025 1952 -0.0987053985 0.0216175262 0.0184400436 -0.1339264957 0.0751822792 0.1640197884 1953 -0.1101071821 -0.0102565002 0.1857171458 -0.1899634367 -0.0216172197 0.0852029504 1954 -0.0955329714 -0.0964931168 0.3048215823 -0.2577790480 0.0650065945 0.0902568899 1955 -0.0653003019 -0.0931149952 0.1741094774 -0.1287474836 -0.0037521418 0.1504401004 1956 -0.1382078481 -0.0463098564 0.1598409997 -0.1475828510 0.0285467756 0.1463562224 1957 -0.0924787442 -0.0744499110 0.2132828402 -0.1905487172 0.0426435608 0.1529722149 1958 -0.0849649257 -0.0787286925 0.1964870639 -0.1690345611 0.0816420865 0.1387428423 1959 -0.0174895318 -0.1173143955 0.2228357169 -0.1964813709 0.0837794484 0.0578837743 1960 -0.0830437006 -0.0935778165 0.1335420218 0.0263637631 -0.0719461805 0.1017068187 Jul Aug Sep Oct Nov Dec 1949 -0.0175467375 -0.0919374953 -0.0845573880 -0.0489740046 -0.0012012013 0.2610263193 1950 -0.0437804375 -0.1318521311 -0.0732034040 -0.0990425008 0.0180952250 0.3595946540 1951 0.0772322010 -0.1115212744 -0.0783690671 -0.0489703553 0.0233497089 0.2323708802 1952 -0.1214246638 -0.0027258289 -0.1974618914 0.0565426503 -0.0147181273 0.2251426335 1953 0.0235482200 -0.0530346967 -0.1675948883 0.0215399175 -0.0426992749 0.2692493398 1954 0.0138499264 -0.1647323226 -0.0930901390 0.0002384892 0.0025900336 0.2410320490 1955 -0.0095694510 -0.1924103165 -0.0584925044 -0.0235534893 -0.0151928838 0.3046289378 1956 -0.0630126191 -0.1187523214 -0.1122087518 -0.0167634099 0.0270664065 0.2429325621 1957 -0.0758554330 -0.0927402395 -0.1492062318 -0.0071757183 0.0230770947 0.2258123867 1958 -0.0598451001 -0.0929837952 -0.2512578528 0.1050510618 -0.0286576015 0.2302607239 1959 0.0325720271 -0.1294221152 -0.2082966053 0.0595085504 0.0117448950 0.2294118289 1960 0.0253855845 -0.1767334525 -0.1503384318 0.0793151339 -0.0701678993 0.2695301530 $ndiffs [1] 1 $adf_stats $adf_stats$test_stat [1] -7.318571 $adf_stats$p_value [1] 0.01 $trans_type [1] "double_diff_log" > util_doubledifflog_ts(BJsales) Double Differencing of order 1 made the time series stationary $stationary_ts Time Series: Start = 3 End = 150 Frequency = 1 [1] 2.501626e-03 -2.009293e-03 3.013311e-03 5.509403e-03 -1.403616e-02 1.504873e-02 [7] -5.525739e-03 2.984319e-03 -2.497098e-03 -2.482253e-03 4.961548e-04 9.876623e-03 [13] -3.020573e-03 3.823663e-03 5.604172e-03 -1.628388e-02 -3.330957e-03 -1.446883e-03 [19] 8.124723e-03 1.416007e-02 -1.516448e-02 4.187404e-03 1.006802e-02 -1.158078e-02 [25] -1.837461e-03 1.167545e-02 -1.933339e-02 8.956576e-03 -1.390597e-02 1.213038e-02 [31] -9.473211e-03 4.097400e-04 9.546207e-03 -9.163224e-04 -1.000522e-02 2.698308e-03 [37] 4.578552e-03 -1.202070e-02 1.387432e-02 1.388557e-03 9.156379e-04 -3.698571e-03 [43] 4.604060e-03 -2.110026e-05 1.443935e-02 -1.008969e-02 -2.101060e-02 5.304418e-03 [49] 3.596797e-03 -2.749852e-03 -1.876955e-03 2.721558e-03 4.618731e-03 -7.445573e-03 [55] -5.339697e-04 1.595107e-02 -4.241033e-03 -7.937937e-03 -2.376522e-03 3.741457e-03 [61] 1.131525e-02 -8.948433e-03 2.816021e-03 -1.035168e-02 1.225000e-02 -4.835732e-04 [67] -1.272583e-02 8.011220e-03 -1.428900e-03 9.020179e-03 -1.281301e-02 5.214950e-03 [73] -2.871489e-03 4.301082e-03 0.000000e+00 8.583744e-03 -2.429878e-03 -1.915573e-03 [79] -5.649061e-03 1.217614e-02 -8.440333e-03 7.841404e-03 -4.207226e-03 2.687023e-03 [85] -1.872679e-03 1.327612e-02 -1.257876e-02 1.332706e-02 -1.013462e-02 -4.741172e-03 [91] 8.731627e-03 -1.441397e-03 -7.078679e-03 -3.284150e-03 -1.630815e-03 4.449262e-03 [97] -6.071827e-03 1.211224e-03 5.628636e-03 -8.041201e-03 5.213078e-03 -1.209859e-03 [103] 1.585986e-03 -1.397416e-02 4.351737e-03 1.047318e-02 1.575458e-03 -5.212912e-03 [109] 7.935118e-03 -6.369506e-03 2.348101e-03 -4.162342e-04 -5.475789e-03 6.234796e-03 [115] 6.133764e-03 -1.312489e-02 6.524821e-03 -8.437804e-03 8.047971e-03 -7.660499e-03 [121] -7.789363e-04 7.576833e-04 2.697868e-03 -5.424417e-03 6.975414e-03 -3.890273e-04 [127] -2.716413e-03 1.552042e-03 1.553851e-03 3.868618e-03 -9.291689e-03 3.869823e-03 [133] -1.554152e-03 3.107853e-03 -3.887876e-03 5.444297e-03 -4.665783e-03 4.275545e-03 [139] -3.497184e-03 1.942276e-03 7.345264e-03 -2.360774e-03 1.108765e-03 -5.349921e-03 [145] -3.421115e-03 -1.911653e-03 5.339151e-03 3.784075e-04 $ndiffs [1] 1 $adf_stats $adf_stats$test_stat [1] -2.110919 $adf_stats$p_value [1] 0.5301832 $trans_type [1] "double_diff_log" > util_doubledifflog_ts(runif(150)) Double Differencing of order 1 made the time series stationary $stationary_ts [1] -1.067536200 2.987998777 -2.314006930 -1.230786223 2.191311846 0.235726666 -2.549298334 [8] 2.911949156 -3.386124062 4.210826292 -2.969903817 0.712444507 -1.167348447 3.491885190 [15] -2.225294216 -0.197307968 -0.863454910 0.299367307 2.651001223 -2.910944937 1.217484101 [22] 0.772273988 -1.059431931 0.170972135 -0.020179459 -1.436214772 2.310517392 -0.707888972 [29] -1.381818918 2.302345298 -1.753624156 1.244897016 -0.456402323 -1.631570093 0.240075742 [36] 3.830603275 -5.342225833 5.191353517 -2.361624211 -0.069849474 -0.185102679 -1.440427541 [43] 3.245000664 -2.911402179 -0.071227717 1.651376441 -1.734669093 4.809903099 -3.134350343 [50] -0.239343529 -2.224418812 4.168678251 -1.671813928 -1.059439562 1.147577788 -0.537213403 [57] -0.141844840 1.097047290 -0.752750395 -0.200954022 -0.032143500 0.126228339 0.401061025 [64] -1.232881523 0.856360705 0.900606836 -1.371555763 -1.855723095 4.371350398 -2.567710523 [71] 1.153513034 -0.037922161 -0.459908278 -0.001916005 -0.561963793 0.767780564 -0.981624594 [78] -0.494193936 1.627054141 0.775095799 -0.875306480 -1.321943000 0.075930851 2.563399910 [85] -2.588623082 1.827323378 -0.925279509 -1.347865030 1.332346193 1.060496667 -1.014205115 [92] 0.277181785 -1.206098253 1.603239076 -0.611947578 -0.496377192 -0.081340132 1.292243585 [99] -2.988689336 4.302796086 -1.754227591 -1.364952694 1.195451827 0.090694918 -0.157933452 [106] 0.329607951 -0.515721048 0.205967760 -0.313735344 -0.404562460 0.679266711 -0.126255515 [113] -2.238472862 2.524205954 1.127749847 -2.949383799 4.091448976 -2.743503602 0.573536465 [120] -0.681967586 -0.120219924 -0.047828647 1.844527037 -2.477903550 0.986019713 -1.800259167 [127] 4.791247809 -3.118542800 -2.337084572 5.367372876 -2.452756772 -2.927803917 4.962517814 [134] -1.971342488 -2.725547190 3.397109242 -0.309188698 -1.367980610 -0.255302793 2.857984822 [141] -1.871737391 -0.654319210 0.673688676 -1.386899756 -0.513916339 5.191616885 -4.374831496 [148] 0.330140782 $ndiffs [1] 1 $adf_stats $adf_stats$test_stat [1] -5.927793 $adf_stats$p_value [1] 0.01 $trans_type [1] "double_diff_log"
The text was updated successfully, but these errors were encountered:
auto_stationarize()
23cb212
Merge pull request #495 from spsanderson/development
4ccd497
Fixes #488
spsanderson
No branches or pull requests
Function:
Examples:
The text was updated successfully, but these errors were encountered: