Standard deviation is a statistical measure that quantifies the amount of variation or dispersion of a set of data values. A low standard deviation indicates that the data points tend to be close to the mean (average) of the set, while a high standard deviation indicates that the data points are spread out over a wider range of values.
It is a crucial metric in finance, science, engineering, and many other fields to understand the consistency and variability of data. For instance, in finance, it's used to measure the risk of an investment – higher standard deviation implies higher risk.
How to Calculate Standard Deviation (Sample Standard Deviation)
The formula for sample standard deviation (denoted by 's') is used when you have a sample of data from a larger population.
The steps are:
Calculate the Mean (Average): Sum all the data values and divide by the number of data values (n).
Mean (x̄) = Σx / n
Calculate Deviations from the Mean: For each data value (x), subtract the mean (x̄).
Deviation = x - x̄
Square the Deviations: Square each of the deviations calculated in the previous step.
Squared Deviation = (x - x̄)²
Sum the Squared Deviations: Add up all the squared deviations.
Sum of Squared Deviations = Σ(x - x̄)²
Calculate the Variance: Divide the sum of squared deviations by (n – 1) for a sample.
Sample Variance (s²) = Σ(x - x̄)² / (n - 1)
Calculate the Standard Deviation: Take the square root of the variance.
Sample Standard Deviation (s) = √[ Σ(x - x̄)² / (n - 1) ]
Example Calculation
Let's calculate the standard deviation for the following sample data set: 5, 8, 12, 15, 20
Mean: (5 + 8 + 12 + 15 + 20) / 5 = 60 / 5 = 12
Deviations:
5 – 12 = -7
8 – 12 = -4
12 – 12 = 0
15 – 12 = 3
20 – 12 = 8
Squared Deviations:
(-7)² = 49
(-4)² = 16
(0)² = 0
(3)² = 9
(8)² = 64
Sum of Squared Deviations: 49 + 16 + 0 + 9 + 64 = 138
Sample Variance: 138 / (5 – 1) = 138 / 4 = 34.5
Sample Standard Deviation: √34.5 ≈ 5.87
So, the sample standard deviation for this data set is approximately 5.87.
function calculateStandardDeviation() {
var dataInput = document.getElementById("dataValues").value;
var values = dataInput.split(',').map(function(item) {
return parseFloat(item.trim());
}).filter(function(item) {
return !isNaN(item);
});
if (values.length < 2) {
alert("Please enter at least two valid data points.");
return;
}
var n = values.length;
var sum = 0;
for (var i = 0; i < n; i++) {
sum += values[i];
}
var mean = sum / n;
var sumOfSquaredDifferences = 0;
for (var i = 0; i < n; i++) {
sumOfSquaredDifferences += Math.pow(values[i] – mean, 2);
}
var variance = sumOfSquaredDifferences / (n – 1);
var standardDeviation = Math.sqrt(variance);
document.getElementById("result-value").innerHTML = standardDeviation.toFixed(4);
document.getElementById("result").style.display = "block";
}