The R Project SVN R

Rev

Rev 61160 | Rev 68948 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
42333 ripley 1
% File src/library/stats/man/makepredictcall.Rd
2
% Part of the R package, http://www.R-project.org
59039 ripley 3
% Copyright 1995-2010 R Core Team
42333 ripley 4
% Distributed under GPL 2 or later
5
 
27442 ripley 6
\name{makepredictcall}
56186 murdoch 7
\alias{makepredictcall}
27442 ripley 8
\alias{makepredictcall.default}
9
\alias{SafePrediction}
10
\title{Utility Function for Safe Prediction}
11
\description{
12
  A utility to help \code{\link{model.frame.default}} create the right
13
  matrices when predicting from models with terms like \code{poly} or
61433 ripley 14
  \code{ns}.
27442 ripley 15
}
16
\usage{
17
makepredictcall(var, call)
18
}
19
\arguments{
20
  \item{var}{A variable.}
21
  \item{call}{The term in the formula, as a call.}
22
}
23
\details{
24
  This is a generic function with methods for \code{poly}, \code{bs} and
25
  \code{ns}: the default method handles \code{scale}.  If
26
  \code{model.frame.default} encounters such a term when
27
  creating a model frame, it modifies the \code{predvars} attribute of
51111 ripley 28
  the terms supplied by replacing the term with one which will work for
27442 ripley 29
  predicting new data.  For example \code{makepredictcall.ns} adds
30
  arguments for the knots and intercept.
31
 
32
  To make use of this, have your model-fitting function return the
33
  \code{terms} attribute of the model frame, or copy the \code{predvars}
34
  attribute of the \code{terms} attribute of the model frame to your
35
  \code{terms} object.
36
 
37
  To extend this, make sure the term creates variables with a class,
38
  and write a suitable method for that class.
39
}
40
\value{
41
  A replacement for \code{call} for the \code{predvars} attribute of
42
  the terms.
43
}
44
\seealso{
31094 ripley 45
  \code{\link{model.frame}}, \code{\link{poly}}, \code{\link{scale}};
51111 ripley 46
  \code{\link{bs}} and \code{\link{ns}} in package \pkg{splines}.
61433 ripley 47
 
51111 ripley 48
  \code{\link{cars}} for an example of prediction from a polynomial fit.
27442 ripley 49
}
50
\examples{
41508 ripley 51
require(graphics)
52
 
27442 ripley 53
## using poly: this did not work in R < 1.5.0
54
fm <- lm(weight ~ poly(height, 2), data = women)
55
plot(women, xlab = "Height (in)", ylab = "Weight (lb)")
56
ht <- seq(57, 73, len = 200)
61160 ripley 57
lines(ht, predict(fm, data.frame(height = ht)))
27442 ripley 58
 
59
## see also example(cars)
60
 
61
## see bs and ns for spline examples.
62
}
63
\keyword{models}