-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathExample plot_year.R
More file actions
68 lines (52 loc) · 1.6 KB
/
Copy pathExample plot_year.R
File metadata and controls
68 lines (52 loc) · 1.6 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
library(dplyr)
library(SpaDES)
set.seed(1)
modulePath <- "~/git/SpaDES_Modules"
start <- end <- 1
# Define simulation parameters
times <- list(start = start, end = end, timeunit = "year")
modules <- list("fireSense_FrequencyFit", "fireSense_FrequencyPredict")
paths <- list(
modulePath = modulePath
)
# Create random weather and fire frequency dataset
dummyData <- data.frame(
weather = rep(1:100, each = 10),
nFires = rpois(1000, lambda=rep(10:1, each = 100)),
year = rep(1:10, each = 100)
)
# Define module parameters
parameters <- list(
fireSense_FrequencyFit = list(
formula = nFires ~ weather,
family = poisson(),
data = "dummyData"
),
fireSense_FrequencyPredict = list(
modelName = "fireSense_FrequencyFitted",
data = "dummyData"
)
)
# Objects to pass from the global environment to the simList environment
objects <- "dummyData"
# Create the simList
sim <- simInit(
times = times,
params = parameters,
modules = modules,
objects = objects,
paths = paths
)
sim <- spades(sim)
# Prepare data
data <- bind_cols(dummyData, list(predict = sim$fireSense_FrequencyPredicted))
# Plot predictions versus observations
data %>%
group_by(year) %>%
summarise(observed = sum(nFires), predicted = sum(predict)) %>%
with(., plot(predicted ~ .$observed, xlim = c(150, 1200), ylim = c(150, 1200), pch = 16))
abline(0,1, col = "red", lwd = 2)
# Predicted number of fires as a function of a covariate, here weather
x11()
with(data, plot(sim$fireSense_FrequencyPredicted ~ weather,
ylab = expression(Predicted~number~of~fires~occurrences), type = "l", lwd = 2))