-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathConvenience.R
More file actions
133 lines (124 loc) · 4.12 KB
/
Convenience.R
File metadata and controls
133 lines (124 loc) · 4.12 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
###############################################################################
###############################################################################
##
## Source file containing some convenience functions to FMradio 1.1
## Statistics for Omics course: Radiomics
##
## Code: Carel F.W. Peeters
## Department of Epidemiology & Biostatistics
## VU University medical center Amsterdam
## Amsterdam, the Netherlands
## cf.peeters@vumc.nl
## Date: 13/06/2019, Amsterdam, VUmc
##
###############################################################################
###############################################################################
#'
#'**---------------------------------**\
#'**Convenience functions*\
#'**---------------------------------**\
Or2 <- function(this){
##############################################################################
# Convenience function for calculating (overall) explained residual variation
# this > crps object from pec
#
# Notes:
# - Function tailored towards the application/comparison at hand.
# Can be further generalized.
##############################################################################
# Dependencies:
# require("base")
# require("pec")
Ar2 <- 1 - this[,1]/this[1,1]
Cr2 <- 1 - this[,2]/this[1,2]
Tab <- cbind(Ar2,Cr2)
colnames(Tab) <- c("AppR2", "crossvalR2")
rownames(Tab)[2] <- "FMradio"
return(Tab)
}
plotR2Table <- function(R2Table, type = "CV", Ylab = NULL, Xlab = "Time"){
##############################################################################
# Convenience function for plotting explained residual variation
# R2Table > R2 object from pec
# type > character indicating if the cross-validated or apparent plot
# must be returned. Must be one of "CV" or "AE"
# Ylab > control over the y-axis label
#
# Notes:
# - Function tailored towards the application/comparison at hand.
# Can be further generalized.
##############################################################################
# Dependencies:
# require("base")
# require("pec")
if (type == "CV"){
if (!is.null(Ylab)){Ylab = Ylab}
if (is.null(Ylab)){Ylab = expression(Averaged ~ cross-validated ~ R^2)}
MIN <- min(R2Table$crossvalErr[,c(-1)])
MAX <- max(R2Table$crossvalErr[,c(-1)])
COL <- 2:3
plot(R2Table$crossvalErr$time,
R2Table$crossvalErr$RR.MetaCox,
type = "l",
axes = FALSE,
xlab = Xlab,
ylab = Ylab,
col = COL[1],
lwd = 1.5,
ylim = c(MIN,MAX)#,
#main = "Explained residual variation under cross-validated error")
)
axis(2, col = "black", lwd = 1)
axis(1, col = "black", lwd = 1)
abline(h = 0)
lines(R2Table$crossvalErr$time,
R2Table$crossvalErr$RR.RforestCox,
type = "l",
col = COL[2],
lwd = 1.5)
legend("bottomright", inset = .03,
legend = c("FMradio",
"Random survival forest"),
col = COL,
lty = 1,
cex = .9,
box.lty = 0,
lwd = 2,
y.intersp = 1.7)
}
if (type == "AE"){
if (!is.null(Ylab)){Ylab = Ylab}
if (is.null(Ylab)){Ylab = expression(Apparent ~ R^2)}
MIN <- min(R2Table$AppErr[,c(-1)])
MAX <- max(R2Table$AppErr[,c(-1)])
COL <- 2:5
plot(R2Table$AppErr$time,
R2Table$AppErr$RR.MetaCox,
type = "l",
axes = FALSE,
xlab = Xlab,
ylab = Ylab,
col = COL[1],
lwd = 1.5,
ylim = c(MIN,MAX)#,
#main = "Explained residual variation under apparent error")
)
axis(2, col = "black", lwd = 1)
axis(1, col = "black", lwd = 1)
abline(h = 0)
lines(R2Table$AppErr$time,
R2Table$AppErr$RR.RforestCox,
type = "l",
col = COL[2],
lwd = 1.5)
legend("bottomright", inset = .03,
legend = c("FMradio",
"Random survival forest"),
col = COL,
lty = 1,
cex = .9,
box.lty = 0,
lwd = 2,
y.intersp = 1.7)
}
}