SSquadpq: self start for quadratic-plateau-quadratic function (xs)

SSquadpqR Documentation

self start for quadratic-plateau-quadratic function (xs)

Description

Self starter for quadratic plateau function with (four) parameters a (intercept), b (slope), xs (break-point), ldxs (log of the difference between break-point and second break-point)

Usage

quadpq(x, a, b, xs, ldxs)

SSquadpq(x, a, b, xs, ldxs)

Arguments

x

input vector

a

the intercept

b

the slope

xs

break-point

ldxs

log of the difference between break-point and second break-point

Details

The equation is, for a response (y) and a predictor (x):
y ~ (x <= xs) * (a + b * x + (-0.5 * b/xs) * x^2) + (x > xs & x <= (xs + dxs)) * (a + (-b^2)/(4 * -0.5 * b/xs)) + (x > (xs + dxs)) * ((a + (-b^2)/(4 * -0.5 * b/xs)) + ((-0.5 * b/xs) * (x - (xs + dxs))^2))

This is a somewhat complicated equation. The interpretation of the parameters are simple. The model is parameterized in terms of the log of dxs (or ldxs). The parameter is ensured to be positive by taking the exponential.

Value

a numeric vector of the same length as x containing parameter estimates for equation specified

quadpq: vector of the same length as x using the quadratic-plateau-quadratic function

Examples


require(ggplot2)
set.seed(123)
x <- 0:25
y <- quadpq(x, 1, 0.5, 10, 1.5) + rnorm(length(x), 0, 0.3)
dat <- data.frame(x = x, y = y)
fit <- nls(y ~ SSquadpq(x, a, b, xs, dxs), data = dat)
## plot
ggplot(data = dat, aes(x = x, y = y)) + 
  geom_point() + 
  geom_line(aes(y = fitted(fit))) + 
  geom_vline(aes(xintercept = coef(fit)[3]), linetype = 2) +
  geom_vline(aes(xintercept = coef(fit)[3] + exp(coef(fit)[4])), linetype = 3)
     


femiguez/nlraa documentation built on April 12, 2025, 12:37 p.m.