public bool CheckH0HypothesisByHistogramData(IExcelSheet sheet)
        {
            IExcelCellValueHolder chi2Observable = sheet.EvaluateCell(ExcelColumnIndex.J, 14);
            IExcelCellValueHolder chi2Critical   = sheet.EvaluateCell(ExcelColumnIndex.J, 16);

            double chi2ObservableValue = chi2Observable.NumericValue;
            double chi2CriticalValue   = chi2Critical.NumericValue;

            _logger.Info($"Chi2 observable: '{chi2ObservableValue.ToString()}'.");
            _logger.Info($"Chi2 critical: '{chi2CriticalValue.ToString()}'.");

            // TODO: remove this dirty hack.
            const int dirtyhack = 100;

            return((chi2ObservableValue / dirtyhack) < chi2CriticalValue);
        }
        private IModelledFunction GetOptimalFunction(IExcelSheet sheet,
                                                     ExcelColumnIndex yColumnIndex)
        {
            var xValues = new List <double>(_iterationsNumber);
            var yValues = new List <double>(_iterationsNumber);

            for (int rowIndex = 1.SkipHeader(); rowIndex <= _lastSegmentValueRowIndex; ++rowIndex)
            {
                IExcelCellHolder sampleSizeCell = sheet[_sampleSizeColumnIndex, rowIndex];
                xValues.Add(sampleSizeCell.NumericValue);

                IExcelCellValueHolder yValueCell = sheet.EvaluateCell(yColumnIndex, rowIndex);
                yValues.Add(yValueCell.NumericValue);
            }

            return(_regression.Fit(xValues, yValues));
        }
        public int GetCalculatedSampleSize(IExcelSheet sheet)
        {
            IExcelCellValueHolder calculatedSampleSize = sheet.EvaluateCell(ExcelColumnIndex.K, 7);

            return(Convert.ToInt32(calculatedSampleSize.NumericValue));
        }
        public void CreateHistogramData(IExcelSheet sheet)
        {
            sheet[ExcelColumnIndex.D, 1].SetValue(ExcelStringsPhaseOnePartTwo.PocketColumnName);
            sheet[ExcelColumnIndex.E, 1].SetValue(ExcelStringsPhaseOnePartTwo.EmpiricalFrequencyColumnName);
            sheet[ExcelColumnIndex.F, 1].SetValue(ExcelStringsPhaseOnePartTwo.RelativeFrequencyColumnName);
            sheet[ExcelColumnIndex.G, 1].SetValue(ExcelStringsPhaseOnePartTwo.TheoreticalFrequencyColumnName);
            sheet[ExcelColumnIndex.H, 1].SetValue(ExcelStringsPhaseOnePartTwo.Chi2ValueColumnName);

            sheet[ExcelColumnIndex.I, 10].SetValue(ExcelStringsPhaseOnePartTwo.MinimumValue);
            sheet[ExcelColumnIndex.I, 11].SetValue(ExcelStringsPhaseOnePartTwo.MaximumValue);
            sheet[ExcelColumnIndex.I, 12].SetValue(ExcelStringsPhaseOnePartTwo.IntervalLength);
            sheet[ExcelColumnIndex.I, 13].SetValue(ExcelStringsPhaseOnePartTwo.HistogramSemisegmentsNumber);
            sheet[ExcelColumnIndex.I, 14].SetValue(ExcelStringsPhaseOnePartTwo.Chi2Observable);
            sheet[ExcelColumnIndex.I, 15].SetValue(ExcelStringsPhaseOnePartTwo.FreedomDegreesNumber);
            sheet[ExcelColumnIndex.I, 16].SetValue(ExcelStringsPhaseOnePartTwo.Chi2Critical);
            sheet[ExcelColumnIndex.I, 17].SetValue(ExcelStringsPhaseOnePartTwo.CheckTestFucntion);

            string lastValueRowIndex    = _args.LaunchesNumber.SkipHeader().ToString();
            string normalizedValueRange = $"$B$2:$B${lastValueRowIndex}";

            sheet[ExcelColumnIndex.J, 10].SetFormula(sheet.FormulaProvider.Min(normalizedValueRange));
            sheet[ExcelColumnIndex.J, 11].SetFormula(sheet.FormulaProvider.Max(normalizedValueRange));

            string scottFormula = ManualFormulaProvider.ScottFormula(
                sheet.FormulaProvider, normalizedValueRange, "$J$6"
                );

            sheet[ExcelColumnIndex.J, 12].SetFormula(scottFormula);
            sheet[ExcelColumnIndex.J, 13].SetFormula(
                sheet.FormulaProvider.RoundUp("($J$11 - $J$10) / $J$12", "0")
                );

            IExcelCellValueHolder histogramSegmentsNumber = sheet.EvaluateCell(ExcelColumnIndex.J, 13);
            int    histogramSegmentsNumberInt             = Convert.ToInt32(histogramSegmentsNumber.NumericValue);
            string histogramSegmentsNumberIndex           =
                histogramSegmentsNumberInt.UseOneBasedIndexing().SkipHeader().ToString();

            CreateIntervalData(sheet, histogramSegmentsNumberInt, normalizedValueRange);

            string chi2Formula = ManualFormulaProvider.Chi2(
                sheet.FormulaProvider, $"$H$2:$H${histogramSegmentsNumberIndex}", "$J$6"
                );

            sheet[ExcelColumnIndex.J, 14].SetFormula(chi2Formula);
            sheet[ExcelColumnIndex.J, 15].SetFormula("$J$13 - 1 - 2");
            sheet[ExcelColumnIndex.J, 16].SetFormula(sheet.FormulaProvider.ChiInv("$J$8", "$J$15"));

            string testFormula = sheet.FormulaProvider.ChiTest(
                $"$F$2:$F${histogramSegmentsNumberIndex}",
                $"$G$2:$G${histogramSegmentsNumberIndex}"
                );

            sheet[ExcelColumnIndex.J, 17].SetFormula(testFormula);

            sheet.AutoSizeColumn(ExcelColumnIndex.D);
            sheet.AutoSizeColumn(ExcelColumnIndex.E);
            sheet.AutoSizeColumn(ExcelColumnIndex.F);
            sheet.AutoSizeColumn(ExcelColumnIndex.G);
            sheet.AutoSizeColumn(ExcelColumnIndex.H);
            sheet.AutoSizeColumn(ExcelColumnIndex.I);
            sheet.AutoSizeColumn(ExcelColumnIndex.J);
        }