The R Project SVN R

Rev

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

Rev 72924 Rev 74690
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, https://www.R-project.org
2
% Part of the R package, https://www.R-project.org
3
% Copyright 1995-2017 R Core Team
3
% Copyright 1995-2018 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 71... Line 71...
71
## To see what knots were selected
71
## To see what knots were selected
72
attr(terms(fm1), "predvars")
72
attr(terms(fm1), "predvars")
73
 
73
 
74
## example of safe prediction
74
## example of safe prediction
75
plot(women, xlab = "Height (in)", ylab = "Weight (lb)")
75
plot(women, xlab = "Height (in)", ylab = "Weight (lb)")
76
ht <- seq(57, 73, length.out = 200)
76
ht <- seq(57, 73, length.out = 200) ; nD <- data.frame(height = ht)
77
lines(ht, predict(fm1, data.frame(height = ht)))
77
lines(ht, p1 <- predict(fm1, nD))
-
 
78
stopifnot(all.equal(p1, predict(update(fm1, . ~
-
 
79
                            splines::ns(height, df=5)), nD)))
-
 
80
          # not true in R < 3.5.0
78
\dontshow{
81
\dontshow{
79
## Consistency:
82
## Consistency:
80
x <- c(1:3, 5:6)
83
x <- c(1:3, 5:6)
81
stopifnot(identical(ns(x), ns(x, df = 1)),
84
stopifnot(identical(ns(x), ns(x, df = 1)),
-
 
85
          identical(ns(x, df = 2),
82
          identical(ns(x, df = 2), ns(x, df = 2, knots = NULL)), # not true till 2.15.2
86
                    ns(x, df = 2, knots = NULL)), # not true till 2.15.2
83
          !is.null(kk <- attr(ns(x), "knots")), # not true till 1.5.1
87
          !is.null(kk <- attr(ns(x), "knots")), # not true till 1.5.1
84
          length(kk) == 0)
88
          length(kk) == 0)
85
}
89
}
86
}
90
}
87
\keyword{smooth}
91
\keyword{smooth}