## NLreg.jl

Nonlinear regression in Julia
Popularity
16 Stars
Updated Last
1 Year Ago
Started In
September 2013

# Nonlinear regression

This package is an experiment in using the `Zygote` automatic differentiation package and the `lowrankupdate!` function in the `LinearAlgebra` package to solve the linear least squares problem for a Gauss-Newton update.

The data are represented as a `Tables.RowTable`, which is a vector of `NamedTuple`s. The model parameters are also a `NamedTuple`. The model function is given as a function of two arguments - the parameters and a data row.

## Example - a Michaelis-Menten fit

In the Michaelis-Menten model for enzyme kinetics,

`v = Vm * c / (K + c)`

the relationship between the velocity, `v`, of a reaction and the concentration, `c`, of the substrate depends on two parameters; `Vm`, the maximum velocity and `K`, the Michaelis parameter. The `Vm` parameter occurs linearly in this expression whereas `K` is a nonlinear parameter.

```julia> using CSV, DataFrames, NLreg

julia> datadir = normpath(joinpath(dirname(pathof(NLreg)), "..", "data"));

12×3 SubDataFrame
│ Row │ conc    │ rate    │ state   │
│     │ Float64 │ Float64 │ String  │
├─────┼─────────┼─────────┼─────────┤
│ 1   │ 0.02    │ 76.0    │ treated │
│ 2   │ 0.02    │ 47.0    │ treated │
│ 3   │ 0.06    │ 97.0    │ treated │
⋮
│ 9   │ 0.56    │ 191.0   │ treated │
│ 10  │ 0.56    │ 201.0   │ treated │
│ 11  │ 1.1     │ 207.0   │ treated │
│ 12  │ 1.1     │ 200.0   │ treated │

julia> pm1 = fit(NLregModel, PurTrt, :rate, (p,d) -> p.Vm * d.conc/(p.K + d.conc),
(Vm = 200., K = 0.05))
Nonlinear regression model fit by maximum likelihood

Data schema (response variable is rate)
Tables.Schema:
:conc   Float64
:rate   Float64
:state  String
Number of observations:                  12

Parameter estimates
───────────────────────────────────────
Estimate   Std.Error  t-statistic
───────────────────────────────────────
Vm  212.684     6.94715        30.6145
K     0.064121  0.00828092      7.74322
───────────────────────────────────────

Sum of squared residuals at convergence: 1195.4488145417758
Achieved convergence criterion:          8.798637504793927e-6```

### Used By Packages

No packages found.