[R] Extract model from deriv3 or nls
Prof J C Nash (U30A)
nashjc at uottawa.ca
Fri Sep 19 17:21:02 CEST 2014
If it is possible, I think you will need to get the expression for
Puro.fun2 and then (essentially manually) put it into nls (or perhaps
better nlmrt or minpack.lm which have better numerics and allow bounds;
nlmrt even has masks or temporarily fixed parameters, but I need to
writa a vignette about that). That is, I believe you essentially need to
do the analytic derivatives to get what you want.
There is also an experimental nls14 on r-forge in the optimizer project,
which Duncan Murdoch and I have been working on. It even includes all-R
replacements for D and deriv (I don't think Duncan implemented deriv3
though). It is, however,
experimental, and we welcome people trying it and letting us know of
bugs and glitches. Note that nlmrt and nls14 try to use analytic
derivatives for the Jacobian of the nonlinear least squares, while nls()
uses numeric approximations. When it works, nls() is generally more
efficient, but it is much more fragile -- trade-offs abound.
Best, JN
On 14-09-19 06:00 AM, r-help-request at r-project.org wrote:
> Date: Thu, 18 Sep 2014 13:33:24 +0000
> From: "Riley, Steve" <Steve.Riley at pfizer.com>
> To: "r-help at r-project.org" <r-help at r-project.org>
> Subject: [R] Extract model from deriv3 or nls
> Message-ID:
> <941F9C738E7ABB459A4306D21D7177CBC8598EAD at NDHAMREXDE03.amer.pfizer.com>
>
> Content-Type: text/plain; charset="UTF-8"
>
> Hello!
>
> I am trying to figure out how to extract the model equation when using deriv3 with nls.
>
> Here is my example:
> #
> # Generate derivatives
> #
> Puro.fun2 <- deriv3(expr = ~(Vmax + VmaxT*state) * conc/(K + Kt * state + conc),
> name = c("Vmax","VmaxT","K","Kt"),
> function.arg = function(conc, state, Vmax, VmaxT, K, Kt) NULL)
> #
> # Fit model using derivative function
> #
> Puro.fit1 <- nls(rate ~ Puro.fun2(conc, state == "treated", Vmax, VmaxT, K, Kt),
> data = Puromycin,
> start = c(Vmax = 160, VmaxT = 47, K = 0.043, Kt = 0.05))
>
> Normally I would use summary(Puro.fit1)$formula to extract the model but because I am implementing deriv3, the following gets returned:
>
>> > summary(Puro.fit1)$formula
> rate ~ Puro.fun2(conc, state == "treated", Vmax, VmaxT, K, Kt)
>
> What I would like to do is find something that returns:
>
> rate ~ (Vmax + VmaxT*state) * conc/(K + Kt * state + conc)
>
> Is there a way to extract this? Please advise. Thanks for your time.
>
> Steve
> 860-441-3435
More information about the R-help
mailing list