An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120406/4a03c195/attachment.pl>
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:
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)
Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com
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
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)))
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
4 days later
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120412/b4348140/attachment.pl>