RE: [R] nls segmented model with unknown joint points

From: andy <afinley_at_gis.umn.edu>
Date: Sun 17 Apr 2005 - 14:41:03 EST

Thank you very much Dr. Venables, I'll give this a try. Regards-
andy

On Sun, 2005-04-17 at 13:36 +1000, Bill.Venables@csiro.au wrote:
> This is how I'd write the formula for use with nls/nlme:
>
> y ~ b41*(x - 1) + b42*(x^2 - 1) +
> ifelse((a41 - x) >= 0, b43*(a41 - x)^2, 0) +
> ifelse((a42 - x) >= 0, b44*(a42 - x)^2, 0)
>
> This is a direct translation from your funny foreign-looking code below
> that probably makes it clear what's going on. A more swish R form might
> be
>
> y ~ b41*(x - 1) + b42*(x^2 - 1) +
> b43*pmax(a41 - x, 0)^2 + b44*pmax(a42 - x, 0)^2
>
> You mention nlm, too. Here you would use a function rather than a
> formula, but the idea is the same.
>
> V.
>
> -----Original Message-----
> From: r-help-bounces@stat.math.ethz.ch
> [mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of andy
> Sent: Sunday, 17 April 2005 1:09 PM
> To: r-help@stat.math.ethz.ch
> Subject: [R] nls segmented model with unknown joint points
>
>
> Hello,
>
> I am interested in fitting a segmented model with unknown joint points
> in nls and perhaps eventually in nlme. I can fit this model in sas (see
> below, joint points to be estimated are a41 and a41), but am unsure how
> to specify this in the nlm function. I would really appreciate any
> suggestions or example code. Thanks a lot. -andy
>
> proc nlin data=Stems.Trees;
> params b41=-3 b42=1.5 b43=-1.5 b44=50 a41=0.75 a42=0.1;
>
> term1 = (b41*(x - 1) + b42*(x**2 -1));
>
> if (a41 - x) >= 0 then
> term2 = (b43*(a41 - x)**2);
> else
> term2 = 0;
>
> if (a42 - x) >=0 then
> term3 = (b44*(a42 - x)**2);
> else
> term3 = 0;
>
> model y = term1+term2+term3;
> run;
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sun Apr 17 14:48:51 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:13 EST