One-Sample t-Test
One-Sample t-Test
Given a sample x and a hypothesized population mean μ₀, compute the one-sample t-statistic.
One-Sample t-Statistic:
t=s/nxˉ−μ0Where: x̄ = sample mean, s = sample standard deviation, n = sample size
Sample standard deviation (Bessel correction):
s=n−11i=1∑n(xi−xˉ)2Function Arguments
x: list or array- Sample observationsmu0: float- Null hypothesis mean (μ₀)
Examples
Input: x=[2.1, 2.4, 1.9, 2.6, 2.0], mu0=2.0
Output: t_stat≈1.53
mean=2.20, std≈0.274, t=(2.20-2.0)/(0.274/√5)
Input: x=[3.0, 5.0], mu0=4.0
Output: t_stat=0.0
mean=4.0 equals mu0
Input: x=[1.0, 1.5, 2.0], mu0=3.0
Output: t_stat≈-5.20
negative t-statistic (sample mean < mu0)
Hint 1
Compute sample mean with np.mean().
Hint 2
Use np.sqrt() for sample standard deviation.
Hint 3
Standard error is s / np.sqrt().
Requirements
- Return scalar float (t-statistic)
- Must convert x to NumPy array
- Use Bessel correction (n-1 denominator)
- No external statistics libraries
Constraints
- len(x) ≥ 2
- NumPy only; time limit: 300ms
Log in to take notes on this problem
Accepts: array
Accepts: number
One-Sample t-Test
One-Sample t-Test
Given a sample x and a hypothesized population mean μ₀, compute the one-sample t-statistic.
One-Sample t-Statistic:
t=s/nxˉ−μ0Where: x̄ = sample mean, s = sample standard deviation, n = sample size
Sample standard deviation (Bessel correction):
s=n−11i=1∑n(xi−xˉ)2Function Arguments
x: list or array- Sample observationsmu0: float- Null hypothesis mean (μ₀)
Examples
Input: x=[2.1, 2.4, 1.9, 2.6, 2.0], mu0=2.0
Output: t_stat≈1.53
mean=2.20, std≈0.274, t=(2.20-2.0)/(0.274/√5)
Input: x=[3.0, 5.0], mu0=4.0
Output: t_stat=0.0
mean=4.0 equals mu0
Input: x=[1.0, 1.5, 2.0], mu0=3.0
Output: t_stat≈-5.20
negative t-statistic (sample mean < mu0)
Hint 1
Compute sample mean with np.mean().
Hint 2
Use np.sqrt() for sample standard deviation.
Hint 3
Standard error is s / np.sqrt().
Requirements
- Return scalar float (t-statistic)
- Must convert x to NumPy array
- Use Bessel correction (n-1 denominator)
- No external statistics libraries
Constraints
- len(x) ≥ 2
- NumPy only; time limit: 300ms
Log in to take notes on this problem
Accepts: array
Accepts: number