[R] Question on CAR appendix on NLS

apjaworski@mmm.com apjaworski at mmm.com
Thu Apr 22 17:00:39 CEST 2004






Ajay,

I beleve there is an error in your hand-calculated derivatives.

model = function(beta1, beta2, beta3, time) {
   m = beta1/(1+exp(beta2+beta3*time))
   term = exp(beta2 + beta3*time)
   gradient = cbind((1+term)^-2,   <--------  the exponent should be -1
     -beta1*(1+term)^-2 * term,
     -beta1*(1+term)^-2 * term * time)
   attr(m, 'gradient') <- gradient
   m
 }

Cheers,

Andy

__________________________________
Andy Jaworski
518-1-01
Process Laboratory
3M Corporate Research Laboratory
-----
E-mail: apjaworski at mmm.com
Tel:  (651) 733-6092
Fax:  (651) 736-3122


                                                                           
             Ajay Shah                                                     
             <ajayshah at mayin.o                                             
             rg>                                                        To 
             Sent by:                  r-help <r-help at stat.math.ethz.ch>   
             r-help-bounces at st                                          cc 
             at.math.ethz.ch                                               
                                                                   Subject 
                                       [R] Question on CAR appendix on NLS 
             04/21/2004 11:12                                              
             AM                                                            
                                                                           
                                                                           
                                                                           
                                                                           




The PDF file on the web, which is an appendix on nonlinear regression
associated with the CAR book, is very nice.

When I ran through the code presented there, I found something
odd. The code does a certain model in 3 ways: Vanilla NLS (using
numerical differentation), Analytical derivatives (where the user
supplies the derivatives) and analytical derivatives (using automatic
differentiation). The three results agree, except for the correlation
of parameter estimates :

          beta1   beta2
  beta2 -0.1662                      Numerical derivatives
  beta3  0.9145 -0.5407

  beta2 -0.7950                      Analytical derivatives
  beta3  0.9145 -0.9661

  beta2 -0.1662                      Automatic differentiation
  beta3  0.9145 -0.5407

Is this just a glitch of a small sample, or should I worry? My source
file (which should be the same as John Fox's file; I typed it in while
reading the PDF file, and made minor changes) is attached.

--
Ajay Shah                                                   Consultant
ajayshah at mayin.org                      Department of Economic Affairs
http://www.mayin.org/ajayshah           Ministry of Finance, New Delhi
[attachment "nls.R" deleted by Andrzej P. Jaworski/US-Corporate/3M/US]
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html




More information about the R-help mailing list