[R] quadratic model with plateau

Gabor Grothendieck ggrothendieck at gmail.com
Sun Apr 8 01:25:18 CEST 2012


Yes, I had fixed that on my end but didn't notice I had copied the old
version.  I think its obvious enough that anyone will fix it
themselves.  Regards.

On Sat, Apr 7, 2012 at 7:23 PM, Rolf Turner <rolf.turner at xtra.co.nz> wrote:
>
> One other minor glitch I just noticed:
>
>    x <- seq_along(x)
>
> should read
>
>    x <- seq_along(y)
>
>    cheers,
>
>        Rolf
>
>
> On 08/04/12 10:08, Gabor Grothendieck wrote:
>>
>> On Sat, Apr 7, 2012 at 3:58 PM, Gabor Grothendieck
>> <ggrothendieck at gmail.com>  wrote:
>>>
>>> On Fri, Apr 6, 2012 at 9:42 PM, help ly<help.ly2005 at gmail.com>  wrote:
>>>>
>>>> Dear All,
>>>>
>>>> I would like to make a quadratic with a plateau model in R. Is there a
>>>> package in R doing this? The bentcableAR package seems won't work.
>>>>
>>>> The link below describes what I am looking for in R exactly:
>>>>
>>>> http://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/viewer.htm#statug_nlin_sect033.htm
>>>>
>>> Use nls directly:
>>>
>>> y<- c(0.46, 0.47, 0.57, 0.61, 0.62, 0.68, 0.69, 0.78, 0.7, 0.74,
>>> 0.77, 0.78, 0.74, 0.8, 0.8, 0.78)
>>> x<- seq_along(x)
>>>
>>> Mean<- function(x, alpha, beta, gamma) {
>>>   pmin(alpha + beta*x + gamma*x*x, alpha - beta^2/(4 * gamma))
>>> }
>>> fm<- nls(y ~ Mean(x, alpha, beta, gamma), start = list(alpha = 0.45,
>>> beta = 0.05, gamma = -0.0025))
>>> fm
>>> summary(fm)
>>>
>>> plot(y ~ x)
>>> lines(fitted(fm) ~ x)
>>
>> It was pointed out to me offline that Mean as defined above is not
>> identical to the definition in the poster's link.  Here is a revision:
>>
>> y<- c(0.46, 0.47, 0.57, 0.61, 0.62, 0.68, 0.69, 0.78, 0.7, 0.74,
>> 0.77, 0.78, 0.74, 0.8, 0.8, 0.78)
>> x<- seq_along(x)
>>
>> Mean<- function(x, alpha, beta, gamma) {
>>        ifelse(x<  -beta/(2 * gamma), alpha + beta*x + gamma*x*x,
>>                alpha - beta^2/(4 * gamma))
>> }
>> fm<- nls(y ~ Mean(x, alpha, beta, gamma), start = list(alpha = 0.45,
>> beta = 0.05, gamma = -0.0025))
>> fm
>> summary(fm)
>>
>> plot(y ~ x)
>> lines(fitted(fm) ~ x)
>> with(as.list(coef(fm)), abline(v = -beta/(2 * gamma)))
>>
>>
>



-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list