Skip to content

quadratic model with plateau

6 messages · help ly, Rolf Turner, Gabor Grothendieck

#
On Fri, Apr 6, 2012 at 9:42 PM, help ly <help.ly2005 at gmail.com> wrote:
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)
#
On Sat, Apr 7, 2012 at 3:58 PM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote:
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)))
#
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:
#
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:

  
    
4 days later