predict.glm              package:stats              R Documentation

_P_r_e_d_i_c_t _M_e_t_h_o_d _f_o_r _G_L_M _F_i_t_s

_D_e_s_c_r_i_p_t_i_o_n:

     Obtains predictions and optionally estimates standard errors of
     those predictions from a fitted generalized linear model object.

_U_s_a_g_e:

     ## S3 method for class 'glm':
     predict(object, newdata = NULL,
                 type = c("link", "response", "terms"),
                 se.fit = FALSE, dispersion = NULL, terms = NULL,
                 na.action = na.pass, ...)

_A_r_g_u_m_e_n_t_s:

  object: a fitted object of class inheriting from '"glm"'.

 newdata: optionally, a data frame in which to look for variables with
          which to predict.  If omitted, the fitted linear predictors
          are used.

    type: the type of prediction required.  The default is on the scale
          of the linear predictors; the alternative '"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. 

  se.fit: logical switch indicating if standard errors are required.

dispersion: the dispersion of the GLM fit to be assumed in computing
          the standard errors.  If omitted, that returned by 'summary'
          applied to the object is used.

   terms: with 'type="terms"' by default all terms are returned. A
          character vector specifies which terms are to be returned

na.action: function determining what should be done with missing values
          in 'newdata'.  The default is to predict 'NA'.

     ...: further arguments passed to or from other methods.

_D_e_t_a_i_l_s:

     If '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'.

_V_a_l_u_e:

     If 'se = FALSE', a vector or matrix of predictions.  If 'se =
     TRUE', a list with components 

     fit: Predictions

  se.fit: Estimated standard errors

residual.scale: A scalar giving the square root of the dispersion used
          in computing the standard errors.

_N_o_t_e:

     Variables are first looked for in 'newdata' and then searched for
     in the usual way (which will include the environment of the
     formula used in the fit).  A warning will be given if the
     variables found are not of the same length as those in 'newdata'
     if it was supplied.

_S_e_e _A_l_s_o:

     'glm', 'SafePrediction'

_E_x_a_m_p_l_e_s:

     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"))

