Keyword: 一変量時系列, 季節階差, 非季節階差
概要
本サンプルは一変量時系列の季節及び非季節階差の計算を行うC#によるサンプルプログラムです。 本サンプルは以下に示される時系列データを分析し、季節及び非季節階差を出力します。
※本サンプルはnAG Library for .NETに含まれる関数 g13aa() のExampleコードです。本サンプル及び関数の詳細情報は g13aa のマニュアルページをご参照ください。
ご相談やお問い合わせはこちらまで
入力データ
(本関数の詳細はg13aa のマニュアルページを参照)| このデータをダウンロード |
g13aa Example Program Data 20 2 1 4 120.0 108.0 98.0 118.0 135.0 131.0 118.0 125.0 121.0 100.0 82.0 82.0 89.0 88.0 86.0 96.0 108.0 110.0 99.0 105.0
- 1行目はタイトル行で読み飛ばされます。
- 2行目に時系列データの数(nx)、非季節階差の次数(nd)、季節階差の次数(nds)、季節性(ns)を指定しています。
- 3〜6行目に時系列データ(x)を指定しています。
出力結果
(本関数の詳細はg13aa のマニュアルページを参照)| この出力例をダウンロード |
g13aa Example Program Results
Non-seasonal differencing of order 2 and seasonal differencing
of order 1 with seasonality 4 are applied
The output array holds 20 values, of which the first 14 are differenced values
-11.0 -10.0 -8.0 4.0 12.0
-2.0 18.0 9.0 -4.0 -6.0
-5.0 -2.0 -12.0 5.0 2.0
-10.0 -13.0 17.0 6.0 105.0
- 3〜4行目に2次の非季節階差と1次の季節階差が適用されていることが示されています。
- 6行目に、出力結果の配列には20個の値があり最初の14個は階差であることが示されています。
- 8〜11行目には階差の値(最初の14個)と再構成データ(残り6個)が出力されています。
ソースコード
(本関数の詳細はg13aa のマニュアルページを参照)
※本サンプルソースコードは .NET環境用の科学技術・統計計算ライブラリである「nAG Library for .NET」の関数を呼び出します。
サンプルのコンパイル及び実行方法
| このソースコードをダウンロード |
// g13aa Example Program Text
// C# version, nAG Copyright 2008
using System;
using NagLibrary;
namespace NagDotNetExamples
{
public class G13AAE
{
static bool defaultdata = true;
static string datafile = "";
static void Main(String[] args)
{
if (args.Length == 1)
{
defaultdata = false;
datafile = args[0];
}
StartExample();
}
public static void StartExample()
{
try
{
DataReader sr = null;
if (defaultdata)
{
sr = new DataReader("exampledata/g13aae.d");
}
else
{
sr = new DataReader(datafile);
}
int i, nd, nds, ns, nx, nxd; int ifail;
Console.WriteLine("g13aa Example Program Results");
// Skip heading in data file
sr.Reset();
sr.Reset();
nx = int.Parse(sr.Next());
nd = int.Parse(sr.Next());
nds = int.Parse(sr.Next());
ns = int.Parse(sr.Next());
double[] x = new double[nx];
double[] xd = new double[nx];
if (nx > 0)
{
sr.Reset();
for (i = 1; i <= nx; i++)
{
x[i - 1] = double.Parse(sr.Next());
}
Console.WriteLine("");
Console.WriteLine(" {0}{1,1}{2}", "Non-seasonal differencing of order ", nd, " and seasonal differencing");
Console.WriteLine(" {0}{1,1}{2}{3,1}{4}", "of order ", nds, " with seasonality ", ns, " are applied");
//
G13.g13aa(x, nx, nd, nds, ns, xd, out nxd, out ifail);
//
Console.WriteLine("");
Console.WriteLine(" {0}{1,2}{2}{3,2}{4}", "The output array holds ", nx, " values, of which the first ", nxd, " are differenced values");
Console.WriteLine("");
for (i = 1; i <= nx; i++)
{
Console.Write(" {0, 9:f1}{1}", xd[i - 1], i%5==0?"\n":"");
}
Console.WriteLine("");
}
//
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine("Exception Raised");
}
}
}
}
