The sample standard deviation is a statistical measure used to quantify the amount of variation or dispersion of a set of data values. It is the square root of the sample variance. A low standard deviation indicates that the data points tend to be close to the mean (also called the expected value) of the set, while a high standard deviation indicates that the data points are spread out over a wider range of values. This calculator helps you compute the sample standard deviation for a given list of numbers.
Enter Data Points
Enter your data points, separated by commas (e.g., 10, 12, 15, 11, 13).
Sample Standard Deviation
—
Please enter valid numbers separated by commas.
function calculateStandardDeviation() {
var dataInput = document.getElementById("dataPoints").value;
var errorMessageDiv = document.getElementById("errorMessage");
var resultSectionDiv = document.getElementById("resultSection");
var resultValueSpan = document.getElementById("resultValue");
// Hide previous error messages and results
errorMessageDiv.style.display = 'none';
resultSectionDiv.style.display = 'none';
// Process the input string
var dataStrings = dataInput.split(',');
var data = [];
// Validate and convert inputs to numbers
for (var i = 0; i < dataStrings.length; i++) {
var cleanValue = dataStrings[i].trim();
if (cleanValue === "") continue; // Skip empty strings
var num = parseFloat(cleanValue);
if (isNaN(num)) {
errorMessageDiv.style.display = 'block';
return; // Exit if any value is not a number
}
data.push(num);
}
// Check if there are enough data points
if (data.length < 2) {
errorMessageDiv.textContent = "At least two data points are required for sample standard deviation.";
errorMessageDiv.style.display = 'block';
return;
}
// 1. Calculate the mean (average)
var sum = 0;
for (var i = 0; i < data.length; i++) {
sum += data[i];
}
var mean = sum / data.length;
// 2. Calculate the sum of squared differences from the mean
var sumSquaredDifferences = 0;
for (var i = 0; i < data.length; i++) {
sumSquaredDifferences += Math.pow((data[i] – mean), 2);
}
// 3. Calculate the sample variance
// For sample variance, we divide by (n-1)
var variance = sumSquaredDifferences / (data.length – 1);
// 4. Calculate the sample standard deviation (square root of variance)
var standardDeviation = Math.sqrt(variance);
// Display the result
resultValueSpan.textContent = standardDeviation.toFixed(4); // Display with 4 decimal places
resultSectionDiv.style.display = 'block';
}