NLreg.jl

Nonlinear regression in Julia
Popularity
10 Stars
Updated Last
11 Months Ago
Started In
September 2013

Nonlinear regression

Stable Dev Build Status Build Status Codecov

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 NamedTuples. 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"));

julia> PurTrt = first(groupby(CSV.read(joinpath(datadir, "Puromycin.csv")), :state))
12×3 SubDataFrame
│ Row │ conc    │ rate    │ state   │
│     │ Float64 │ Float64 │ String  │
├─────┼─────────┼─────────┼─────────┤
│ 10.0276.0    │ treated │
│ 20.0247.0    │ treated │
│ 30.0697.0    │ treated │
⋮
│ 90.56191.0   │ treated │
│ 100.56201.0   │ treated │
│ 111.1207.0   │ treated │
│ 121.1200.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.