Re: [R] nls and if statements

2012-05-18 Thread John C Nash
Your issue is that nls returns "singular gradient", but I believe the real trouble is that if or ifelse are not in the derivatives table. My own (experimental, but in R-forge) package nlmrt has nlxb to mirror nls but be much more aggressive in finding a solution, and it gives an error msg that i

Re: [R] nls and if statements

2012-05-17 Thread DWatts
Peter Ehlers wrote > > >> > > If the above data is all you have, I wouldn't chugg too long. > Looking at plots of Cfl~Pw and Cfl~Tsoil says to me that you > have far too much variability to fit your model. > > You might find this plot instructive: > >library(rgl) >plot3d(Pw, Tsoil, Cf

Re: [R] nls and if statements

2012-05-17 Thread Peter Ehlers
On 2012-05-17 08:40, DWatts wrote: David Winsemius wrote and provide commented, minimal, self-contained, reproducible code. Still untested in absence of data. Thank you, and my apologies for not giving some sample numbers. Below is a short subset of the data set I'm working with. Cfl=c

Re: [R] nls and if statements

2012-05-17 Thread Rui Barradas
Hello, I don't know if this is what you want, but your formula is equivalent to nlstest=nls(Cfl~K*ifelse(Pw > z, 1, exp(-a*Tsoil))*exp(-b*Pw)+c ,start=c(K=5.5, a=0.1, b=0.1, c=2, z=5)) Hope this helps, Rui Barradas -- View this message in context: http://r.789695.n4.nabble.com/nls-a

Re: [R] nls and if statements

2012-05-17 Thread DWatts
David Winsemius wrote > >>> and provide commented, minimal, self-contained, reproducible code. >> > Still untested in absence of data. > Thank you, and my apologies for not giving some sample numbers. Below is a short subset of the data set I'm working with. Cfl=c(2.61,4.21,2,2.75,7.47,1.2,3.2

Re: [R] nls and if statements

2012-05-17 Thread David Winsemius
On May 17, 2012, at 11:08 AM, David Winsemius wrote: On May 17, 2012, at 10:06 AM, DWatts wrote: Hi All, I have a situation where I want an 'if' variable to be parameterized. It's entirely possible that the way I'm trying to do this is wrong, especially given the error message I get tha

Re: [R] nls and if statements

2012-05-17 Thread David Winsemius
On May 17, 2012, at 10:06 AM, DWatts wrote: Hi All, I have a situation where I want an 'if' variable to be parameterized. It's entirely possible that the way I'm trying to do this is wrong, especially given the error message I get that indicates I can't do this using an 'if' statement.

[R] nls and if statements

2012-05-17 Thread DWatts
Hi All, I have a situation where I want an 'if' variable to be parameterized. It's entirely possible that the way I'm trying to do this is wrong, especially given the error message I get that indicates I can't do this using an 'if' statement. Essentially, I have data where I think a relationship