
Last chance! 50% off unlimited learning
Sale ends in
# S3 method for glm
predict(object, newdata = NULL,
type = c("link", "response", "terms"),
se.fit = FALSE, dispersion = NULL, terms = NULL,
na.action = na.pass, …)
"glm"
."response"
is on the scale of the response variable. Thus for a default
binomial model the default predictions are of log-odds (probabilities
on logit scale) and type = "response"
gives the predicted
probabilities. The "terms"
option returns a matrix giving the
fitted values of each term in the model formula on the linear predictor
scale.The value of this argument can be abbreviated.
summary
applied to the object is used.type = "terms"
by default all terms are returned.
A character vector specifies which terms are to be returnednewdata
. The default is to predict NA
.se.fit = FALSE
, a vector or matrix of predictions.
For type = "terms"
this is a matrix with a column per term, and
may have an attribute "constant"
. If se.fit = TRUE
, a list with components
se.fit = FALSE
.newdata
is omitted the predictions are based on the data
used for the fit. In that case how cases with missing values in the
original fit is determined by the na.action
argument of that
fit. If na.action = na.omit
omitted cases will not appear in
the residuals, whereas if na.action = na.exclude
they will
appear (in predictions and standard errors), with residual value
NA
. See also napredict
.glm
, SafePrediction
require(graphics)
## example from Venables and Ripley (2002, pp. 190-2.)
ldose <- rep(0:5, 2)
numdead <- c(1, 4, 9, 13, 18, 20, 0, 2, 6, 10, 12, 16)
sex <- factor(rep(c("M", "F"), c(6, 6)))
SF <- cbind(numdead, numalive = 20-numdead)
budworm.lg <- glm(SF ~ sex*ldose, family = binomial)
summary(budworm.lg)
plot(c(1,32), c(0,1), type = "n", xlab = "dose",
ylab = "prob", log = "x")
text(2^ldose, numdead/20, as.character(sex))
ld <- seq(0, 5, 0.1)
lines(2^ld, predict(budworm.lg, data.frame(ldose = ld,
sex = factor(rep("M", length(ld)), levels = levels(sex))),
type = "response"))
lines(2^ld, predict(budworm.lg, data.frame(ldose = ld,
sex = factor(rep("F", length(ld)), levels = levels(sex))),
type = "response"))
Run the code above in your browser using DataLab