The R Project SVN R

Rev

Rev 89737 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 89737 Rev 90227
Line 60... Line 60...
60
    the object. Default is \code{FALSE}.}
60
    the object. Default is \code{FALSE}.}
61
  \item{lower, upper}{vectors of lower and upper bounds, replicated to
61
  \item{lower, upper}{vectors of lower and upper bounds, replicated to
62
    be as long as \code{start}.  If unspecified, all parameters are
62
    be as long as \code{start}.  If unspecified, all parameters are
63
    assumed to be unconstrained.  Bounds can only be used with the
63
    assumed to be unconstrained.  Bounds can only be used with the
64
    \code{"port"} algorithm.  They are ignored, with a warning, if given
64
    \code{"port"} algorithm.  They are ignored, with a warning, if given
-
 
65
    for other algorithms. If given as named vectors, they can be reordered to
65
    for other algorithms.}
66
    match the coefficient order.}
66
  \item{\dots}{Additional optional arguments.  None are used at present.}
67
  \item{\dots}{Additional optional arguments.  None are used at present.}
67
}
68
}
68
\details{
69
\details{
69
  An \code{nls} object is a type of fitted model object.  It has methods
70
  An \code{nls} object is a type of fitted model object.  It has methods
70
  for the generic functions \code{\link{anova}}, \code{\link{coef}},
71
  for the generic functions \code{\link{anova}}, \code{\link{coef}},
Line 326... Line 327...
326
## given in a list (with names):
327
## given in a list (with names):
327
b <- coef(musc.1)
328
b <- coef(musc.1)
328
musc.2 <- nls(Length ~ a[Strip] + b[Strip]*exp(-Conc/th), MASS::muscle,
329
musc.2 <- nls(Length ~ a[Strip] + b[Strip]*exp(-Conc/th), MASS::muscle,
329
              start = list(a = rep(b[2], 21), b = rep(b[3], 21), th = b[1]))
330
              start = list(a = rep(b[2], 21), b = rep(b[3], 21), th = b[1]))
330
summary(musc.2)
331
summary(musc.2)
-
 
332
 
-
 
333
## Example with constraint, using "port" algorithm. Also showing possibility
-
 
334
## for reordering if using named vector for lower=
-
 
335
dd <- structure(list(time = c(1L, 2L, 3L, 6L, 12L, 24L, 48L), y = c(1.95, 
-
 
336
6.43, 10.39, 27.01, 113.72, 251.14, 314.22)), row.names = c(NA, 
-
 
337
-7L), class = "data.frame")
-
 
338
 
-
 
339
st0 <- list(Max = 200, k = 0.1, Lag = 0.5)
-
 
340
lwr <- c(k = 0.1, Max =-Inf, Lag = -Inf)
-
 
341
form <- y ~ (time > Lag) * Max * (1-exp(-k * (time - Lag)))
-
 
342
m1 <- nls(form,
-
 
343
    data = dd,
-
 
344
    algorithm="port",
-
 
345
    lower = lwr,
-
 
346
    start = st0)
-
 
347
stopifnot(coef(m1)[["k"]] >= lwr[["k"]])
-
 
348
 
331
})
349
})
332
}
350
}
333
\dontshow{options(od)}
351
\dontshow{options(od)}
334
}
352
}
335
\keyword{nonlinear}
353
\keyword{nonlinear}