This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

# time series
library(astsa)
## Warning: package 'astsa' was built under R version 3.1.2
data(jj)
str(jj)
##  Time-Series [1:84] from 1960 to 1981: 0.71 0.63 0.85 0.44 0.61 0.69 0.92 0.55 0.72 0.77 ...
summary(jj)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   0.440   1.248   3.510   4.800   7.132  16.200
class(jj)
## [1] "ts"
# ts data is a vector in R
options(digits=2)
(zardoz =ts(rnorm(48), start=c(2293, 6), frequency=12))
##         Jan    Feb    Mar    Apr    May    Jun    Jul    Aug    Sep    Oct
## 2293                                     0.303 -1.113 -1.670 -1.214  0.012
## 2294  0.804  1.851  0.507  0.957  0.865 -1.653 -0.907  0.616 -0.116  2.340
## 2295  1.531 -0.993 -0.065  0.708 -1.070  0.656 -0.370 -0.700 -0.459 -0.729
## 2296 -0.904  0.118 -0.767 -0.487 -0.503  0.689  0.735  0.426 -1.492 -0.333
## 2297 -0.374  1.348 -1.644 -0.625  0.482                                   
##         Nov    Dec
## 2293  1.121 -0.354
## 2294  1.328 -0.064
## 2295 -0.088 -1.466
## 2296  0.126 -0.817
## 2297
window(zardoz, start=c(2293,2), end=(2295))
## Warning in window.default(x, ...): 'start' value not changed
##         Jan    Feb    Mar    Apr    May    Jun    Jul    Aug    Sep    Oct
## 2293                                     0.303 -1.113 -1.670 -1.214  0.012
## 2294  0.804  1.851  0.507  0.957  0.865 -1.653 -0.907  0.616 -0.116  2.340
## 2295  1.531                                                               
##         Nov    Dec
## 2293  1.121 -0.354
## 2294  1.328 -0.064
## 2295
plot.ts(jj)

#filtering/smoothing 2 sided moving average
plot(jj2 <- stl(log(jj), "per"))

acf(jj2$time.series[,3])

plot(jj2 <- stl(log(jj), s.win=4))
#Seasonal Decomposition of Time Series by Loess
plot(jj2 <- stl(log(jj), s.win=4))

jj2$time.series[,3]
##          Qtr1     Qtr2     Qtr3     Qtr4
## 1960  0.09023 -0.03109  0.01801 -0.09997
## 1961 -0.08730  0.01163  0.04238  0.02432
## 1962 -0.00455  0.01545 -0.02233 -0.03669
## 1963  0.02878 -0.03501 -0.01875  0.01097
## 1964 -0.02677 -0.01017  0.00869  0.00018
## 1965  0.02947  0.05070 -0.02886 -0.00078
## 1966 -0.03298 -0.02902  0.06564  0.00618
## 1967  0.05242 -0.02753 -0.05649  0.01193
## 1968 -0.08621  0.03071  0.01993  0.05012
## 1969  0.02735 -0.03847 -0.02338 -0.11510
## 1970  0.01429  0.03030  0.02882  0.08078
## 1971 -0.03778  0.00465 -0.01064  0.00492
## 1972  0.04814  0.00329 -0.03018 -0.03116
## 1973  0.01164  0.00992  0.05121  0.01926
## 1974 -0.02051 -0.02902 -0.01568  0.01639
## 1975  0.00678  0.01186  0.01534 -0.01767
## 1976 -0.02141  0.01060 -0.00978 -0.02663
## 1977  0.00521 -0.00448 -0.03373  0.05578
## 1978  0.00340  0.01741  0.00627 -0.03123
## 1979  0.01236 -0.02389  0.05200 -0.02845
## 1980  0.02360 -0.01892 -0.00204  0.00406
#The function acf computes (and by default plots) estimates of the autocovariance or autocorrelation function. Function pacf is the function used for the partial autocorrelations. Function ccf computes the cross-correlation or cross-covariance of two univariate series