TensorTonicTensorTonic
Problems
Study PlansProjectsNewInterviewPricingFeedback
Problems
Loading...
1 / 1

One-Sample t-Test

Probability and Statistics
Medium

Compute the one-sample t-statistic for observations x1,…,xnx_1,\ldots,x_nx1​,…,xn​ and hypothesized mean μ0\mu_0μ0​. First compute the sample standard deviation:

s=1n−1∑i=1n(xi−xˉ)2s = \sqrt{\frac{1}{n-1}\sum_{i=1}^{n}(x_i-\bar{x})^2}s=n−11​i=1∑n​(xi​−xˉ)2​

Then compute:

t=xˉ−μ0s/nt = \frac{\bar{x}-\mu_0}{s/\sqrt{n}}t=s/n​xˉ−μ0​​

Here, xˉ\bar{x}xˉ is the sample mean. If s=0s=0s=0, return zero when xˉ=μ0\bar{x}=\mu_0xˉ=μ0​ and signed infinity otherwise. Return the statistic as a Python float.

Loading visualization...

Examples

Input: x = [2.1, 2.4, 1.9, 2.6, 2.0], mu0 = 2.0

Output: 1.53393

Explanation: The sample mean is above the hypothesized mean by about 1.53 standard errors.

Input: x = [3.0, 5.0], mu0 = 4.0

Output: 0.0

Input: x = [1.0, 1.5, 2.0], mu0 = 3.0

Output: -5.196152

Hint 1

Compute centered = x - np.mean(x) before the corrected variance.

Hint 2

The standard error is sample_std / np.sqrt(x.size).

Requirements

  • Compute sample standard deviation with Bessel's correction
  • Divide the mean difference by the standard error
  • Handle zero sample variance as stated
  • Return a Python float

Constraints

  • x is a one-dimensional numeric list with at least two values
  • mu0 is finite
  • Use NumPy only
Try Similar Problems
Chi2 IndependenceBootstrap MeanSample Var StdMean Median ModeExpected Value Discrete

Sign in to take notes on this problem

Case 1
Case 2
Case 3

Accepts: array

Accepts: number

You must run your code first.
PrevNext

One-Sample t-Test

Probability and Statistics
Medium

Compute the one-sample t-statistic for observations x1,…,xnx_1,\ldots,x_nx1​,…,xn​ and hypothesized mean μ0\mu_0μ0​. First compute the sample standard deviation:

s=1n−1∑i=1n(xi−xˉ)2s = \sqrt{\frac{1}{n-1}\sum_{i=1}^{n}(x_i-\bar{x})^2}s=n−11​i=1∑n​(xi​−xˉ)2​

Then compute:

t=xˉ−μ0s/nt = \frac{\bar{x}-\mu_0}{s/\sqrt{n}}t=s/n​xˉ−μ0​​

Here, xˉ\bar{x}xˉ is the sample mean. If s=0s=0s=0, return zero when xˉ=μ0\bar{x}=\mu_0xˉ=μ0​ and signed infinity otherwise. Return the statistic as a Python float.

Loading visualization...

Examples

Input: x = [2.1, 2.4, 1.9, 2.6, 2.0], mu0 = 2.0

Output: 1.53393

Explanation: The sample mean is above the hypothesized mean by about 1.53 standard errors.

Input: x = [3.0, 5.0], mu0 = 4.0

Output: 0.0

Input: x = [1.0, 1.5, 2.0], mu0 = 3.0

Output: -5.196152

Hint 1

Compute centered = x - np.mean(x) before the corrected variance.

Hint 2

The standard error is sample_std / np.sqrt(x.size).

Requirements

  • Compute sample standard deviation with Bessel's correction
  • Divide the mean difference by the standard error
  • Handle zero sample variance as stated
  • Return a Python float

Constraints

  • x is a one-dimensional numeric list with at least two values
  • mu0 is finite
  • Use NumPy only
Try Similar Problems
Chi2 IndependenceBootstrap MeanSample Var StdMean Median ModeExpected Value Discrete

Sign in to take notes on this problem

Case 1
Case 2
Case 3

Accepts: array

Accepts: number

You must run your code first.