-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.R
83 lines (56 loc) · 2.75 KB
/
server.R
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
library('shiny')
library('mice')
library(RSkittleBrewer)
library(magrittr)
library(dplyr)
library(markdown)
load('model/pooled-model.Rdata')
shinyServer(function(input, output, session) {
predicted_prob <- reactive({
predict_pooled(betas = pooledModel$qbar,
covariance = pooledModel$t, preopventilat = input$preopventilat,
preopsepsis = input$preopsepsis, fsteroid = input$fsteroid,
prwbcf = input$prwbcf, prplatef = input$prplatef, prcreat = input$prcreat, numage = input$numage)
})
plot_data <- reactive({
n_points <- 100
age_ranges <- seq(19, 91, length.out = n_points)
res <- do.call(rbind, lapply(age_ranges,
function(i, b, c, v, s, f, w, p, cr) predict_pooled(numage = i, betas = b, covariance = c,
preopventilat = v, preopsepsis = s, fsteroid = f,
prwbcf = w, prplatef = p, prcreat = cr),
b = pooledModel$qbar, c = pooledModel$t,
v = input$preopventilat,
s = input$preopsepsis, f = input$fsteroid,
w = input$prwbcf, p = input$prplatef, cr = input$prcreat))
res
})
# Generate an HTML table view of the data ----
output$table <- renderTable({
summary(pooledModel)
})
output$print_pred = renderPrint({
sprintf("Probability of mortality: %.2f,\n 95%% Confidence Interval: [%.2f, %.2f]",
predicted_prob()[,"prob"],predicted_prob()[,"lower"],predicted_prob()[,"upper"])
# predicted_prob()
# predicted_prob[,"prob"]
# input$preopventilat
})
output$prob1 <- renderText({
paste("Probability of mortality:",round(predicted_prob()[,"prob"],3))
})
output$CI <- renderText({
paste("95% Confidence Interval: [",round(predicted_prob()[,"lower"],3), ", ",round(predicted_prob()[,"upper"],3) ,"]")
})
output$plot <- renderPlot({
trop <- RSkittleBrewer::RSkittleBrewer("trop")
par(mai=c(0.85,0.9,0.1,0.2))
# par(oma = c(4, 1, 1, 1))
plot(plot_data()[,"numage"], plot_data()[,"prob"], lwd = 4, type = "l", ylab = "Probability of Death", xlab = "Age", col = trop[2],
bty="n", xaxt="n", cex.lab = 1.4, xlim = c(20,100), ylim = range(plot_data()[,c("prob","lower","upper")]))
axis(1, labels = T, at = seq(20,90,10))
lines(plot_data()[,"numage"], plot_data()[,"lower"], lty = 2, col = "grey")
lines(plot_data()[,"numage"], plot_data()[,"upper"], lty = 2, col = "grey")
points(x = input$numage,y = predicted_prob()[,"prob"], pch = 19, col = "red", cex = 2)
})
})