Single Sample t Test
Menu location: Analysis_Parametric_Single Sample t.
This function gives a single sample Student t test with a confidence interval for the mean difference.
The single sample t method tests a null hypothesis that the population mean is equal to a specified value. If this value is zero (or not entered) then the confidence interval for the sample mean is given (Altman, 1991; Armitage and Berry, 1994).
The test statistic is calculated as:
- where x bar is the sample mean, s² is the sample variance, n is the sample size, µ is the specified population mean and t is a Student t quantile with n-1 degrees of freedom.
Power is calculated as the power achieved with the given sample size and variance for detecting the observed mean difference with a two-sided type I error probability of (100-CI%)% (Dupont, 1990).
Example
Test workbook (Parametric worksheet: Systolic BP).
Consider 20 first year resident female doctors drawn at random from one area, resting systolic blood pressures measured using an electronic sphygmomanometer were:
| 128 | 127 |
| 118 | 115 |
| 144 | 142 |
| 133 | 140 |
| 132 | 131 |
| 111 | 132 |
| 149 | 122 |
| 139 | 119 |
| 136 | 129 |
| 126 | 128 |
From previous large studies of women drawn at random from the healthy general public, a resting systolic blood pressure of 120 mm Hg was predicted as the population mean for the relevant age group. To analyse these data in StatsDirect first prepare a workbook column containing the 20 data above or open the test workbook and select the single sample t test from the parametric methods section of the analysis menu. Select the column marked "Systolic BP" when prompted and enter the population mean as 120.
For this example:
Single sample t test
Sample name: Systolic BP
Sample mean = 130.05
Population mean = 120
Sample size n = 20
Sample sd = 9.960316
95% confidence interval for mean difference = 5.388429 to 14.711571
df = 19
t = 4.512404
One sided P = 0.0001
Two sided P = 0.0002
Power (for 5% significance) = 98.97%
A null hypothesis of no difference between sample and population means has clearly been rejected. Using the 95% CI we expect the mean systolic BP for this population of doctors to be at least 5 mm Hg greater than the age and sex matched general public, lying somewhere between 125 and 135 mm Hg.
R code
This R code reproduces the example above. It needs no packages and was checked with R 4.6.1. Paste it into R, or save it as a script and run it.
# Single sample t test: the StatsDirect help example (resting systolic blood
# pressure of 20 first year resident doctors) in R
bp <- c(128, 127, 118, 115, 144, 142, 133, 140, 132, 131, 111, 132, 149, 122, 139,
119, 136, 129, 126, 128)
mu <- 120 # the population mean to compare with
n <- length(bp)
# R's standard test gives t, df, the two sided P and a 95% confidence interval for
# the mean. StatsDirect's interval is for the difference between the sample and
# population means, so its limits are these less 120.
r <- t.test(bp, mu = mu)
print(r)
# The report's other lines, to 6 decimal places
six <- function(x) formatC(x, digits = 6, format = "f", drop0trailing = TRUE)
cat("Sample mean =", six(mean(bp)), " Sample size n =", n,
" Sample sd =", six(sd(bp)), "\n")
cat("95% confidence interval for mean difference =", six(r$conf.int[1] - mu), "to",
six(r$conf.int[2] - mu), "\n")
cat("df =", r$parameter, " t =", six(r$statistic), "\n")
cat(sprintf("One sided P = %.4f Two sided P = %.4f\n", r$p.value / 2, r$p.value))
# Power of a two sided test at the 5% level to detect the difference and sd seen,
# from the noncentral t distribution; strict = TRUE counts rejections in both
# tails, as StatsDirect does.
pw <- power.t.test(n = n, delta = mean(bp) - mu, sd = sd(bp), sig.level = 0.05,
type = "one.sample", strict = TRUE)
cat(sprintf("Power (for 5%% significance) = %.2f%%\n", 100 * pw$power))