ci_mean_t_stat() calculates the mean's confidence interval (CI) using the classic formula with Student's t coefficient when descriptive statistics (mean, standard deviation, sample size) are provided. Useful when these values are reported in scientific literature.

ci_mean_t_stat(mean_, sd_, n, group = "", conf.level = 0.95)

Arguments

mean_

Vector of group means.

sd_

Vector of group standard deviations.

n

Vector of group sizes.

group

Group name. Default: empty string ("").

conf.level

Confidence level. Default: 0.95.

Value

A data frame with columns:

  • group (<fct>) – group name;

  • mean (<dbl>) – mean estimate;

  • lwr.ci (<dbl>) – lower CI bound (lwr. = lower);

  • upr.ci (<dbl>) – upper CI bound (upr. = upper);

  • sd (<dbl>) – standard deviation;

  • n (<int>) – sample/group size.

Calculations can be performed for multiple groups simultaneously.

Note

Each of mean_, sd_, n, group must have length (a) of one value, or (b) matching the longest vector in this argument group.

See examples for clarification.

Examples

# Basic example: Test scores
# Suppose a class of 25 students has a mean score of 75 with SD of 10
ci_mean_t_stat(mean_ = 75, sd_ = 10, n = 25)
#> # A tibble: 1 × 6
#>   group  mean lwr.ci upr.ci    sd     n
#>   <fct> <dbl>  <dbl>  <dbl> <dbl> <int>
#> 1 ""       75   70.9   79.1    10    25

# The result tells us we can be 95% confident that the true mean score
# lies between the lower and upper CI bounds

# Example from literature: A study reports mean = 362, SD = 35, n = 100
ci_mean_t_stat(mean_ = 362, sd_ = 35, n = 100)
#> # A tibble: 1 × 6
#>   group  mean lwr.ci upr.ci    sd     n
#>   <fct> <dbl>  <dbl>  <dbl> <dbl> <int>
#> 1 ""      362   355.   369.    35   100

# Without argument names (order matters: mean, sd, n):
ci_mean_t_stat(362, 35, 100)
#> # A tibble: 1 × 6
#>   group  mean lwr.ci upr.ci    sd     n
#>   <fct> <dbl>  <dbl>  <dbl> <dbl> <int>
#> 1 ""      362   355.   369.    35   100


# Comparing multiple groups (e.g., teaching methods):
# Method A: mean = 78, SD = 8, n = 30 students
# Method B: mean = 82, SD = 7, n = 28 students
# Method C: mean = 75, SD = 9, n = 32 students
mean_val <- c(78, 82, 75)
std_dev  <- c(8,   7,  9)
n        <- c(30, 28, 32)
group    <- c("Method A", "Method B", "Method C")

ci_mean_t_stat(mean_val, std_dev, n, group)
#> # A tibble: 3 × 6
#>   group     mean lwr.ci upr.ci    sd     n
#>   <fct>    <dbl>  <dbl>  <dbl> <dbl> <int>
#> 1 Method A    78   75.0   81.0     8    30
#> 2 Method B    82   79.3   84.7     7    28
#> 3 Method C    75   71.8   78.2     9    32


# Educational example: Effect of sample size on CI width
# Same mean and SD, but different sample sizes
ci_mean_t_stat(mean_ = 75, sd_ = 10, n = c(10, 25, 50, 100))
#> # A tibble: 4 × 6
#>   group  mean lwr.ci upr.ci    sd     n
#>   <fct> <dbl>  <dbl>  <dbl> <dbl> <int>
#> 1 ""       75   67.8   82.2    10    10
#> 2 ""       75   70.9   79.1    10    25
#> 3 ""       75   72.2   77.8    10    50
#> 4 ""       75   73.0   77.0    10   100
# Notice: Larger samples give narrower (more precise) confidence intervals


# Educational example: Changing confidence level (default is 95%)
ci_mean_t_stat(mean_ = 75, sd_ = 10, n = 25, conf.level = 0.99)
#> # A tibble: 1 × 6
#>   group  mean lwr.ci upr.ci    sd     n
#>   <fct> <dbl>  <dbl>  <dbl> <dbl> <int>
#> 1 ""       75   69.4   80.6    10    25
# 99% CI is wider than 95% CI (more confident = less precise)

# NOTE: Changing conf.level just to get narrower CI is a BAD PRACTICE!
# Please choose confidence level based on study design, not desired CI width.


# To display more decimal places, convert tibble to data frame:
result_ci <- ci_mean_t_stat(75, 10, 25)
as.data.frame(result_ci)
#>   group mean  lwr.ci  upr.ci sd  n
#> 1         75 70.8722 79.1278 10 25

# Or use:
# View(result_ci)