Commit 3a946e7e authored by Boulangeat Isabelle's avatar Boulangeat Isabelle
Browse files

prepa reu 15-10

parent e2f8c33c
No preview for this file type
No preview for this file type
This diff is collapsed.
......@@ -19,37 +19,11 @@ knitr::opts_chunk$set(echo = TRUE)
library(tidyr)
sapply(list.files("R_fct"), function(x)source(paste0("R_fct/",x)))
data = readRDS("data.rds")
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)
source("workflow1_biomasse.r")
```
## Biomasse
```{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")
......@@ -80,20 +54,11 @@ 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}
......@@ -133,7 +98,7 @@ ggplot(dat_h_veg, aes(x = reorder(ref_typoveg, hmad/hmean, na.rm=TRUE), y = hmad
```
## Sites topography
## Sites topography and vegetation types
```{r ,echo=FALSE}
sites_all = readRDS("sites_all_plus.rds")
```
......@@ -159,17 +124,20 @@ ggplot(sites_all@data, aes(x = reorder(ref_typoveg, easting, na.rm=TRUE), y = ea
labs(y="easting", x="Type vegetation")
```
### Ensemble de variables abiotiques
## Ensemble de variables abiotiques
### PCA all abiotic variables
```{r ,fig=TRUE}
releves_all = readRDS("releves_all_plus.rds")
releves_all$date600 = releves_all$last_snow_day.gdd300 + releves_all$gddspeed.gdd600
str(releves_all)
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",
"albedo.gdd600", "albedo.gdd900","temperature.gdd300", "frost.gdd300",
"gddspeed.gdd300", "gddspeed.gdd600", "gddspeed.gdd900", "radiations.gdd300",
"radiations.gdd600", "radiations.gdd900", "rainfall.gdd300", "rainfall.gdd600",
"rainfall.gdd900", "snowdays.gdd300", "snowdays.gdd600", "snowdays.gdd900" )
"rainfall.gdd900", "snowdays.gdd300", "snowdays.gdd600", "snowdays.gdd900")
dat = na.omit(releves_all[,vars])
dim(dat)
pca = dudi.pca(dat, scan=FALSE, nf = 4)
......@@ -179,26 +147,187 @@ s.corcircle(pca$co)
s.corcircle(pca$co, xax=3, yax=4)
```
### Modélisation de la hauteur moyenne
## 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")
```
```{r ,fig=TRUE}
dat = na.omit(releves_all[,c(vars, "hmean")])
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")])
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 = randomForest(hmean ~ ., data = dat, ntree = 100, mtry=16)
mod
varImpPlot(mod)
```
### 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")
```
```{r ,fig=TRUE}
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")
```
mod = randomForest(hmean ~ gddspeed.gdd300 + radiations.gdd300 + cumgdd60d + rainfall.gdd900 + slope + northing + easting + lf, data = dat, ntree = 100, mtry=16)
```{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)
mod = randomForest(hmean ~., data = dat, ntree = 100, mtry=16)
mod
varImpPlot(mod)
```
library(plotmo)
plotmo(mod, ylim = NA)
```{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)
mod = randomForest(hmean ~., data = dat, ntree = 100, mtry=16)
mod
varImpPlot(mod)
```
```{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)
mod = randomForest(hmean ~., data = dat, ntree = 100, mtry=16)
mod
varImpPlot(mod)
```
```{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
varImpPlot(mod)
```
### Interannuel
```{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 %in% c("HUM", "LAND", "NA", "EBOU")),c(vars, "hmean")])
# dat$lf = as.factor(dat$lf)
dim(dat)
dat
mod = randomForest(hmean ~., data = dat, ntree = 100, mtry=16)
mod
varImpPlot(mod)
```
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment