predictGLM: Compute the influence function for the prediction.

Description Usage Arguments Examples

Description

Compute the influence function for the prediction from a linear or logistic model.

Usage

1
predictGLM(object, newdata, average.iid = FALSE)

Arguments

object

glm model.

newdata

[data.frame] dataset containing the covariate to condition on.

average.iid

[logical] Should the influence function be averaged over the empirical distribution.

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
25
26
27
28
29
30
31
32
## Not run: 
library(lava)
m <- lvm(Y~X1+X2+X3)

set.seed(10)
d <- lava::sim(m, 1e2)

## check for lm
e.lm <- lm(Y~X1+X2+X3, data = d)
test <- predictGLM(e.lm, newdata = d)
test.av <- predictGLM(e.lm, newdata = d, average.iid = TRUE)

GS <- lava::estimate(e.lm, f = function(p,data){
  p["(Intercept)"] + d[,"X1"] * p["X1"] + d[,"X2"] * p["X2"] + d[,"X3"] * p["X3"]
})
range(test[,1]-GS$coef)
range(attr(test,"iid")-t(GS$iid))
range(colMeans(attr(test,"iid"))-attr(test.av,"iid"))

## check for glm
e.glm <- glm(I(Y>0)~X1+X2+X3, data = d, family = binomial(link = "logit"))
test <- predictGLM(e.glm, newdata = d)
test.av <- predictGLM(e.glm, newdata = d, average.iid = TRUE)

GS <- lava::estimate(e.glm, f = function(p,data){
  lava::expit(p["(Intercept)"] + d[,"X1"] * p["X1"] + d[,"X2"] * p["X2"] + d[,"X3"] * p["X3"])
})
range(test[,1]-GS$coef)
range(attr(test,"iid")-t(GS$iid))
range(colMeans(attr(test,"iid"))-attr(test.av,"iid"))

## End(Not run)

bozenne/riskRegressionLight documentation built on May 7, 2019, 12:52 a.m.