The R Project SVN R

Rev

Rev 68948 | Rev 85996 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 68948 Rev 73628
Line 1... Line 1...
1
% File src/library/stats/man/SSfpl.Rd
1
% File src/library/stats/man/SSfpl.Rd
2
% Part of the R package, https://www.R-project.org
2
% Part of the R package, https://www.R-project.org
3
% Copyright 1995-2010 R Core Team
3
% Copyright 1995-2017 R Core Team
4
% Distributed under GPL 2 or later
4
% Distributed under GPL 2 or later
5
 
5
 
6
\name{SSfpl}
6
\name{SSfpl}
7
\encoding{UTF-8}
-
 
8
\title{Self-Starting Nls Four-Parameter Logistic Model}
7
\title{Self-Starting Nls Four-Parameter Logistic Model}
-
 
8
\alias{SSfpl}
-
 
9
\encoding{UTF-8}
9
\usage{
10
\usage{
10
SSfpl(input, A, B, xmid, scal)
11
SSfpl(input, A, B, xmid, scal)
11
}
12
}
12
\alias{SSfpl}
-
 
13
\arguments{
13
\arguments{
14
 \item{input}{a numeric vector of values at which to evaluate the model.}
14
 \item{input}{a numeric vector of values at which to evaluate the model.}
15
 \item{A}{a numeric parameter representing the horizontal asymptote on
15
 \item{A}{a numeric parameter representing the horizontal asymptote on
16
   the left side (very small values of \code{input}).}
16
   the left side (very small values of \code{input}).}
17
 \item{B}{a numeric parameter representing the horizontal asymptote on
17
 \item{B}{a numeric parameter representing the horizontal asymptote on
Line 21... Line 21...
21
   midway between \code{A} and \code{B} at \code{xmid}.}
21
   midway between \code{A} and \code{B} at \code{xmid}.}
22
 \item{scal}{a numeric scale parameter on the \code{input} axis.}
22
 \item{scal}{a numeric scale parameter on the \code{input} axis.}
23
}
23
}
24
\description{
24
\description{
25
  This \code{selfStart} model evaluates the four-parameter logistic
25
  This \code{selfStart} model evaluates the four-parameter logistic
26
  function and its gradient.  It has an \code{initial} attribute that
26
  function and its gradient.  It has an \code{initial} attribute computing
27
  will evaluate initial estimates of the parameters \code{A}, \code{B},
27
  initial estimates of the parameters \code{A}, \code{B},
28
  \code{xmid}, and \code{scal} for a given set of data.
28
  \code{xmid}, and \code{scal} for a given set of data.
29
}
29
}
30
\value{
30
\value{
31
  a numeric vector of the same length as \code{input}.  It is the value of
31
  a numeric vector of the same length as \code{input}.  It is the value of
32
  the expression \code{A+(B-A)/(1+exp((xmid-input)/scal))}.  If all of
32
  the expression \code{A+(B-A)/(1+exp((xmid-input)/scal))}.  If all of
Line 38... Line 38...
38
\seealso{\code{\link{nls}}, \code{\link{selfStart}}
38
\seealso{\code{\link{nls}}, \code{\link{selfStart}}
39
}
39
}
40
\examples{
40
\examples{
41
Chick.1 <- ChickWeight[ChickWeight$Chick == 1, ]
41
Chick.1 <- ChickWeight[ChickWeight$Chick == 1, ]
42
SSfpl(Chick.1$Time, 13, 368, 14, 6)  # response only
42
SSfpl(Chick.1$Time, 13, 368, 14, 6)  # response only
-
 
43
local({
43
A <- 13; B <- 368; xmid <- 14; scal <- 6
44
  A <- 13; B <- 368; xmid <- 14; scal <- 6
44
SSfpl(Chick.1$Time, A, B, xmid, scal) # response and gradient
45
  SSfpl(Chick.1$Time, A, B, xmid, scal) # response _and_ gradient
-
 
46
})
45
print(getInitial(weight ~ SSfpl(Time, A, B, xmid, scal), data = Chick.1),
47
print(getInitial(weight ~ SSfpl(Time, A, B, xmid, scal), data = Chick.1),
46
      digits = 5)
48
      digits = 5)
47
## Initial values are in fact the converged values
49
## Initial values are in fact the converged values
48
fm1 <- nls(weight ~ SSfpl(Time, A, B, xmid, scal), data = Chick.1)
50
fm1 <- nls(weight ~ SSfpl(Time, A, B, xmid, scal), data = Chick.1)
49
summary(fm1)
51
summary(fm1)
50
\dontshow{
-
 
51
require(graphics)
-
 
52
 
52
 
-
 
53
## Visualizing the  SSfpl()  parametrization
53
  xx <- seq(-0.5, 5, len = 101)
54
  xx <- seq(-0.5, 5, len = 101)
54
  yy <- 1 + 4 / ( 1 + exp((2-xx)))
55
  yy <- 1 + 4 / (1 + exp((2-xx))) # == SSfpl(xx, *) :
-
 
56
  stopifnot( all.equal(yy, SSfpl(xx, A = 1, B = 5, xmid = 2, scal = 1)) )
-
 
57
  require(graphics)
55
  par(mar = c(0, 0, 3.5, 0))
58
  op <- par(mar = c(0, 0, 3.5, 0))
56
  plot(xx, yy, type = "l", axes = FALSE, ylim = c(0,6), xlim = c(-1, 5),
59
  plot(xx, yy, type = "l", axes = FALSE, ylim = c(0,6), xlim = c(-1, 5),
57
       xlab = "", ylab = "", lwd = 2,
60
       xlab = "", ylab = "", lwd = 2,
58
       main = "Parameters in the SSfpl model")
61
       main = "Parameters in the SSfpl model")
-
 
62
  mtext(quote(list(phi[1] == "A", phi[2] == "B", phi[3] == "xmid", phi[4] == "scal")))
59
  usr <- par("usr")
63
  usr <- par("usr")
60
  arrows(usr[1], 0, usr[2], 0, length = 0.1, angle = 25)
64
  arrows(usr[1], 0, usr[2], 0, length = 0.1, angle = 25)
61
  arrows(0, usr[3], 0, usr[4], length = 0.1, angle = 25)
65
  arrows(0, usr[3], 0, usr[4], length = 0.1, angle = 25)
62
  text(usr[2] - 0.2, 0.1, "x", adj = c(1, 0))
66
  text(usr[2] - 0.2, 0.1, "x", adj = c(1, 0))
63
  text(-0.1, usr[4], "y", adj = c(1, 1))
67
  text(     -0.1, usr[4], "y", adj = c(1, 1))
64
  abline(h = 5, lty = 2, lwd = 0)
68
  abline(h = c(1, 5), lty = 3)
65
  arrows(-0.8, 2.1, -0.8, 0, length = 0.1, angle = 25)
69
  arrows(-0.8, c(2.1, 2.9),
66
  arrows(-0.8, 2.9, -0.8, 5, length = 0.1, angle = 25)
70
         -0.8, c(0,   5  ), length = 0.1, angle = 25)
67
  text(-0.8, 2.5, expression(phi[1]), adj = c(0.5, 0.5))
71
  text  (-0.8, 2.5, quote(phi[1]))
68
  abline(h = 1, lty = 2, lwd = 0)
72
  arrows(-0.3, c(1/4, 3/4),
69
  arrows(-0.3, 0.25, -0.3, 0, length = 0.07, angle = 25)
73
         -0.3, c(0,   1  ), length = 0.07, angle = 25)
70
  arrows(-0.3, 0.75, -0.3, 1, length = 0.07, angle = 25)
74
  text  (-0.3, 0.5, quote(phi[2]))
71
  text(-0.3, 0.5, expression(phi[2]), adj = c(0.5, 0.5))
75
  text(2, -.1, quote(phi[3]))
72
  segments(2, 0, 2, 3.3, lty = 2, lwd = 0.75)
76
  segments(c(2,3,3), c(0,3,4), # SSfpl(x = xmid = 2) = 3
73
  text(2, 3.3, expression(phi[3]), adj = c(0.5, 0))
-
 
74
  segments(3, 1+4/(1+exp(-1)) - 0.025, 3, 2.5, lty = 2, lwd = 0.75)
77
           c(2,3,2), c(3,4,3),    lty = 2, lwd = 0.75)
75
  arrows(2.3, 2.7, 2.0, 2.7, length = 0.08, angle = 25)
78
  arrows(c(2.3, 2.7), 3,
76
  arrows(2.7, 2.7, 3.0, 2.7, length = 0.08, angle = 25)
79
         c(2.0, 3  ), 3, length = 0.08, angle = 25)
77
  text(2.5, 2.7, expression(phi[4]), adj = c(0.5, 0.5))
80
  text(      2.5,     3, quote(phi[4])); text(3.1, 3.5, "1")
78
}
81
  par(op)
79
}
82
}
80
\keyword{models}
83
\keyword{models}