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.

Essentially, I have data where I think a relationship enters when a variable (here Pwd) is below some value (z). I don't know that value, so I want to
fit it. The data is Pw, Tsoil, and Cfl.

nlstest=nls(if(Pw>z){Cfl~K*exp(-b*Pw)+c
        }else{
        Cfl~K*(exp(-a*Tsoil))*exp(-b*Pw)+c
        },start=c(K=5.5, a=0.1, b=0.1, c=2, z=5))


Perhaps recasting as Boolean equivalent:

nlstest== <- nls({Cfl~ (Pw>z)*K*exp(-b*Pw)+c) +
                       !(Pw>z)*(K*(exp(-a*Tsoil))*exp(-b*Pw)+c)},
             start=c(K=5.5, a=0.1, b=0.1, c=2, z=5))

and provide commented, minimal, self-contained, reproducible code.

Untested in absence of data.

--

David Winsemius, MD
West Hartford, CT

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to