r-tools to analyse bird data_henk sierdsema_bird numbers 2016
TRANSCRIPT
R-tools to analyse bird data
Henk Sierdsema
Christian Kampichler
Bird data
• Monitoring data
• Atlas data
• Casual observations and lists
Saxifraga – Piet Munsterman
Bird data analysis
• Trends
• Distribution maps
• Trend maps / change
maps
Saxifraga – Piet Munsterman
Analysis tools
• Dedicated programs
– Trends: TRIM
– Maps: GIS (ArcGis, QGis), Maxent
• Scripting
Saxifraga – Piet Munsterman
• Free
• http://www.r-project.org/
• Large user community
• Many plugins called ‘packages’ dedicated
to specific statistical issues
• You can perfom very basic and very advanced statistics with R
• But it’s also very useful if you have to (almost) the same thing many times, like: – Make trends graphs for 100 species
– Make correlation plots for 100 species and 50 variables
– Make distribution maps for 100 species
• And if you want to redo an analysis because you got new data
Trend analysis of monitoring data
• Most organisations use TRIM to calculate
trends
TRIM
• Data files needed for TRIM
– Observations
– For automated runs (batches): Command-file
TRIM-observation file
• Complete matrix: – Positive observations
– Zero-observations
– Missing values
– (Covariates)
5 1976 -1
5 1977 -1
5 1978 -1
5 1979 -1
5 1980 0
5 1981 -1
5 1982 0
5 1983 1
5 1984 0
5 1985 0
5 1986 5
5 1987 0
Statistics in TRIM
• Generalized Estimating Equations
– Modelling of repeated/correlated
observations
– Robust regression method
– Estimating procedure, no likelihood function
TRIM output
• Estimated numbers per site per year
• Trend estimates
• Basic graphs in interactive mode
BirdStats
• Facilitate data preparation, trend
calculation and retrieval of output
• Access-database
BirdStats
• However, also requires data-processing
before data can be read into BirdStats
• Limited flexibility
• Other option: make R-script to prepare
data and retrieval of output
TRIM R-script
• Retrieve data directly from database or
read .csv-files
• Set number of parameters like:
– Time period (can be species specific)
– Species selection
– Site-selection (shape or csv-file)
TRIM R-script
• Run TRIM in batch mode with tcf-
command files
• Retrieve TRIM-output
• Makes observations maps and maps
Saxifraga – Mark Zekhuis
TRIM R-script
• Retrieve data directly from Postgres-
database or read .csv-files:
– Sites
– Visits
– Observations
Examples
• Make files for TRIM
– make.TRIM.files()
• Run TRIM
• Import TRIM-output
– Import.TRIM.output()
Examples
• Read data ## ROUTE LOCATIONS
pktrute <- read.csv2("pktrute.csv", as.is = TRUE,
fileEncoding = "UTF8")
## SPECIES CODES AND NAMES
speciescodes <- read.csv2("speciescodes.csv", as.is = TRUE,
fileEncoding = "UTF8")
• Set parameters minyear <- 1976
maxyear <- 2015
map.format <- "pdf“
test.run <- TRUE
Output: maps with observations
© Danish bird data: DOF
Output: trend graphs
MAPS
Spatial modeling with TRIMmaps
Saxifraga – Piet Munsterman
TRIMmaps
• Facilitate production of maps from
monitoring data and casual
observations
• R-programme
• Open source / freeware
Statistics TRIMmaps
• Combination of
– Regression type statistics
– Spatial interpolation of residuals
• Uses TRIM-input (data-files) or -output
(F1-files) and a number of other formats
Interpolation of residuals
• Inversed Distance Weighting (IDW)
• Kriging
Include observed local deviations from regression model
Better maps
Combined map
interpolated residuals
regression model
What do you need to run TRIMmaps ?
Observations
• Counts
• Presence-absence
• Presence-only
• Local trend data
• CSV-file
• TRIM F1- or dat-files
Site/location info
• X- and Y-coordinates
Environmental maps
• Raster maps
– Like:
• Climate
• Land use
• Landscape
Optional: site specific covariates
• Environmental characteristics for sites
that have a different spatial extend than
the prediction grids
– Like:
• buffers around points
• Transects with distance bands
• Plots with natural bounderies
• Squares that are bigger than the prediction grid
• Have to be pre-prepared with GIS
And some basic R-knowledge
We even made a small course for you
Running TRIMmaps
Zeroes
• Add zeroes for TRIM F1- or dat-files
• Generate zeroes with Maxent
Overlay with environmental data
sets
• Climate
• Altitude (DTM)
• Land cover
• …
Regression models
• GLM
• GAM
• MARS
• Mixed models
• Boosted Regression Trees
• Random Forests
• ..
Output
• Maps
– Observations
– Predictions regression
– Residuals
– Combined map
• Regression models
• Model validations
• Shape-files, ASCII-grids and geoTIFF with predictions
Observations
Distribution maps: regression
predictions
Interpolated residuals
Distribution maps
Regression predictions and
interpolated residuals
Regression predictions
Interpolated residuals
Variable contributions
Variable Relative
importance (%)
Precipitation Seasonality 18.8
Precipitation of Driest Month 17.4
Arable land 15.6
Precipitation of Warmest Quarter 8.5
Temperature Seasonality 6.1
Potential evapotranspiration 5.8
Silt soil 4.7
Mean Temperature of Driest
Quarter 3.9
Complex cultivation patterns 3.6
Response curves
18 20 22 24 26 28 302
46
81
0
bio_15
Pre
dic
ted
co
un
t
19.9 %
0.0 0.2 0.4 0.6 0.8 1.0
23
45
6
c00_f12_1km
Pre
dic
ted
co
un
t
16.6 %
30 35 40 45
34
56
78
bio_14
Pre
dic
ted
co
un
t
15.9 %
160 180 200 220
3.0
3.2
3.4
3.6
bio_18
Pre
dic
ted
co
un
t
8.8 %
5600 5800 6000 6200 6400
3.1
3.2
3.3
3.4
3.5
bio_4
Pre
dic
ted
co
un
t
6 %
480 520 560 600
3.0
3.4
3.8
4.2
pet_he_yr
Pre
dic
ted
co
un
t
5.4 %
Model quality
• Explained deviance
• Error statistics (MAE, MFE)
• ROC-plots
• Cross-validation
• Covariate maps
• QQ-plots, etc
Combining
trend and distribution:
trend maps
Trend maps
• Standardized difference between the
average count in the last three years and
the first three years of the period of
interest
Nend of period – Nstart of period
(N1+N2)/2
Corn Bunting trend 1984-1995
Corn Bunting trend 1994-2005
Corn Bunting trend 2004-2015
Difference maps
• Difference between predicted
distribution in two time periods
Saxifraga – Piet Munsterman
Absolute difference map
2010
2000
Important remarks
• Bird observed Birds present !
• Assumes minor influence of differences in
detection probabilities between habitats
• Next steps: account for imperfect
detection
Comparison with other R-
packages
• Site-specific covariates
– like buffer around point or transect
– downscaling larger grids
• Account for spatial correlation in
residuals
• Use TRIM-files for input
Download TRIMmaps
www.sovon.nl/nl/content/trimmaps
Download TRIMmaps
or simply google ‘trimmaps’
Installing TRIMmaps
• Install R
• Install 64-bits Java manually!
• Run ‘install_TRIMmaps.r’
• Check dependent packages with
firstLibraryStart()
• That’s it!
Thank you for your attention… And we are happy to help you with the use of TRIMmaps!
An extented version of this presentation
can be download from Slideshare.net
Saxifraga – Mark Zekhuis