Welch confidence interval — solution

Estimating the difference of means with unequal variances.

Calculated chart: Welch confidence interval
Figure 1 — Calculated chart: Welch confidence interval

Estimate the difference between independent means with a 95% Welch interval. Its standard error is the square root of s₁²/n₁ + s₂²/n₂.

Run Rscript --vanilla analysis.R results.csv and quarto render dashboard.qmd. The same synthetic result table can be connected to Superset using the SQL below.

Calculated results

Table 1 — Welch confidence interval — solution
statistic difference
lower 0.84802
estimate 4.44100
upper 8.03400

analysis.R

# Синтетические данные и расчёт метрик для обоих дашбордов.
set.seed(2026)
control <- rnorm(35, 50, 7)
treated <- rnorm(45, 55, 10)
test <- t.test(treated, control, var.equal = FALSE, conf.level = 0.95)
result <- data.frame(statistic = c("lower", "estimate", "upper"),
                     difference = c(test$conf.int[1], mean(treated) - mean(control), test$conf.int[2]))

# Проверяет конечность основной метрики перед экспортом.
stopifnot(nrow(result) > 1, all(is.finite(result$difference)))
if (sys.nframe() == 0L) {
  arguments <- commandArgs(trailingOnly = TRUE)
  stopifnot(length(arguments) == 1L)
  write.csv(result, arguments[1], row.names = FALSE)
}

dashboard.qmd

---
title: "Доверительный интервал Уэлча"
lang: ru
format: dashboard
execute:
  echo: false
---

```{r}
source("analysis.R", local = TRUE)
```

# Результаты

## Row

### График

```{r}
x <- result$statistic
y <- result$difference
if (is.numeric(x)) {
  plot(x, y, xlab = "statistic", ylab = "difference", pch = 19, col = "#245d76")
} else {
  par(mar = c(7, 4, 2, 1))
  barplot(y, names.arg = x, ylab = "difference", las = 2, col = "#245d76")
}
```

### Таблица

```{r}
knitr::kable(result, digits = 3)
```

## Row

### Как читать результат

Уэлч оценивает стандартную ошибку разницы как корень из суммы s₁²/n₁ и s₂²/n₂ и применяет t-распределение с поправкой на неодинаковые дисперсии.

superset.sql

-- Замените portfolio_results именем таблицы, куда импортирован results.csv.
SELECT statistic, difference
FROM portfolio_results
ORDER BY statistic;

Related projects, disciplines and materials