IPA: Explained variation for settings with binary, survival and...

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

View source: R/IPA.R

Description

Index of Prediction Accuracy: General R^2 for binary outcome and right censored time to event (survival) outcome also with competing risks

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
rsquared(object,...)
IPA(object,...)
## Default S3 method:
rsquared(object,formula,newdata,times,cause,...)
## S3 method for class 'glm'
rsquared(object,formula,newdata,...)
## S3 method for class 'coxph'
rsquared(object,formula,newdata,times,...)
## S3 method for class 'CauseSpecificCox'
rsquared(object,formula,newdata,times,cause,...)
## Default S3 method:
IPA(object,formula,newdata,times,cause,...)
## S3 method for class 'glm'
IPA(object,formula,newdata,...)
## S3 method for class 'coxph'
IPA(object,formula,newdata,times,...)
## S3 method for class 'CauseSpecificCox'
IPA(object,formula,newdata,times,cause,...)

Arguments

object

Model for which we want IPA.

...

passed to riskRegression::Score

newdata

Optional validation data set in which to compute IPA

formula

Formula passed to Score. If not provided, try to use the formula of the call of object, if any.

cause

For competing risk models the event of interest

times

Vector of time points used as prediction horizon for the computation of Brier scores.

Details

IPA (R^2) is calculated based on the model's predicted risks. The Brier score of the model is compared to the Brier score of the null model.

Value

Data frame with explained variation values for the full model.

Author(s)

Thomas A. Gerds <tag@biostat.ku.dk>

See Also

Score

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
library(prodlim)
library(data.table)
# binary outcome
library(lava)
set.seed(18)
learndat <- sampleData(48,outcome="binary")
lr1 = glm(Y~X1+X2+X7+X9,data=learndat,family=binomial)
IPA(lr1)

## validation data
valdat=sampleData(94,outcome="binary")
IPA(lr1,newdata=valdat)

## predicted risks externally given
p1=predictRisk(lr1,newdata=valdat)
IPA(p1,formula=Y~1,valdat)

# survival
library(survival)
data(pbc)
pbc=na.omit(pbc)
pbctest=(1:NROW(pbc)) %in% sample(1:NROW(pbc),size=.632*NROW(pbc))
pbclearn=pbc[pbctest,]
cox1= coxph(Surv(time,status!=0)~age+sex+log(bili)+log(albumin)+log(protime),
      data=pbclearn,x=TRUE)

## same data
IPA(cox1,formula=Surv(time,status!=0)~1,times=1000)

## validation data
pbcval=pbc[!pbctest,]
IPA(cox1,formula=Surv(time,status!=0)~1,newdata=pbcval,times=1000)

## predicted risks externally given
p2=predictRisk(cox1,newdata=pbcval,times=1000)
IPA(cox1,formula=Surv(time,status!=0)~1,newdata=pbcval,times=1000)
 
# competing risks
data(Melanoma)
Melanomatest=(1:NROW(Melanoma)) %in% sample(1:NROW(Melanoma),size=.632*NROW(Melanoma))
Melanomalearn=Melanoma[Melanomatest,]
fit1 <- CSC(list(Hist(time,status)~sex,
                 Hist(time,status)~invasion+epicel+age),
                 data=Melanoma)
IPA(fit1,times=1000,cause=2)

## validation data
Melanomaval=Melanoma[!Melanomatest,]
IPA(fit1,formula=Hist(time,status)~1,newdata=Melanomaval,times=1000)

## predicted risks externally given
p3= predictRisk(fit1,cause=1,newdata=Melanomaval,times=1000)
IPA(p3,formula=Hist(time,status)~1,cause=1,newdata=Melanomaval,times=1000)
 

Example output

Loading required package: data.table
Loading required package: ggplot2
Loading required package: prodlim
riskRegression version 2019.01.29

Attaching package: 'lava'

The following object is masked from 'package:ggplot2':

    vars

    Variable     Brier       IPA    IPA.gain
1 Null model 0.2482639 0.0000000 0.370730236
2 Full model 0.1562250 0.3707302 0.000000000
3         X1 0.1947265 0.2156470 0.155083228
4         X2 0.1581592 0.3629393 0.007790924
5         X7 0.1604585 0.3536777 0.017052544
6         X9 0.2120601 0.1458277 0.224902508
    Variable     Brier          IPA     IPA.gain
1 Null model 0.2363060  0.000000000 -0.012762674
2 Full model 0.2393219 -0.012762674  0.000000000
3         X1 0.2385218 -0.009376808 -0.003385865
4         X2 0.2319291  0.018522455 -0.031285129
5         X7 0.2402771 -0.016804840  0.004042167
6         X9 0.2350781  0.005196390 -0.017959064
        model     Brier         IPA
1: Null model 0.2363060  0.00000000
2:    numeric 0.2393219 -0.01276267
      Variable times      Brier       IPA      IPA.gain
1   Null model  1000 0.15745835 0.0000000  0.3905309910
2   Full model  1000 0.09596599 0.3905310  0.0000000000
3          age  1000 0.09584326 0.3913104 -0.0007793944
4          sex  1000 0.09551803 0.3933759 -0.0028449431
5    log(bili)  1000 0.12337771 0.2164423  0.1740886997
6 log(albumin)  1000 0.09789668 0.3782694  0.0122615989
7 log(protime)  1000 0.10376810 0.3409806  0.0495503519
      Variable times     Brier        IPA     IPA.gain
1   Null model  1000 0.1520053 0.00000000  0.085276766
2   Full model  1000 0.1390427 0.08527677  0.000000000
3          age  1000 0.1382030 0.09080106 -0.005524293
4          sex  1000 0.1398202 0.08016193  0.005114841
5    log(bili)  1000 0.1393507 0.08325089  0.002025880
6 log(albumin)  1000 0.1408206 0.07358063  0.011696138
7 log(protime)  1000 0.1303232 0.14264051 -0.057363743
      Variable times     Brier        IPA     IPA.gain
1   Null model  1000 0.1520053 0.00000000  0.085276766
2   Full model  1000 0.1390427 0.08527677  0.000000000
3          age  1000 0.1382030 0.09080106 -0.005524293
4          sex  1000 0.1398202 0.08016193  0.005114841
5    log(bili)  1000 0.1393507 0.08325089  0.002025880
6 log(albumin)  1000 0.1408206 0.07358063  0.011696138
7 log(protime)  1000 0.1303232 0.14264051 -0.057363743
    Variable times      Brier          IPA      IPA.gain
1 Null model  1000 0.03309285  0.000000000  0.0285615211
2 Full model  1000 0.03214767  0.028561521  0.0000000000
3        sex  1000 0.03217774  0.027652985  0.0009085359
4   invasion  1000 0.03175291  0.040490290 -0.0119287688
5     epicel  1000 0.03207379  0.030794000 -0.0022324793
6        age  1000 0.03335216 -0.007835724  0.0363972450
    Variable times     Brier          IPA      IPA.gain
1 Null model  1000 0.1600000  0.000000000  0.0053744739
2 Full model  1000 0.1591401  0.005374474  0.0000000000
3        sex  1000 0.1654793 -0.034245604  0.0396200782
4   invasion  1000 0.1592865  0.004459129  0.0009153451
5     epicel  1000 0.1593328  0.004169882  0.0012045921
6        age  1000 0.1586368  0.008519763 -0.0031452891
        model times     Brier         IPA
1: Null model  1000 0.1600000 0.000000000
2:     matrix  1000 0.1591401 0.005374474

riskRegression documentation built on Jan. 13, 2021, 11:12 a.m.