diff --git a/.DS_Store b/.DS_Store index aee14fbaf2cf0228c6ff935f308fb485d8a9fcd3..6cc5ef7076185357ee44c8454812adeecf7ebbb7 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/Main_analyse.Rmd b/Main_analyse.Rmd new file mode 100644 index 0000000000000000000000000000000000000000..7a579fd02649c378f47b75f664a85ff6b033aeda --- /dev/null +++ b/Main_analyse.Rmd @@ -0,0 +1,93 @@ +--- +title: "Main_analyse.Rmd" +author: "Isabelle Boulangeat" +date: "23/01/2020" +output: html_document +editor_options: + chunk_output_type: console +--- + +```{r setup, include=FALSE} +knitr::opts_chunk$set(echo = TRUE) +library(Jmisc) +sourceAll("R_fct") +``` + +## Load data +- Load climate +- Load species cover data +- Filter out treatment plots +- filter out un-repeated plots +- filter out years > 2014 because of missing in climatologies + +```{r load_data} +DATA = load.datasets() +str(DATA$cover) +str(DATA$climato) + +mostRecordedSP = DATA$cover %>% group_by(Name) %>% summarise(nobs = length(Name)) %>% arrange(desc(nobs)) +selection = as.vector(t(mostRecordedSP[1:22, "Name"])) +selection = selection[-which(selection %in% c("Arctagrostis latifolia", "Persicaria vivipara", "Carex aquatilis", "Cassiope tetragona", "Luzula confusa", "Luzula nivalis", "Salix arctica", "Poa arctica", "Eriophorum angustifolium", "Petasites frigidus", "Vaccinium uliginosum", "Dryas integrifolia"))] +``` + +N.B. I have quickly selected 10 species among the 22 having the most observations, with no problem with zero-days growing season in the previous years before an observation, and no problem in the dataset... **selection procedure to discuss** + +## Prepare species specific datasets +Step 1: `create_dataset`: +- only subsites where the species have been seen (then ok for N=1) +- extract plot info +- build transition table +- merge with plot info +- calculate interval (years) +- tag transition types +- combine with climate (5 years earlier average) +- merge all +Step 2: adjustments +- Add anomalies +- remove intervals>=10 years +- select variables c("snowDays", "GSL", "GST", "SoilMoist", "TotalCover") +- modify SoilMoist levels (-1, 0, 1) +Step 3: prepare dataset to fit +- separate colonisation and extinction datasets +- scale data (not SoilMoist) +- prepare data for LaplacesDemon fit (optional) +- add event column for glm fit + +```{r species_specific_datasets} +spDATA.list = lapply(selection, function(SPECIES){ + print(SPECIES) + spDATA = dat.species(SPECIES, DATA) + return(spDATA) +} ) +names(spDATA.list) = selection +(spDATA.check = lapply(spDATA.list, check.nas)) + +lapply(spDATA.list, function(x) table(x$spdat$trType)) +``` + + +## Fit models +```{r species_specific_models} +spDATA.fit = lapply(spDATA.list, fit.species) +``` + +## Summary of model evaluation +```{r model_evaluation} +spDATA.fit[[1]]$colo +eval.models = lapply(spDATA.fit, function(glm.fit){ + eval.colo = eval.fit(glm.fit$colo, glm.fit$dat$colo, "colo.event")[-1] + vars.colo = paste(names(sort(abs(glm.fit$colo$coefficients[-1]), dec=T)), collapse=";") + eval.ext = eval.fit(glm.fit$ext, glm.fit$dat$ext, "ext.event")[-1] + vars.ext = paste(names(sort(abs(glm.fit$ext$coefficients[-1]), dec=T)), collapse=";") + return(list(colo.R2 = eval.colo$R2, colo.AUC = eval.colo$AUC, ext.R2 = eval.ext$R2, ext.AUC = eval.ext$AUC, vars.colo = vars.colo, vars.ext = vars.ext)) +}) +res.tab = do.call(rbind, eval.models) +res.tab +``` + +# ```{r model_evaluation} +# plot_model(glm.fit$colo, transform = NULL, show.values=TRUE, title = paste(SPECIES, "colonisation")) +# plot_model(glm.fit$ext, transform = NULL, show.values=TRUE, title = paste(SPECIES, "extinction")) +# plot_model(glm.fit$colo, type = "eff") +# ``` + diff --git a/Main_analyse.html b/Main_analyse.html new file mode 100644 index 0000000000000000000000000000000000000000..a40cb242d66e0989d48981844c920b2bdb86a4bc --- /dev/null +++ b/Main_analyse.html @@ -0,0 +1,771 @@ + + + + +
+ + + + + + + + + + +DATA = load.datasets()
+str(DATA$cover)
+## 'data.frame': 32793 obs. of 43 variables:
+## $ SUBSITE : chr "ALEXFIORD:CASSIOPE" "ALEXFIORD:CASSIOPE" "ALEXFIORD:CASSIOPE" "ALEXFIORD:CASSIOPE" ...
+## $ SemiUniquePLOT : chr "ALEXFIORD:CASSIOPE_Cas.c.c.10new_CTL" "ALEXFIORD:CASSIOPE_Cas.c.c.10new_CTL" "ALEXFIORD:CASSIOPE_Cas.c.c.10new_CTL" "ALEXFIORD:CASSIOPE_Cas.c.c.10new_CTL" ...
+## $ YEAR : num 1995 1995 1995 1995 1995 ...
+## $ Name : chr "Cassiope tetragona" "Papaver radicatum" "Oxyria digyna" "Luzula confusa" ...
+## $ SITE : chr "ALEXFIORD" "ALEXFIORD" "ALEXFIORD" "ALEXFIORD" ...
+## $ TRTMT : chr "CTL" "CTL" "CTL" "CTL" ...
+## $ PLOT : chr "Cas.c.c.10new" "Cas.c.c.10new" "Cas.c.c.10new" "Cas.c.c.10new" ...
+## $ GFNARROWwalker : chr "SEVER" "FORB" "FORB" "RUSH" ...
+## $ GFNARROWarft : chr "ESHRUB" "FORBSV" "FORBSV" "GRAMINOID" ...
+## $ COVER : num 22 0 1 0 6 3 7 5 0 8 ...
+## $ UniquePLOT : chr "ALEXFIORD:CASSIOPE_Cas.c.c.10new_CTL_1995" "ALEXFIORD:CASSIOPE_Cas.c.c.10new_CTL_1995" "ALEXFIORD:CASSIOPE_Cas.c.c.10new_CTL_1995" "ALEXFIORD:CASSIOPE_Cas.c.c.10new_CTL_1995" ...
+## $ NumSurveysPerSubsite: int 3 3 3 3 3 3 3 3 3 3 ...
+## $ NumSurveysPerPlot : int 3 3 3 3 3 3 3 3 3 3 ...
+## $ MinYearSubsite : num 1995 1995 1995 1995 1995 ...
+## $ MaxYearSubsite : num 2007 2007 2007 2007 2007 ...
+## $ DurationSubsite : num 13 13 13 13 13 13 13 13 13 13 ...
+## $ MinYearPlot : num 1995 1995 1995 1995 1995 ...
+## $ MaxYearPlot : num 2007 2007 2007 2007 2007 ...
+## $ DurationPlot : num 13 13 13 13 13 13 13 13 13 13 ...
+## $ SiteOnly : chr "ALEXFIORD" "ALEXFIORD" "ALEXFIORD" "ALEXFIORD" ...
+## $ SubsiteOnly : chr "CASSIOPE" "CASSIOPE" "CASSIOPE" "CASSIOPE" ...
+## $ MultipleSubsites : num 1 1 1 1 1 1 1 1 1 1 ...
+## $ RepeatedSubsites : num 1 1 1 1 1 1 1 1 1 1 ...
+## $ RepeatedPlots : num 1 1 1 1 1 1 1 1 1 1 ...
+## $ MixedPlots : num 0 0 0 0 0 0 0 0 0 0 ...
+## $ Morphosp : num 0 0 0 0 0 0 0 0 1 0 ...
+## $ Genus : chr "Cassiope" "Papaver" "Oxyria" "Luzula" ...
+## $ Family : chr "Ericaceae" "Papaveraceae" "Polygonaceae" "Juncaceae" ...
+## $ SppInPlot : num 1 1 1 1 1 1 1 1 1 1 ...
+## $ TotalCover : num 44 44 44 44 44 44 44 44 44 46 ...
+## $ RelCover : num 0.5 0 0.0227 0 0.1364 ...
+## $ Latitude : num 78.9 78.9 78.9 78.9 78.9 ...
+## $ Longitude : num -75.8 -75.8 -75.8 -75.8 -75.8 ...
+## $ MaxTemp : num 70.5 70.5 70.5 70.5 70.5 ...
+## $ MAT : num -164 -164 -164 -164 -164 ...
+## $ MinTemp : num -367 -367 -367 -367 -367 ...
+## $ WarmQuarterTemp : num 25.6 25.6 25.6 25.6 25.6 ...
+## $ ColdQuarterTemp : num -321 -321 -321 -321 -321 ...
+## $ WClimGrid : num 57684506 57684506 57684506 57684506 57684506 ...
+## $ CRUGrid : num 16049 16049 16049 16049 16049 ...
+## $ WClimGroup : num 2 2 2 2 2 2 2 2 2 2 ...
+## $ SoilMoist : chr "MOIST" "MOIST" "MOIST" "MOIST" ...
+## $ WClimGroupSM : num 3 3 3 3 3 3 3 3 3 3 ...
+str(DATA$climato)
+## 'data.frame': 257 obs. of 172 variables:
+## $ SITE : Factor w/ 62 levels "ABISKO","AKUREYRI",..: 3 3 3 3 3 3 3 3 3 38 ...
+## $ SUBSITE : Factor w/ 254 levels "A","ABISKODRY",..: 1 37 46 64 67 68 82 122 123 215 ...
+## $ COMMTYPE : Factor w/ 5 levels "","DRY","MIXED",..: 5 5 5 5 2 2 5 2 2 4 ...
+## $ LAT : num 78.9 78.9 78.9 78.9 78.9 ...
+## $ LONG : num -75.7 -75.7 -75.7 -75.7 -75.9 ...
+## $ Checked_Coords : Factor w/ 2 levels "","x": 1 1 1 1 2 2 1 2 2 2 ...
+## $ HasCover : int 0 0 0 0 1 1 0 1 1 1 ...
+## $ ELEV : int 30 30 30 30 540 540 30 540 540 580 ...
+## $ AZONE : Factor w/ 4 levels "ALPINE","ANT",..: 3 3 3 3 3 3 3 3 3 4 ...
+## $ PI : Factor w/ 42 levels "","Blok","COOPER",..: 12 12 12 12 12 12 12 22 22 24 ...
+## $ DomGrazer : Factor w/ 10 levels "","LARGE","Small",..: 8 8 8 8 8 8 8 5 5 7 ...
+## $ GrazerIntensity : Factor w/ 5 levels "","LOW","high",..: 4 4 4 4 4 4 4 4 4 5 ...
+## $ CAVM : Factor w/ 22 levels "","B1","B3","B4",..: 21 21 21 21 4 3 21 4 3 8 ...
+## $ CAVMBROAD : Factor w/ 7 levels "","B","G","P",..: 7 7 7 7 2 2 7 2 2 3 ...
+## $ PlotSize_m2 : Factor w/ 16 levels "","0.04","0.0531",..: 1 1 1 1 12 12 1 16 16 6 ...
+## $ SurveyMethod : Factor w/ 13 levels "","BraunBlanquet",..: 4 4 4 4 8 8 4 3 3 2 ...
+## $ HitsPerPlot : Factor w/ 10 levels "","100","137",..: 1 1 1 1 2 2 1 NA NA NA ...
+## $ Comments : Factor w/ 20 levels "","\"0.25 m2 plots in 1992; 0.49 m2 in 2009\"",..: 1 1 1 1 1 1 1 2 2 1 ...
+## $ CHELSA_snow_days_1979 : int 365 365 365 365 365 365 365 365 365 365 ...
+## $ CHELSA_snow_days_1980 : int 365 365 365 365 365 365 365 365 365 298 ...
+## $ CHELSA_snow_days_1981 : int 365 365 365 365 365 365 365 365 365 365 ...
+## $ CHELSA_snow_days_1982 : int 365 365 365 365 365 365 365 365 365 365 ...
+## $ CHELSA_snow_days_1983 : int 365 365 365 365 365 365 365 365 365 365 ...
+## $ CHELSA_snow_days_1984 : int 365 365 365 365 365 365 365 365 365 321 ...
+## $ CHELSA_snow_days_1985 : int 365 365 365 365 365 365 365 365 365 271 ...
+## $ CHELSA_snow_days_1986 : int 365 365 365 365 365 365 365 365 365 365 ...
+## $ CHELSA_snow_days_1987 : int 365 365 365 365 365 365 365 365 365 311 ...
+## $ CHELSA_snow_days_1988 : int 365 365 365 365 365 365 365 365 365 312 ...
+## $ CHELSA_snow_days_1989 : int 365 365 365 365 365 365 365 365 365 365 ...
+## $ CHELSA_snow_days_1990 : int 365 365 365 365 365 365 365 365 365 340 ...
+## $ CHELSA_snow_days_1991 : int 365 365 365 365 365 365 365 365 365 334 ...
+## $ CHELSA_snow_days_1992 : int 365 365 365 365 365 365 365 365 365 365 ...
+## $ CHELSA_snow_days_1993 : int 365 365 365 365 355 355 365 355 355 355 ...
+## $ CHELSA_snow_days_1994 : int 365 365 365 365 365 365 365 365 365 351 ...
+## $ CHELSA_snow_days_1995 : int 365 365 365 365 365 365 365 365 365 365 ...
+## $ CHELSA_snow_days_1996 : int 365 365 365 365 365 365 365 365 365 292 ...
+## $ CHELSA_snow_days_1997 : int 365 365 365 365 365 365 365 365 365 317 ...
+## $ CHELSA_snow_days_1998 : int 365 365 365 365 346 346 365 346 346 365 ...
+## $ CHELSA_snow_days_1999 : int 365 365 365 365 354 354 365 354 354 308 ...
+## $ CHELSA_snow_days_2000 : int 365 365 365 365 365 365 365 365 365 311 ...
+## $ CHELSA_snow_days_2001 : int 365 365 365 365 365 365 365 365 365 307 ...
+## $ CHELSA_snow_days_2002 : int 365 365 365 365 365 365 365 365 365 306 ...
+## $ CHELSA_snow_days_2003 : int 365 365 365 365 365 365 365 365 365 303 ...
+## $ CHELSA_snow_days_2004 : int 365 365 365 365 365 365 365 365 365 299 ...
+## $ CHELSA_snow_days_2005 : int 365 365 365 365 316 316 365 316 316 328 ...
+## $ CHELSA_snow_days_2006 : int 365 365 365 365 340 340 365 340 340 318 ...
+## $ CHELSA_snow_days_2007 : int 338 338 338 338 324 324 338 324 324 354 ...
+## $ CHELSA_snow_days_2008 : int 334 334 334 334 297 297 334 297 297 302 ...
+## $ CHELSA_snow_days_2009 : int 303 303 303 303 298 298 303 298 298 342 ...
+## $ CHELSA_snow_days_2010 : int 365 365 365 365 344 344 365 344 344 283 ...
+## $ CHELSA_snow_days_2011 : int 313 313 313 313 306 306 313 306 306 365 ...
+## $ CHELSA_snow_days_2012 : int 312 312 312 312 295 295 312 295 295 337 ...
+## $ CHELSA_snow_days_2013 : int 365 365 365 365 365 365 365 365 365 365 ...
+## $ GSL_1979 : int 0 0 0 0 0 0 0 0 0 0 ...
+## $ GSL_1980 : int 0 0 0 0 0 0 0 0 0 61 ...
+## $ GSL_1981 : int 0 0 0 0 0 0 0 0 0 15 ...
+## $ GSL_1982 : int 0 0 0 0 0 0 0 0 0 0 ...
+## $ GSL_1983 : int 0 0 0 0 0 0 0 0 0 0 ...
+## $ GSL_1984 : int 0 0 0 0 0 0 0 0 0 50 ...
+## $ GSL_1985 : int 0 0 0 0 0 0 0 0 0 53 ...
+## $ GSL_1986 : int 0 0 0 0 0 0 0 0 0 0 ...
+## $ GSL_1987 : int 0 0 0 0 0 0 0 0 0 54 ...
+## $ GSL_1988 : int 0 0 0 0 0 0 0 0 0 50 ...
+## $ GSL_1989 : int 0 0 0 0 0 0 0 0 0 18 ...
+## $ GSL_1990 : int 0 0 0 0 0 0 0 0 0 19 ...
+## $ GSL_1991 : int 0 0 0 0 0 0 0 0 0 37 ...
+## $ GSL_1992 : int 0 0 0 0 0 0 0 0 0 0 ...
+## $ GSL_1993 : int 0 0 0 0 5 5 0 5 5 13 ...
+## $ GSL_1994 : int 0 0 0 0 0 0 0 0 0 0 ...
+## $ GSL_1995 : int 0 0 0 0 0 0 0 0 0 12 ...
+## $ GSL_1996 : int 0 0 0 0 0 0 0 0 0 70 ...
+## $ GSL_1997 : int 0 0 0 0 0 0 0 0 0 43 ...
+## $ GSL_1998 : int 0 0 0 0 0 0 0 0 0 26 ...
+## $ GSL_1999 : int 0 0 0 0 10 10 0 10 10 57 ...
+## $ GSL_2000 : int 0 0 0 0 0 0 0 0 0 57 ...
+## $ GSL_2001 : int 0 0 0 0 0 0 0 0 0 68 ...
+## $ GSL_2002 : int 0 0 0 0 0 0 0 0 0 61 ...
+## $ GSL_2003 : int 0 0 0 0 0 0 0 0 0 67 ...
+## $ GSL_2004 : int 0 0 0 0 0 0 0 0 0 55 ...
+## $ GSL_2005 : int 0 0 0 0 17 17 0 17 17 35 ...
+## $ GSL_2006 : int 0 0 0 0 17 17 0 17 17 58 ...
+## $ GSL_2007 : int 3 3 3 3 23 23 3 23 23 68 ...
+## $ GSL_2008 : int 26 26 26 26 43 43 26 43 43 60 ...
+## $ GSL_2009 : int 32 32 32 32 41 41 32 41 41 24 ...
+## $ GSL_2010 : int 0 0 0 0 10 10 0 10 10 85 ...
+## $ GSL_2011 : int 17 17 17 17 34 34 17 34 34 0 ...
+## $ GSL_2012 : int 19 19 19 19 44 44 19 44 44 0 ...
+## $ GSL_2013 : int 0 0 0 0 0 0 0 0 0 8 ...
+## $ GST_1979 : num NA NA NA NA NA NA NA NA NA NA ...
+## $ GST_1980 : num NA NA NA NA NA ...
+## $ GST_1981 : num NA NA NA NA NA ...
+## $ GST_1982 : num NA NA NA NA NA NA NA NA NA NA ...
+## $ GST_1983 : num NA NA NA NA NA NA NA NA NA NA ...
+## $ GST_1984 : num NA NA NA NA NA ...
+## $ GST_1985 : num NA NA NA NA NA ...
+## $ GST_1986 : num NA NA NA NA NA NA NA NA NA NA ...
+## $ GST_1987 : num NA NA NA NA NA ...
+## $ GST_1988 : num NA NA NA NA NA ...
+## $ GST_1989 : num NA NA NA NA NA ...
+## [list output truncated]
+mostRecordedSP = DATA$cover %>% group_by(Name) %>% summarise(nobs = length(Name)) %>% arrange(desc(nobs))
+selection = as.vector(t(mostRecordedSP[1:22, "Name"]))
+selection = selection[-which(selection %in% c("Arctagrostis latifolia", "Persicaria vivipara", "Carex aquatilis", "Cassiope tetragona", "Luzula confusa", "Luzula nivalis", "Salix arctica", "Poa arctica", "Eriophorum angustifolium", "Petasites frigidus", "Vaccinium uliginosum", "Dryas integrifolia"))]
+N.B. I have quickly selected 10 species among the 22 having the most observations, with no problem with zero-days growing season in the previous years before an observation, and no problem in the dataset… selection procedure to discuss
+Step 1: create_dataset
: - only subsites where the species have been seen (then ok for N=1) - extract plot info - build transition table - merge with plot info - calculate interval (years) - tag transition types - combine with climate (5 years earlier average) - merge all Step 2: adjustments - Add anomalies - remove intervals>=10 years - select variables c(“snowDays”, “GSL”, “GST”, “SoilMoist”, “TotalCover”) - modify SoilMoist levels (-1, 0, 1) Step 3: prepare dataset to fit - separate colonisation and extinction datasets - scale data (not SoilMoist) - prepare data for LaplacesDemon fit (optional) - add event column for glm fit
spDATA.list = lapply(selection, function(SPECIES){
+ print(SPECIES)
+ spDATA = dat.species(SPECIES, DATA)
+ return(spDATA)
+} )
+## [1] "Vaccinium vitis-idaea"
+## [1] "Carex bigelowii"
+## [1] "Ledum palustre"
+## [1] "Betula nana"
+## [1] "Eriophorum vaginatum"
+## [1] "Salix pulchra"
+## [1] "Eriophorum chamissonis"
+## [1] "Persicaria bistorta"
+## [1] "Dupontia fisheri"
+## [1] "Rubus chamaemorus"
+names(spDATA.list) = selection
+(spDATA.check = lapply(spDATA.list, check.nas))
+## [1] "Vaccinium vitis-idaea"
+## [1] "Carex bigelowii"
+## [1] "Ledum palustre"
+## [1] "Betula nana"
+## [1] "Eriophorum vaginatum"
+## [1] "Salix pulchra"
+## [1] "Eriophorum chamissonis"
+## [1] "Persicaria bistorta"
+## [1] "Dupontia fisheri"
+## [1] "Rubus chamaemorus"
+## $`Vaccinium vitis-idaea`
+## [1] 0
+##
+## $`Carex bigelowii`
+## [1] 0
+##
+## $`Ledum palustre`
+## [1] 0
+##
+## $`Betula nana`
+## [1] 0
+##
+## $`Eriophorum vaginatum`
+## [1] 0
+##
+## $`Salix pulchra`
+## [1] 0
+##
+## $`Eriophorum chamissonis`
+## [1] 0
+##
+## $`Persicaria bistorta`
+## [1] 0
+##
+## $`Dupontia fisheri`
+## [1] 0
+##
+## $`Rubus chamaemorus`
+## [1] 0
+lapply(spDATA.list, function(x) table(x$spdat$trType))
+## $`Vaccinium vitis-idaea`
+##
+## AA COLO EXT PP
+## 168 18 13 647
+##
+## $`Carex bigelowii`
+##
+## AA COLO EXT PP
+## 194 53 38 490
+##
+## $`Ledum palustre`
+##
+## AA COLO EXT PP
+## 147 22 17 513
+##
+## $`Betula nana`
+##
+## AA COLO EXT PP
+## 191 19 5 510
+##
+## $`Eriophorum vaginatum`
+##
+## AA COLO EXT PP
+## 199 34 27 419
+##
+## $`Salix pulchra`
+##
+## AA COLO EXT PP
+## 287 50 31 376
+##
+## $`Eriophorum chamissonis`
+##
+## AA COLO EXT PP
+## 81 40 46 251
+##
+## $`Persicaria bistorta`
+##
+## AA COLO EXT PP
+## 296 77 60 183
+##
+## $`Dupontia fisheri`
+##
+## AA COLO EXT PP
+## 214 29 38 218
+##
+## $`Rubus chamaemorus`
+##
+## AA COLO EXT PP
+## 315 34 22 191
+spDATA.fit = lapply(spDATA.list, fit.species)
+## [1] "Vaccinium vitis-idaea"
+## [1] "Carex bigelowii"
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+## [1] "Ledum palustre"
+## [1] "Betula nana"
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+## [1] "Eriophorum vaginatum"
+## [1] "Salix pulchra"
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+## [1] "Eriophorum chamissonis"
+## [1] "Persicaria bistorta"
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+
+## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
+## [1] "Dupontia fisheri"
+## [1] "Rubus chamaemorus"
+spDATA.fit[[1]]$colo
+##
+## Call: glm(formula = colo.event ~ GSL + GST + TotalCover + SoilMoist +
+## GSL:SoilMoist + GST:SoilMoist + TotalCover:SoilMoist, family = "binomial",
+## data = spDATA$colo)
+##
+## Coefficients:
+## (Intercept) GSL GST
+## -3.9995 -0.9393 3.2678
+## TotalCover SoilMoist GSL:SoilMoist
+## 0.9502 -1.4958 -2.5655
+## GST:SoilMoist TotalCover:SoilMoist
+## 6.5223 3.2555
+##
+## Degrees of Freedom: 185 Total (i.e. Null); 178 Residual
+## Null Deviance: 118.3
+## Residual Deviance: 77.27 AIC: 93.27
+eval.models = lapply(spDATA.fit, function(glm.fit){
+ eval.colo = eval.fit(glm.fit$colo, glm.fit$dat$colo, "colo.event")[-1]
+ vars.colo = paste(names(sort(abs(glm.fit$colo$coefficients[-1]), dec=T)), collapse=";")
+ eval.ext = eval.fit(glm.fit$ext, glm.fit$dat$ext, "ext.event")[-1]
+ vars.ext = paste(names(sort(abs(glm.fit$ext$coefficients[-1]), dec=T)), collapse=";")
+ return(list(colo.R2 = eval.colo$R2, colo.AUC = eval.colo$AUC, ext.R2 = eval.ext$R2, ext.AUC = eval.ext$AUC, vars.colo = vars.colo, vars.ext = vars.ext))
+})
+res.tab = do.call(rbind, eval.models)
+res.tab
+## colo.R2 colo.AUC ext.R2 ext.AUC
+## Vaccinium vitis-idaea 0.420457 0.8941799 0.03035965 0.6103912
+## Carex bigelowii 0.3131377 0.7919665 0.08320889 0.6446294
+## Ledum palustre 0.1403581 0.6742424 0.03557624 0.6017659
+## Betula nana 0.2892933 0.8483053 0.1751081 0.8796078
+## Eriophorum vaginatum 0.02042669 0.5316287 0.0713155 0.6987978
+## Salix pulchra 0.1812621 0.7474913 0.02601676 0.5888384
+## Eriophorum chamissonis 0.2176915 0.7401235 0.064756 0.6487095
+## Persicaria bistorta 0.1146254 0.6679756 0.08382495 0.6345628
+## Dupontia fisheri 0.2435445 0.7993877 0.2461762 0.8039594
+## Rubus chamaemorus 2.351904e-16 0.5 4.573867e-16 0.5
+## vars.colo
+## Vaccinium vitis-idaea "GST:SoilMoist;GST;TotalCover:SoilMoist;GSL:SoilMoist;SoilMoist;TotalCover;GSL"
+## Carex bigelowii "GSL;snowDays:SoilMoist;snowDays;TotalCover:SoilMoist;SoilMoist;TotalCover"
+## Ledum palustre "SoilMoist;TotalCover:SoilMoist;GST;TotalCover"
+## Betula nana "TotalCover:SoilMoist;snowDays;GSL;SoilMoist;TotalCover"
+## Eriophorum vaginatum "SoilMoist"
+## Salix pulchra "GSL;snowDays;SoilMoist;TotalCover:SoilMoist;TotalCover"
+## Eriophorum chamissonis "snowDays:SoilMoist;GSL:SoilMoist;TotalCover:SoilMoist;SoilMoist;TotalCover;snowDays;GSL"
+## Persicaria bistorta "SoilMoist;snowDays:SoilMoist;GST:SoilMoist;snowDays;GSL;GST"
+## Dupontia fisheri "GSL:SoilMoist;snowDays;snowDays:SoilMoist;GST;GSL;SoilMoist;TotalCover"
+## Rubus chamaemorus ""
+## vars.ext
+## Vaccinium vitis-idaea "SoilMoist"
+## Carex bigelowii "SoilMoist;TotalCover:SoilMoist;snowDays;TotalCover"
+## Ledum palustre "snowDays"
+## Betula nana "TotalCover;snowDays"
+## Eriophorum vaginatum "GSL;snowDays;TotalCover;GST"
+## Salix pulchra "TotalCover:SoilMoist;SoilMoist;TotalCover"
+## Eriophorum chamissonis "snowDays:SoilMoist;GSL:SoilMoist;GSL;GST;snowDays;SoilMoist"
+## Persicaria bistorta "SoilMoist;snowDays;GSL"
+## Dupontia fisheri "snowDays;snowDays:SoilMoist;GSL;GSL:SoilMoist;TotalCover:SoilMoist;TotalCover;SoilMoist"
+## Rubus chamaemorus ""
+{r model_evaluation} # plot_model(glm.fit$colo, transform = NULL, show.values=TRUE, title = paste(SPECIES, "colonisation")) # plot_model(glm.fit$ext, transform = NULL, show.values=TRUE, title = paste(SPECIES, "extinction")) # plot_model(glm.fit$colo, type = "eff") #
load("coverc_sub.rdata")
hist(coverc.sub$COVER)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.000 0.000 2.000 5.979 7.000 100.000
#----
-PA_COVER_TRESHOLD = 1
-#----
-cover.dom = cover.sub[which(cover.sub$COVER>PA_COVER_TRESHOLD),]
+cover.dom = cover.sub[which(cover.sub$YEAR<2014),]
SPECIES = "Vaccinium vitis-idaea"
-# SPECIES = "Betula nana"
+SPECIES = "Betula nana"
# SPECIES = "Salix arctica"
# SPECIES = "Salix pulchra"
# SPECIES = "Vaccinium uliginosum"
@@ -234,59 +234,128 @@ cover.dom = cover.sub[which(cover.sub$COVER>PA_COVER_TRESHOLD),]
source("R_fct/shape_data.r")
-spdat = create_dataset(SPECIES, cover.dom, sp.distri.path= "ArcticShrubCurrent/Vaccinium.vitisidaea_cur_pc_n.img")
-## Loading required package: raster
-## Loading required package: sp
-The steps of create_dataset
: - only subsites where the species have been seen - extract plot info - build transition table - merge with plot info - calculate interval (years) - tag “present” and “absent” - combine with climate (5 years earlier average) - extract spatial distribution - merge all
The steps of create_dataset
: - only subsites where the species have been seen (then ok for N=1) - extract plot info - build transition table - merge with plot info - calculate interval (years) - tag transition types - combine with climate (5 years earlier average) - merge all
spdat$GSL_anom = spdat$GSL-spdat$GSL_av
+spdat$GST_anom = spdat$GST-spdat$GST_av
+spdat$snowDays_anom = spdat$snowDays-spdat$snow_days_av
table(spdat$trType)
##
## absent colonisation extinction present
-## 205 49 28 639
-unique(spdat[which(spdat$st0=="colonisation"&spdat$distriArea==0),c("SUBSITE", "y0", "y1", "st0", "st1", "SoilMoist")])
-## [1] SUBSITE y0 y1 st0 st1 SoilMoist
-## <0 rows> (or 0-length row.names)
+## 199 20 6 515
+nrow(spdat)
+## [1] 740
+Here it means that 617 successive observations of presences are outside of the species distribution range!!
+#unique(spdat[which(spdat$trType=="present"&spdat$distriArea==0),c("SUBSITE", "y0", "y1", "st0", "st1", "SoilMoist", "distriArea")])
+spdat$trType = factor(spdat$trType)
+levels(spdat$trType) <- c("AA", "COLO", "EXT", "PP")
+
+bp <- ggplot(na.omit(spdat), aes(fill=trType, y=snowDays, x=trType)) +
+ geom_point() +
+ ggtitle("Snow") +
+ facet_wrap(~SUBSITE) +
+ theme(legend.position="none") +
+ xlab("")
+bp
+