Skip to contents

Create the weights file required to run frescalo, as outlined in (Hill, 2011). For more information on frescalo see frescalo. This function takes a table of geographical distances between sites and a table of numeric data from which to calculate similarity (for example, landcover or abiotic data)

Usage

createWeights(
  distances,
  attributes,
  dist_sub = 200,
  sim_sub = 100,
  normalise = FALSE,
  verbose = TRUE
)

Arguments

distances

a dataframe giving the distance between sites in a long format with three columns. The first column give the ID of the first site, the second column gives the ID of the second site and the third column gives the distance between them. The table should include reciprocal data i.e. both rows 'A, B, 10' and 'B, A, 10' should exist.

attributes

a dataframe of numeric attributes of each site. The first column must contain the site IDs and all other columns are used to calculate the similarity between sites using dist() and method 'euclidean'.

dist_sub

the number of neighbours to include after ranking by distance. In Hill (2011), this is set to 200 and is the default here

sim_sub

the number of neighbours to include after ranking by similarity. This is the final number of sites that will be included in a neighbourhood. In Hill (2011), this is set to 100 and is the default here.

normalise

Logical. If TRUE each attribute is divided by its maximum value to produce values between 0 and 1. Default is FALSE

verbose

Logical, should progress be printed to console. Defaults to TRUE

Value

A dataframe is returned in a format that can be used directly in frescalo() or sparta(). The dataframe has three columns giving the target cell, the neighbourhood cell, and the weight.

References

Hill, Mark. Local frequency as a key to interpreting species occurrence data when recording effort is not known. 2011. Methods in Ecology and Evolution, 3 (1), 195-205.

Examples

if (FALSE) {

mySites <- paste('Site_', 1:100, sep = '')

# Build a table of distances
myDistances <- merge(mySites, mySites) 

# add random distances
myDistances$dist <- runif(n = nrow(myDistances), min = 10, max = 10000) 

# to be realistic the distance from a site to itself should be 0
myDistances$dist[myDistances$x == myDistances$y] <- 0

# Build a table of attributes
myHabitatData <- data.frame(site = mySites,
                            grassland = runif(length(mySites), 0, 1),
                            woodland = runif(length(mySites), 0, 1),
                            heathland = runif(length(mySites), 0, 1),
                            urban = runif(length(mySites), 0, 1),
                            freshwater = runif(length(mySites), 0, 1))

# This pretend data is supposed to be proportional cover so lets 
# make sure each row sums to 1
multiples <- apply(myHabitatData[,2:6], 1, sum)
for(i in 1:length(mySites)){
  myHabitatData[i,2:6] <- myHabitatData[i,2:6]/multiples[i]
}

# Create the weights file
weights <- createWeights(distances = myDistances,
                          attributes = myHabitatData,
                          dist_sub = 20,
                          sim_sub = 10)
}