Calculate Z-scores, T-scores, or Chi-Squared statistics for your data.
Inputs
Z-Test (Mean, Known σ)
T-Test (Mean, Unknown σ)
Chi-Squared (Goodness-of-Fit)
Result
Enter values and select test type to begin.
Understanding Standardized Test Statistics
Standardized test statistics are crucial in inferential statistics, allowing us to quantify how a sample result deviates from a population hypothesis. They help us determine if observed differences are statistically significant or likely due to random chance. Common test statistics include Z-scores, T-scores, and Chi-Squared statistics.
Z-Test for a Mean (Known Population Standard Deviation)
The Z-test is used when you want to compare a sample mean to a known population mean, and importantly, the population standard deviation (σ) is known. The formula is:
Z = (X̄ - μ) / (σ / √n)
X̄ (Sample Mean): The average of your sample data.
μ (Population Mean): The hypothesized mean of the population.
σ (Population Standard Deviation): The standard deviation of the population (assumed known).
n (Sample Size): The number of observations in your sample.
A larger absolute Z-score indicates a greater difference between the sample mean and the population mean.
T-Test for a Mean (Unknown Population Standard Deviation)
When the population standard deviation (σ) is unknown and must be estimated from the sample data using the sample standard deviation (s), the T-test is more appropriate. The formula is:
t = (X̄ - μ) / (s / √n)
X̄ (Sample Mean): The average of your sample data.
μ (Population Mean): The hypothesized mean of the population.
s (Sample Standard Deviation): The standard deviation calculated from your sample data.
n (Sample Size): The number of observations in your sample.
The T-distribution, unlike the Z-distribution, depends on the degrees of freedom (df), typically calculated as df = n - 1. T-scores are interpreted similarly to Z-scores but account for the added uncertainty from estimating the population standard deviation.
Chi-Squared Test (Goodness-of-Fit)
The Chi-Squared (χ²) test is used to determine if there's a significant difference between observed frequencies and expected frequencies in one or more categories. For a goodness-of-fit test, it assesses how well a sample distribution fits a hypothesized distribution. The formula is:
χ² = Σ [ (Oᵢ - Eᵢ)² / Eᵢ ]
Oᵢ (Observed Frequency): The actual count in each category from your sample.
Eᵢ (Expected Frequency): The theoretical count for each category based on the null hypothesis.
Σ: Indicates the sum across all categories.
This calculator simplifies the Chi-Squared input by requiring the final calculated statistic directly, as observed and expected frequencies are complex to input generically. The result represents the calculated Chi-Squared value.
Use Cases
Research: Comparing experimental group results to a control group or a known baseline.
Quality Control: Checking if a manufacturing process produces items within acceptable parameters.
Surveys: Analyzing whether survey responses align with expected distributions.
Hypothesis Testing: Making data-driven decisions about population parameters.
function updateInputLabels() {
var testType = document.getElementById("testType").value;
var sampleStdDevInput = document.getElementById("sampleStdDev");
var sampleStdDevLabel = sampleStdDevInput.previousElementSibling; // Label is the sibling before the input
var dfInputGroup = document.getElementById("df-input-group");
if (testType === "z-test-mean") {
sampleStdDevLabel.textContent = "Population Standard Deviation (σ):";
sampleStdDevInput.placeholder = "e.g., 15 (Known)";
dfInputGroup.style.display = 'none';
} else if (testType === "t-test-mean") {
sampleStdDevLabel.textContent = "Sample Standard Deviation (s):";
sampleStdDevInput.placeholder = "e.g., 15 (Estimated)";
dfInputGroup.style.display = 'flex';
document.getElementById("degreesOfFreedom").value = "; // Clear df if switching to t-test
} else if (testType === "chi-squared-goodness") {
sampleStdDevLabel.textContent = "Chi-Squared Statistic (χ²):"; // Placeholder for actual input
sampleStdDevInput.placeholder = "Enter calculated χ² value";
dfInputGroup.style.display = 'flex';
document.getElementById("degreesOfFreedom").value = "; // Clear df if switching to chi-squared
}
}
function calculateStatistic() {
var sampleMean = parseFloat(document.getElementById("sampleMean").value);
var populationMean = parseFloat(document.getElementById("populationMean").value);
var sampleStdDev = parseFloat(document.getElementById("sampleStdDev").value);
var sampleSize = parseFloat(document.getElementById("sampleSize").value);
var testType = document.getElementById("testType").value;
var degreesOfFreedom = parseFloat(document.getElementById("degreesOfFreedom").value); // Needed for t-test and chi-squared
var resultDiv = document.getElementById("result");
var statisticValue = NaN;
var explanation = "";
// Input validation
if (isNaN(sampleMean) || isNaN(populationMean) || isNaN(sampleStdDev) || isNaN(sampleSize) || sampleSize 0).";
return;
}
if (testType === "z-test-mean") {
// Z-Test for Mean
if (isNaN(sampleStdDev) || sampleStdDev 0) is required.";
return;
}
var standardError = sampleStdDev / Math.sqrt(sampleSize);
if (standardError === 0) {
resultDiv.innerHTML = "Standard Error cannot be zero. Check your standard deviation and sample size.";
return;
}
statisticValue = (sampleMean – populationMean) / standardError;
explanation = "This is a Z-score, quantifying how many standard errors the sample mean is from the population mean.";
} else if (testType === "t-test-mean") {
// T-Test for Mean
if (isNaN(sampleStdDev) || sampleStdDev 0) is required.";
return;
}
if (isNaN(degreesOfFreedom) || degreesOfFreedom <= 0) {
// Automatically calculate degrees of freedom if not provided for t-test
degreesOfFreedom = sampleSize – 1;
if (degreesOfFreedom <= 0) {
resultDiv.innerHTML = "Sample size must be greater than 1 to calculate degrees of freedom for T-test.";
return;
}
document.getElementById("degreesOfFreedom").value = degreesOfFreedom; // Update input field
explanation = "Calculated Degrees of Freedom (df) as n-1.";
} else if (degreesOfFreedom !== sampleSize – 1) {
// Warn if provided df doesn't match n-1, but proceed with calculation
explanation = `Note: Provided Degrees of Freedom (${degreesOfFreedom}) differs from calculated (n-1 = ${sampleSize – 1}). Calculation uses provided df.`;
}
var standardError = sampleStdDev / Math.sqrt(sampleSize);
if (standardError === 0) {
resultDiv.innerHTML = "Standard Error cannot be zero. Check your standard deviation and sample size.";
return;
}
statisticValue = (sampleMean – populationMean) / standardError;
explanation += " This is a T-score, similar to a Z-score but accounts for uncertainty due to estimating the population standard deviation.";
} else if (testType === "chi-squared-goodness") {
// Chi-Squared Goodness-of-Fit (Direct Input)
// For Chi-Squared, the user typically inputs the calculated statistic value directly or we'd need observed/expected frequencies.
// This implementation assumes the user inputs the final Chi-Squared value in the 'sampleStdDev' field for this type.
// A more robust implementation would require separate inputs for observed and expected frequencies.
if (isNaN(sampleStdDev) || sampleStdDev < 0) {
resultDiv.innerHTML = "For Chi-Squared (Goodness-of-Fit), please enter the calculated Chi-Squared statistic (χ² ≥ 0) in the 'Standard Deviation' field.";
return;
}
if (isNaN(degreesOfFreedom) || degreesOfFreedom 0) is required.";
return;
}
statisticValue = sampleStdDev; // Use the value from the 'sampleStdDev' input as the Chi-Squared statistic
explanation = "This is a Chi-Squared (χ²) statistic value, used to assess the goodness-of-fit between observed and expected frequencies.";
// We don't use sampleMean, populationMean, sampleSize in the calculation itself for Chi-Squared here, but they might be contextually relevant.
}
if (!isNaN(statisticValue)) {
resultDiv.innerHTML = `Your ${testType.replace('-', ' ').toUpperCase()} Statistic is: ${statisticValue.toFixed(4)}${explanation}`;
} else {
resultDiv.innerHTML = "Calculation error. Please check your inputs.";
}
}
// Initialize labels based on default selection
window.onload = updateInputLabels;