Here you can find the code listings in `R`

language from the corresponding chapter of the book.

You need to load `Rssa`

, `ssabook`

, `lattice`

, `latticeExtra`

, `plyr`

, `fma`

to run these examples.

- Chapter 2: SSA analysis of one-dimensional time series, Sections 2.1 — 2.7
- Fragments 2.1.1 (‘Australian Wines’: Input) and 2.1.2 (‘FORT’: Reconstruction)
- Fragment 2.1.3 (‘FORT’: Identification)
- Fragment 2.2.1 (Noisy sinusoid: Toeplitz SSA)
- Fragment 2.2.2 (Simulation: comparison of Toeplitz and Basic SSA)
- Fragment 2.3.1 (‘CO2’: SSA with projection)
- Fragment 2.3.2 (Polynomial trend: SSA with projection)
- Fragment 2.4.1 (Noisy sum of three sinusoids: Iterative O-SSA)
- Fragment 2.4.2 (Noisy sum of three sinusoids: Iterative O-SSA, summary)
- Fragment 2.4.3 (Dependence of iossa error on difference between frequencies)
- Fragment 2.5.1 (Separation of two sine waves with equal amplitudes)
- Fragment 2.6.1 (Decomposition for series with a gap)
- Fragment 2.6.2 (Incomplete decomposition for a series with a gap)
- Fragment 2.7.1 (‘White dwarf’: Auto grouping by clustering)
- Fragment 2.7.2 (‘Production’: Auto grouping by frequency analysis)

*‘FORT’: Decomposition.*

```
$F1
period rate | Mod Arg | Re Im
11.971 0.000000 | 1.00000 0.52 | 0.86540 0.50109
$F2
period rate | Mod Arg | Re Im
4.005 0.000000 | 1.00000 1.57 | 0.00177 1.00000
```

*‘FORT’: 1D graphs of eigenvectors.*

*‘FORT’: 2D scatterplots of eigenvectors.*

*‘FORT’: Weighted correlations.*

*‘FORT’: Reconstructed sine waves.*

*Noisy sinusoid: 1D graphs of eigenvectors (top: Toeplitz SSA, bottom: Basic SSA).*

*Noisy sinusoid: Reconstruction (top: Toeplitz SSA, bottom: Basic SSA).*

Warning: this example takes a lot of computational time.

*Simulation: Reconstruction accuracy
of Toeplitz (dash red line) and Basic SSA (solid black line).*

*‘CO2’: Reconstruction of linear trend.*

*‘CO2’: Reconstruction of the cubic trend.*

*‘CO2’: 1D graphs of eigenvectors.*

*‘CO2’: Reconstruction of signal.*

*Polynomial trend: Comparison of trend reconstructions.*

*Noisy sum of three sinusoids: The original series.*

*Noisy sum of three sinusoids, Basic SSA: w-Correlation matrix.*

*Noisy sum of three sinusoids, Basic SSA: Eigenvectors.*

*Noisy sum of three sinusoids, Iterative O-SSA: Eigenvectors.*

*Noisy sum of three sinusoids, Iterative O-SSA: Reconstruction.*

```
[[1]]
[1] 3 4
[[2]]
[1] 5 6
Call:
iossa.ssa(x = s, nested.groups = list(3:4, 5:6), maxiter = 1000)
Series length: 100, Window length: 50, SVD method: eigen
Special triples: 0
Computed:
Eigenvalues: 50, Eigenvectors: 50, Factor vectors: 6
Precached: 0 elementary series (0 MiB)
Overall memory consumption (estimate): 0.0352 MiB
Iterative O-SSA result:
Converged: yes
Iterations: 243
Initial mean(tau): 0.1032
Initial tau: 0.0007976, 0.2055299
I. O-SSA mean(tau): 0.0004452
I. O-SSA tau: 0.0006709, 0.0002196
Initial max wcor: 0.02442
I. O-SSA max wcor: 0.06986
I. O-SSA max owcor: 0.0732
```

Warning: this example takes a lot of computational time.

*Dependence of number of iterations (top) and RMSE errors of
frequency estimations (bottom) on 𝝎 _{1} for 𝝎_{2}=0.6.*

*Noisy sum of sinusoids: Graph of eigenvalues for Basic SSA.*

*Noisy sum of sinusoids: 1D graphs of eigenvectors for Basic SSA (top),
DerivSSA (middle) and Iterative O-SSA, 1 iteration (second from bottom) and 2 iterations (bottom).*

*Noisy sum of sinusoids: Reconstructions for DerivSSA (top) and
Iterative O-SSA, 2 iterations (bottom).*

```
[1] 100
[1] 99.62939
[1] 101.7544
```

```
In .contribution(x, idx, ...):
Elementary matrices are not F-orthogonal (max F-cor is -0.016).
Contributions can be irrelevant
```

*‘CO2’ with gaps, Shaped SSA: Dependence of proportion of complete vectors on window length.*

*‘CO2’ with gaps, Shaped SSA: Eigenvectors, L=72.*

*‘CO2’ with gaps, Shaped SSA: Elementary reconstructed series, L=72.*

*‘CO2’ with gaps, Shaped SSA: w-Correlation matrix, L=72.*

*‘CO2’ with gaps, Shaped SSA: Trend reconstruction, L=72.*

*‘CO2’ with gaps, Shaped SSA: Incomplete trend reconstruction, L=120.*

*‘White dwarf’: w-Correlation matrix, L=100.*

*‘White dwarf’: Decomposition with automatic
grouping performed by clustering.*

```
[1] 1 2 3 4 5 6 7 8 9 10 11
```

*‘Production’: Ordered frequency contributions of factor vectors, L=120.*

*‘Production’: Factor vectors, L=120.*

*‘Production’: Two extracted trends of different resolution,
automatic grouping by frequencies.*

```
8
0.861955
[1] 1 2
[1] 1 2 3 6 8 11 12 17 18
```