-
Notifications
You must be signed in to change notification settings - Fork 0
/
PredictSCSPico_example.R
66 lines (53 loc) · 2.09 KB
/
PredictSCSPico_example.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
setwd("~/OneDrive/SCS_pico_niche")
#First, load disco package
library(dismo)
library(gbm)
load('np.Rdata')
#A full gbm model for South China Sea picophytoplankton
#All predictors included
c_brt_full <- gbm.step(data=np, gbm.x = 1:7, gbm.y = 8,
tree.complexity = 15,
learning.rate = 0.01,
family = "gaussian", silent = T)
p_brt_full <- gbm.step(data=np, gbm.x = 1:7, gbm.y = 9,
tree.complexity = 15,
learning.rate = 0.01,
max.trees = 20000,
family = "gaussian", silent = T)
s_brt_full <- gbm.step(data=np, gbm.x = 1:7, gbm.y = 10,
tree.complexity = 15,
learning.rate = 0.01,
max.trees = 20000,
family = "gaussian", silent = T)
e_brt_full <- gbm.step(data=np, gbm.x = 1:7, gbm.y = 11,
tree.complexity = 15,
learning.rate = 0.01,
max.trees = 20000,
family = "gaussian", silent = T)
tDOY <- function(x) cos(x/365 * 2*pi) #Transform DOY
#Create the dataframe for prediction
newdat <- data.frame(
lon = 116,
lat = 18,
Depth = 5,
DOY = tDOY(15),
logChl0 = log(0.1),
T0 = 30,
I0 = 50
)
c.p <- predict.gbm(c_brt_full, newdat,
n.trees=c_brt_full$gbm.call$best.trees,
type="response")
(exp(c.p)) #Predict Chl a concentration
p.p <- predict.gbm(p_brt_full, newdat,
n.trees=p_brt_full$gbm.call$best.trees,
type="response")
(exp(p.p)) #Predict Prochlorococcus abundance
s.p <- predict.gbm(s_brt_full, newdat,
n.trees=s_brt_full$gbm.call$best.trees,
type="response")
(exp(s.p)) #Predict Synechococccus abundance
e.p <- predict.gbm(e_brt_full, newdat,
n.trees=e_brt_full$gbm.call$best.trees,
type="response")
(exp(e.p)) #Predict Picoeukaryote abundance