pub fn std_dev<T>(data: &[T]) -> StatsResult<f64>where
T: ToPrimitive + Debug,Expand description
Calculate the standard deviation of a dataset.
The standard deviation is a measure of the amount of variation or dispersion of a set of values. It is calculated as the square root of the variance.
§Arguments
data- A slice of numeric values implementingToPrimitive
§Returns
StatsResult<f64>- The standard deviation as af64, or an error if the input is invalid
§Errors
Returns StatsError::EmptyData if the input slice is empty.
Returns StatsError::ConversionError if any value cannot be converted to f64.
§Examples
use rs_stats::prob::std_dev;
// Calculate standard deviation of integers
let int_data = [1, 2, 3, 4, 5];
let sd = std_dev(&int_data)?;
println!("Standard deviation of integers: {}", sd);
// Calculate standard deviation of floats
let float_data = [1.0, 2.5, 3.0, 4.5, 5.0];
let sd = std_dev(&float_data)?;
println!("Standard deviation of floats: {}", sd);
// Handle empty input
let empty_data: &[i32] = &[];
assert!(std_dev(empty_data).is_err());