[Rd] nls fails with large numbers of variables (PR#9873)

h.y.wong at leeds.ac.uk h.y.wong at leeds.ac.uk
Wed Aug 22 14:48:17 CEST 2007


Full_Name: Yan Wong
Version: 2.5.1
OS: Mac OS X 10.4
Submission from: (NULL) (129.11.77.198)


If nls is called with a large number of variables & parameters (>200), then it
fails because of the default setting of max.names = 200 in the all.vars
function. I guess that nls should either give a meaningful warning ("you can
only have 200 names in an nls formula"), or should not have such a restriction.
If this restriction is kept, for my purposes it would be useful to have a way of
setting max.names in the nls call.

I encountered this in a real dataset, but  an example 

> #nls fails on 100 vars+ 100 params
> d<-data.frame(matrix(runif(100*1000), 1000, 100))
> y <- rowSums(d)+rnorm(1000)
> params <- paste("c", colnames(d), sep=".")
> st <- rep(1,100); names(st) <- params
> nls(as.formula(paste("y ~", paste(params, "*", colnames(d), collapse=" + "))),
data=d, start=st)
Error in eval(expr, envir, enclos) : object "X100" not found


> #works with 50 vars+ 50 params
> d<-data.frame(matrix(runif(100*1000), 1000, 50))
> y <- rowSums(d)+rnorm(1000)
> params <- paste("c", colnames(d), sep=".")
> st <- rep(1,50); names(st) <- params
> nls(as.formula(paste("y ~", paste(params, "*", colnames(d), collapse=" + "))),
data=d, start=st)
Nonlinear regression model
  model:  y ~ c.X1 * X1 + c.X2 * X2 + c.X3 * X3 + c.X4 * X4 + c.X5 * X5 +     
c.X6 * X6 + c.X7 * X7 + c.X8 * X8 + c.X9 * X9 + c.X10 * X10 +      c.X11 * X11 +
c.X12 * X12 + c.X13 * X13 + c.X14 * X14 + c.X15 *      X15 + c.X16 * X16 + c.X17
* X17 + c.X18 * X18 + c.X19 * X19 +      c.X20 * X20 + c.X21 * X21 + c.X22 * X22
+ c.X23 * X23 + c.X24 *      X24 + c.X25 * X25 + c.X26 * X26 + c.X27 * X27 +
c.X28 * X28 +      c.X29 * X29 + c.X30 * X30 + c.X31 * X31 + c.X32 * X32 + c.X33
*      X33 + c.X34 * X34 + c.X35 * X35 + c.X36 * X36 + c.X37 * X37 +      c.X38
* X38 + c.X39 * X39 + c.X40 * X40 + c.X41 * X41 + c.X42 *      X42 + c.X43 * X43
+ c.X44 * X44 + c.X45 * X45 + c.X46 * X46 +      c.X47 * X47 + c.X48 * X48 +
c.X49 * X49 + c.X50 * X50 
   data:  d 
  c.X1   c.X2   c.X3   c.X4   c.X5   c.X6   c.X7   c.X8   c.X9  c.X10  c.X11 
c.X12  c.X13  c.X14  c.X15  c.X16  c.X17  c.X18  c.X19  c.X20  c.X21  c.X22 
c.X23 
0.9400 0.9750 0.9614 1.1029 0.9663 1.1426 1.1534 1.0353 1.0560 0.8258 0.9527
1.1092 0.4769 0.8955 1.0689 0.7415 1.0656 1.0657 1.0430 1.1034 0.9392 1.1177
1.0712 
 c.X24  c.X25  c.X26  c.X27  c.X28  c.X29  c.X30  c.X31  c.X32  c.X33  c.X34 
c.X35  c.X36  c.X37  c.X38  c.X39  c.X40  c.X41  c.X42  c.X43  c.X44  c.X45 
c.X46 
0.8883 0.9722 1.1377 1.1142 0.9033 1.1225 0.7447 1.2757 0.8746 1.1901 1.1669
1.0322 0.9043 1.0546 1.0222 0.9641 1.0834 0.9977 1.0723 0.9720 1.0978 0.9222
0.8162 
 c.X47  c.X48  c.X49  c.X50 
0.8824 1.0690 1.0078 0.9063 
 residual sum-of-squares: 959.4

Number of iterations to convergence: 1 
Achieved convergence tolerance: 1.215e-07



More information about the R-devel mailing list