-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.R
103 lines (94 loc) · 3.27 KB
/
app.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# implementing app to visualize influence of margin size on predictive performance
library(shiny)
server <- shinyServer(function(input, output) {
source("app_imports.R")
data <- reactive({
set.seed(123)
sites <- readRDS("Daten/evidence.csv") %>%
dplyr::filter(site == 1) %>%
dplyr::select(lon, lat)
nonsites <- buffsample(ssize = 8000, distance = input$buffer, returnsize = 12000)
evidence <- generateEvidenceApp(sitesdata = sites, nonsitesdata = nonsites)
evidence <- finalizeEvidence(evidence)
subset_sites <- sample_n(sites, size = input$ssize)
sp_sites <- sp::SpatialPoints(coords = subset_sites[, c("lon", "lat")], proj4string = predictors@crs)
nonsites <- dplyr::filter(evidence, site == F) %>% dplyr::select(lon, lat)
subset_nonsites <- sample_n(nonsites, size = input$ssize)
sp_nonsites <- sp::SpatialPoints(coords = subset_nonsites[, c("lon", "lat")], proj4string = predictors@crs)
form <- paste(input$variables, collapse = " + ")
if (identical(form, "")) {
form <- "site ~ dem"
} else {
form <- paste("site ~ dem", form, sep = " + ")
}
basefit <- glm(
formula = form,
family = binomial(),
data = evidence
)
list(
bsf = basefit, evd = evidence, formula = form, spsite = sp_sites,
spnsite = sp_nonsites
)
})
output$map <- renderPlot({
df <- as.data.frame(predictors)
pdata <- predict(data()$bsf, newdata = df, type = "response")
x_pred <- predictors
x_pred$pred <- pdata
plot(x_pred$pred, main = "Predictive Map: Logistic Regression", ylab = "Latitude", xlab = "Longitude")
if (input$points == T) {
plot(data()$spsite, add = TRUE, col = "blue")
}
if (input$npoints == T) {
plot(data()$spnsite, add = TRUE, col = "red")
}
})
output$auroc <- renderPrint({
pROC::auc(data()$evd$site, fitted(data()$bsf))
})
output$formel <- renderPrint({
cat("Model formula: ", "\n", data()$formula)
})
})
ui <- shinyUI(fluidPage(
theme = shinytheme("journal"),
titlePanel("Predictive Performance vs. Buffersize"),
sidebarLayout(
sidebarPanel(
sliderInput("buffer",
"Radius of Buffer:",
min = 50,
max = 7500,
value = 50
),
sliderInput("ssize",
"Number of Points to Render:",
min = 50,
max = 5000,
value = 500
),
checkboxGroupInput("variables", "Variable Selection:",
c(
"Temperature" = "temp", "Rain" = "rain", "Distance to Water" = "distance_water",
"Frostdays" = "frostdays", "Sunhours" = "sunhours", "Topographic Position Index" = "tpi",
"Slope" = "slope", "Aspect" = "aspect"
),
selected = c(
"Temperature" = "temp", "Rain" = "rain", "Distance to Water" = "distance_water",
"Frostdays" = "frostdays", "Sunhours" = "sunhours", "Topographic Position Index" = "tpi",
"Slope" = "slope", "Aspect" = "aspect"
)
),
checkboxInput("points", "Render Sites?", FALSE),
checkboxInput("npoints", "Render Nonsites?", FALSE),
submitButton(text = "Refresh!", icon = icon("refresh"), width = NULL)
),
mainPanel(
plotOutput("map"),
textOutput("auroc"),
textOutput("formel")
)
)
))
shinyApp(ui = ui, server = server)