predict.lm               package:stats               R Documentation

_P_r_e_d_i_c_t _m_e_t_h_o_d _f_o_r _L_i_n_e_a_r _M_o_d_e_l _F_i_t_s

_D_e_s_c_r_i_p_t_i_o_n:

     Predicted values based on linear model object.

_U_s_a_g_e:

     ## S3 method for class 'lm':
     predict(object, newdata, se.fit = FALSE, scale = NULL, df = Inf, 
             interval = c("none", "confidence", "prediction"),
             level = 0.95, type = c("response", "terms"),
             terms = NULL, na.action = na.pass, ...)

_A_r_g_u_m_e_n_t_s:

  object: Object of class inheriting from '"lm"'

 newdata: An optional data frame in which to look for variables with
          which to predict.  If omitted, the fitted values are used.

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

   scale: Scale parameter for std.err. calculation

      df: Degrees of freedom for scale

interval: Type of interval calculation.  '"prediction"' is only allowed
          if 'newdata' is supplied.

   level: Tolerance/confidence level

    type: Type of prediction (response or model term).

   terms: If 'type="terms"', which terms (default is all terms)

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:

     'predict.lm' produces predicted values, obtained by evaluating the
     regression function in the frame 'newdata' (which defaults to
     'model.frame(object)'.  If the logical 'se.fit' is 'TRUE',
     standard errors of the predictions are calculated.  If the numeric
     argument 'scale' is set (with optional 'df'), it is used as the
     residual standard deviation in the computation of the standard
     errors, otherwise this is extracted from the model fit. Setting
     'intervals' specifies computation of confidence or prediction
     (tolerance) intervals at the specified 'level', sometimes 
     referred to as narrow vs. wide intervals.

     If the fit is rank-deficient, some of the columns of the design
     matrix will have been dropped.  Prediction from such a fit only
     makes sense if 'newdata' is contained in the same subspace as the
     original data.  That cannot be checked accurately, so a warning is
     issued.

     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, standard errors or interval limits), with
     residual value 'NA'.  See also 'napredict'.

     The prediction intervals are for a single observation at each case
     in 'newdata' (which must be supplied) with error variance sigma^2
     as estimated during the fitting.

_V_a_l_u_e:

     'predict.lm' produces a vector of predictions or a matrix of
     predictions and bounds with column names 'fit', 'lwr', and 'upr'
     if 'interval' is set.  If 'se.fit' is 'TRUE', a list with the
     following components is returned:  

     fit: vector or matrix as above

  se.fit: standard error of predicted means

residual.scale: residual standard deviations

      df: degrees of freedom for residual

_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).  As from R 2.0.0 a warning will be given
     if the variables found are not of the same length as those in
     'newdata' if it was supplied.

     Offsets specified by 'offset' in the fit by 'lm' will not be
     included in predictions, whereas those specified by an offset term
     in the formula will be.

_S_e_e _A_l_s_o:

     The model fitting function 'lm', 'predict', 'SafePrediction'

_E_x_a_m_p_l_e_s:

     ## Predictions
     x <- rnorm(15)
     y <- x + rnorm(15)
     predict(lm(y ~ x))
     new <- data.frame(x = seq(-3, 3, 0.5))
     predict(lm(y ~ x), new, se.fit = TRUE)
     pred.w.plim <- predict(lm(y ~ x), new, interval="prediction")
     pred.w.clim <- predict(lm(y ~ x), new, interval="confidence")
     matplot(new$x,cbind(pred.w.clim, pred.w.plim[,-1]),
             lty=c(1,2,2,3,3), type="l", ylab="predicted y")

