[R] nls model parameter compare?

peter dalgaard
Wed, 26 Aug 2015 08:33:08 -0000

On 26 Aug 2015, at 00:34 , Jianling Fan <fanjianling at gmail.com> wrote:

> Hello everyone,
>
> I am doing nonlinear regression using a same sigmoidal model for
> different treatments. for each treatment, I got a set of estimated
> parameters (a1, b1, c1 for treatment 1; a2, b2, c2 for treatment 2;
> a3, b3, c3 for treatment 3). And I want to compare these parameters
> for different treatments to see is there any differences? does
> estimated parameter for treatment i different from other treatments?
>
> How can I do this analysis please?


Notwithstanding possibly well-founded snide remarks from Bert and Rolf...

If we take this as a purely technical question, it might be helpful to notice
that you can do stuff like this:

> plot(y~x,data=dd)
> y1 <- rnorm(10,exp(0.1*x),.1)
> y2 <- rnorm(10,exp(0.2*x),.1)
> y3 <- rnorm(10,exp(0.3*x),.1)
> dd <- data.frame(x=c(x,x,x), y=c(y1,y2,y3), g = factor(rep(1:3,
each=10)))
> plot(y~x, pch=g, data=dd)

> nls(y ~ exp(a[g]*x), data=dd, start=list(a=c(.1,.2,.3)))
Nonlinear regression model
  model: y ~ exp(a[g] * x)
   data: dd
    a1     a2     a3
0.1017 0.2011 0.2997
 residual sum-of-squares: 0.2578

Number of iterations to convergence: 2
Achieved convergence tolerance: 2.678e-06

> m1 <- nls(y ~ exp(a[g]*x), data=dd, start=list(a=c(.1,.2,.3)))
> m2 <- nls(y ~ exp(a*x), data=dd, start=list(a=.2))
> anova(m1,m2)
Analysis of Variance Table

Model 1: y ~ exp(a[g] * x)
Model 2: y ~ exp(a * x)
  Res.Df Res.Sum Sq Df  Sum Sq F value    Pr(>F)
1     27      0.258
2     29    315.326 -2 -315.07   16498 < 2.2e-16 ***
---
Signif. codes:  0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1

I.e.:

1) The principle is to formulate your three separate models as a single model
for _all_ data, with parameters depending on group, then reduce the model by
letting one or more of the parameter sets being a single parameter.

2) The []-notation for group-dependent parameters in nls() is useful and rather
easily overlooked.


--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com