Ejemplo n.º 1
0
        public void addLags(Variable variable, int numberOfLags, DataSet dataSet)
        {
            //for (int i = 1; i <= numberOfLags; i++)
            //{
            //    for (int j = 1; j <= numberOfLags; j++)
            //    {
            //        worksheet.Cells[i + 1, range.Columns.Count + j] = 0;
            //    }
            //}

            for (int i = 1; i <= numberOfLags; i++)
            {
                Range source = rangeLayout == COLUMNS
                    ? variable.getRange().extendRangeByRows(-i)
                    : variable.getRange().extendRangeByColumns(-i);

                Range destination = rangeLayout == COLUMNS
                    ? variable.getRange()
                                    .extendRangeByRows(-i, false)
                                    .shiftRangeByColumns(variables.Count - variables.IndexOf(variable) + i - 1)
                    : variable.getRange()
                                    .extendRangeByColumns(-i, false)
                                    .shiftRangeByRows(variables.Count - variables.IndexOf(variable) + i - 1);

                source.Copy(destination);
                if (!variableNamesInFirstRowOrColumn)
                {
                    continue;
                }
                source = rangeLayout == COLUMNS
                    ? variable.getRange().first().shiftRangeByRows(-1)
                    : variable.getRange().first().shiftRangeByColumns(-1);

                destination = rangeLayout == COLUMNS
                    ? variable.getRange()
                              .first()
                              .shiftRangeByRows(-1)
                              .shiftRangeByColumns(variables.Count - variables.IndexOf(variable) + i - 1)
                    : variable.getRange()
                              .first()
                              .shiftRangeByColumns(-1)
                              .shiftRangeByRows(variables.Count - variables.IndexOf(variable) + i - 1);

                destination.Value = source.Value + " Lag " + i.ToString();
            }
            Globals.ExcelAddIn.Application.CutCopyMode = XlCutCopyMode.xlCopy;

            DataSet nwRange = DataSetFactory.modify(dataSet, ColumnIndexToColumnLetter(range.Columns.Count + numberOfLags));

            dataSet.setRange(nwRange.getRange());
            dataSet.setVariables(nwRange.getVariables());

            //range = rangeLayout == COLUMNS
            //    ? range.Resize[range.Rows.Count, range.Columns.Count + numberOfLags]
            //    : range.Resize[range.Rows.Count + numberOfLags, range.Columns.Count];
            //recalculateVariables();
        }
Ejemplo n.º 2
0
        public void generateProcessCapability(int LSL, int USL, DataSet dataSet, _Worksheet sheet)
        {
            int    index = 0;
            int    row = 1;
            int    column = 1;
            double correctionFactor1, correctionFactor2;

            double[] averages                = new double[dataSet.amountOfVariables()];
            double[] Rvalues                 = new double[dataSet.amountOfVariables()];
            double[] averageOfAverages       = new double[dataSet.amountOfVariables()];
            double[] xChartUpperControlLimit = new double[dataSet.amountOfVariables()];
            double[] xChartLowerControlLimit = new double[dataSet.amountOfVariables()];
            double[] rChartUpperControlLimit = new double[dataSet.amountOfVariables()];
            double[] rChartLowerControlLimit = new double[dataSet.amountOfVariables()];
            double[] averageOfRvalues        = new double[dataSet.amountOfVariables()];
            int[]    ArrayIndex              = new int[dataSet.amountOfVariables()];
            double[] constantC4              = new double[25] {
                0.0, 0.7979, 0.8862, 0.9213, 0.9400, 0.9515, 0.9594, 0.9650, 0.9693, 0.9727, 0.9754, 0.9776, 0.9794, 0.9810, 0.9823, 0.9835, 0.9845, 0.9854, 0.9862, 0.9869, 0.9876, 0.9882, 0.9887, 0.9892, 0.9896
            };
            double[] constantD2 = new double[25] {
                0.0, 1.128, 1.693, 2.059, 2.326, 2.534, 2.704, 2.847, 2.970, 3.078, 3.173, 3.258, 3.336, 3.407, 3.472, 3.532, 3.588, 3.640, 3.689, 3.735, 3.778, 3.819, 3.858, 3.895, 3.931
            };
            sheet.Cells[row, column]     = "Index";
            sheet.Cells[row, column + 1] = "Observation";
            sheet.Cells[row, column + 2] = "Average";
            sheet.Cells[row, column + 3] = "Max";
            sheet.Cells[row, column + 4] = "Min";
            sheet.Cells[row, column + 5] = "R";

            for (index = 1; index < dataSet.amountOfVariables(); index++)
            {
                row++;
                sheet.Cells[row, column]     = index - 1;
                sheet.Cells[row, column + 1] = dataSet.getVariables()[index].name;
                sheet.Cells[row, column + 2] = "=AVERAGE(" + dataSet.getWorksheet().Name + "!" + dataSet.getVariables()[index].Range + ")";
                sheet.Cells[row, column + 3] = "=MAX(" + dataSet.getWorksheet().Name + "!" + dataSet.getVariables()[index].Range + ")";
                sheet.Cells[row, column + 4] = "=MIN(" + dataSet.getWorksheet().Name + "!" + dataSet.getVariables()[index].Range + ")";
                sheet.Cells[row, column + 5] = (double)(sheet.Cells[row, column + 3] as Range).Value - (double)(sheet.Cells[row, column + 4] as Range).Value;
                ArrayIndex[index - 1]        = index;
                var cellValue = (double)(sheet.Cells[row, column + 2] as Range).Value;
                if (cellValue < -214682680)
                {
                    cellValue = 0;                         // if cellValue is the result of a division by 0, set value to 0
                }
                averages[index - 1] = cellValue;
                cellValue           = (double)(sheet.Cells[row, column + 5] as Range).Value;
                Rvalues[index - 1]  = cellValue;
            }

            // create variable to limit amount of subsamples in 1 measurement to 25
            int safe;

            if (dataSet.rangeSize() > 24)
            {
                safe = 24;
            }
            else
            {
                safe = dataSet.rangeSize();
            }

            if (dataSet.getVariableNamesInFirstRowOrColumn())
            {
                correctionFactor1 = constantC4[safe - 1];
                correctionFactor2 = constantD2[safe - 1];
            }
            else
            {
                correctionFactor1 = constantC4[safe];
            }
            correctionFactor2 = constantD2[safe];

            double sigma = Rvalues.Average() / correctionFactor2;
            double Cp    = (USL - LSL) / (6 * sigma);
            double Cpk   = Math.Min((USL - averages.Average()) / (3 * sigma), (averages.Average() - LSL) / (3 * sigma));

            row    = 1;
            column = 1;
            sheet.Cells[row, column + 7]  = "LSL";
            sheet.Cells[row, column + 8]  = "USL";
            sheet.Cells[row, column + 9]  = "Cp";
            sheet.Cells[row, column + 10] = "Cpk";
            row++;
            sheet.Cells[row, column + 7]  = LSL;
            sheet.Cells[row, column + 8]  = USL;
            sheet.Cells[row, column + 9]  = Cp;
            sheet.Cells[row, column + 10] = Cpk;
        }
Ejemplo n.º 3
0
        private void generatePChart(int startindex, int stopindex, DataSet dataSet, _Worksheet sheet, int plotstartindex, int plotstopindex)
        {
            int index  = 0;
            int row    = 1;
            int column = 1;

            double[] pValues                 = new double[dataSet.amountOfVariables() - 1];
            double[] averageOfPValues        = new double[dataSet.amountOfVariables() - 1];
            double[] pValuesInRange          = new double[stopindex - startindex + 1];
            double[] pChartUpperControlLimit = new double[dataSet.amountOfVariables()];
            double[] pChartLowerControlLimit = new double[dataSet.amountOfVariables()];

            sheet.Cells[row, column]     = "Index";
            sheet.Cells[row, column + 1] = "Observation";
            sheet.Cells[row, column + 2] = "Average";

            for (index = 1; index < dataSet.amountOfVariables(); index++)
            {
                row++;
                sheet.Cells[row, column]     = index - 1;
                sheet.Cells[row, column + 1] = dataSet.getVariables()[index].name;
                sheet.Cells[row, column + 2] = "=AVERAGE(" + dataSet.getWorksheet().Name + "!" + dataSet.getVariables()[index].Range + ")";
                var cellValue = (double)(sheet.Cells[row, column + 2] as Range).Value;
                if (cellValue < -214682680)
                {
                    cellValue = 0;                         // if cellValue is the result of a division by 0, set value to 0
                }
                pValues[index - 1] = cellValue;
                if (cellValue > 1)
                {
                    MessageBox.Show("Cannot generate P-Chart; Data in " + dataSet.Name + " contains samples greater than 1");
                    return;
                }
            }

            for (index = startindex; index <= stopindex; index++)
            {
                pValuesInRange[index - startindex] = pValues[index];
            }

            double pChartCorrection = Math.Pow(((pValuesInRange.Average() * (1 - pValuesInRange.Average())) / dataSet.rangeSize()), (0.3333333));

            for (index = 0; index < dataSet.amountOfVariables() - 1; index++)
            {
                averageOfPValues[index]        = pValuesInRange.Average();
                pChartUpperControlLimit[index] = pValues.Average() + pChartCorrection;
                pChartLowerControlLimit[index] = pValues.Average() - pChartCorrection;
            }

            // new arrays for subsets of existing arrays but within limits

            double[] plotpValues                 = new double[plotstopindex - plotstartindex + 1];
            double[] plotaverageOfPValues        = new double[plotstopindex - plotstartindex + 1];
            double[] plotpChartUpperControlLimit = new double[plotstopindex - plotstartindex + 1];
            double[] plotpChartLowerControlLimit = new double[plotstopindex - plotstartindex + 1];
            int[]    ArrayIndex = new int[plotstopindex - plotstartindex + 1];

            for (int i = plotstartindex; i <= plotstopindex; i++)
            {
                plotpValues[i - plotstartindex]                 = pValues[i];
                plotaverageOfPValues[i - plotstartindex]        = averageOfPValues[i];
                plotpChartLowerControlLimit[i - plotstartindex] = pChartLowerControlLimit[i];
                plotpChartUpperControlLimit[i - plotstartindex] = pChartUpperControlLimit[i];
                ArrayIndex[i - plotstartindex] = i;
            }

            var Xcharts      = (ChartObjects)sheet.ChartObjects();
            var XchartObject = Xcharts.Add(340, 20, 550, 300);
            var Xchart       = XchartObject.Chart;

            Xchart.ChartType = XlChartType.xlXYScatterLines;
            Xchart.ChartWizard(Title: "P-Chart " + dataSet.Name, HasLegend: true);
            var XseriesCollection = (SeriesCollection)Xchart.SeriesCollection();
            var pseries           = XseriesCollection.NewSeries();
            var CLseries          = XseriesCollection.NewSeries();
            var UCLseries         = XseriesCollection.NewSeries();
            var LCLseries         = XseriesCollection.NewSeries();

            pseries.Name      = ("Proportion");
            CLseries.Name     = ("Center line");
            UCLseries.Name    = ("UCL");
            LCLseries.Name    = ("LCL");
            pseries.Values    = plotpValues;
            CLseries.Values   = plotaverageOfPValues;
            UCLseries.Values  = plotpChartUpperControlLimit;
            LCLseries.Values  = plotpChartLowerControlLimit;
            pseries.XValues   = ArrayIndex;
            CLseries.XValues  = ArrayIndex;
            UCLseries.XValues = ArrayIndex;
            LCLseries.XValues = ArrayIndex;
        }
Ejemplo n.º 4
0
        public void Interaction(Variable variable, Variable variable2, DataSet dataSet) //cat = gender var = salary
        {
            String colLetter      = dataSet.getVariables()[dataSet.getVariables().Count - 1].Range[1].ToString();
            int    columnIndex    = ColumnLetterToColumnIndex(colLetter) + 1;
            string ran2           = variable.Range.ToString();
            String colLetterCat   = variable.Range[1].ToString();
            int    columnIndexCat = ColumnLetterToColumnIndex(colLetterCat) - 1;
            Array  distCat        = dataSet.getWorksheet().Range[ran2].Value;
            Array  cat            = dataSet.getWorksheet().Range[ran2].Value;

            string ran            = variable2.Range.ToString();
            String colLetterVar   = variable2.Range[1].ToString();
            int    columnIndexVar = ColumnLetterToColumnIndex(colLetterVar) - 1;
            Array  dist           = dataSet.getWorksheet().Range[ran].Value;
            int    count          = 0;

            foreach (var item in distCat)
            {
                if (item == null)
                {
                    count = 2;
                }
                else if (item.GetType().ToString() == "System.String")
                {
                    count = 1;
                    break;
                }
                else
                {
                    count = 2;
                    break;
                }
            }
            foreach (var item in dist)
            {
                if (item == null)
                {
                    count = 2;
                }
                else if (item.GetType().ToString() == "System.String")
                {
                    count = 1;
                    break;
                }
                else
                {
                    count = 2;
                    break;
                }
            }
            if (count == 1)
            {
                MessageBox.Show("Interaction can only be calculated for numbers.");
                return;
            }
            double[] var1 = distCat.OfType <double>().ToArray();
            double[] var2 = dist.OfType <double>().ToArray();

            System.Diagnostics.Debug.WriteLine(var1.Length);
            System.Diagnostics.Debug.WriteLine(var2.Length);

            int row    = 1;
            int column = columnIndex;

            worksheet.Cells[row, column] = dataSet.getVariables()[columnIndexCat].name + " - " + dataSet.getVariables()[columnIndexVar].name;
            row = 0;

            int len = var1.Length;

            if (var2.Length < var1.Length)
            {
                len = var2.Length;
            }

            while (row < len)
            {
                if (var1.Length < var2.Length)
                {
                    column = columnIndex;
                    int temp = var2.Length - var1.Length;
                    worksheet.Cells[row + 2 + temp, column] = var1[row] * var2[row + temp];
                    row = row + 1;
                }
                else
                {
                    column = columnIndex;
                    int temp = var1.Length - var2.Length;
                    worksheet.Cells[row + 2 + temp, column] = var1[row + temp] * var2[row];
                    row = row + 1;
                }
            }
            DataSet nwRange = DataSetFactory.modify(dataSet, ColumnIndexToColumnLetter(column));

            dataSet.setRange(nwRange.getRange());
            dataSet.setVariables(nwRange.getVariables());
        }
Ejemplo n.º 5
0
        public void addUnstacked(Variable category, Variable variable, DataSet dataSet)         //cat = gender var = salary
        {
            string ran2           = category.Range.ToString();
            String colLetterCat   = category.Range[1].ToString();
            int    columnIndexCat = ColumnLetterToColumnIndex(colLetterCat) - 1;
            Array  distCat        = dataSet.getWorksheet().Range[ran2].Value;
            Array  cat            = dataSet.getWorksheet().Range[ran2].Value;

            string ran            = variable.Range.ToString();
            String colLetterVar   = variable.Range[1].ToString();
            int    columnIndexVar = ColumnLetterToColumnIndex(colLetterVar) - 1;
            Array  dist           = dataSet.getWorksheet().Range[ran].Value;
            int    count          = 0;

            Worksheet newworksheet;

            try
            {
                newworksheet      = dataSet.getWorksheet().Application.Worksheets.Add();
                newworksheet.Name = "Unstack" + dataSet.getVariables()[columnIndexVar].name + "-" + dataSet.getVariables()[columnIndexCat].name;
            }
            catch (SystemException e)
            {
                MessageBox.Show("Unstacked data already exists, change name of existing worksheet and try again.");
                return;
            }


            foreach (var item in distCat)
            {
                if (item == null)
                {
                    count = 2;
                }
                else if (item.GetType().ToString() == "System.String")
                {
                    count = 1;
                }
                else
                {
                    count = 2;
                }
                break;
            }
            if (count == 1)
            {
                List <String> valuesCat = distCat.OfType <String>().ToList();
                List <Double> valuesVar = dist.OfType <Double>().ToList();
                distCat = valuesCat.Distinct <String>().ToArray();
                int row    = 1;
                int column = 1;
                foreach (var item in distCat)
                {
                    newworksheet.Cells[row, column] = dataSet.getVariables()[columnIndexVar].name + "(" + item.ToString() + ")";
                    column = column + 1;
                }
                column = 1;
                foreach (var item in distCat)
                {
                    row = 0;
                    int counter = row;
                    while (row < valuesVar.Count)
                    {
                        String temp = valuesCat[row];
                        if (temp.Equals(item.ToString()))
                        {
                            newworksheet.Cells[counter + 2, column] = valuesVar[row];
                            counter = counter + 1;
                        }
                        row = row + 1;
                    }
                    column = column + 1;
                }
            }
            else
            {
                List <Double> valueSortCat = distCat.OfType <Double>().ToList(); // één lijst gaat gesorteerd worden en de andere niet
                List <Double> valueCat     = distCat.OfType <Double>().ToList();
                List <Double> valuesVar    = dist.OfType <Double>().ToList();
                valueSortCat.Sort();
                distCat = valueSortCat.Distinct <Double>().ToArray();
                int row    = 1;
                int column = 1;
                foreach (var item in distCat)
                {
                    newworksheet.Cells[row, column] = dataSet.getVariables()[columnIndexVar].name + "(" + item.ToString() + ")";
                    column = column + 1;
                }
                column = 1;
                foreach (var item in distCat)
                {
                    row = 0;
                    int counter = row;
                    while (row < valuesVar.Count)
                    {
                        double temp = valueCat[row];
                        if (temp == Convert.ToDouble(item.ToString()))
                        {
                            newworksheet.Cells[counter + 2, column] = valuesVar[row];
                            counter = counter + 1;
                        }
                        row = row + 1;
                    }
                    column = column + 1;
                }
            }
        }
Ejemplo n.º 6
0
        public void addDummy(Variable variable, DataSet dataSet)
        {
            string ran          = variable.Range.ToString();
            String colLetter2   = variable.Range[1].ToString();
            int    columnIndex2 = ColumnLetterToColumnIndex(colLetter2) - 1;
            String colLetter    = dataSet.getVariables()[dataSet.getVariables().Count - 1].Range[1].ToString();
            int    columnIndex  = ColumnLetterToColumnIndex(colLetter) + 1;
            Array  dist         = dataSet.getWorksheet().Range[ran].Value;
            int    count        = 0;

            foreach (var item in dist)
            {
                if (item.GetType().ToString() == "System.String")
                {
                    count = 1;
                }
                else
                {
                    count = 2;
                }
                break;
            }
            if (count == 1)
            {
                List <String> values = dist.OfType <String>().ToList();
                dist = values.Distinct <String>().ToArray();
                int row    = 1;
                int column = columnIndex;
                foreach (var item in dist)
                {
                    worksheet.Cells[row, column] = dataSet.getVariables()[columnIndex2].name + "=" + item.ToString();
                    column = column + 1;
                }
                row = 0;
                while (row < values.Count)
                {
                    String temp = values[row];
                    column = columnIndex;
                    foreach (var item in dist)
                    {
                        if (temp.Equals(item.ToString()))
                        {
                            worksheet.Cells[row + 2, column] = "1";
                        }
                        else
                        {
                            worksheet.Cells[row + 2, column] = "0";
                        }
                        column = column + 1;
                    }
                    row = row + 1;
                }
                DataSet nwRange = DataSetFactory.modify(dataSet, ColumnIndexToColumnLetter(column - 1));
                dataSet.setRange(nwRange.getRange());
                dataSet.setVariables(nwRange.getVariables());
            }
            else
            {
                List <Double> values = dist.OfType <Double>().ToList();
                List <Double> value  = dist.OfType <Double>().ToList();
                values.Sort();
                dist = values.Distinct <Double>().ToArray();
                int row    = 1;
                int column = columnIndex;
                foreach (var item in dist)
                {
                    worksheet.Cells[row, column] = dataSet.getVariables()[columnIndex2].name + "=" + item.ToString();
                    column = column + 1;
                }
                row = 0;
                while (row < values.Count)
                {
                    double temp = value[row];
                    column = columnIndex;
                    foreach (var item in dist)
                    {
                        if (temp == Convert.ToInt16(item))
                        {
                            worksheet.Cells[row + 2, column] = "1";
                        }
                        else
                        {
                            worksheet.Cells[row + 2, column] = "0";
                        }
                        column = column + 1;
                    }
                    row = row + 1;
                }
                DataSet nwRange = DataSetFactory.modify(dataSet, ColumnIndexToColumnLetter(column - 1));
                dataSet.setRange(nwRange.getRange());
                dataSet.setVariables(nwRange.getVariables());
            }
        }
Ejemplo n.º 7
0
        public void generateXRChart(int startindex, int stopindex, int plotstartindex, int plotstopindex, DataSet dataSet, int offset, _Worksheet sheet)
        {
            // declaration of variables
            int    index = 0;
            int    row = 1;
            int    column = 1;
            double xControlLimitFactor, rControlLimitFactor1, rControlLimitFactor2;

            double[] averages                 = new double[dataSet.amountOfVariables()];
            double[] Rvalues                  = new double[dataSet.amountOfVariables()];
            double[] averageOfAverages        = new double[dataSet.amountOfVariables()];
            double[] xChartUpperControlLimit  = new double[dataSet.amountOfVariables()];
            double[] xChartLowerControlLimit  = new double[dataSet.amountOfVariables()];
            double[] rChartUpperControlLimit  = new double[dataSet.amountOfVariables()];
            double[] rChartLowerControlLimit  = new double[dataSet.amountOfVariables()];
            double[] averageOfRvalues         = new double[dataSet.amountOfVariables()];
            double[] RvaluesInRange           = new double[stopindex - startindex + 1];
            double[] averageOfAveragesInRange = new double[stopindex - startindex + 1];
            int[]    ArrayIndex               = new int[plotstopindex - plotstartindex + 1];
            double[] xChartConstants          = new double[25] {
                0.0, 1.880, 1.023, 0.729, 0.577, 0.483, 0.419, 0.373, 0.337, 0.308, 0.285, 0.266, 0.249, 0.235, 0.223, 0.212, 0.203, 0.194, 0.187, 0.180, 0.173, 0.167, 0.162, 0.157, 0.153
            };
            double[] rChartConstants1 = new double[25] {
                0, 0, 0, 0, 0, 0, 0.076, 0.136, 0.184, 0.223, 0.256, 0.283, 0.307, 0.328, 0.347, 0.363, 0.378, 0.391, 0.403, 0.415, 0.425, 0.434, 0.443, 0.451, 0.459
            };
            double[] rChartConstants2 = new double[25] {
                0, 3.267, 2.574, 2.282, 2.114, 2.004, 1.924, 1.864, 1.816, 1.777, 1.744, 1.717, 1.693, 1.672, 1.653, 1.637, 1.662, 1.607, 1.597, 1.585, 1.575, 1.566, 1.557, 1.548, 1.541
            };
            // write  labels to sheet
            sheet.Cells[row, column]     = "Index";
            sheet.Cells[row, column + 1] = "Observation";
            sheet.Cells[row, column + 2] = "Average";
            sheet.Cells[row, column + 3] = "Max";
            sheet.Cells[row, column + 4] = "Min";
            sheet.Cells[row, column + 5] = "R";

            // write values to sheet
            for (index = 1; index < dataSet.amountOfVariables(); index++)
            {
                row++;
                sheet.Cells[row, column]     = index - 1;
                sheet.Cells[row, column + 1] = dataSet.getVariables()[index].name;
                sheet.Cells[row, column + 2] = "=AVERAGE(" + dataSet.getWorksheet().Name + "!" + dataSet.getVariables()[index].Range + ")";
                sheet.Cells[row, column + 3] = "=MAX(" + dataSet.getWorksheet().Name + "!" + dataSet.getVariables()[index].Range + ")";
                sheet.Cells[row, column + 4] = "=MIN(" + dataSet.getWorksheet().Name + "!" + dataSet.getVariables()[index].Range + ")";
                sheet.Cells[row, column + 5] = (double)(sheet.Cells[row, column + 3] as Range).Value - (double)(sheet.Cells[row, column + 4] as Range).Value;
                var cellValue = (double)sheet.Cells[row, column + 2].Value;
                if (cellValue < -214682680)
                {
                    cellValue = 0;                         // if cellValue is the result of a division by 0, set value to 0
                }
                averages[index - 1] = cellValue;
                cellValue           = (double)(sheet.Cells[row, column + 5] as Range).Value;
                Rvalues[index - 1]  = cellValue;
            }
            // make arrays for calculation within limits
            for (index = startindex; index <= stopindex; index++)
            {
                RvaluesInRange[index - startindex]           = Rvalues[index];
                averageOfAveragesInRange[index - startindex] = averages[index];
            }

            // create variable to limit amount of subsamples in 1 measurement to 25
            int safe;

            if (dataSet.rangeSize() > 24)
            {
                safe = 24;
            }
            else
            {
                safe = dataSet.rangeSize();
            }
            if (dataSet.getVariableNamesInFirstRowOrColumn())
            {
                xControlLimitFactor  = xChartConstants[safe - 1];
                rControlLimitFactor1 = rChartConstants1[safe - 1];
                rControlLimitFactor2 = rChartConstants2[safe - 1];
            }
            else
            {
                xControlLimitFactor = xChartConstants[safe];
            }
            rControlLimitFactor1 = rChartConstants1[safe];
            rControlLimitFactor2 = rChartConstants2[safe];

            for (index = 0; index < dataSet.amountOfVariables(); index++)
            {
                averageOfAverages[index]       = averageOfAveragesInRange.Average();
                xChartUpperControlLimit[index] = averageOfAveragesInRange.Average() + (xControlLimitFactor * Rvalues.Average());
                xChartLowerControlLimit[index] = averageOfAveragesInRange.Average() - (xControlLimitFactor * Rvalues.Average());
                averageOfRvalues[index]        = RvaluesInRange.Average();
                rChartUpperControlLimit[index] = RvaluesInRange.Average() * rControlLimitFactor2;
                rChartLowerControlLimit[index] = RvaluesInRange.Average() * rControlLimitFactor1;
            }

            // new subsets of arrays for plotting data

            double[] plotaverages                = new double[plotstopindex - plotstartindex + 1];
            double[] plotRvalues                 = new double[plotstopindex - plotstartindex + 1];
            double[] plotaverageOfAverages       = new double[plotstopindex - plotstartindex + 1];
            double[] plotxChartUpperControlLimit = new double[plotstopindex - plotstartindex + 1];
            double[] plotxChartLowerControlLimit = new double[plotstopindex - plotstartindex + 1];
            double[] plotrChartUpperControlLimit = new double[plotstopindex - plotstartindex + 1];
            double[] plotrChartLowerControlLimit = new double[plotstopindex - plotstartindex + 1];
            double[] plotaverageOfRvalues        = new double[plotstopindex - plotstartindex + 1];

            for (int i = plotstartindex; i <= plotstopindex; i++)
            {
                ArrayIndex[i - plotstartindex]                  = i;
                plotaverages[i - plotstartindex]                = averages[i];
                plotRvalues[i - plotstartindex]                 = Rvalues[i];
                plotaverageOfAverages[i - plotstartindex]       = averageOfAverages[i];
                plotxChartUpperControlLimit[i - plotstartindex] = xChartUpperControlLimit[i];
                plotxChartLowerControlLimit[i - plotstartindex] = xChartLowerControlLimit[i];
                plotrChartUpperControlLimit[i - plotstartindex] = rChartUpperControlLimit[i];
                plotrChartLowerControlLimit[i - plotstartindex] = rChartLowerControlLimit[i];
                plotaverageOfRvalues[i - plotstartindex]        = averageOfRvalues[i];
            }

            var Xcharts      = (ChartObjects)sheet.ChartObjects();
            var XchartObject = Xcharts.Add(340, 20, 550, 300);
            var Xchart       = XchartObject.Chart;

            Xchart.ChartType = XlChartType.xlXYScatterLines;
            Xchart.ChartWizard(Title: "X-Chart " + dataSet.Name, HasLegend: true);
            var XseriesCollection = (SeriesCollection)Xchart.SeriesCollection();
            var avgseries         = XseriesCollection.NewSeries();
            var avgAvgseries      = XseriesCollection.NewSeries();
            var UCLseries         = XseriesCollection.NewSeries();
            var LCLseries         = XseriesCollection.NewSeries();

            avgseries.Name       = ("Observation Averages");
            avgAvgseries.Name    = ("Center Line");
            UCLseries.Name       = ("UCL");
            LCLseries.Name       = ("LCL");
            avgseries.Values     = plotaverages;
            avgAvgseries.Values  = plotaverageOfAverages;
            UCLseries.Values     = plotxChartUpperControlLimit;
            LCLseries.Values     = plotxChartLowerControlLimit;
            avgseries.XValues    = ArrayIndex;
            UCLseries.XValues    = ArrayIndex;
            LCLseries.XValues    = ArrayIndex;
            avgAvgseries.XValues = ArrayIndex;

            var Rcharts      = (ChartObjects)sheet.ChartObjects();
            var RchartObject = Rcharts.Add(340, 20 + offset, 550, 300);
            var Rchart       = RchartObject.Chart;

            Rchart.ChartType = XlChartType.xlXYScatterLines;
            Rchart.ChartWizard(Title: "R-Chart " + dataSet.Name, HasLegend: true);
            var RseriesCollection = (SeriesCollection)Rchart.SeriesCollection();
            var rSeries           = RseriesCollection.NewSeries();
            var averageRSeries    = RseriesCollection.NewSeries();
            var UCLSeries         = RseriesCollection.NewSeries();
            var LCLSeries         = RseriesCollection.NewSeries();

            rSeries.Name           = ("Observation R");
            averageRSeries.Name    = ("Center Line");
            UCLSeries.Name         = ("UCL");
            LCLSeries.Name         = ("LCL");
            rSeries.Values         = plotRvalues;
            averageRSeries.Values  = plotaverageOfRvalues;
            UCLSeries.Values       = plotrChartUpperControlLimit;
            LCLSeries.Values       = plotrChartLowerControlLimit;
            rSeries.XValues        = ArrayIndex;
            averageRSeries.XValues = ArrayIndex;
            UCLSeries.XValues      = ArrayIndex;
            LCLSeries.XValues      = ArrayIndex;
        }