Beispiel #1
0
        //This region contains the handlers for all of the statistical functions presented to the user

        /// <summary>
        /// Performs a single-variable reductive statistical function on a user-selected variable from the data set.<para/>
        /// This operation takes one variable from each row and turns it into one number.
        /// </summary>
        /// <param name="name">The name of the statistical function as presented to the user.</param>
        /// <param name="reductionFunction">
        /// The reduction function to use.<para/>
        /// This turns a list of numbers into one number through some transformation.
        /// </param>
        private void StatFunction(string name, Func <IEnumerable <double>, double> reductionFunction)
        {
            char[] variables = SelectVariableDialog.SelectVariables(name, DataSet.Variables, name + " of:");
            if (variables != null && SaveChanges())
            {
                var    data  = DataSet.RowSelect(variables[0]);
                double value = reductionFunction(data);
                MessageBox.Show(name + ": " + value.ToString("0.#####"), "Statistics", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Prompts the user to select a number of variables from a predefined selection of choices.
        /// </summary>
        /// <param name="title">The title of the selection dialog.</param>
        /// <param name="possibleValues">An array of possible character values that each choice can take.</param>
        /// <param name="labels">
        /// The labels for each different required variable choice.<para/>
        /// The size of this parameter array determines the size of the array returned by the method.
        /// </param>
        /// <returns>Returns an array of user-selected variables from the <c>possibleValues</c> parameter.<para/>
        /// If the user cancels the dialog interaction then this method returns null.</returns>
        public static char[] SelectVariables(string title, char[] possibleValues, params string[] labels)
        {
            SelectVariableDialog dialog = new SelectVariableDialog(title, possibleValues, labels);

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                return(dialog.Value);
            }
            else
            {
                return(null);
            }
        }
Beispiel #3
0
 private void pMCCToolStripMenuItem_Click(object sender, EventArgs e)
 {
     char[] variables = SelectVariableDialog.SelectVariables("Product-moment correlation coefficient", DataSet.Variables, "PMCC of:", "with:");
     if (variables != null && variables[0] != variables[1])
     {
         if (variables != null && SaveChanges())
         {
             double value = DataSet.Pmcc(variables[0], variables[1]);
             MessageBox.Show("Product-moment correlation coefficient: " + value.ToString("0.#####"), "Statistics", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
     else
     {
         MessageBox.Show("The chosen variables must not be the same.", "Statistics", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Beispiel #4
0
 /// <summary>
 /// Performs a double-variable reductive statistical function on a user-selected variable from the data set.<para/>
 /// This operation takes two variables from each row and turns it into one number.
 /// </summary>
 /// <param name="name">The name of the statistical function as presented to the user.</param>
 /// <param name="reductionFunction">
 /// The reduction function to use.<para/>
 /// This turns a list of pairs of numbers into one number through some transformation.
 /// </param>
 /// <param name="uniqueVariables">True if chosen variables must be unique; false otherwise.</param>
 private void StatFunction(string name, Func <IEnumerable <Tuple <double, double> >, double> reductionFunction, bool uniqueVariables = false)
 {
     char[] variables = SelectVariableDialog.SelectVariables(name, DataSet.Variables, name + " of:", "and:");
     if (variables != null && variables[0] != variables[1])
     {
         if (variables != null && SaveChanges())
         {
             var    data  = DataSet.RowSelect(variables[0], variables[1]);
             double value = reductionFunction(data);
             MessageBox.Show(name + ": " + value.ToString("0.#####"), "Statistics", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
     else
     {
         MessageBox.Show("The chosen variables must not be the same.", "Statistics", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Beispiel #5
0
 private void createRegressionLineToolStripMenuItem_Click(object sender, EventArgs e)
 {
     char[] variables = SelectVariableDialog.SelectVariables("Regression line", DataSet.Variables, "Independent variable:", "Dependent variable:");
     if (variables != null && variables[0] != variables[1])
     {
         if (variables != null && SaveChanges())
         {
             LinearCurve line = DataSet.FitLinear(variables[0], variables[1]);
             Document.Add(line.ToEquation());
             MessageBox.Show(
                 "The regression line has been added to the Document.\r\n" + line.ToString(),
                 "Statistics", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
     else
     {
         MessageBox.Show("The chosen variables must not be the same.", "Statistics", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }