This function takes in data for a recorder and calculates the spatial metrics. Note that the spatial projection of the data allows for estimates of distance in meters. Pay particular attention to the specification of the parameters crs and new_crs

spatialBehaviour(recorder_name, data, y_col, x_col, crs, new_crs,
  recorder_col = "recorders", upper_percentile = 95,
  lower_percentile = 60, h = 5000, res = 1000, threshold = 5)

Arguments

recorder_name

the name of the recorder for whom you want to calculate the metrics

data

the data.frame of recording information

y_col

the name of the column that contains the y coordinate (e.g. latitude) of the observation. This should be a numeric.

x_col

the name of the column that contains the x coordinate (e.g. longitude) of the observation. This should be a numeric.

crs

the proj4 string that describes the projection your data are using. For GPS lat long this is "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs". You can find more at http://spatialreference.org/

new_crs

the proj4 string that the describes the coordinate system your data should be reprojected to. THIS IS IMPORTANT. Your data must be on a projection that has units in meters so that results are comparable to other studies. An appropriate system in the UK is the UK national grid "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs". If your original crs (given in the argument crs), already has units in meters then set new_crs = NULL. WARNING: if you set this to NULL but your coordinate system is not in units of meters you will likely have errors.

recorder_col

the name of the column that contains the recorder names

upper_percentile

The percentile used to create a polygon that encapsulates a proportion of the recorders observations using the kernel method (?adehabitatHR::kernelUD). This is used to estimate the area covered as will as the ratio of core to total area covered, see Value.

lower_percentile

see upper_percentile

h

a numeric smoothing parameter for drawing the kernels. See ?adehabitatHR::kernelUD for details.

res

a numeric giving the resolution for kernel estimation.

threshold

If there are less than this number of observations NA values will be returned for the metrics. Default is 5

Value

A data.frame with seven columns

  • recorder - The name of the recorder, as given in the recorder_name argument

  • spPoint - The observation points as a SpatialPoints object

  • poly_upper - A SpatialPolygonsDataFrame object giving the are containing the upper_percentile percentage of records using the kernel method

  • poly_lower - A SpatialPolygonsDataFrame object giving the are containing the lower_percentile percentage of records using the kernel method

  • upper_n_poly - The number of polygons that make up poly_upper

  • lower_n_poly - The number of polygons that make up poly_lower

  • upper_area - The area of the polygons that make up poly_upper in km squared

  • lower_area - The area of the polygons that make up poly_upper in km squared

  • ratio - The ratio of lower_area to upper_area calculated as lower_area/upper_area

  • n - The total number of observations made by this recorder

Examples

# NOT RUN {
# load example data
head(cit_sci_data)

# Run for one recorder using the UK grid

## get the proj4 strings from http://spatialreference.org
# current form is lat long
WGS_84 <- "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"
# I want to change to UK national grid as that is in meters
UKNG <- "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs"

SB <- spatialBehaviour(recorder_name = 3007,
                       data = cit_sci_data,
                       crs = WGS_84,
                       new_crs = UKNG,
                       y_col = 'lat',
                       x_col = 'long',
                       recorder_col = 'recorder')

SB
plot(SB$poly_upper)

# Run for more than one recorder, this can be slow 
SB_all <- lapply(unique(cit_sci_data$recorder)[1:10],
                FUN = spatialBehaviour,
                data = cit_sci_data,
                crs = WGS_84,
                new_crs = UKNG,
                y_col = 'lat',
                x_col = 'long',
                recorder_col = 'recorder')

# summarise as one table
SB_all_sum <- do.call(rbind, SB_all)

SB_all_sum
# }