/// <summary> /// Kelas untuk menghitung nilai batas atas dan bawah /// </summary> /// / // <param name="data"> data yang digunakan untuk analisis </param> /// <param name="lag"> Jumlah lag yang di include kan</param> public Boundaries(double[] data, int lag, bool whiteNoiseACf) { double[] t = new double[] { 12.706, 4.303, 3.182, 2.776, 2.571, 2.447, 2.365, 2.306, 2.262, 2.228, 2.201, 2.179, 2.160, 2.145, 2.131, 2.120, 2.110, 2.101, 2.093, 2.086, 2.080, 2.074, 2.069, 2.064, 2.060, 2.056, 2.052, 2.048, 2.045, 1.96 }; int n = data.Length; this.whiteNoiseAcf = whiteNoiseACf; this.acfup = new double[lag]; this.acfdown = new double[lag]; this.pacfup = new double[lag]; this.pacfdown = new double[lag]; // calculate ACF if (!this.whiteNoiseAcf) { double seacf; double se2acf; Vector A = new Vector(data, data.Length); LjungBoxQTest k = new LjungBoxQTest(A, lag); //Nilai batas atas dan bawah berdasar buku "Peramalan Bisnis" by John E. Hanke if (n < 30) { double sumacf = 0; for (int a = 0; a < lag; a++) { se2acf = (1 + 2 * sumacf) / n; seacf = Math.Sqrt(se2acf); acfup[a] = t[n - 2] * seacf; acfdown[a] = -1 * t[n - 2] * seacf; sumacf += Math.Pow(k.ACF[a], 2); } // previous way //for (int a = 0; a < lag; a++) //{ // double sumacf = 0; // for (int j = 0; j < a; j++) // { // sumacf += Math.Pow(k.ACF[j], 2); // } // se2acf = (1 + 2 * sumacf) / n; // seacf = Math.Sqrt(se2acf); // acfup[a] = t[n - 2] * seacf; // acfdown[a] = -1 * t[n - 2] * seacf; //} } else { double sumacf = 0; for (int a = 0; a < lag; a++) { se2acf = (1 + 2 * sumacf) / n; seacf = Math.Sqrt(se2acf); acfup[a] = 1.96 * seacf; acfdown[a] = -1 * 1.96 * seacf; sumacf += Math.Pow(k.ACF[a], 2); } // previous way //for (int a = 0; a < lag; a++) //{ // double sumacf = 0; // for (int j = 0; j < a; j++) // { // sumacf += Math.Pow(k.ACF[j], 2); // } // se2acf = (1 + 2 * sumacf) / n; // seacf = Math.Sqrt(se2acf); // acfup[a] = 1.96 * seacf; // acfdown[a] = -1 * 1.96 * seacf; //} } } else { //white noise double seacf; seacf = Math.Sqrt((double)1 / n); for (int i = 0; i < lag; i++) { acfup[i] = 1.96 * seacf; acfdown[i] = -1 * 1.96 * seacf; } } //Penghitungan nilai batas atas dan bawah berdasar buku Gujarati (white noise) // calculate PACF double sepacf; sepacf = Math.Sqrt((double)1 / n); for (int i = 0; i < lag; i++) { pacfup[i] = 1.96 * sepacf; pacfdown[i] = -1 * 1.96 * sepacf; } }
public void DisplayResult() { Vector Y = new Vector(data, data.Length); Boundaries k = new Boundaries(data, lag, this.whiteNoiseAcf); LjungBoxQTest Q = new LjungBoxQTest(Y, lag); //I GRAFIK ACF //Mengeset nilai pada grafik sumbu x double[] xAxis = new double[lag]; for (int i = 0; i < lag; i++) { xAxis[i] = i + 1.0; } //mengeset nilai-nilai ACF pada sumbu y double[] yAxis = new double[lag]; for (int i = 0; i < lag; i++) { yAxis[i] = Q.ACF[i]; } GraphPane variablePane = this.zedGraphControl1.GraphPane; //Memberi nama pada grafik variablePane.Title.Text = "ACF Graph"; string whiteNoiseText = ""; //if (this.whiteNoiseAcf) whiteNoiseText += "(white noise)"; variablePane.XAxis.Title.Text = "Lag"; variablePane.YAxis.Title.Text = "ACF"; //Menampilkan grafik batas atas dan batas bawah variablePane.AddCurve("Upper Bound " + whiteNoiseText, xAxis, k.ACFUp, Color.Blue, SymbolType.None); variablePane.AddCurve("Lower Bound " + whiteNoiseText, xAxis, k.ACFDown, Color.Blue, SymbolType.None); //Menampilkan grafik ACF BarItem myCurve = variablePane.AddBar("ACF", xAxis, yAxis, Color.Red); //myCurve.Line.Width = 5.0f; //Batas max dan min sumbu y variablePane.YAxis.Scale.Min = -1; variablePane.YAxis.Scale.Max = 1; variablePane.XAxis.Scale.Min = 0; variablePane.XAxis.Scale.Max = lag + 1; //Memberi warna pada grafik variablePane.Chart.Fill = new Fill(Color.FromArgb(255, 255, 245), Color.FromArgb(255, 255, 190), 90F); variablePane.Fill = new Fill(Color.White, Color.LightBlue, 135.0f); zedGraphControl1.AxisChange(); zedGraphToolstrip1.SetData(zedGraphControl1, variablePane); //II GRAFIK PACF //Mengeset nilai pada grafik sumbu x double[] xAxis1 = new double[lag]; for (int i = 0; i < lag; i++) { xAxis1[i] = i + 1.0; } //mengeset nilai-nilai PACF pada sumbu y double[] yAxis1 = new double[lag]; for (int i = 0; i < lag; i++) { yAxis1[i] = Q.PACF[i, i]; } GraphPane variablePane1 = this.zedGraphControl2.GraphPane; //Memberi nama pada grafik variablePane1.Title.Text = "PACF Graph"; variablePane1.XAxis.Title.Text = "Lag"; variablePane1.YAxis.Title.Text = "PACF"; //Menampilkan grafik batas atas dan batas bawah LineItem cv1 = variablePane1.AddCurve("Upper Bound", xAxis, k.PACFUp, Color.Blue, SymbolType.None); LineItem cv2 = variablePane1.AddCurve("lower Bound", xAxis, k.PACFDown, Color.Blue, SymbolType.None); //Menampilkan grafik PACF BarItem myCurve1 = variablePane1.AddBar("PACF", xAxis1, yAxis1, Color.Red); //myCurve1.Line.Width = 5.0f; //Batas max dan min sumbu y variablePane1.YAxis.Scale.Min = -1; variablePane1.YAxis.Scale.Max = 1; variablePane1.XAxis.Scale.Min = 0; variablePane1.XAxis.Scale.Max = lag + 1; //Memberi warna pada grafik variablePane1.Chart.Fill = new Fill(Color.FromArgb(255, 255, 245), Color.FromArgb(255, 255, 190), 90F); variablePane1.Fill = new Fill(Color.White, Color.LightBlue, 135.0f); zedGraphControl2.AxisChange(); zedGraphToolstrip2.SetData(zedGraphControl2, variablePane1); dataGridView2.RowCount = lag; dataGridView2.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders; //Menampilkan tabel yang berisi nilai ACF, PACF, Statistik Q, PValue for (int i = 0; i < lag; i++) { dataGridView2.Rows[i].HeaderCell.Value = "" + (i + 1); dataGridView2[0, i].Value = Q.ACF[i].ToString("F4"); dataGridView2[1, i].Value = Q.PACF[i, i].ToString("F4"); dataGridView2[2, i].Value = Q.LB[i].ToString("F4"); if (Q.PValue[i].ToString() == "NaN") { dataGridView2[3, i].Value = ""; } else { dataGridView2[3, i].Value = Q.PValue[i].ToString("F3"); } } }
public void DisplayResult() { Vector Y = new Vector(data, data.Length); Boundaries k = new Boundaries(data, lag, this.whiteNoiseAcf); LjungBoxQTest Q = new LjungBoxQTest(Y, lag); //I GRAFIK ACF //Mengeset nilai pada grafik sumbu x double[] xAxis = new double[lag]; for (int i = 0; i < lag; i++) xAxis[i] = i + 1.0; //mengeset nilai-nilai ACF pada sumbu y double[] yAxis = new double[lag]; for (int i = 0; i < lag; i++) yAxis[i] = Q.ACF[i]; GraphPane variablePane = this.zedGraphControl1.GraphPane; //Memberi nama pada grafik variablePane.Title.Text = "ACF Graph"; string whiteNoiseText=""; //if (this.whiteNoiseAcf) whiteNoiseText += "(white noise)"; variablePane.XAxis.Title.Text = "Lag"; variablePane.YAxis.Title.Text = "ACF"; //Menampilkan grafik batas atas dan batas bawah variablePane.AddCurve("Upper Bound " + whiteNoiseText, xAxis, k.ACFUp, Color.Blue, SymbolType.None); variablePane.AddCurve("Lower Bound " + whiteNoiseText, xAxis, k.ACFDown, Color.Blue, SymbolType.None); //Menampilkan grafik ACF BarItem myCurve = variablePane.AddBar("ACF", xAxis, yAxis, Color.Red); //myCurve.Line.Width = 5.0f; //Batas max dan min sumbu y variablePane.YAxis.Scale.Min = -1; variablePane.YAxis.Scale.Max = 1; variablePane.XAxis.Scale.Min = 0; variablePane.XAxis.Scale.Max = lag + 1; //Memberi warna pada grafik variablePane.Chart.Fill = new Fill(Color.FromArgb(255, 255, 245), Color.FromArgb(255, 255, 190), 90F); variablePane.Fill = new Fill(Color.White, Color.LightBlue, 135.0f); zedGraphControl1.AxisChange(); zedGraphToolstrip1.SetData(zedGraphControl1, variablePane); //II GRAFIK PACF //Mengeset nilai pada grafik sumbu x double[] xAxis1 = new double[lag]; for (int i = 0; i < lag; i++) xAxis1[i] = i + 1.0; //mengeset nilai-nilai PACF pada sumbu y double[] yAxis1 = new double[lag]; for (int i = 0; i < lag; i++) yAxis1[i] = Q.PACF[i, i]; GraphPane variablePane1 = this.zedGraphControl2.GraphPane; //Memberi nama pada grafik variablePane1.Title.Text = "PACF Graph"; variablePane1.XAxis.Title.Text = "Lag"; variablePane1.YAxis.Title.Text = "PACF"; //Menampilkan grafik batas atas dan batas bawah LineItem cv1 = variablePane1.AddCurve("Upper Bound", xAxis, k.PACFUp, Color.Blue, SymbolType.None); LineItem cv2 = variablePane1.AddCurve("lower Bound", xAxis, k.PACFDown, Color.Blue, SymbolType.None); //Menampilkan grafik PACF BarItem myCurve1 = variablePane1.AddBar("PACF", xAxis1, yAxis1, Color.Red); //myCurve1.Line.Width = 5.0f; //Batas max dan min sumbu y variablePane1.YAxis.Scale.Min = -1; variablePane1.YAxis.Scale.Max = 1; variablePane1.XAxis.Scale.Min = 0; variablePane1.XAxis.Scale.Max = lag + 1; //Memberi warna pada grafik variablePane1.Chart.Fill = new Fill(Color.FromArgb(255, 255, 245), Color.FromArgb(255, 255, 190), 90F); variablePane1.Fill = new Fill(Color.White, Color.LightBlue, 135.0f); zedGraphControl2.AxisChange(); zedGraphToolstrip2.SetData(zedGraphControl2, variablePane1); dataGridView2.RowCount = lag; dataGridView2.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders; //Menampilkan tabel yang berisi nilai ACF, PACF, Statistik Q, PValue for (int i = 0; i < lag; i++) { dataGridView2.Rows[i].HeaderCell.Value = "" + (i + 1); dataGridView2[0, i].Value = Q.ACF[i].ToString("F4"); dataGridView2[1, i].Value = Q.PACF[i, i].ToString("F4"); dataGridView2[2, i].Value = Q.LB[i].ToString("F4"); if (Q.PValue[i].ToString() == "NaN") { dataGridView2[3, i].Value = ""; } else dataGridView2[3, i].Value = Q.PValue[i].ToString("F3"); } }
/// <summary> /// Kelas untuk menghitung nilai batas atas dan bawah /// </summary> /// / // <param name="data"> data yang digunakan untuk analisis </param> /// <param name="lag"> Jumlah lag yang di include kan</param> public Boundaries(double[] data, int lag, bool whiteNoiseACf) { double[] t = new double[] {12.706, 4.303, 3.182, 2.776, 2.571, 2.447, 2.365, 2.306, 2.262, 2.228, 2.201, 2.179, 2.160, 2.145, 2.131, 2.120, 2.110, 2.101, 2.093, 2.086, 2.080, 2.074, 2.069, 2.064, 2.060, 2.056, 2.052, 2.048, 2.045, 1.96}; int n = data.Length; this.whiteNoiseAcf = whiteNoiseACf; this.acfup = new double[lag]; this.acfdown = new double[lag]; this.pacfup = new double[lag]; this.pacfdown = new double[lag]; // calculate ACF if (!this.whiteNoiseAcf) { double seacf; double se2acf; Vector A = new Vector(data, data.Length); LjungBoxQTest k = new LjungBoxQTest(A, lag); //Nilai batas atas dan bawah berdasar buku "Peramalan Bisnis" by John E. Hanke if (n < 30) { double sumacf = 0; for (int a = 0; a < lag; a++) { se2acf = (1 + 2 * sumacf) / n; seacf = Math.Sqrt(se2acf); acfup[a] = t[n - 2] * seacf; acfdown[a] = -1 * t[n - 2] * seacf; sumacf += Math.Pow(k.ACF[a], 2); } // previous way //for (int a = 0; a < lag; a++) //{ // double sumacf = 0; // for (int j = 0; j < a; j++) // { // sumacf += Math.Pow(k.ACF[j], 2); // } // se2acf = (1 + 2 * sumacf) / n; // seacf = Math.Sqrt(se2acf); // acfup[a] = t[n - 2] * seacf; // acfdown[a] = -1 * t[n - 2] * seacf; //} } else { double sumacf = 0; for (int a = 0; a < lag; a++) { se2acf = (1 + 2 * sumacf) / n; seacf = Math.Sqrt(se2acf); acfup[a] = 1.96 * seacf; acfdown[a] = -1 * 1.96 * seacf; sumacf += Math.Pow(k.ACF[a], 2); } // previous way //for (int a = 0; a < lag; a++) //{ // double sumacf = 0; // for (int j = 0; j < a; j++) // { // sumacf += Math.Pow(k.ACF[j], 2); // } // se2acf = (1 + 2 * sumacf) / n; // seacf = Math.Sqrt(se2acf); // acfup[a] = 1.96 * seacf; // acfdown[a] = -1 * 1.96 * seacf; //} } } else { //white noise double seacf; seacf = Math.Sqrt((double)1 / n); for (int i = 0; i < lag; i++) { acfup[i] = 1.96 * seacf; acfdown[i] = -1 * 1.96 * seacf; } } //Penghitungan nilai batas atas dan bawah berdasar buku Gujarati (white noise) // calculate PACF double sepacf; sepacf = Math.Sqrt((double)1 / n); for (int i = 0; i < lag; i++) { pacfup[i] = 1.96 * sepacf; pacfdown[i] = -1 * 1.96 * sepacf; } }