normalOneSample

Computes statistics for mean and variance inferences using a sample from a normal population.

Synopsis

normalOneSample (x)

Required Arguments

float x[] (Input)
Array of length nObservations.

Return Value

The mean of the sample.

Optional Arguments

confidenceMean, float (Input)
Confidence level (in percent) for two-sided interval estimate of the mean. Argument confidenceMean must be between 0.0 and 100.0 and is often 90.0, 95.0, or 99.0. For a one-sided confidence interval with confidence level c (at least 50 percent), set confidenceMean = 100.0 − 2.0 × (100.0 − c). If confidenceMean is not specified, a 95-percent confidence interval is computed.
ciMean, lowerLimit, upperLimit (Output)
Argument lowerLimit contains the lower confidence limit for the mean, and argument upperLimit contains the upper confidence limit for the mean.
stdDev (Output)
Standard deviation of the sample.
tTest, df, t, pValue (Output)
Argument df is the degrees of freedom associated with the t test for the mean, t is the test statistic, and pValue is the probability of a larger t in absolute value. The t test is a test, against a two-sided alternative, of the hypothesis \(\mu=\mu_0\), where \(\mu_0\) is the null hypothesis value as described in tTestNull.
tTestNull, float (Input)

Null hypothesis value for t test for the mean.

Default: tTestNull = 0.0

confidenceVariance, float (Input)
Confidence level (in percent) for two-sided interval estimate of the variances. Argument confidenceVariance must be between 0.0 and 100.0 and is often 90.0, 95.0, 99.0. For a one-sided confidence interval with confidence level c (at least 50 percent), set confidenceVariance = 100.0 − 2.0 × (100.0 − c). If this option is not used, a 95-percent confidence interval is computed.
ciVariance, lowerLimit, upperLimit (Output)
Contains the lower and upper confidence limits for the variance.
chiSquaredTest, df, chiSquared, pValue (Output)

Argument df is the degrees of freedom associated with the chi-squared test for variances, chiSquared is the test statistic, and pValue is the probability of a larger chi-squared. The chi-squared test is a test of the hypothesis

\[\sigma^2 = \sigma_0^2\]

where

\[\sigma_0^2\]

is the null hypothesis value as described in chiSquaredTestNull.

chiSquaredTestNull, float (Input)

Null hypothesis value for the chi-squared test.

Default: chiSquaredTestNull = 1.0

Description

Statistics for mean and variance inferences using a sample from a normal population are computed, including confidence intervals and tests for both mean and variance. The definitions of mean and variance are given below. The summation in each case is over the set of valid observations, based on the presence of missing values in the data.

Mean, return value

\[\overline{x} = \frac{\Sigma x_i}{n}\]

Standard deviation, stdDev

\[s = \sqrt{\frac{\Sigma \left(x_i - \overline{x}\right)^2}{n-1}}\]

The t statistic for the two-sided test concerning the population mean is given by

\[t = \frac{\overline{x} - \mu_0}{s / \sqrt{n}}\]

where s and \(\bar{x}\) are given above. This quantity has a T distribution with n − 1 degrees of freedom.

The chi-squared statistic for the two-sided test concerning the population variance is given by

\[\chi^2 = \frac{(n-1) s^2}{\sigma_0^2}\]

where s is given above. This quantity has a \(\chi^2\) distribution with n − 1 degrees of freedom.

Examples

Example 1

This example uses data from Devore (1982, p. 335), which is based on data published in the Journal of Materials. There are 15 observations; the mean is the only output.

from __future__ import print_function
from numpy import *
from pyimsl.stat.normalOneSample import normalOneSample

x = array([
    26.7, 25.8, 24.0, 24.9, 26.4,
    25.9, 24.4, 21.7, 24.1, 25.9,
    27.3, 26.9, 27.3, 24.8, 23.6])

# Perform analysis
mean = normalOneSample(x)

# Print results
print("Sample Mean = %5.2f" % mean)

Output

Sample Mean = 25.31

Example 2

This example uses the same data as the initial example. The hypothesis \(H_0 : \mu=20.0\) is tested. The extremely large t value and the correspondingly small p‑value provide strong evidence to reject the null hypothesis.

from __future__ import print_function
from numpy import *
from pyimsl.stat.normalOneSample import normalOneSample

x = array([
    26.7, 25.8, 24.0, 24.9, 26.4,
    25.9, 24.4, 21.7, 24.1, 25.9,
    27.3, 26.9, 27.3, 24.8, 23.6])

ciMean = {}
stdDev = []
tTest = {}
civ = {}
cst = {}

# Perform analysis
mean = normalOneSample(x,
                       stdDev=stdDev,
                       ciMean=ciMean,
                       tTestNull=20.0,
                       tTest=tTest)

# Print results
print("Sample Mean = %5.2f" % (mean))
print("Sample Standard Deviation = %5.2f" % (stdDev[0]))
print("95%% CI for the mean is (%5.2f,%5.2f)" %
      (ciMean["lowerLimit"], ciMean["upperLimit"]))
print("df = %3d" % (tTest["df"]))
print("t = %5.2f" % (tTest["t"]))
print("p-value = %8.5f" % (tTest["pValue"]))

Output

Sample Mean = 25.31
Sample Standard Deviation =  1.58
95% CI for the mean is (24.44,26.19)
df =  14
t = 13.03
p-value =  0.00000