
import numpy as np
# Example data
data = [70, 75, 80, 85, 90]
# Calculate standard deviation
standard_deviation = np.std(data)
print(f"Standard Deviation: {standard_deviation}")Definition
Calculation
- Standard error is the sample standard deviation s divided by the square root of the sample size .
- Where is the sample standard deviation and is the sample size.
Interpretation
Example Code
import numpy as np
# Example data (sample)
sample_data = [70, 75, 80, 85, 90]
# Calculate sample standard deviation
sample_standard_deviation = np.std(sample_data, ddof=1)
# Sample size
n = len(sample_data)
# Calculate standard error
standard_error = sample_standard_deviation / np.sqrt(n)
print(f"Standard Error: {standard_error}")
| Purpose | Calculation | Usage | Dependence on Sample Size | |
|---|---|---|---|---|
| Standard Deviation | Measure the spread of data points around the mean in a single sample. | Calculated directly from the data points. | Used to describe the variability within a dataset. | Independent of sample size. |
| Standard Error | Measure how much the sample mean is expected to vary from the true population mean. | Derived from the standard deviation of the sample and the sample size. | Used to describe the accuracy of a sample mean as an estimate of the population mean. | Decreases as the sample size increases (larger sample sizes provide more accurate estimates of the population mean). |
A statistical method used to make decisions about a population parameter based on sample data.
import numpy as np
from scipy import stats
# Example data (students' scores)
data = [78, 82, 79, 83, 76, 77, 85, 88, 75, 74, 80, 79]
# Calculate sample mean and sample standard deviation
sample_mean = np.mean(data)
sample_std = np.std(data, ddof=1)
n = len(data)
# Null hypothesis mean
mu_0 = 75
# Calculate t-statistic
t_statistic = (sample_mean - mu_0) / (sample_std / np.sqrt(n))
# Significance level and degrees of freedom
alpha = 0.05
df = n - 1
# Determine the critical value for a two-tailed test
t_critical = stats.t.ppf(1 - alpha/2, df)
# Make a decision
if abs(t_statistic) > t_critical:
print(f"t-statistic: {t_statistic}, Critical value: {t_critical}")
print("Reject the null hypothesis.")
else:
print(f"t-statistic: {t_statistic}, Critical value: {t_critical}")
print("Fail to reject the null hypothesis.")