/// <summary> /// Does the standard deviation on an entire pupulation. /// </summary> /// <param name="listToDoStandardDeviationOn">This is the list of the entire population to have their standaerd deviation Calulated.</param> /// <param name="standardDeviation">This is the calculated standard Deviation.</param> /// <returns>Returns true if the standard Deviation succeaded, else false.</returns> public static bool TryStandardDeviationEntirePopulation(IEnumerable <double> listToDoStandardDeviationOn, out double standardDeviation) { standardDeviation = System.Math.Sqrt(StatisticsFunctionHelper.VarianceForAnEntirePopulation(listToDoStandardDeviationOn)); if (standardDeviation == 0 && listToDoStandardDeviationOn.All(x => x == -1)) { return(false); } return(true); }
private bool TryStandardDeviationEntirePopulation(List <double> listToDoStandardDeviationOn, out double standardDeviation) { standardDeviation = MathObj.Sqrt(StatisticsFunctionHelper.VarianceForAnEntirePopulation(listToDoStandardDeviationOn)); if (standardDeviation == 0 && listToDoStandardDeviationOn.All(x => x == -1)) { return(false); } return(true); }
/// <summary> /// Executes the Excel STDEV function. /// </summary> /// <param name="arguments">The arguments to execute the function with.</param> /// <param name="context">The context to execute the function under.</param> /// <returns>The result of the function evaluation.</returns> public override CompileResult Execute(IEnumerable <FunctionArgument> arguments, ParsingContext context) { if (this.ArgumentsAreValid(arguments, 1, out eErrorType argumentError) == false) { return(new CompileResult(argumentError)); } var values = base.ArgsToDoubleEnumerable(arguments, context, false); return(base.CreateResult(StatisticsFunctionHelper.Stdev(values), DataType.Decimal)); }
/// <summary> /// The standard deviation is a measure of how widely values are dispersed from the average value (the mean). /// Logical values and text representations of numbers that you type directly into the list of arguments are counted. /// If an argument is an array or reference, only numbers in that array or reference are counted.Empty cells, logical values, text, or error values in the array or reference are ignored. /// </summary> /// <param name="arguments">Up to 254 individual arguments.</param> /// <param name="context">Unused, this is information about where the function is being executed.</param> /// <returns>The standard deviation based on the entire population.</returns> public override CompileResult Execute(IEnumerable <FunctionArgument> arguments, ParsingContext context) { if (this.ArgumentsAreValid(arguments, 1, out eErrorType argumentError) == false) { return(new CompileResult(argumentError)); } //Note: This follows the Functionality of excel which is diffrent from the excel documentation. //If you pass in a null Stdev.P(1,1,1,,) it will treat those emtpy spaces as zeros insted of ignoring them. List <double> listToDoStandardDeviationOn = new List <double>(); bool onlyStringInputsGiven = true; foreach (var item in arguments) { if (item.ValueAsRangeInfo != null) { foreach (var cell in item.ValueAsRangeInfo) { if (StatisticsFunctionHelper.TryToParseValuesFromInputArgumentByRefrenceOrRange(this.IgnoreHiddenValues, cell, context, false, out double numberToAddToList, out bool onlyStringInputsGiven1)) { listToDoStandardDeviationOn.Add(numberToAddToList); } onlyStringInputsGiven = onlyStringInputsGiven1; } } else { if (StatisticsFunctionHelper.TryToParseValuesFromInputArgument(this.IgnoreHiddenValues, item, context, out double numberToAddToList, out bool onlyStringInputsGiven2)) { listToDoStandardDeviationOn.Add(numberToAddToList); } onlyStringInputsGiven = onlyStringInputsGiven2; if (item.ValueFirst == null) { listToDoStandardDeviationOn.Add(0.0); } } } if (onlyStringInputsGiven) { return(new CompileResult(eErrorType.Value)); } if (listToDoStandardDeviationOn.Count() == 0) { return(new CompileResult(eErrorType.Div0)); } if (!StatisticsFunctionHelper.TryStandardDeviationEntirePopulation(listToDoStandardDeviationOn, out double standardDeviation)) { return(new CompileResult(eErrorType.Value)); } return(this.CreateResult(standardDeviation, DataType.Decimal)); }
/// <summary> /// Does the standard deviation on an sample pupulation. /// </summary> /// <param name="listToDoStandardDeviationOn">This is the list of the sample population to have their standaerd deviation Calulated.</param> /// <param name="standardDeviation">This is the calculated standard Deviation.</param> /// <returns>Returns true if the standard Deviation succeaded, else false.</returns> public static bool TryStandardDeviationOnASamplePopulation(List <double> listToDoStandardDeviationOn, out double standardDeviation) { standardDeviation = System.Math.Sqrt(StatisticsFunctionHelper.VarianceForASample(listToDoStandardDeviationOn)); if (listToDoStandardDeviationOn.Count() <= 1) { return(false); } if (standardDeviation == 0 && listToDoStandardDeviationOn.All(x => x == -1)) { return(false); } return(true); }
public override CompileResult Execute(IEnumerable <FunctionArgument> arguments, ParsingContext context) { if (this.ArgumentsAreValid(arguments, 1, out eErrorType argumentError) == false) { return(new CompileResult(argumentError)); } List <double> listToDoVarianceOn = new List <double>(); foreach (var item in arguments) { if (item.ValueAsRangeInfo != null) { foreach (var cell in item.ValueAsRangeInfo) { if (StatisticsFunctionHelper.TryToParseValuesFromInputArgumentByRefrenceOrRange(this.IgnoreHiddenValues, cell, context, false, out double numberToAddToList, out bool onlyStringInputsGiven1)) { listToDoVarianceOn.Add(numberToAddToList); } } } else { if (StatisticsFunctionHelper.TryToParseValuesFromInputArgument(this.IgnoreHiddenValues, item, context, out double numberToAddToList, out bool onlyStringInputsGiven2)) { listToDoVarianceOn.Add(numberToAddToList); } if (item.ValueFirst == null) { listToDoVarianceOn.Add(0.0); } } } if (listToDoVarianceOn.Count() == 0) { return(new CompileResult(eErrorType.Div0)); } if (!StatisticsFunctionHelper.TryVarSamplePopulationForAValueErrorCheck(listToDoVarianceOn, out double variance)) { return(new CompileResult(eErrorType.Value)); } return(new CompileResult(variance, DataType.Decimal)); }