predictvglm: Predict Method for a VGLM fit

Description Usage Arguments Details Value Warning Note Author(s) References See Also Examples

View source: R/predict.vglm.q

Description

Predicted values based on a vector generalized linear model (VGLM) object.

Usage

1
2
3
4
5
predictvglm(object, newdata = NULL,
            type = c("link", "response", "terms"),
            se.fit = FALSE, deriv = 0, dispersion = NULL,
            untransform = FALSE,
            type.fitted = NULL, percentiles = NULL, ...)

Arguments

object

Object of class inheriting from "vlm", e.g., vglm.

newdata

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

type

The value of this argument can be abbreviated. The type of prediction required. The default is the first one, meaning on the scale of the linear predictors. This should be a n x M matrix.

The alternative "response" is on the scale of the response variable, and depending on the family function, this may or may not be the mean. Often this is the fitted value, e.g., fitted(vglmObject) (see fittedvlm). Note that the response is output from the @linkinv slot, where the eta argument is the n x M matrix of linear predictors.

The "terms" option returns a matrix giving the fitted values of each term in the model formula on the linear predictor scale. The terms have been centered.

se.fit

logical: return standard errors?

deriv

Non-negative integer. Currently this must be zero. Later, this may be implemented for general values.

dispersion

Dispersion parameter. This may be inputted at this stage, but the default is to use the dispersion parameter of the fitted model.

type.fitted

Some VGAM family functions have an argument by the same name. If so, then one can obtain fitted values by setting type = "response" and choosing a value of type.fitted from what's available. If type.fitted = "quantiles" is available then the percentiles argument can be used to specify what quantile values are requested.

percentiles

Used only if type.fitted = "quantiles" is available and is selected.

untransform

Logical. Reverses any parameter link function. This argument only works if type = "link", se.fit = FALSE, deriv = 0. Setting untransform = TRUE does not work for all VGAM family functions; only ones where there is a one-to-one correspondence between a simple link function and a simple parameter might work.

...

Arguments passed into predictvlm.

Details

Obtains predictions and optionally estimates standard errors of those predictions from a fitted vglm object.

This code implements smart prediction (see smartpred).

Value

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

fitted.values

Predictions

se.fit

Estimated standard errors

df

Degrees of freedom

sigma

The square root of the dispersion parameter

Warning

This function may change in the future.

Note

Setting se.fit = TRUE and type = "response" will generate an error.

The arguments type.fitted and percentiles are provided in this function to give more convenience than modifying the extra slot directly.

Author(s)

Thomas W. Yee

References

Yee, T. W. and Hastie, T. J. (2003). Reduced-rank vector generalized linear models. Statistical Modelling, 3, 15–41.

See Also

predict, vglm, predictvlm, smartpred, calibrate.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Illustrates smart prediction
pneumo <- transform(pneumo, let = log(exposure.time))
fit <- vglm(cbind(normal, mild, severe) ~ poly(c(scale(let)), 2),
            propodds, data = pneumo, trace = TRUE, x.arg = FALSE)
class(fit)

(q0 <- head(predict(fit)))
(q1 <- predict(fit, newdata = head(pneumo)))
(q2 <- predict(fit, newdata = head(pneumo)))
all.equal(q0, q1)  # Should be TRUE
all.equal(q1, q2)  # Should be TRUE

head(predict(fit))
head(predict(fit, untransform = TRUE))

p0 <- head(predict(fit, type = "response"))
p1 <- head(predict(fit, type = "response", newdata = pneumo))
p2 <- head(predict(fit, type = "response", newdata = pneumo))
p3 <- head(fitted(fit))
all.equal(p0, p1)  # Should be TRUE
all.equal(p1, p2)  # Should be TRUE
all.equal(p2, p3)  # Should be TRUE

predict(fit, type = "terms", se = TRUE)

Example output

Loading required package: stats4
Loading required package: splines
VGLM    linear loop  1 :  deviance = 4.162527
VGLM    linear loop  2 :  deviance = 3.951629
VGLM    linear loop  3 :  deviance = 3.946558
VGLM    linear loop  4 :  deviance = 3.94655
VGLM    linear loop  5 :  deviance = 3.94655
[1] "vglm"
attr(,"package")
[1] "VGAM"
  logit(P[Y>=2]) logit(P[Y>=3])
1     -6.6420717      -7.540193
2     -2.7470610      -3.645182
3     -1.6175447      -2.515666
4     -0.9547998      -1.852921
5     -0.4876278      -1.385749
6     -0.1414232      -1.039544
  logit(P[Y>=2]) logit(P[Y>=3])
1   -5.773141107     -6.6712621
2   -2.059406372     -2.9575274
3   -1.017291252     -1.9154122
4   -0.420223629     -1.3183446
5   -0.009188218     -0.9073092
6    0.287785773     -0.6103352
  logit(P[Y>=2]) logit(P[Y>=3])
1   -5.773141107     -6.6712621
2   -2.059406372     -2.9575274
3   -1.017291252     -1.9154122
4   -0.420223629     -1.3183446
5   -0.009188218     -0.9073092
6    0.287785773     -0.6103352
[1] "Mean relative difference: 0.2354654"
[1] TRUE
  logit(P[Y>=2]) logit(P[Y>=3])
1     -6.6420717      -7.540193
2     -2.7470610      -3.645182
3     -1.6175447      -2.515666
4     -0.9547998      -1.852921
5     -0.4876278      -1.385749
6     -0.1414232      -1.039544
      P[Y>=2]      P[Y>=3]
1 0.001302623 0.0005310131
2 0.060252851 0.0254519377
3 0.165543769 0.0747672299
4 0.277920572 0.1355303291
5 0.380452564 0.2000873101
6 0.464703016 0.2612379561
[1] TRUE
[1] TRUE
[1] TRUE
$fitted.values
  poly(c(scale(let)), 2):1 poly(c(scale(let)), 2):2
1               -5.1276963               -5.1276963
2               -1.2326855               -1.2326855
3               -0.1031692               -0.1031692
4                0.5595757                0.5595757
5                1.0267477                1.0267477
6                1.3729523                1.3729523
7                1.6576137                1.6576137
8                1.8466615                1.8466615
attr(,"vterm.assign")
attr(,"vterm.assign")$`poly(c(scale(let)), 2)`
[1] 1 2


$se.fit
  poly(c(scale(let)), 2):1 poly(c(scale(let)), 2):2
1                1.7242629                1.7242629
2                0.2327739                0.2327739
3                0.3311413                0.3311413
4                0.3768132                0.3768132
5                0.3653147                0.3653147
6                0.3317412                0.3317412
7                0.3044709                0.3044709
8                0.3113166                0.3113166
attr(,"vterm.assign")
attr(,"vterm.assign")$`poly(c(scale(let)), 2)`
[1] 1 2


$df
[1] 12

$sigma
[1] 1

VGAM documentation built on Jan. 16, 2021, 5:21 p.m.