# Parameter bounds and confidence intervals in LsqFit.jl?

**URL:** <https://discourse.julialang.org/t/parameter-bounds-and-confidence-intervals-in-lsqfit-jl/113366>\
**Category:** Optimization (Mathematical)\
**Tags:** curve-fitting, nonlinear\
**Created:** [April 23, 2024, 12:17am UTC](https://discourse.julialang.org/t/parameter-bounds-and-confidence-intervals-in-lsqfit-jl/113366 "2024-04-23T00:17:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![PeX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pex/32/49986_2.png) [@PeX](https://discourse.julialang.org/u/PeX)\
**Post date:** [April 23, 2024, 12:17am UTC](https://discourse.julialang.org/t/parameter-bounds-and-confidence-intervals-in-lsqfit-jl/113366/1 "2024-04-23T00:17:44Z")

</div>

HI all,

I’m trying to use LsqFit.jl to fit a model in the form of:

```julia
model(t, p) = @. p[1] * t^3 + p[2] * t + p[5]*sin(2*π*p[3]*t + p[4])

```

However, I need `p[4]` to be strictly between 0 and pi. Is it possible to do it?  
In addition, is there a wat to calculate or plot the 95% confidence intervals of the fit?

If not, is there another recommended package that can deal with this effectively?

Thank you!

---

<div class="post-metadata">

**Author:** ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Post date:** [April 23, 2024, 7:40am UTC](https://discourse.julialang.org/t/parameter-bounds-and-confidence-intervals-in-lsqfit-jl/113366/2 "2024-04-23T07:40:03Z")

</div>

> [@PeX](#):
>
> However, I need `p[4]` to be strictly between 0 and pi. Is it possible to do it?

I don’t think LsqFit.jl supports bounded optimization. However in this case it would not be too hard to transform the parameters found by the optimization to the desired interval.

> [@PeX](#):
>
> In addition, is there a wat to calculate or plot the 95% confidence intervals of the fit?

The [Readme lists](https://juliahub.com/ui/Packages/General/LsqFit#Existing-Functionality)

```julia
confidence_interval = confint(fit; level=0.05, atol, rtol):

```

- `fit`: result of curve\_fit (a LsqFitResult type)
- `level`: confidence level
- `atol`: absolute tolerance for negativity check
- `rtol`: relative tolerance for negativity check  
This returns confidence interval of each parameter at level significance level.

> [@PeX](#):
>
> If not, is there another recommended package that can deal with this effectively?

I think there are quite a few packages for optimization but I am not familiar with the ecosystem. Maybe someone else will make a recommendation.
