README.Rmd 10.5 KB
Newer Older
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
---
title: "README"
author: "Isabelle Boulangeat"
date: "25/01/2021"
output:
  html_document:
    keep_md: yes
    variant: markdown_github
editor_options:
  chunk_output_type: console
always_allow_html: true
---

```{r setup, include=FALSE}
library(knitr)
# library(kableExtra)
knitr::opts_chunk$set(echo = TRUE)
# library(Jmisc)
library(tidyr)
sapply(list.files("R_fct"), function(x)source(paste0("R_fct/",x)))
data = readRDS("data.rds")
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
22
source("workflow1_biomasse.r")
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
23

Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
24
```
25
## Biomasse
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
26
27
28
29
```{r ,fig=TRUE}
ggplot(dat_long, aes(fill=stat, x=ref_typoveg, y=value)) +
  geom_bar(position = "dodge", stat = "identity") +
  facet_wrap(~stat, ncol = 1, scales = "free")
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
30
31
32
33
34
35
36
37
38
39
40

```

```{r ,fig=TRUE}

## boxplot par milieu ##

ggplot(dat_h_veg, aes(x = reorder(ref_typoveg, hmean, na.rm=TRUE), y = hmean)) +
  geom_boxplot() +
  labs(y="Hauteur moyenne (est. biomasse)", x="Type vegetation")

Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
41
42
```

Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
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
```{r ,fig=TRUE}

## H series par milieu ##

pl <- ggplot(dat_h_veg, aes(x = date_releve, y = hmean)) +
  geom_line(aes(color = ref_site), show.legend = FALSE) +
  facet_wrap(~ref_typoveg)

pl + theme(legend.position = "none")


```

```{r ,fig=TRUE}

ggplot(cal_mean, aes(x = reorder(site, hmean), y = hmean)) +
  geom_boxplot() +
  geom_point() 

```

```{r ,fig=TRUE}
ggplot(obs_error, aes(x = reorder(site, hm), y = hmad_st)) +
  geom_bar(stat = "identity")

```

```{r ,fig=TRUE}
### sd vs mad
ggplot(dat_h_veg, aes(x = hmad, y = hsd)) +
  geom_point() 

```

```{r ,fig=TRUE}
### dans le temps
ggplot(dat_h_veg, aes(x = date_releve, y = hmad)) +
  geom_line(aes(color = ref_site), show.legend = FALSE) +
  facet_wrap(~ref_typoveg)

## boxplot par milieu ##

```

```{r ,fig=TRUE}
ggplot(dat_h_veg, aes(x = reorder(ref_typoveg, hmad, na.rm=TRUE), y = hmad)) +
  geom_boxplot() +
  labs(y="Variation intra de hauteur", x="Type vegetation")

```

```{r ,fig=TRUE}
ggplot(dat_h_veg, aes(x = reorder(ref_typoveg, hmad/hmean, na.rm=TRUE), y = hmad/hmean)) +
  geom_boxplot() +
  labs(y="Variation intra de hauteur (stand. moy.)", x="Type vegetation")
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
98

99
100
```

Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
101
## Sites topography and vegetation types
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
```{r ,echo=FALSE}
sites_all = readRDS("sites_all_plus.rds")
```

```{r ,fig=TRUE}
ggplot(sites_all@data, aes(x = reorder(ref_typoveg, alti, na.rm=TRUE), y = alti)) +
  geom_boxplot() +
  labs(y="alti", x="Type vegetation")
```
```{r ,fig=TRUE}
ggplot(sites_all@data, aes(x = reorder(ref_typoveg, slope, na.rm=TRUE), y = slope)) +
  geom_boxplot() +
  labs(y="slope", x="Type vegetation")
```
```{r ,fig=TRUE}
ggplot(sites_all@data, aes(x = reorder(ref_typoveg, northing, na.rm=TRUE), y = northing)) +
  geom_boxplot() +
  labs(y="northing", x="Type vegetation")
```
```{r ,fig=TRUE}
ggplot(sites_all@data, aes(x = reorder(ref_typoveg, easting, na.rm=TRUE), y = easting)) +
  geom_boxplot() +
  labs(y="easting", x="Type vegetation")
```

Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
127
128
129
## Ensemble de variables abiotiques

### PCA all abiotic variables
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
130
131
```{r ,fig=TRUE}
releves_all = readRDS("releves_all_plus.rds")
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
132
133
releves_all$date600 = releves_all$last_snow_day.gdd300 + releves_all$gddspeed.gdd600
str(releves_all)
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
134
135
136

library(ade4)
vars = c("alti", "slope", "lf", "northing", "easting", "snowfree_time", "cumgdd0", "cumgdd60d", "albedo.gdd300",
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
137
"albedo.gdd600", "albedo.gdd900","temperature.gdd300", "frost.gdd300",
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
138
139
"gddspeed.gdd300", "gddspeed.gdd600", "gddspeed.gdd900", "radiations.gdd300",
"radiations.gdd600", "radiations.gdd900", "rainfall.gdd300", "rainfall.gdd600",
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
140
"rainfall.gdd900", "snowdays.gdd300", "snowdays.gdd600", "snowdays.gdd900")
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
141
142
143
144
145
146
147
148
149
dat = na.omit(releves_all[,vars])
dim(dat)
pca = dudi.pca(dat, scan=FALSE, nf = 4)
inertia.dudi(pca, row=FALSE, col =TRUE)
par(mfrow=c(1,2))
s.corcircle(pca$co)
s.corcircle(pca$co, xax=3, yax=4)
```

Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
## Modélisation de la hauteur moyenne

### climate et type vegetation
```{r ,fig=TRUE}
ggplot(releves_all, aes(x = reorder(ref_typoveg, cumgdd0, na.rm=TRUE), y = cumgdd0)) +
  geom_boxplot() +
  labs(y="cum GDD 0degC", x="Type vegetation")
```
```{r ,fig=TRUE}
ggplot(releves_all, aes(x = reorder(ref_typoveg, cumgdd60d, na.rm=TRUE), y = cumgdd60d)) +
  geom_boxplot() +
  labs(y="cum GDD 60d", x="Type vegetation")
```

```{r ,fig=TRUE}
ggplot(releves_all, aes(x = reorder(ref_typoveg, temperature.gdd300, na.rm=TRUE), y = temperature.gdd300)) +
  geom_boxplot() +
  labs(y="temperature moy", x="Type vegetation")
```

```{r ,fig=TRUE}
  ggplot(releves_all, aes(x = reorder(ref_typoveg, last_snow_day.gdd300, na.rm=TRUE), y = last_snow_day.gdd300)) +
    geom_boxplot() +
    labs(y="LSD", x="Type vegetation")
```
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
175
```{r ,fig=TRUE}
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
ggplot(releves_all, aes(x = reorder(ref_typoveg, gddspeed.gdd600, na.rm=TRUE), y = gddspeed.gdd600)) +
    geom_boxplot() +
    labs(y="gddspeed 600", x="Type vegetation")
```

```{r ,fig=TRUE}
releves_all$date600 = releves_all$last_snow_day.gdd300 + releves_all$gddspeed.gdd600

ggplot(releves_all, aes(x = reorder(ref_typoveg, date600, na.rm=TRUE), y = date600)) +
    geom_boxplot() +
    labs(y="dateGDD600", x="Type vegetation")
```




### Modèle exploratoire complet
```{r ,fig=TRUE}
library(randomForest)
vars = c("alti", "slope", "lf", "northing", "easting", "snowfree_time", "cumgdd0", "cumgdd60d", "albedo.gdd300",
"albedo.gdd600", "albedo.gdd900","temperature.gdd300", "frost.gdd300", "frost.gdd600", "frost.gdd900",
"gddspeed.gdd300", "gddspeed.gdd600", "gddspeed.gdd900", "radiations.gdd300",
"radiations.gdd600", "radiations.gdd900", "rainfall.gdd300", "rainfall.gdd600",
"rainfall.gdd900", "snowdays.gdd300", "snowdays.gdd600", "snowdays.gdd900", "ref_typoveg" )
dat = na.omit(releves_all[-which(releves_all$ref_typoveg %in% c("HUM", "LAND", "NA", "EBOU")),c(vars, "hmean")])
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
201
202
dat$lf = as.factor(dat$lf)
dim(dat)
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
203
mod = randomForest(log(hmean+1) ~ ., data = dat, ntree = 100, mtry=16)
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
204
205
206
207
208

mod
varImpPlot(mod)
```

Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
209
210
211
212
213
214
215
216
217
218
219
220
221
222
### Response graphs
```{r ,fig=TRUE}
library(plotmo)
# plotmo(mod, ylim = NA)
```

### Graphs univariés
```{r ,fig=TRUE}
ggplot(releves_all, aes(x = cumgdd0, y = hmean)) +
  geom_point() +
  geom_smooth(method="auto", se=TRUE, fullrange=FALSE, level=0.95) +
  labs(y="Hauteur", x="GDD 0degree")
```

Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
223
```{r ,fig=TRUE}
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
224
225
226
227
228
ggplot(releves_all, aes(x = slope, y = hmean)) +
  geom_point() +
  geom_smooth(method="auto", se=TRUE, fullrange=FALSE, level=0.95) +
  labs(y="Hauteur", x="slope")
```
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
229

Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
```{r ,fig=TRUE}
ggplot(releves_all, aes(x = gddspeed.gdd600, y = hmean)) +
  geom_point() +
  geom_smooth(method="auto", se=TRUE, fullrange=FALSE, level=0.95) +
  labs(y="Hauteur", x="GDD.600")
```


### Modèle par type

```{r ,fig=TRUE}
vars = c("alti", "slope", "lf", "northing", "easting", "snowfree_time", "cumgdd0", "cumgdd60d", "albedo.gdd300",
"albedo.gdd600", "albedo.gdd900","temperature.gdd300", "frost.gdd300", "frost.gdd600", "frost.gdd900",
"gddspeed.gdd300", "gddspeed.gdd600", "gddspeed.gdd900", "radiations.gdd300",
"radiations.gdd600", "radiations.gdd900", "rainfall.gdd300", "rainfall.gdd600",
"rainfall.gdd900", "snowdays.gdd300", "snowdays.gdd600", "snowdays.gdd900" )
#vars = c("slope", "lf", "northing", "easting", "snowfree_time", "cumgdd60d", "ref_typoveg")

# dat = na.omit(releves_all[-which(releves_all$ref_typoveg %in% c("HUM", "LAND", "NA", "EBOU")),c(vars, "hmean")])
dat = na.omit(releves_all[which(releves_all$ref_typoveg =="PROD"),c(vars, "hmean")])
# dat$lf = as.factor(dat$lf)
dim(dat)
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
252
mod = randomForest(log(hmean+1) ~., data = dat, ntree = 100, mtry=16)
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
253
254

mod
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
255
varImpPlot(mod, main="PROD")
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
256
```
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
257

Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
258
259
260
261
262
263
264
265
266
267
268
269
```{r ,fig=TRUE}
vars = c("alti", "slope", "lf", "northing", "easting", "snowfree_time", "cumgdd0", "cumgdd60d", "albedo.gdd300",
"albedo.gdd600", "albedo.gdd900","temperature.gdd300", "frost.gdd300", "frost.gdd600", "frost.gdd900",
"gddspeed.gdd300", "gddspeed.gdd600", "gddspeed.gdd900", "radiations.gdd300",
"radiations.gdd600", "radiations.gdd900", "rainfall.gdd300", "rainfall.gdd600",
"rainfall.gdd900", "snowdays.gdd300", "snowdays.gdd600", "snowdays.gdd900" )
#vars = c("slope", "lf", "northing", "easting", "snowfree_time", "cumgdd60d", "ref_typoveg")

# dat = na.omit(releves_all[-which(releves_all$ref_typoveg %in% c("HUM", "LAND", "NA", "EBOU")),c(vars, "hmean")])
dat = na.omit(releves_all[which(releves_all$ref_typoveg =="ALP"),c(vars, "hmean")])
# dat$lf = as.factor(dat$lf)
dim(dat)
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
270
mod = randomForest(log(hmean+1) ~., data = dat, ntree = 100, mtry=16)
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
271
272

mod
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
273
varImpPlot(mod, main="ALP")
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
274
275
276
277
278
279
280
281
282
283
284
285
286
287
```

```{r ,fig=TRUE}
vars = c("alti", "slope", "lf", "northing", "easting", "snowfree_time", "cumgdd0", "cumgdd60d", "albedo.gdd300",
"albedo.gdd600", "albedo.gdd900","temperature.gdd300", "frost.gdd300", "frost.gdd600", "frost.gdd900",
"gddspeed.gdd300", "gddspeed.gdd600", "gddspeed.gdd900", "radiations.gdd300",
"radiations.gdd600", "radiations.gdd900", "rainfall.gdd300", "rainfall.gdd600",
"rainfall.gdd900", "snowdays.gdd300", "snowdays.gdd600", "snowdays.gdd900" )
#vars = c("slope", "lf", "northing", "easting", "snowfree_time", "cumgdd60d", "ref_typoveg")

# dat = na.omit(releves_all[-which(releves_all$ref_typoveg %in% c("HUM", "LAND", "NA", "EBOU")),c(vars, "hmean")])
dat = na.omit(releves_all[which(releves_all$ref_typoveg =="SUB"),c(vars, "hmean")])
# dat$lf = as.factor(dat$lf)
dim(dat)
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
288
mod = randomForest(log(hmean+1) ~., data = dat, ntree = 100, mtry=16)
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
289
290

mod
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
291
varImpPlot(mod, main="SUB")
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
```

```{r ,fig=TRUE}
vars = c("alti", "slope", "lf", "northing", "easting", "snowfree_time", "cumgdd0", "cumgdd60d", "albedo.gdd300",
"albedo.gdd600", "albedo.gdd900","temperature.gdd300", "frost.gdd300", "frost.gdd600", "frost.gdd900",
"gddspeed.gdd300", "gddspeed.gdd600", "gddspeed.gdd900", "radiations.gdd300",
"radiations.gdd600", "radiations.gdd900", "rainfall.gdd300", "rainfall.gdd600",
"rainfall.gdd900", "snowdays.gdd300", "snowdays.gdd600", "snowdays.gdd900" )
#vars = c("slope", "lf", "northing", "easting", "snowfree_time", "cumgdd60d", "ref_typoveg")

# dat = na.omit(releves_all[-which(releves_all$ref_typoveg %in% c("HUM", "LAND", "NA", "EBOU")),c(vars, "hmean")])
dat = na.omit(releves_all[which(releves_all$ref_typoveg =="NIV"),c(vars, "hmean")])
# dat$lf = as.factor(dat$lf)
dim(dat)
mod = randomForest(hmean ~., data = dat, ntree = 100, mtry=16)

mod
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
309
varImpPlot(mod, main="NIV")
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
310
311
312
313
314
```

### Interannuel

```{r ,fig=TRUE}
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
315
vars = c("id_site", "cumgdd0", "albedo.gdd300","temperature.gdd300", "frost.gdd300",
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
316
"gddspeed.gdd300", "gddspeed.gdd600", "gddspeed.gdd900", "radiations.gdd300",
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
317
318
 "rainfall.gdd300")

Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
319

Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
320
# dat = na.omit(releves_all[-which(releves_all$ref_typoveg %in% c("HUM", "LAND", "NA", "EBOU")),c(vars, "hmean")])
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
321
sort(table(releves_all$id_site), dec=TRUE)
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
322
323
324
dat = na.omit(releves_all[-which(releves_all$ref_typoveg %in% c("HUM", "LAND", "NA", "EBOU")),c(vars, "hmean")])
# dat$lf = as.factor(dat$lf)
dim(dat)
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
325
mod = randomForest(log(hmean+1) ~., data = dat, ntree = 100, mtry=16)
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
326
327

mod
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
328
varImpPlot(mod, main="interannuel")
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
329
330
```