-
Notifications
You must be signed in to change notification settings - Fork 1
/
elasticnet.Rmd
94 lines (78 loc) · 1.93 KB
/
elasticnet.Rmd
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
---
title: "elasticnet"
output:
bookdown::html_document2:
fig.width: 18
fig.height: 8
---
```{r elasticnet_setup, message = FALSE}
library("targets")
library("ameld")
library("viridisLite")
tar_load(arcvob)
tar_load(bootrcv)
tar_load(bootarcv)
#tar_load(bootarcv9)
tar_load(amelddata)
tar_load(ameldcfg)
tar_load(zlog_data)
```
# Tuning alpha
```{r arcvob}
arcvob
```
```{r arcvob-plot-alpha}
plot(arcvob)
```
```{r arcvob-plot-lambdamin}
plot(arcvob, what = "lambda.min")
```
```{r arcvob-plot-lambda1se}
plot(arcvob, what = "lambda.1se")
```
# Bootstrapping
## rcv.glmnet
```{r bootrcv}
plot(bootrcv, what = "calibration")
ps <- lapply(
zlog_data[paste0("SurvProbMeld", c("Unos", "NaUnos", "Plus7"))],
function(p) {
ctpnts <- cutpoints(p, n = ameldcfg$m)
f <- cut(p, ctpnts, include.lowest = TRUE)
list(
predicted = groupmean(p, f = f),
observed = observed_survival(
amelddata$y, f = f, times = ameldcfg$times
)
)
}
)
names(ps) <- c("MELD", "MELD-Na", "MELD-Plus7")
col <- viridisLite::viridis(6)[4:6]
for (i in seq_along(ps)) {
lines(
ps[[i]]$predicted, ps[[i]]$observed, col = col[i], type = "b", pch = 19
)
}
legend("topleft", col = col, legend = names(ps), pch = 19, bty = "n")
plot(bootrcv, what = "selected", cex = 0.5)
plot(bootrcv$fit$glmnet.fit, xvar = "norm")
plot(bootrcv$fit$glmnet.fit, xvar = "lambda")
plot(bootrcv$fit$glmnet.fit, xvar = "dev")
```
## arcv.glmnet
```{r bootarcv}
a <- c(table(sapply(bootarcv$models, function(m)m$fit$alpha)))
plot(bootarcv, what = "calibration")
```
```{r bootarcv2, fig.height = 12}
plot(bootarcv, what = "selected")
plot_dots(a, main = "Selected Alpha Values")
```
## arcv9.glmnet
```{r bootarcv9}
#a <- c(table(sapply(bootarcv9$models, function(m)m$fit$alpha)))
#plot(bootarcv9 , what = "calibration")
#plot(bootarcv9, what = "selected")
#plot_dots(a, main = "Selected Alpha Values")
```