predict.glmrob: Predict Method for Robust GLM ("glmrob") Fits

Description Usage Arguments Value Author(s) See Also Examples

View source: R/glmrobPredict.R

Description

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

Usage

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

Arguments

object

a fitted object of class inheriting from "glmrob".

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.

...

optional further arguments, currently simply passed to predict.lmrob().

Value

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.

Author(s)

Andreas Ruckstuhl

See Also

glmrob() to fit these robust GLM models, residuals.glmrob() and other methods; predict.lm(), the method used for a non-robust fit.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
data(carrots)
## simplistic testing & training:
i.tr <- sample(24, 20)
fm1 <- glmrob(cbind(success, total-success) ~ logdose + block,
              family = binomial, data = carrots, subset = i.tr)
fm1
predict(fm1, carrots[-i.tr, ]) # --> numeric vector
predict(fm1, carrots[-i.tr, ],
        type="response", se = TRUE)# -> a list





data(vaso)
Vfit <- glmrob(Y ~ log(Volume) + log(Rate), family=binomial, data=vaso)
newd <- expand.grid(Volume = (V. <- seq(.5, 4, by = 0.5)),
                    Rate   = (R. <- seq(.25,4, by = 0.25)))
p <- predict(Vfit, newd)
filled.contour(V., R., matrix(p, length(V.), length(R.)),
      main = "predict(glmrob(., data=vaso))", xlab="Volume", ylab="Rate")

Example output

Call:  glmrob(formula = cbind(success, total - success) ~ logdose +      block, family = binomial, data = carrots, subset = i.tr) 

Coefficients:
(Intercept)      logdose      blockB2      blockB3  
     3.1935      -2.5095       0.1538      -0.4529  

Number of observations: 20 
Fitted by method  'Mqle' 
        4         5        15        16 
-1.524378 -1.825518 -2.273959 -2.575099 
$fit
         4          5         15         16 
0.17881776 0.13877310 0.09330277 0.07075832 

$se.fit
         4          5         15         16 
0.02692593 0.02419306 0.02177522 0.01972411 

$residual.scale
[1] 1

Warning message:
In glmrobMqle(X = X, y = Y, weights = weights, start = start, offset = offset,  :
  fitted probabilities numerically 0 or 1 occurred

robustbase documentation built on Sept. 21, 2018, 6:26 p.m.