public void Correlogram()
        {
            SelectAnalyzedVariable dlg = new SelectAnalyzedVariable(this.data.SeriesVariables);
            dlg.ShowDialog();

            if (dlg.DialogResult == DialogResult.OK)
            {
                CorrelogramForm co = new CorrelogramForm();
                co.SetVariable(dlg.SelectedVariable);
                co.ShowDialog();

                if (co.DialogResult == DialogResult.OK)
                {
                    double[] data = co.Data;
                    int lag = co.Lag;
                    bool whiteNoiseAcf = co.WhiteNoiseAcf;

                    CorrelogramResult tp = new CorrelogramResult();
                    tp.Title = "Correlogram ";

                    switch (co.Series)
                    {
                        case CorrelogramForm.CorrelogramSeries.Level:
                            tp.Title += "(Level)";
                            break;
                        case CorrelogramForm.CorrelogramSeries.FirstDifference:
                            tp.Title += "(1st diff)";
                            break;
                        case CorrelogramForm.CorrelogramSeries.SecondDifference:
                            tp.Title += "(2nd diff)";
                            break;
                    }

                    tp.Title += " : '" + dlg.SelectedVariable.VariableName + "'";
                    tp.SetData(data, lag, whiteNoiseAcf);
                    tp.DisplayResult();

                    tp.IsDrawn = true;
                    this.tabControlResult.AddTab(tp);
                    this.tabControlData.SelectedTab = this.tabPageResult;
                    this.tabControlResult.SelectedItem = tp;

                }
            }
        }
        public void NeuralNetworkAnalysis()
        {
            SelectAnalyzedVariable dlg = new SelectAnalyzedVariable(this.data.SeriesVariables);
            dlg.ShowDialog();

            if (dlg.DialogResult == DialogResult.OK)
            {
                NeuralNetworkAnalysisForm neural = new NeuralNetworkAnalysisForm();
                neural.SetVariable(dlg.SelectedVariable);
                neural.ShowDialog();
                if (neural.DialogResult == DialogResult.Yes)
                {
                    ANNSelectResultView select = new ANNSelectResultView();
                    select.ShowDialog();
                    if (select.DialogResult == DialogResult.OK)
                    {
                        ANNResultTabPage annTabPage = new ANNResultTabPage();

                        annTabPage.Title = "Neural Network: '" + dlg.SelectedVariable.VariableName + "'";

                        if (select.IsForecastedDataGridChecked)
                        {
                            annTabPage.SetData(this.data, dlg.SelectedVariable, neural.NetworkProperties, neural.Solution, neural.Forecast(select.ForecastingStep));
                        }
                        else
                        {
                            annTabPage.SetData(this.data, dlg.SelectedVariable, neural.NetworkProperties, neural.Solution, null);
                        }

                        annTabPage.IsAnnModelSummaryVisible = select.IsAnnModelSummaryChecked;
                        annTabPage.IsActualPredictedResidualDataGridVisible = select.IsActualPredictedResidualDataGridChecked;
                        annTabPage.IsForecastedDataGridVisible = select.IsForecastedDataGridChecked;
                        annTabPage.IsActualAndPredictedGraphVisible = select.IsActualAndPredictedGraphChecked;
                        annTabPage.IsActualAndForecastedGraphVisible = select.IsActualAndForecastedGraphChecked;
                        annTabPage.IsActualVsPredictedGraphVisible = select.IsActualVsPredictedGraphChecked;
                        annTabPage.IsResidualGraphVisible = select.IsResidualGraphChecked;
                        annTabPage.IsResidualVsActualGraphVisible = select.IsResidualVsActualGraphChecked;
                        annTabPage.IsResidualVsPredictedGraphVisible = select.IsResidualVsPredictedGraphChecked;

                        annTabPage.DrawControl();

                        annTabPage.IsDrawn = true;
                        this.tabControlResult.AddTab(annTabPage);
                        this.tabControlResult.SelectedItem = annTabPage;

                        this.tabControlData.SelectedTab = this.tabPageResult;

                    }

                }
            }
        }
        public void MovingAverage()
        {
            SelectAnalyzedVariable dlg = new SelectAnalyzedVariable(this.data.SeriesVariables);
            dlg.ShowDialog();
            if (dlg.DialogResult == DialogResult.OK)
            {
                MovingAverageForm maForm = new MovingAverageForm();
                maForm.SetVariable(dlg.SelectedVariable);
                maForm.ShowDialog();
                if (maForm.DialogResult == DialogResult.Yes)
                {

                    if (maForm.MaProperties.isSingleMA)
                    {
                        if (maForm.IsStoreSmoothed)
                        {
                            SeriesVariable var = new SeriesVariable(maForm.SmoothedName, "Smoothed Value of MA(" + maForm.MaProperties.orde +
                                ") analysis of variable '" + dlg.SelectedVariable.VariableName + "'");
                            int lag = dlg.SelectedVariable.SeriesValues.Count - maForm.MaProperties.includedObservations;
                            var.InitializeItem(dlg.SelectedVariable.SeriesValues.Count);
                            for (int i = 0; i < lag; i++) var[i] = double.NaN;
                            for (int i = lag; i < lag + maForm.MaProperties.orde; i++) var[i] = double.NaN;
                            for (int i = lag + maForm.MaProperties.orde; i < maForm.MaProperties.includedObservations + lag; i++) var[i] = maForm.MaTable.singleSmoothed[i - lag];
                            this.data.SeriesVariables.Add(var);
                            this.seriesDataList.Refresh();
                        }

                        if (maForm.IsStorePredicted)
                        {
                            SeriesVariable var = new SeriesVariable(maForm.PredictedName, "Predicted Value of MA(" + maForm.MaProperties.orde +
                                ") analysis of variable '" + dlg.SelectedVariable.VariableName + "'");
                            int lag = dlg.SelectedVariable.SeriesValues.Count - maForm.MaProperties.includedObservations;
                            var.InitializeItem(dlg.SelectedVariable.SeriesValues.Count);
                            for (int i = 0; i < lag; i++) var[i] = double.NaN;
                            for (int i = lag; i < lag + maForm.MaProperties.orde; i++) var[i] = double.NaN;
                            for (int i = lag + maForm.MaProperties.orde; i < maForm.MaProperties.includedObservations + lag; i++) var[i] = maForm.MaTable.predicted[i - lag];
                            this.data.SeriesVariables.Add(var);
                            this.seriesDataList.Refresh();
                        }

                        if (maForm.IsStoreResidual)
                        {
                            SeriesVariable var = new SeriesVariable(maForm.ResidualName, "Residual Value of MA(" + maForm.MaProperties.orde +
                                ") analysis of variable '" + dlg.SelectedVariable.VariableName + "'");
                            int lag = dlg.SelectedVariable.SeriesValues.Count - maForm.MaProperties.includedObservations;
                            var.InitializeItem(dlg.SelectedVariable.SeriesValues.Count);
                            for (int i = 0; i < lag; i++) var[i] = double.NaN;
                            for (int i = lag; i < lag + maForm.MaProperties.orde; i++) var[i] = double.NaN;
                            for (int i = lag + maForm.MaProperties.orde; i < maForm.MaProperties.includedObservations + lag; i++) var[i] = maForm.MaTable.residual[i - lag];
                            this.data.SeriesVariables.Add(var);
                            this.seriesDataList.Refresh();
                        }
                    }
                    else
                    {
                        if (maForm.IsStoreSmoothed)
                        {
                            SeriesVariable var = new SeriesVariable(maForm.SmoothedName, "Smoothed Value of MA(" + maForm.MaProperties.orde +
                                "X" + maForm.MaProperties.orde + ") analysis of variable '" + dlg.SelectedVariable.VariableName + "'");
                            int lag = dlg.SelectedVariable.SeriesValues.Count - maForm.MaProperties.includedObservations;
                            var.InitializeItem(dlg.SelectedVariable.SeriesValues.Count);
                            for (int i = 0; i < lag; i++) var[i] = double.NaN;
                            for (int i = lag; i < lag + (2 * (maForm.MaProperties.orde - 1)); i++) var[i] = double.NaN;
                            for (int i = lag + (2 * (maForm.MaProperties.orde - 1)); i < maForm.MaProperties.includedObservations + lag; i++) var[i] = maForm.MaTable.doubleSmoothed[i - lag];
                            this.data.SeriesVariables.Add(var);
                            this.seriesDataList.Refresh();
                        }
                        if (maForm.IsStorePredicted)
                        {
                            SeriesVariable var = new SeriesVariable(maForm.PredictedName, "Predicted Value of MA(" + maForm.MaProperties.orde +
                                "X" + maForm.MaProperties.orde + ") analysis of variable '" + dlg.SelectedVariable.VariableName + "'");
                            int lag = dlg.SelectedVariable.SeriesValues.Count - maForm.MaProperties.includedObservations;
                            var.InitializeItem(dlg.SelectedVariable.SeriesValues.Count);
                            for (int i = 0; i < lag; i++) var[i] = double.NaN;
                            for (int i = lag; i < lag + (2 * (maForm.MaProperties.orde - 1)); i++) var[i] = double.NaN;
                            for (int i = lag + (2 * (maForm.MaProperties.orde - 1)); i < maForm.MaProperties.includedObservations + lag; i++) var[i] = maForm.MaTable.predicted[i - lag];
                            this.data.SeriesVariables.Add(var);
                            this.seriesDataList.Refresh();
                        }
                        if (maForm.IsStoreResidual)
                        {
                            SeriesVariable var = new SeriesVariable(maForm.ResidualName, "Residual Value of MA(" + maForm.MaProperties.orde +
                                "," + maForm.MaProperties.orde + ") analysis of variable '" + dlg.SelectedVariable.VariableName + "'");
                            int lag = dlg.SelectedVariable.SeriesValues.Count - maForm.MaProperties.includedObservations;
                            var.InitializeItem(dlg.SelectedVariable.SeriesValues.Count);
                            for (int i = 0; i < lag; i++) var[i] = double.NaN;
                            for (int i = lag; i < lag + (2 * (maForm.MaProperties.orde - 1)); i++) var[i] = double.NaN;
                            for (int i = lag + (2 * (maForm.MaProperties.orde - 1)); i < maForm.MaProperties.includedObservations + lag; i++) var[i] = maForm.MaTable.residual[i - lag];
                            this.data.SeriesVariables.Add(var);
                            this.seriesDataList.Refresh();
                        }
                    }

                    MAResultTabPage maTabPage = new MAResultTabPage();

                    maTabPage.Title = "Moving Average : '" + dlg.SelectedVariable.VariableName + "'";

                    if (maForm.IsForecastedDataGridChecked)
                    {
                        if (maForm.MaProperties.isSingleMA)
                        {
                            maTabPage.SetData(this.data, dlg.SelectedVariable, maForm.MaProperties,
                                maForm.MaTable, maForm.SmaForecast(maForm.ForecastingStep));
                        }
                        else
                        {
                            maTabPage.SetData(this.data, dlg.SelectedVariable, maForm.MaProperties,
                                maForm.MaTable, maForm.DmaForecast(maForm.ForecastingStep));
                        }
                    }
                    else
                    {
                        maTabPage.SetData(this.data, dlg.SelectedVariable, maForm.MaProperties,
                            maForm.MaTable, null);
                    }
                    maTabPage.IsMaModelSummaryVisible = maForm.IsMaModelSummaryChecked;
                    maTabPage.IsSmoothingVisible = maForm.IsSmoothingChecked;
                    maTabPage.IsMovingAverageDataGridVisible = maForm.IsMovingAverageDataGridChecked;
                    maTabPage.IsForecastedDataGridVisible = maForm.IsForecastedDataGridChecked;
                    maTabPage.IsActualAndPredictedGraphVisible = maForm.IsActualAndPredictedGraphChecked;
                    maTabPage.IsActualAndPredictedGraphVisible = maForm.IsActualAndPredictedGraphChecked;
                    maTabPage.IsActualAndSmoothedGraphVisible = maForm.IsActualAndSmoothedGraphChecked;
                    maTabPage.IsActualAndForecastedGraphVisible = maForm.IsActualAndForecastedGraphChecked;
                    maTabPage.IsActualVsPredictedGraphVisible = maForm.IsActualVsPredictedGraphChecked;
                    maTabPage.IsResidualGraphVisible = maForm.IsResidualGraphChecked;
                    maTabPage.IsResidualVsActualGraphVisible = maForm.IsResidualVsActualGraphChecked;
                    maTabPage.IsResidualVsPredictedGraphVisible = maForm.IsResidualVsPredictedGraphChecked;

                    maTabPage.DrawControl();

                    maTabPage.IsDrawn = true;
                    this.tabControlResult.AddTab(maTabPage);
                    this.tabControlResult.SelectedItem = maTabPage;

                    this.tabControlData.SelectedTab = this.tabPageResult;

                }
            }
        }
        public void ExponentialSmoothing()
        {
            SelectAnalyzedVariable dlg = new SelectAnalyzedVariable(this.data.SeriesVariables);
            dlg.ShowDialog();
            if (dlg.DialogResult == DialogResult.OK)
            {
                ExponentialSmoothingForm esForm = new ExponentialSmoothingForm();
                esForm.SetVariable(dlg.SelectedVariable);
                esForm.ShowDialog();
                if (esForm.DialogResult == DialogResult.Yes)
                {

                    if (esForm.IsStoreSmoothed)
                    {
                        SeriesVariable var = new SeriesVariable(esForm.SmoothedName, "Smoothed Value of exponential smoothing of variable '"
                            + dlg.SelectedVariable.VariableName + "'");
                        int lag = dlg.SelectedVariable.SeriesValues.Count - esForm.EsTable.predicted.Length;
                        var.InitializeItem(dlg.SelectedVariable.SeriesValues.Count);
                        for (int i = 0; i < lag; i++) var[i] = double.NaN;
                        for (int i = 0; i < esForm.EsTable.smoothed.Length; i++) var[i + lag] = esForm.EsTable.smoothed[i];
                        this.data.SeriesVariables.Add(var);
                        this.seriesDataList.Refresh();
                    }

                    if (esForm.IsStorePredicted)
                    {
                        SeriesVariable var = new SeriesVariable(esForm.PredictedName, "Predicted Value of exponential smoothing of variable '"
                            + dlg.SelectedVariable.VariableName + "'");
                        int lag = dlg.SelectedVariable.SeriesValues.Count - esForm.EsTable.predicted.Length;
                        var.InitializeItem(dlg.SelectedVariable.SeriesValues.Count);
                        for (int i = 0; i < lag; i++) var[i] = double.NaN;
                        for (int i = 0; i < esForm.EsTable.predicted.Length; i++) var[i + lag] = esForm.EsTable.predicted[i];
                        this.data.SeriesVariables.Add(var);
                        this.seriesDataList.Refresh();
                    }

                    if (esForm.IsStoreResidual)
                    {
                        SeriesVariable var = new SeriesVariable(esForm.ResidualName, "Residual Value of exponential smoothing of variable '"
                            + dlg.SelectedVariable.VariableName + "'");
                        int lag = dlg.SelectedVariable.SeriesValues.Count - esForm.EsTable.residual.Length;
                        var.InitializeItem(dlg.SelectedVariable.SeriesValues.Count);
                        for (int i = 0; i < lag; i++) var[i] = double.NaN;
                        for (int i = 0; i < esForm.EsTable.residual.Length; i++) var[i + lag] = esForm.EsTable.residual[i];
                        this.data.SeriesVariables.Add(var);
                        this.seriesDataList.Refresh();
                    }

                    ESResultTabPage esTabPage = new ESResultTabPage();

                    if (esForm.EsProperties.initialModel == 1)
                        esTabPage.Title = "Single ES : '" + dlg.SelectedVariable.VariableName + "'";
                    if (esForm.EsProperties.initialModel == 2)
                        esTabPage.Title = "Double ES (Brown) : '" + dlg.SelectedVariable.VariableName + "'";
                    if (esForm.EsProperties.initialModel == 3)
                        esTabPage.Title = "Double ES (Holt) : '" + dlg.SelectedVariable.VariableName + "'";
                    if (esForm.EsProperties.initialModel == 4)
                        esTabPage.Title = "Triple ES (Winter) : '" + dlg.SelectedVariable.VariableName + "'";

                    if (esForm.IsForecastedDataGridChecked)
                    {
                        if (esForm.EsProperties.initialModel == 1)
                        {
                            esTabPage.SetData(this.data, dlg.SelectedVariable, esForm.EsProperties,
                                esForm.EsTable, esForm.SesForecast(esForm.ForecastingStep));
                        }
                        if (esForm.EsProperties.initialModel == 2)
                        {
                            esTabPage.SetData(this.data, dlg.SelectedVariable, esForm.EsProperties,
                                esForm.EsTable, esForm.BrownForecast(esForm.ForecastingStep));
                        }
                        if (esForm.EsProperties.initialModel == 3)
                        {
                            esTabPage.SetData(this.data, dlg.SelectedVariable, esForm.EsProperties,
                                esForm.EsTable, esForm.HoltForecast(esForm.ForecastingStep));
                        }
                        if (esForm.EsProperties.initialModel == 4)
                        {
                            esTabPage.SetData(this.data, dlg.SelectedVariable, esForm.EsProperties,
                                esForm.EsTable, esForm.WinterForecast(esForm.ForecastingStep));
                        }
                    }

                    else
                    {
                        esTabPage.SetData(this.data, dlg.SelectedVariable, esForm.EsProperties,
                            esForm.EsTable, null);
                    }
                    esTabPage.IsEsModelSummaryVisible = esForm.IsEsModelSummaryChecked;

                    esTabPage.IsExponentialSmoothingDataGridVisible = esForm.IsExponentialSmoothingDataGridChecked;
                    esTabPage.IsSmoothingVisible = esForm.IsSmoothingChecked;
                    esTabPage.IsTrendVisible = esForm.IsTrendChecked;
                    esTabPage.IsSeasonalVisible = esForm.IsSeasonalChecked;
                    esTabPage.IsForecastedDataGridVisible = esForm.IsForecastedDataGridChecked;
                    esTabPage.IsActualAndPredictedGraphVisible = esForm.IsActualAndPredictedGraphChecked;
                    esTabPage.IsActualAndSmoothedGraphVisible = esForm.IsActualAndSmoothedGraphChecked;
                    esTabPage.IsActualAndForecastedGraphVisible = esForm.IsActualAndForecastedGraphChecked;
                    esTabPage.IsActualVsPredictedGraphVisible = esForm.IsActualVsPredictedGraphChecked;
                    esTabPage.IsResidualGraphVisible = esForm.IsResidualGraphChecked;
                    esTabPage.IsResidualVsActualGraphVisible = esForm.IsResidualVsActualGraphChecked;
                    esTabPage.IsResidualVsPredictedGraphVisible = esForm.IsResidualVsPredictedGraphChecked;

                    esTabPage.DrawControl();

                    esTabPage.IsDrawn = true;
                    this.tabControlResult.AddTab(esTabPage);
                    this.tabControlResult.SelectedItem = esTabPage;

                    this.tabControlData.SelectedTab = this.tabPageResult;

                }
            }
        }
        public void Decomposition()
        {
            SelectAnalyzedVariable dlg = new SelectAnalyzedVariable(this.data.SeriesVariables);
            dlg.ShowDialog();
            if (dlg.DialogResult == DialogResult.OK)
            {
                DecompositionForm decForm = new DecompositionForm();
                decForm.SetVariable(dlg.SelectedVariable);
                decForm.ShowDialog();
                if (decForm.DialogResult == DialogResult.Yes)
                {

                    if (decForm.IsStoreTrend)
                    {
                        SeriesVariable var = new SeriesVariable(decForm.TrendName, "Trend Value of Decomposition Classic analysis of variable '"
                            + dlg.SelectedVariable.VariableName + "'");
                        int lag = dlg.SelectedVariable.SeriesValues.Count - decForm.DecTable.trend.Length;
                        var.InitializeItem(dlg.SelectedVariable.SeriesValues.Count);
                        for (int i = 0; i < lag; i++) var[i] = double.NaN;
                        for (int i = 0; i < decForm.DecTable.trend.Length; i++) var[i + lag] = decForm.DecTable.trend[i];
                        this.data.SeriesVariables.Add(var);
                        this.seriesDataList.Refresh();
                    }
                    if (decForm.IsStoreDetrend)
                    {
                        SeriesVariable var = new SeriesVariable(decForm.DetrendName, "Detrended Value of Decomposition Classic analysis of variable '"
                            + dlg.SelectedVariable.VariableName + "'");
                        int lag = dlg.SelectedVariable.SeriesValues.Count - decForm.DecTable.detrend.Length;
                        var.InitializeItem(dlg.SelectedVariable.SeriesValues.Count);
                        for (int i = 0; i < lag; i++) var[i] = double.NaN;
                        for (int i = 0; i < decForm.DecTable.detrend.Length; i++) var[i + lag] = decForm.DecTable.detrend[i];
                        this.data.SeriesVariables.Add(var);
                        this.seriesDataList.Refresh();
                    }
                    if (decForm.IsStoreDeseasonal)
                    {
                        SeriesVariable var = new SeriesVariable(decForm.DeseasonalName, "Seasonally Adj. Value of Decomposition Classic analysis of variable '"
                            + dlg.SelectedVariable.VariableName + "'");
                        int lag = dlg.SelectedVariable.SeriesValues.Count - decForm.DecTable.deseasonal.Length;
                        var.InitializeItem(dlg.SelectedVariable.SeriesValues.Count);
                        for (int i = 0; i < lag; i++) var[i] = double.NaN;
                        for (int i = 0; i < decForm.DecTable.deseasonal.Length; i++) var[i + lag] = decForm.DecTable.deseasonal[i];
                        this.data.SeriesVariables.Add(var);
                        this.seriesDataList.Refresh();
                    }

                    if (decForm.IsStorePredicted)
                    {
                        SeriesVariable var = new SeriesVariable(decForm.PredictedName, "Predicted Value of Decomposition Classic analysis of variable '"
                            + dlg.SelectedVariable.VariableName + "'");
                        int lag = dlg.SelectedVariable.SeriesValues.Count - decForm.DecTable.predicted.Length;
                        var.InitializeItem(dlg.SelectedVariable.SeriesValues.Count);
                        for (int i = 0; i < lag; i++) var[i] = double.NaN;
                        for (int i = 0; i < decForm.DecTable.predicted.Length; i++) var[i + lag] = decForm.DecTable.predicted[i];
                        this.data.SeriesVariables.Add(var);
                        this.seriesDataList.Refresh();
                    }

                    if (decForm.IsStoreResidual)
                    {
                        SeriesVariable var = new SeriesVariable(decForm.ResidualName, "Residual Value of Decomposition Classic analysis of variable '"
                            + dlg.SelectedVariable.VariableName + "'");
                        int lag = dlg.SelectedVariable.SeriesValues.Count - decForm.DecTable.residual.Length;
                        var.InitializeItem(dlg.SelectedVariable.SeriesValues.Count);
                        for (int i = 0; i < lag; i++) var[i] = double.NaN;
                        for (int i = 0; i < decForm.DecTable.residual.Length; i++) var[i + lag] = decForm.DecTable.residual[i];
                        this.data.SeriesVariables.Add(var);
                        this.seriesDataList.Refresh();
                    }

                    DECResultTabPage decTabPage = new DECResultTabPage();

                    decTabPage.Title = "Decomposition : '" + dlg.SelectedVariable.VariableName + "'";

                    if (decForm.IsForecastedDataGridChecked)
                    {
                        decTabPage.SetData(this.data, dlg.SelectedVariable, decForm.DecProperties,
                            decForm.DecTable, decForm.Forecast(decForm.ForecastingStep));
                    }
                    else
                    {
                        decTabPage.SetData(this.data, dlg.SelectedVariable, decForm.DecProperties,
                            decForm.DecTable, null);
                    }
                    decTabPage.IsDecModelSummaryVisible = decForm.IsDecModelSummaryChecked;

                    decTabPage.IsDecompositionDataGridVisible = decForm.IsDecompositionDataGridChecked;
                    decTabPage.IsTrendVisible = decForm.IsTrendChecked;
                    decTabPage.IsDetrendVisible = decForm.IsDetrendChecked;
                    decTabPage.IsSeasonalVisible = decForm.IsSeasonalChecked;
                    decTabPage.IsDeseasonalVisible = decForm.IsDeseasonalChecked;
                    decTabPage.IsForecastedDataGridVisible = decForm.IsForecastedDataGridChecked;
                    decTabPage.IsActualPredictedAndTrendGraphVisible = decForm.IsActualPredictedAndTrendGraphChecked;
                    decTabPage.IsActualAndForecastedGraphVisible = decForm.IsActualAndForecastedGraphChecked;
                    decTabPage.IsActualVsPredictedGraphVisible = decForm.IsActualVsPredictedGraphChecked;
                    decTabPage.IsResidualGraphVisible = decForm.IsResidualGraphChecked;
                    decTabPage.IsResidualVsActualGraphVisible = decForm.IsResidualVsActualGraphChecked;
                    decTabPage.IsResidualVsPredictedGraphVisible = decForm.IsResidualVsPredictedGraphChecked;
                    decTabPage.IsDetrendGraphVisible = decForm.IsDetrendGraphChecked;
                    decTabPage.IsDeseasonalGraphVisible = decForm.IsDeseasonalGraphChecked;

                    decTabPage.DrawControl();

                    decTabPage.IsDrawn = true;
                    this.tabControlResult.AddTab(decTabPage);
                    this.tabControlResult.SelectedItem = decTabPage;

                    this.tabControlData.SelectedTab = this.tabPageResult;

                }
            }
        }
        public void TrendAnalysis()
        {
            SelectAnalyzedVariable dlg = new SelectAnalyzedVariable(this.data.SeriesVariables);
            dlg.ShowDialog();
            if (dlg.DialogResult == DialogResult.OK)
            {
                TrendAnalysisForm trendForm = new TrendAnalysisForm();
                trendForm.SetVariable(dlg.SelectedVariable);
                trendForm.ShowDialog();
                if (trendForm.DialogResult == DialogResult.OK)
                {

                    if (trendForm.IsStorePredicted)
                    {
                        SeriesVariable var = new SeriesVariable(trendForm.PredictedName, "Predicted Value of trend analysis of variable '"
                            + dlg.SelectedVariable.VariableName + "'");
                        int lag = dlg.SelectedVariable.SeriesValues.Count - trendForm.Predicted.Length;
                        var.InitializeItem(dlg.SelectedVariable.SeriesValues.Count);
                        for (int i = 0; i < lag; i++) var[i] = double.NaN;
                        for (int i = 0; i < trendForm.Predicted.Length; i++) var[i + lag] = trendForm.Predicted[i];
                        try
                        {
                            this.data.SeriesVariables.Add(var);
                        }
                        catch (DuplicateVariableException)
                        {
                            MessageBox.Show("Variable '" + var.VariableName + "' already exist", "Duplicate Variable Name", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        this.seriesDataList.Refresh();
                    }

                    if (trendForm.IsStoreResidual)
                    {
                        SeriesVariable var = new SeriesVariable(trendForm.ResidualName, "Residual Value of trend analysis of variable '"
                            + dlg.SelectedVariable.VariableName + "'");
                        int lag = dlg.SelectedVariable.SeriesValues.Count - trendForm.Residual.Length;
                        var.InitializeItem(dlg.SelectedVariable.SeriesValues.Count);
                        for (int i = 0; i < lag; i++) var[i] = double.NaN;
                        for (int i = 0; i < trendForm.Residual.Length; i++) var[i + lag] = trendForm.Residual[i];
                        try
                        {
                            this.data.SeriesVariables.Add(var);
                        }
                        catch (DuplicateVariableException)
                        {
                            MessageBox.Show("Variable '" + var.VariableName + "' already exist", "Duplicate Variable Name", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        this.seriesDataList.Refresh();
                    }

                    TrendAnalysisResultTabPage trendTabPage = new TrendAnalysisResultTabPage();

                    trendTabPage.Title = "Trend Analysis : '" + dlg.SelectedVariable.VariableName + "'";

                    if (trendForm.IsForecastedDataGridChecked)
                    {
                        trendTabPage.SetData(this.data, dlg.SelectedVariable, trendForm.TrendProperties, trendForm.Predicted,
                            trendForm.Forecast(trendForm.ForecastingStep), trendForm.Residual);
                    }
                    else
                    {
                        trendTabPage.SetData(this.data, dlg.SelectedVariable, trendForm.TrendProperties,
                            trendForm.Predicted, null, trendForm.Residual);
                    }

                    trendTabPage.IsTrendAnalysisModelSummaryVisible = trendForm.IsTrendAnalysisModelSummaryChecked;
                    trendTabPage.IsActualPredictedResidualDataGridVisible = trendForm.IsActualPredictedResidualDataGridChecked;
                    trendTabPage.IsForecastedDataGridVisible = trendForm.IsForecastedDataGridChecked;
                    trendTabPage.IsActualAndPredictedGraphVisible = trendForm.IsActualAndPredictedGraphChecked;
                    trendTabPage.IsActualAndForecastedGraphVisible = trendForm.IsActualAndForecastedGraphChecked;
                    trendTabPage.IsActualVsPredictedGraphVisible = trendForm.IsActualVsPredictedGraphChecked;
                    trendTabPage.IsResidualGraphVisible = trendForm.IsResidualGraphChecked;
                    trendTabPage.IsResidualVsActualGraphVisible = trendForm.IsResidualVsActualGraphChecked;
                    trendTabPage.IsResidualVsPredictedGraphVisible = trendForm.IsResidualVsPredictedGraphChecked;

                    trendTabPage.DrawControl();

                    trendTabPage.IsDrawn = true;
                    this.tabControlResult.AddTab(trendTabPage);
                    this.tabControlResult.SelectedItem = trendTabPage;

                    this.tabControlData.SelectedTab = this.tabPageResult;

                }
            }
        }