Summary Data t Test
Menu location: Analysis_Parametric_Summary Data t.
StatsDirect enables you to calculate t tests from summary data. These data are entered as means and standard deviations on screen instead of being calculated from selected workbook columns.
Example
The single sample t test example (20 systolic blood pressures) and the unpaired t test example (weight gain of 19 rats) can be repeated from their summary statistics. Select Summary Data t from the Parametric section of the Analysis menu, then Single Sample, and enter a sample size of 20, a sample mean of 130.05, a sample standard deviation of 9.960316 and a population mean of 120:
Single sample t test
Sample name: * from summary data
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%
For the unpaired test select Summary Data t, then Unpaired, and enter sample sizes of 12 and 7, means of 120 and 101 and standard deviations of 21.38819 and 20.62361:
Unpaired t test
Mean of * sample 1 from summary = 120 (n = 12)
Mean of * sample 2 from summary = 101 (n = 7)
Assuming equal variances
Combined standard error = 10.045276
df = 17
t = 1.891436
One sided P = 0.0379
Two sided P = 0.0757
95% confidence interval for difference between means = -2.193681 to 40.193681
Power (for 5% significance) = 43.05%
Assuming unequal variances
Combined standard error = 9.943999
df = 13.081704
t(d) = 1.9107
One sided P = 0.0391
Two sided P = 0.0782
95% confidence interval for difference between means = -2.469073 to 40.469073
Power (for 5% significance) = 42.49%
Comparison of variances
Two sided F test is not significant
No need to assume unequal variances
These are the results of the two examples calculated from the data, apart from the last digits of the equal variances confidence interval and the unequal variances degrees of freedom, because the standard deviations were entered to five decimal places.
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.
# t tests from summary statistics: the StatsDirect help example (the single sample
# and unpaired t test examples again, from their means and standard deviations) in R
# R's t.test needs the data themselves, so the report's lines are calculated here.
six <- function(x) formatC(x, digits = 6, format = "f", drop0trailing = TRUE)
power <- function(t, df) { # two sided test at the 5% level, from the
tc <- qt(0.975, df) # noncentral t distribution with the t
pt(-tc, df, ncp = t) + pt(tc, df, ncp = t, lower.tail = FALSE) # observed as ncp
}
# Single sample: 20 systolic blood pressures with mean 130.05 and sd 9.960316,
# against a population mean of 120
n <- 20
m <- 130.05
s <- 9.960316
mu <- 120
se <- s / sqrt(n)
t <- (m - mu) / se
p <- 2 * pt(-abs(t), n - 1)
cat("Single sample: mean =", m, " n =", n, " sd =", s, " population mean =", mu,
"\n")
ci <- m - mu + c(-1, 1) * qt(0.975, n - 1) * se
cat("95% confidence interval for mean difference =", six(ci[1]), "to", six(ci[2]), "\n")
cat("df =", n - 1, " t =", six(t), "\n")
cat(sprintf("One sided P = %.4f Two sided P = %.4f\n", p / 2, p))
cat(sprintf("Power (for 5%% significance) = %.2f%%\n", 100 * power(t, n - 1)))
# Unpaired: 12 rats on a high protein diet, mean 120 and sd 21.38819, and 7 on a
# low protein diet, mean 101 and sd 20.62361
n1 <- 12
m1 <- 120
s1 <- 21.38819
n2 <- 7
m2 <- 101
s2 <- 20.62361
delta <- m1 - m2
report <- function(se, df, label, name) {
t <- delta / se
p <- 2 * pt(-abs(t), df)
cat(label, "\n")
cat("Combined standard error =", six(se), " df =", six(df), " ", name, "=", six(t),
"\n")
cat(sprintf("One sided P = %.4f Two sided P = %.4f\n", p / 2, p))
cat("95% confidence interval for difference between means =",
six(delta - qt(0.975, df) * se), "to", six(delta + qt(0.975, df) * se), "\n")
cat(sprintf("Power (for 5%% significance) = %.2f%%\n", 100 * power(t, df)))
}
# Assuming equal variances: the pooled variance
pooled <- ((n1 - 1) * s1^2 + (n2 - 1) * s2^2) / (n1 + n2 - 2)
report(sqrt(pooled * (1 / n1 + 1 / n2)), n1 + n2 - 2, "Assuming equal variances", "t")
# Assuming unequal variances: Welch's standard error and degrees of freedom
se2 <- sqrt(s1^2 / n1 + s2^2 / n2)
df2 <- se2^4 / ((s1^2 / n1)^2 / (n1 - 1) + (s2^2 / n2)^2 / (n2 - 1))
report(se2, df2, "Assuming unequal variances", "t(d)")
# The F test of the variances, larger over smaller, with its upper tail P doubled
f <- max(s1, s2)^2 / min(s1, s2)^2
pf2 <- 2 * pf(f, if (s1 > s2) n1 - 1 else n2 - 1, if (s1 > s2) n2 - 1 else n1 - 1,
lower.tail = FALSE)
cat("Two sided F test is", if (pf2 < 0.05) "significant" else "not significant", "\n")