predict.glm {stats} R Documentation

## Predict Method for GLM Fits

### Description

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

### Usage

```## S3 method for class 'glm'
predict(object, newdata = NULL,
se.fit = FALSE, dispersion = NULL, terms = NULL,
na.action = na.pass, ...)
```

### Arguments

 `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.

### Details

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`.

### Value

If `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

 `fit` Predictions, as for `se.fit = FALSE`. `se.fit` Estimated standard errors. `residual.scale` A scalar giving the square root of the dispersion used in computing the standard errors.

### Note

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.

`glm`, `SafePrediction`

### Examples

```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)))
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")
{"ft_lang_label":"__label__en","ft_lang_prob":0.71826935,"math_prob":0.93912005,"size":2788,"snap":"2021-31-2021-39","text_gpt3_token_len":770,"char_repetition_ratio":0.109913796,"word_repetition_ratio":0.030434782,"special_character_ratio":0.2862267,"punctuation_ratio":0.19097222,"nsfw_num_words":3,"has_unicode_error":false,"math_prob_llama3":0.9937273,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-09-17T13:56:20Z\",\"WARC-Record-ID\":\"<urn:uuid:f64c1154-d36d-4644-ab13-b37883eb32c4>\",\"Content-Length\":\"5956\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:518c2495-94a9-421b-b7a8-ba84be4c60cb>\",\"WARC-Concurrent-To\":\"<urn:uuid:059035f7-430f-43cc-8d24-ce931e2750c6>\",\"WARC-IP-Address\":\"137.208.57.46\",\"WARC-Target-URI\":\"https://search.r-project.org/R/refmans/stats/html/predict.glm.html\",\"WARC-Payload-Digest\":\"sha1:VQQ52F6AUYM7ELO4TJRUNIK2T3VHLSRD\",\"WARC-Block-Digest\":\"sha1:MVOJB75S3HANZ7N6WVW466RMJMXEGXIB\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-39/CC-MAIN-2021-39_segments_1631780055645.75_warc_CC-MAIN-20210917120628-20210917150628-00041.warc.gz\"}"}