//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); } }
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); } }
/// <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); } }
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); } }