README.Rmd 5.08 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
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

data$otable[which(is.na(data$otable$hauteur)),]

dat_h_veg = unique(merge(data$h, data$sites[,c("id_site", "ref_typoveg")], by.x = "ref_site", by.y ="id_site"))

length(unique(dat_h_veg$releve))
dim(dat_h_veg)

summary(dat_h_veg$hmean)

#==============================

library(dplyr)
# library(reshape)
library(tidyr)
library(ggplot2)

Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
39
```
40
## Biomasse
Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
```{r ,fig=TRUE}

library(dplyr)
library(tidyr)
library(ggplot2)
dat_long <- dat_h_veg %>%
 select(hmean, hmad, ref_typoveg) %>%
 drop_na() %>%
 group_by(ref_typoveg) %>%
 summarize(hauteur=mean(hmean), var_inter=mad(hmean), var_intra = mean(hmad)) %>%
 gather(stat, value, hauteur:var_intra)

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
56
57
58
59
60
61
62
63
64
65
66

```

```{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
67
68
```

Boulangeat Isabelle's avatar
Boulangeat Isabelle committed
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
```{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}
calage = read.csv("../PNE_calage_reformat.csv", sep= ";", dec = ",")
head(calage)
str(calage)
calage$releve = paste0(calage$site, calage$Releveur)

cal_mean = unique(calage %>% group_by(releve) %>% summarize(site = site, hmean = mean(hauteur, na.rm=TRUE)))

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

obs_error = cal_mean %>% group_by(site) %>% summarize(hmad = mad(hmean), hmad_st = mad(hmean)/mean(hmean), hm = mean(hmean))


```

```{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
133

134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
```

## Sites topography
```{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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
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
201
202
203
204
### Ensemble de variables abiotiques
```{r ,fig=TRUE}
releves_all = readRDS("releves_all_plus.rds")

library(ade4)
vars = c("alti", "slope", "lf", "northing", "easting", "snowfree_time", "cumgdd0", "cumgdd60d", "albedo.gdd300",
"albedo.gdd600", "albedo.gdd900", "frost_severe.gdd300", "frost_severe.gdd600",
"frost_severe.gdd900", "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" )
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)
```

### Modélisation de la hauteur moyenne
```{r ,fig=TRUE}
dat = na.omit(releves_all[,c(vars, "hmean")])
dat$lf = as.factor(dat$lf)
dim(dat)
library(randomForest)
mod = randomForest(hmean ~ gddspeed.gdd300 + radiations.gdd300 + cumgdd60d + rainfall.gdd300 + rainfall.gdd900 + frost_severe.gdd300 + slope + northing + easting + lf, data = dat, ntree = 150, mtry=16)

mod
varImpPlot(mod)
```

```{r ,fig=TRUE}

mod = randomForest(hmean ~ gddspeed.gdd300 + radiations.gdd300 + cumgdd60d + rainfall.gdd900 + slope + northing + easting + lf, data = dat, ntree = 100, mtry=16)

mod

library(plotmo)
plotmo(mod, ylim = NA)

```