[R] Running a batch of nls fits.

Douglas Bates bates at stat.wisc.edu
Tue Sep 19 17:31:38 CEST 2000


Peter Dalgaard BSA <p.dalgaard at biostat.ku.dk> writes:

> Jesus Maria Frias Celayeta <iosu at ucc.ie> writes:
> 
> > script, leaving me the morning after with most of the work undone. Is there a
> > way to trap that error in R and make the script continue, so the day after I
> > will have all the fits but the ones that yielded errors (and then I can take
> > care of the faulty ones).
> 
> Look at the help pages for try() and stop()

Also, if you have the data configured as a single data frame with an
indicator of the group you can use the nlsList function from the nlme
library.  In the example below the algorithm fails to converge on the
1989P8 data but continues to fit the rest of the data sets.

 > library(nlme)
 > data(Soybean)
 > formula(Soybean)
 weight ~ Time | Plot
 > fm1 <- nlsList(weight ~ SSlogis(Time, Asym, xmid, scal), data = Soybean)
 Error in qr.solve(QR.B, cc) : singular matrix `a' in solve
 > fm1
 Call:
   Model: weight ~ SSlogis(Time, Asym, xmid, scal) | Plot 
    Data: Soybean 

 Coefficients:
              Asym      xmid      scal
 1988F4  15.151570  52.83412  5.176845
 1988F2  19.745419  56.57506  8.406567
 1988F1  20.338405  57.40242  9.604741
 1988F7  19.871186  56.16156  8.069266
 1988F5  30.648899  64.12997 11.262829
 1988F8  22.777015  59.33030  9.000630
 1988F6  23.293130  59.59761  9.718836
 1988F3  23.697107  56.42460  7.642384
 1988P1  17.300492  48.84945  6.362357
 1988P5  17.703753  51.27156  6.809089
 1988P4  24.008852  57.75117 11.744674
 1988P8  28.249548  62.98009 10.947115
 1988P7  27.485995  61.49839 10.177798
 1988P3  24.938993  56.32519  8.315910
 1988P2  36.660944  66.56061 11.916069
 1988P6 163.701280 104.97325 17.929666
 1989F6   8.509305  55.27330  8.856056
 1989F5   9.669089  51.26708  7.205921
 1989F4  11.247526  53.81049  6.486578
 1989F1  11.251046  56.62629  6.068117
 1989F2  11.233333  52.24016  7.016426
 1989F7  10.071396  51.37755  5.500164
 1989F8  10.609519  47.96772  5.960926
 1989F3  18.419562  66.12355  9.224761
 1989P7  15.471897  46.34313  5.393891
 1989P4  18.177517  57.18040  8.402093
 1989P6  20.498823  58.23817 10.613519
 1989P5  17.891596  54.05667  6.051020
 1989P1  21.683987  59.69306  9.972838
 1989P3  22.283744  53.39564  7.900587
 1989P2  28.296944  67.17502 12.523494
 1989P8         NA        NA        NA
 1990F2  19.459134  66.28547 13.157246
 1990F3  19.867936  58.27752 12.796292
 1990F4  27.435503  70.27178 14.560181
 1990F5  18.719500  51.27603  7.758447
 1990F1  19.790742  55.69341  9.617032
 1990F8  20.290447  55.54950  7.771090
 1990F7  19.835322  54.73622  6.792187
 1990F6  21.197129  54.56187  9.263620
 1990P8  18.513478  52.44788  8.580973
 1990P7  19.160790  54.80237 10.847308
 1990P3  19.198080  49.71494  9.322300
 1990P1  18.448387  47.91708  6.611851
 1990P6  17.689675  50.23027  6.626873
 1990P5  19.544897  51.15028  7.293158
 1990P2  25.787214  62.35962 11.656903
 1990P4  26.128960  61.19892 10.971568

 Degrees of freedom: 404 total; 263 residual
 Residual standard error: 1.043835
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list