Fitted: Array;
The Fitted property returns a fitted series.
Use the ISmSingularSpectrumAnalysis.Residuals property to get residual series.
To execute the example, add a link to the Stat system assembly.
Sub UserSSA;
Var
ssa: ISmSingularSpectrumAnalysis;
d0, d1, d2: Double;
i, res: Integer;
can: Array[18] Of double;
incl: Array[2] Of Integer;
Begin
ssa := New SmSingularSpectrumAnalysis.Create;
// Set missing data treatment method
ssa.MissingData.Method := MissingDataMethod.AnyValue;
// Set input series values
can[00] := Double.Nan; can[06] := 7349; can[12] := 7473;
can[01] := 6385; can[07] := 7213; can[13] := 7722;
can[02] := 6752; can[08] := 7061; can[14] := 8088;
can[03] := 6837; can[09] := 7180; can[15] := 8516;
can[04] := 6495; can[10] := 7132; can[16] := 8941;
can[05] := 6907; can[11] := 7137; can[17] := Double.Nan;
// Set input series
ssa.Serie.Value := can;
// Set window width
ssa.Width := 4;
// Set the number of principal components
ssa.PCCount := 3;
// Set principal components to be used
incl[0] := 0;
incl[1] := 2;
ssa.IncludedComponents := incl;
// Define matrix centering type
ssa.MatrixAlignmentType := AlignmentType.SingleAlignment;
// Set sample period
ssa.ModelPeriod.FirstPoint := 3;
ssa.ModelPeriod.LastPoint := 15;
// Run calculation and output the results to console window
res := ssa.Execute;
If res <> 0 Then
Debug.WriteLine(ssa.Errors);
Else
Debug.WriteLine("Statistics:");
For i := 1 To ssa.PCCount + 1 Do
Debug.WriteLine("Principal component №" + i.ToString);
d0 := ssa.Statistics[i - 1, 0];
Debug.WriteLine(" - eigenvalue: " + d0.ToString);
d0 := ssa.Statistics[i - 1, 1];
Debug.WriteLine(" - variance:" + d0.ToString);
d0 := ssa.Statistics[i - 1, 2];
Debug.WriteLine(" - cumulative variance: " + d0.ToString);
d0 := ssa.Statistics[i - 1, 3];
Debug.WriteLine(" - chi-square statistic: " + d0.ToString);
d0 := ssa.Statistics[i - 1, 4];
Debug.WriteLine(" - number of degrees of freedom for chi-square statistics: " + d0.ToString);
d0 := ssa.Statistics[i - 1, 5];
Debug.WriteLine(" - probability for chi-square statistics: " + d0.ToString);
End For;
Debug.WriteLine("Eigenvectors: ");
For i := 1 To ssa.PCCount Do
d0 := ssa.P[0, i - 1];
d1 := ssa.P[1, i - 1];
d2 := ssa.P[2, i - 1];
Debug.WriteLine("Principal component №" +
i.ToString + ": " + d0.ToString +
" " + d1.ToString + " " + d2.ToString);
End For;
Debug.WriteLine("================================");
Debug.WriteLine("Values of principal components: ");
Debug.WriteLine("Principal component №1, №2, №3");
For i := 1 To ssa.v.GetUpperBound(1) + 1 Do
d0 := ssa.V[i - 1, 1];
d1 := ssa.V[i - 1, 2];
d2 := ssa.V[i - 1, 3];
Debug.WriteLine("Observation №" +
i.ToString + ": " + d0.ToString +
" " + d1.ToString + " " + d2.ToString);
End For;
d0 := ssa.V[0, 0];
Debug.WriteLine("================================");
Debug.WriteLine("Total average: " + d0.ToString);
Debug.WriteLine("================================");
Debug.WriteLine("Fitted series");
For i := 0 To ssa.Fitted.Length - 1 Do
Debug.WriteLine(ssa.Fitted[i]);
End For;
Debug.WriteLine("================================");
Debug.WriteLine("Residual series");
For i := 0 To ssa.Residuals.Length - 1 Do
Debug.WriteLine(ssa.Residuals[i]);
End For;
End If;
End Sub UserSSA;
Result of example execution: singular spectrum analysis is configured and performed, execution results are displayed to the console window.
See also: