calculate_chem_ci <- function(x_bar, s, n, conf_level = 0.95) {
degrees_of_freedom <- n - 1
t_score <- qt((1 + conf_level) / 2, df = degrees_of_freedom)
margin_error <- t_score * (s / sqrt(n))
ci_lower <- x_bar - margin_error
ci_upper <- x_bar + margin_error
return(c(ci_lower, ci_upper))
}
# Example: Copper sulfate solution concentration
x_bar <- 0.1025 # mol/L
s <- 0.0015 # mol/L
n <- 5
ci <- calculate_chem_ci(x_bar, s, n)
cat("95% CI:", round(ci[1], 4), "to", round(ci[2], 4), "mol/L")
## 95% CI: 0.1006 to 0.1044 mol/L