Manuel.A.Morales at williams.edu
2009-Feb-19 19:55 UTC
[Rd] bugfix for nls with port algorithm (PR#13540)
Full_Name: Manuel A. Morales Version: 2.8.1 OS: Linux Submission from: (NULL) (137.165.199.246) When fitting a model in nls using the algorithm port with constraints and the shorthand parameter[factor] in the model, I get the following error message: "Error in nls_port_fit(m, start, lower, upper, control, trace) : (list) object cannot be coerced to type 'double' In addition: Warning message: In start < low : longer object length is not a multiple of shorter object length" This error can be fixed by changing line 423 in nls.R from: if(any(start < low || start > upp)) { to: if(any(unlist(start) < low || unlist(start) > upp)) { The following code will generate the error: x = runif(200) b0 = c(rep(0,100),runif(100)) b1 = 1 fac <- as.factor(rep(c(0,1), each=100)) y = b0+b1*x+rnorm(200,sd=0.05) nls(y~b0[fac]+b1*x, start=list(b0=c(1,1),b1=1), algorithm="port", upper=c(100,100,100)) Manuel
> -----Original Message----- > From: r-devel-bounces at r-project.org > [mailto:r-devel-bounces at r-project.org] On Behalf Of > Manuel.A.Morales at williams.edu > Sent: Thursday, February 19, 2009 11:55 AM > To: r-devel at stat.math.ethz.ch > Cc: R-bugs at r-project.org > Subject: [Rd] bugfix for nls with port algorithm (PR#13540) > > Full_Name: Manuel A. Morales > Version: 2.8.1 > OS: Linux > Submission from: (NULL) (137.165.199.246) > > > When fitting a model in nls using the algorithm port with > constraints and the > shorthand parameter[factor] in the model, I get the following > error message: > > "Error in nls_port_fit(m, start, lower, upper, control, trace) : > (list) object cannot be coerced to type 'double' > In addition: Warning message: > In start < low : > longer object length is not a multiple of shorter object length" > > This error can be fixed by changing line 423 in nls.R from: > > if(any(start < low || start > upp)) { > > to: > > if(any(unlist(start) < low || unlist(start) > upp)) {The || should be changed to | or this should be converted to 2 calls to any() joined by a ||. (I prefer the latter.) Otherwise you get no notice that your start value is out of bounds in many cases. E.g., with your data and fix the following ought to complain: nls(y~b0[fac]+b1*x, start=list(b0=c(1,-1),b1=101), algorithm="port", upper=c(100,100,100), lower=c(0,0,0)) Changing that line to if (any(unlist(start) < low) || any(unlist(start) > upp)) { makes it give a proper complaint: > nls(y~b0[fac]+b1*x, start=list(b0=c(1,-1),b1=101), algorithm="port", + upper=c(100,100,100), lower=c(0,0,0)) Error in nls(y ~ b0[fac] + b1 * x, start = list(b0 = c(1, -1), b1 101), : Convergence failure: initial par violates constraints Should '||' and '&&' warn if their arguments are not scalar (or perhaps 0-long also)? The related 'if' does: > if(c(TRUE,FALSE)) cat("yes\n") else cat("no\n") yes Warning message: In if (c(TRUE, FALSE)) cat("yes\n") else cat("no\n") : the condition has length > 1 and only the first element will be used Bill Dunlap TIBCO Software Inc - Spotfire Division wdunlap tibco.com> > The following code will generate the error: > x = runif(200) > b0 = c(rep(0,100),runif(100)) > b1 = 1 > fac <- as.factor(rep(c(0,1), each=100)) > y = b0+b1*x+rnorm(200,sd=0.05) > nls(y~b0[fac]+b1*x, start=list(b0=c(1,1),b1=1), algorithm="port", > upper=c(100,100,100)) > > Manuel > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >
wdunlap at tibco.com
2009-Feb-19 20:25 UTC
[Rd] bugfix for nls with port algorithm (PR#13540)
> -----Original Message----- > From: r-devel-bounces at r-project.org=20 > [mailto:r-devel-bounces at r-project.org] On Behalf Of=20 > Manuel.A.Morales at williams.edu > Sent: Thursday, February 19, 2009 11:55 AM > To: r-devel at stat.math.ethz.ch > Cc: R-bugs at r-project.org > Subject: [Rd] bugfix for nls with port algorithm (PR#13540) >=20 > Full_Name: Manuel A. Morales > Version: 2.8.1 > OS: Linux > Submission from: (NULL) (137.165.199.246) >=20 >=20 > When fitting a model in nls using the algorithm port with=20 > constraints and the > shorthand parameter[factor] in the model, I get the following=20 > error message: >=20 > "Error in nls_port_fit(m, start, lower, upper, control, trace) :=20 > (list) object cannot be coerced to type 'double' > In addition: Warning message: > In start < low : > longer object length is not a multiple of shorter object length" >=20 > This error can be fixed by changing line 423 in nls.R from: >=20 > if(any(start < low || start > upp)) { >=20 > to: >=20 > if(any(unlist(start) < low || unlist(start) > upp)) {The || should be changed to | or this should be converted to 2 calls to any() joined by a ||. (I prefer the latter.) Otherwise you get no notice that your start value is out of bounds in many cases. E.g., with your data and fix the following ought to complain: nls(y~b0[fac]+b1*x, start=3Dlist(b0=3Dc(1,-1),b1=3D101), algorithm=3D"port", upper=3Dc(100,100,100), lower=3Dc(0,0,0)) Changing that line to if (any(unlist(start) < low) || any(unlist(start) > upp)) { makes it give a proper complaint: > nls(y~b0[fac]+b1*x, start=3Dlist(b0=3Dc(1,-1),b1=3D101), algorithm=3D"port", + upper=3Dc(100,100,100), lower=3Dc(0,0,0)) Error in nls(y ~ b0[fac] + b1 * x, start =3D list(b0 =3D c(1, -1), b1 =3D 101), : Convergence failure: initial par violates constraints Should '||' and '&&' warn if their arguments are not scalar (or perhaps 0-long also)? The related 'if' does: > if(c(TRUE,FALSE)) cat("yes\n") else cat("no\n") yes Warning message: In if (c(TRUE, FALSE)) cat("yes\n") else cat("no\n") : the condition has length > 1 and only the first element will be used Bill Dunlap TIBCO Software Inc - Spotfire Division wdunlap tibco.com=20>=20 > The following code will generate the error: > x =3D runif(200) > b0 =3D c(rep(0,100),runif(100)) > b1 =3D 1 > fac <- as.factor(rep(c(0,1), each=3D100)) > y =3D b0+b1*x+rnorm(200,sd=3D0.05) > nls(y~b0[fac]+b1*x, start=3Dlist(b0=3Dc(1,1),b1=3D1), algorithm=3D"port", > upper=3Dc(100,100,100)) >=20 > Manuel >=20 > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >=20