Skip to content

Commit 128fe91

Browse files
JamesWrigleyChrisRackauckas
authored andcommitted
Make margin_error() public
1 parent d9dc176 commit 128fe91

File tree

5 files changed

+14
-7
lines changed

5 files changed

+14
-7
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "CurveFit"
22
uuid = "5a033b19-8c74-5913-a970-47c3779ef25c"
3-
version = "1.4.0"
3+
version = "1.5.0"
44
authors = ["Paulo José Saiz Jabardo <pjabardo@gmail.com>, Avik Pal <avikpal@mit.edu> and contributors"]
55

66
[deps]

docs/src/_changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ CurrentModule = CurveFit
77
This documents notable changes in CurveFit.jl. The format is based on [Keep a
88
Changelog](https://keepachangelog.com).
99

10-
## [v1.4.0] - 2026-01-26
10+
## [v1.4.0] - 2026-01-30
1111

1212
### Added
13+
- Implemented [`margin_error()`](@ref) ([#81]).
1314
- Added support for standard deviation weights for linear fits ([#80]).
1415

1516
## [v1.3.0] - 2026-01-26

docs/src/api/solutions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ rss
2828
isconverged
2929
vcov
3030
stderror
31+
margin_error
3132
confint
3233
```

src/CurveFit.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export CurveFitSolution
4848

4949
export solve, solve!, init
5050

51-
export coef, residuals, predict, fitted, nobs, dof, dof_residual, rss, mse, vcov, stderror, confint
51+
export coef, residuals, predict, fitted, nobs, dof, dof_residual, rss, mse, vcov, stderror, margin_error, confint
5252
export isconverged
5353

5454
end

src/stats.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,13 @@ function StatsAPI.stderror(sol::CurveFitSolution; rtol::Real = NaN, atol::Real =
331331
return sqrt.(abs.(vars))
332332
end
333333

334+
"""
335+
margin_error(sol::CurveFitSolution, alpha = 0.05; rtol::Real = NaN, atol::Real = 0)
336+
337+
Returns the margin of error of the fitted coefficients, computed as
338+
`stderror(sol) * t` where `t` is the critical value of the t-distribution for `1
339+
- alpha / 2`.
340+
"""
334341
function margin_error(sol::CurveFitSolution, alpha = 0.05; rtol::Real = NaN, atol::Real = 0)
335342
std_errors = stderror(sol; rtol = rtol, atol = atol)
336343
dist = TDist(dof(sol))
@@ -343,10 +350,8 @@ end
343350
344351
Return confidence intervals for the fitted parameters.
345352
346-
Confidence intervals are computed using [`stderror()`](@ref) internally. The
347-
confidence intervals are returned as a vector of `(lower, upper)` tuples,
348-
computed as `coef(sol) ± stderror(sol) * t` where `t` is the critical value
349-
of the t-distribution for the given confidence `level`.
353+
The confidence intervals are returned as a vector of `(lower, upper)` tuples,
354+
computed as `coef(sol) ± margin_error(sol)`.
350355
"""
351356
function StatsAPI.confint(sol::CurveFitSolution; level = 0.95, rtol::Real = NaN, atol::Real = 0)
352357
margin_of_errors = margin_error(sol, 1 - level; rtol = rtol, atol = atol)

0 commit comments

Comments
 (0)