~elachuni/chaid/partykit

« back to all changes in this revision

Viewing changes to partykit/pkg/man/party-predict.Rd

  • Committer: Anthony Lenton
  • Date: 2010-12-07 18:42:51 UTC
  • Revision ID: anthony.lenton@canonical.com-20101207184251-ei0pvabzhjly2ez6
Initial import from svn.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
\name{party-predict}
 
2
\alias{party-predict}
 
3
\alias{predict.party}
 
4
\alias{predict_party}
 
5
\alias{predict_party.default}
 
6
\alias{predict_party.constparty}
 
7
\alias{predict_party.simpleparty}
 
8
\title{ Tree Predictions }
 
9
\description{
 
10
 
 
11
  Compute predictions from \code{party} objects.
 
12
 
 
13
}
 
14
\usage{
 
15
\method{predict}{party}(object, newdata = NULL, ...)
 
16
predict_party(party, id, newdata = NULL, ...)
 
17
\method{predict_party}{default}(party, id, newdata = NULL, ...) 
 
18
\method{predict_party}{constparty}(party, id, newdata = NULL,
 
19
    type = c("response", "prob", "node"), FUN = NULL, 
 
20
    simplify = TRUE, ...)
 
21
\method{predict_party}{simpleparty}(party, id, newdata = NULL,
 
22
    type = c("response", "prob", "node"), ...)
 
23
}
 
24
\arguments{
 
25
  \item{object}{ objects of class \code{\link{party}}. }
 
26
  \item{newdata}{ an optional data frame in which to look for variables with
 
27
          which to predict, if omitted, the fitted values are used.}
 
28
  \item{party}{ objects of class \code{\link{party}}. }
 
29
  \item{id}{ a vector of terminal node identifiers. }
 
30
  \item{type}{ a character string denoting the type of predicted value
 
31
          returned, ignored when argument \code{FUN} is given.  
 
32
          For \code{"response"}, the mean of a numeric response, the predicted
 
33
          class for a categorical response or the median survival time
 
34
          for a censored response is returned. For a categorical response,
 
35
          \code{"prob"} returns the matrix of conditional class probabilities 
 
36
          (\code{simplify = TRUE}) or a list with the conditional
 
37
          class probabilities for each observation (\code{simplify = FALSE}).
 
38
          \code{"node"} returns an integer vector of terminal node
 
39
          identifiers.}
 
40
  \item{FUN}{ a function to compute summary statistics, i.e., constant
 
41
              predictions for each node with argument list \code{(y, w)}
 
42
              where \code{y} is the response and \code{w} are case weights.}
 
43
  \item{simplify}{ a logical indicating whether the resulting list 
 
44
                   of predictions should be converted to a suitable
 
45
                   vector or matrix (if possible).}
 
46
  \item{\dots}{ additional arguments. }
 
47
}
 
48
\details{
 
49
 
 
50
  The \code{\link{predict}} method for \code{\link{party}} objects
 
51
  computes the identifiers of the predicted terminal nodes, either
 
52
  for new data in \code{newdata} or for the learning samples
 
53
  (only possible for objects of class \code{constparty}).
 
54
  These identifiers are delegated to the corresponding
 
55
  \code{predict_party} method which computes (via 
 
56
  \code{FUN} for class \code{constparty})
 
57
  or extracts (class \code{simpleparty}) the actual predictions.
 
58
 
 
59
}
 
60
\value{
 
61
  A list of predictions, possibly simplified to a numeric vector, 
 
62
  numeric matrix or factor.
 
63
}
 
64
\examples{
 
65
 
 
66
  ## fit tree using rpart
 
67
  library("rpart")
 
68
  rp <- rpart(skips ~ Opening + Solder + Mask + PadType + Panel,
 
69
              data = solder, method = 'anova')
 
70
 
 
71
  ## coerce to `constparty'
 
72
  pr <- as.party(rp)
 
73
 
 
74
  ## mean predictions
 
75
  predict(pr, newdata = solder[c(3, 541, 640),])
 
76
 
 
77
  ## terminal node identifiers
 
78
  predict(pr, newdata = solder[c(3, 541, 640),], type = "node")
 
79
 
 
80
  ## median predictions
 
81
  predict(pr, newdata = solder[c(3, 541, 640),], 
 
82
          FUN = function(y, w = 1) median(y))
 
83
 
 
84
}
 
85
\keyword{tree}