| Line 1... |
Line 1... |
| 1 |
% File src/library/splines/man/ns.Rd
|
1 |
% File src/library/splines/man/ns.Rd
|
| 2 |
% Part of the R package, http://www.R-project.org
|
2 |
% Part of the R package, http://www.R-project.org
|
| 3 |
% Copyright 1995-2012 R Core Team
|
3 |
% Copyright 1995-2013 R Core Team
|
| 4 |
% Distributed under GPL 2 or later
|
4 |
% Distributed under GPL 2 or later
|
| 5 |
|
5 |
|
| 6 |
\name{ns}
|
6 |
\name{ns}
|
| 7 |
\alias{ns}
|
7 |
\alias{ns}
|
| 8 |
\title{Generate a Basis Matrix for Natural Cubic Splines}
|
8 |
\title{Generate a Basis Matrix for Natural Cubic Splines}
|
| Line 30... |
Line 30... |
| 30 |
boundary conditions and anchor the B-spline basis (default the range
|
30 |
boundary conditions and anchor the B-spline basis (default the range
|
| 31 |
of the data). If both \code{knots} and \code{Boundary.knots} are
|
31 |
of the data). If both \code{knots} and \code{Boundary.knots} are
|
| 32 |
supplied, the basis parameters do not depend on \code{x}. Data can
|
32 |
supplied, the basis parameters do not depend on \code{x}. Data can
|
| 33 |
extend beyond \code{Boundary.knots}}
|
33 |
extend beyond \code{Boundary.knots}}
|
| 34 |
}
|
34 |
}
|
| 35 |
\value{
|
35 |
\details{
|
| 36 |
A matrix of dimension \code{length(x) * df} where either \code{df} was
|
36 |
\code{ns} is based on the function \code{\link{spline.des}}. It
|
| 37 |
supplied or if \code{knots} were supplied,
|
37 |
generates a basis matrix for representing the family of
|
| 38 |
\code{df = length(knots) + 1 + intercept}.
|
38 |
piecewise-cubic splines with the specified sequence of
|
| 39 |
Attributes are returned that correspond to the arguments to \code{ns},
|
39 |
interior knots, and the natural boundary conditions. These enforce
|
| 40 |
and explicitly give the \code{knots}, \code{Boundary.knots} etc for
|
40 |
the constraint that the function is linear beyond the boundary knots,
|
| 41 |
use by \code{predict.ns()}.
|
41 |
which can either be supplied or default to the extremes of the
|
| - |
|
42 |
data.
|
| 42 |
|
43 |
|
| 43 |
\code{ns()} is based on the function \code{\link{spline.des}}. It
|
44 |
A primary use is in modeling formula to directly specify a
|
| 44 |
generates a basis matrix for representing the family of
|
45 |
natural spline term in a model: see the examples.
|
| - |
|
46 |
}
|
| - |
|
47 |
|
| - |
|
48 |
\value{
|
| 45 |
piecewise-cubic splines with the specified sequence of
|
49 |
A matrix of dimension \code{length(x) * df} where either \code{df} was
|
| 46 |
interior knots, and the natural boundary conditions. These enforce
|
50 |
supplied or if \code{knots} were supplied,
|
| 47 |
the constraint that the function is linear beyond the boundary knots,
|
51 |
\code{df = length(knots) + 1 + intercept}.
|
| 48 |
which can either be supplied, else default to the extremes of the
|
52 |
Attributes are returned that correspond to the arguments to \code{ns},
|
| 49 |
data. A primary use is in modeling formula to directly specify a
|
53 |
and explicitly give the \code{knots}, \code{Boundary.knots} etc for
|
| 50 |
natural spline term in a model.
|
54 |
use by \code{predict.ns()}.
|
| 51 |
}
|
55 |
}
|
| 52 |
\seealso{
|
56 |
\seealso{
|
| 53 |
\code{\link{bs}}, \code{\link{predict.ns}}, \code{\link{SafePrediction}}
|
57 |
\code{\link{bs}}, \code{\link{predict.ns}}, \code{\link{SafePrediction}}
|
| 54 |
}
|
58 |
}
|
| 55 |
\references{
|
59 |
\references{
|
| Line 61... |
Line 65... |
| 61 |
\examples{
|
65 |
\examples{
|
| 62 |
require(stats); require(graphics)
|
66 |
require(stats); require(graphics)
|
| 63 |
ns(women$height, df = 5)
|
67 |
ns(women$height, df = 5)
|
| 64 |
summary(fm1 <- lm(weight ~ ns(height, df = 5), data = women))
|
68 |
summary(fm1 <- lm(weight ~ ns(height, df = 5), data = women))
|
| 65 |
|
69 |
|
| - |
|
70 |
## To see what knots were selected
|
| - |
|
71 |
attr(terms(fm1), "predvars")
|
| - |
|
72 |
|
| 66 |
## example of safe prediction
|
73 |
## example of safe prediction
|
| 67 |
plot(women, xlab = "Height (in)", ylab = "Weight (lb)")
|
74 |
plot(women, xlab = "Height (in)", ylab = "Weight (lb)")
|
| 68 |
ht <- seq(57, 73, length.out = 200)
|
75 |
ht <- seq(57, 73, length.out = 200)
|
| 69 |
lines(ht, predict(fm1, data.frame(height = ht)))
|
76 |
lines(ht, predict(fm1, data.frame(height = ht)))
|
| 70 |
\dontshow{
|
77 |
\dontshow{
|