unitimeseries

# Differences

This shows you the differences between two versions of the page.

 — unitimeseries [2018/12/28 11:20] (current) Line 1: Line 1: + ~~CLOSETOC~~ + + ~~TOC 1-3 wide~~ + + + ```juliarepl + julia> pkgchk.( [ "​julia"​ => v"​1.0.3",​ "​Distributions"​ => v"​0.15.0",​ "​TimeSeries"​ => v"​0.11.1"​ ] ); + + ``` + + # Multi Time Series + + ## Panel Data + + ### Arrelano-Bond (1991) + + + ## Two-Step Procedures for Instrumental Variables for Endogenous Corrections + + + + + + # Time-Series + + FIXME Unfortunately,​ the TimeSeries package is not working in 1.0.0 as of September 2018. + + ## Tests for AutoCorrelation + + [HypothesisTests](http://​juliastats.github.io/​HypothesisTests.jl/​stable/​) offers tests for whether there is autocorrelation in values. + + ### Augmented Dickey-Fuller Test: Unit-Root (Is x like a random walk?) + + ```juliarepl + + + julia> ADFTest( x, :none, 0 ) + Augmented Dickey-Fuller unit root test + -------------------------------------- + Population details: + parameter of interest: ​  ​coefficient on lagged non-differenced variable + value under h_0:         0 + point estimate: ​         -0.9506767150463514 + + Test summary: + outcome with 95% confidence: reject h_0 + p-value: ​                    <​1e-15 + + Details: + sample size in regression: ​         99 + number of lags:                     0 + ADF statistic: ​                     -9.41503163545725 + Critical values at 1%, 5%, and 10%: [-2.58846 -1.94399 -1.61441] + + + ``` + + ### LjungBox/​BoxPierce:​ Does X seem to have Autocorrelation or Serial Uncorrelatedness?​ + + ``` + julia> LjungBoxTest( x, 1 ) + Ljung-Box autocorrelation test + ------------------------------ + Population details: + parameter of interest: ​  ​autocorrelations up to lag k + value under h_0:         all zero + point estimate: ​         NaN + + Test summary: + outcome with 95% confidence: fail to reject h_0 + one-sided p-value: ​          ​0.6249 + + Details: + number of observations: ​        100 + number of lags:                 1 + degrees of freedom correction: ​ 0 + Q statistic: ​                   0.23906259199508553 + + + julia> BoxPierceTest( x, 1 ) + Box-Pierce autocorrelation test + ------------------------------- + Population details: + parameter of interest: ​  ​autocorrelations up to lag k + value under h_0:         all zero + point estimate: ​         NaN + + Test summary: + outcome with 95% confidence: fail to reject h_0 + one-sided p-value: ​          ​0.6300 + + Details: + number of observations: ​        100 + number of lags:                 1 + degrees of freedom correction: ​ 0 + Q statistic: ​                   0.23203133928934774 + + ``` + + + + + + + ## Basic + + [StatsBase](http://​juliastats.github.io/​StatsBase.jl/​latest/​signalcorr.html) offers `autocov`, `autocor`, and cross-covariance/​cross-correlations (with lags), all with options to demean. + + In the Box-Jenkins spirit, it also calculates partial autocorrelation functions (`pacf`) + + ```juliarepl + julia> x= zeros(10_002);​ for i=3:10_002; x[i]= 0.3*x[i-1]+ 0.1*x[i-2] + rand( Normal(0,1) ); end; x= x[3:​10_000];​ + + julia> #pacf( x, [10] ) + ``` + + FIXME This is not what I wanted. ​ I wanted 10 lags of PACF + + FIXME show autocor and autocov + + + ## Generate a Random Walk or Autoregressive or ARMA Process + + Unlike interpreted languages, there is little penalty in julia to explicit specification:​ + + FIXME this oulines how one could generate an arama. + + ```juliafix + using Distributions:​Normal + + function arma( n::Int, ar::​Vector{Float64}= [ 0.0 ] , ma::​Vector{Float64}= [ 0.0 ], + ​sigma::​Float64= 1.0, startvalues::​Vector{Float64}= []) + ## AbstractVector,​ rather than Vector? + ## check that we have enough valid starting values + ## check that we want enough values to use up ar and ma parameters + ## check that sigma is positive + ## check that scalars are allowed. + + err= rand(Normal(0,​sigma),​ n ) + rv= vcat( startvalues,​ zeros( n - length(startvalues) ) ) + for i=(length(startvalues)+1):​n;​ + rv[i]= (ar .* rv[ (i-length(ar)):​(i-1) ] + ma .* err[ (i-length(ar)):​(i-1) ] + err[i])[] + end#for + rv + end#​function arma + + julia> rw= ar(10, [ 1.0 ], 10.0 ) + ... + + julia> + + ``` + + + ## Full Time-Series Analysis with TimeSeries Package + + The [TimeSeries.jl Package](http://​juliastats.github.io/​TimeSeries.jl) facilitates more involved time-series analysis. ​ Each value in a time-series object must be accompanied by a date. + + ```juliarepl + julia> using TimeSeries:​TimeArray + + julia> x = TimeArray([Date(2000,​ 1, 1), Date(2000, 1, 2), Date(2000, 1, 3)], [11,22,33]) + 3x1 TimeSeries.TimeArray{Int64,​1,​Date,​Array{Int64,​1}} 2000-01-01 to 2000-01-03 + │            │       │ + ├────────────┼───────┤ + │ 2000-01-01 │ 11    │ + │ 2000-01-02 │ 22    │ + │ 2000-01-03 │ 33    │ + + ``` + + The simplest functionality is leading and lagging: + + ```juliarepl + julia> using TimeSeries + + julia> x = TimeArray([Date(2000,​ 1, 1), Date(2000, 1, 2), Date(2000, 1, 3)], [11,​22,​33]);​ + + julia> lead(x) + 2x1 TimeSeries.TimeArray{Int64,​1,​Date,​Array{Int64,​1}} 2000-01-01 to 2000-01-02 + │            │       │ + ├────────────┼───────┤ + │ 2000-01-01 │ 22    │ + │ 2000-01-02 │ 33    │ + + julia> lag(x) + 2x1 TimeSeries.TimeArray{Int64,​1,​Date,​Array{Int64,​1}} 2000-01-02 to 2000-01-03 + │            │       │ + ├────────────┼───────┤ + │ 2000-01-02 │ 11    │ + │ 2000-01-03 │ 22    │ + + ``` + + For simpler, equal-spaced data, it is often easier to work with plain arrays. You can then use the simpler lead and lag functions in [[fundispatch#​adding_missing_unions_to_array_arguments|Functions]]. + + + + ### Estimating Auto-Regressive and Moving-Average Models + + FIXME Estimating ARMA models is to be written. + + + # Backmatter + + ## Useful Packages on Julia Repository + + ## Notes + + ## References +