[R] nls and if statements

DWatts tropical at ufl.edu
Thu May 17 17:40:39 CEST 2012


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.24,12.49,2.37,3.28,4.3,2.61,2.75,2.92,3.78,2.25,2.84,3.33,2.39)
Tsoil=c(30.01,27.72,34.91,21.96,22.83,29.65,20.56,23.72,33.96,31.57,19.15,28.49,30.02,20.14,30.23,33.99,32.58,17.87,19.78)
Pw=c(30,29,24,22,22,41.2,-33.1,-49.21,29.6,24.5,-6.1544,42.8,63,55.5,43.3,38.5,87.2,-0.32,79.5)

Rui's code seems to elegantly do what I was attempting (and will try the
Boolian version next), but I'm having initial parameterization problems.
I've tried doing what I've done before, which is use the excel solver to
give me some simple early estimates of params, but it doesn't appear to be
helping in this case. 

nlstest=nls(Cfl~K*ifelse(Pw > z, 1, exp(-a*Tsoil))*exp(-b*Pw)+c,
	start=c(K=0.14, a=0.01, b=0.04, c=3.5, z=5), trace=T) 

I'll keep chugging away at this. Thank you for your help!



--
View this message in context: http://r.789695.n4.nabble.com/nls-and-if-statements-tp4630391p4630410.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list