tdbscan: tdbscan

View source: R/tdbscan.R

tdbscanR Documentation

tdbscan

Description

tdbscan

Usage

tdbscan(track, eps, minPts = 5, borderPoints = FALSE, maxLag = 6, minTenure)

Arguments

track

A projected Track.

eps

size of the epsilon neighborhood (see dbscan::dbscan() ).

minPts

number of minimum points in the eps region (for core points). Default is 5 points (see dbscan::dbscan() ).

borderPoints

Logical; default to FALSE (see dbscan::dbscan() ).

maxLag

maximum relative temporal lag (see notes). Default to 6.

minTenure

minimum time difference, in hours, between the last and the first entry a cluster. Clusters with values smaller than minTenure are discarded.

Note

When maxLag is set to maxLag>N output is the same as for dbscan.

Examples

require(tdbscan)
require(data.table)
require(magrittr)
require(ggplot2)
require(ggrepel)

# Pectoral Sandpiper
data(pesa56511)
z = tdbscan(pesa56511, eps =6600, minPts   = 8, maxLag = 6, borderPoints = TRUE )

o = cbind(sp::coordinates(pesa56511), z)
ggplot(o, aes(longitude/10000,latitude/10000,color = factor(clustID))) +
geom_path(aes(color= NULL), col = 'grey', size = .5) + 
geom_point( alpha = .5, size = 2)


# Set minTenure
z = tdbscan(pesa56511, eps =6600, minPts   = 8, maxLag = 6, borderPoints = TRUE, minTenure= 24 )
o = cbind(sp::coordinates(pesa56511), z)
ggplot(o, aes(longitude/10000,latitude/10000,color = factor(clustID))) +
geom_path(aes(color= NULL), col = 'grey', size = .5) + 
geom_point( alpha = .5, size = 2)

# z bird
data(zbird)
z = tdbscan(zbird, eps =12, minPts   = 5, maxLag = 5, borderPoints = TRUE )
z = z[, clustID := factor(clustID)]

o = data.frame(zbird) %>% data.table
o = merge(z, o, by.x = 'id', by.y = 'sp.ID')

clustLab = o[!is.na(clustID), .(x = mean(x), y = mean(y), 
	arrival = min(time), departure = max(time)  ), by = clustID]
clustLab[, tenure := difftime(departure, arrival, units = 'hours')]
clustLab[, lab := paste("ID: ", clustID, ",", tenure, "hours")]

ggplot(o, aes(y,x, color = clustID ) )+
 geom_path(aes(color= NULL), col = 'grey', size = .5) + 
 geom_point( alpha = .5, size = 2) + 
 geom_label_repel(data = clustLab, aes(y,x, label = lab), alpha = 0.7, size = 3)

mpio-be/tdbscan documentation built on June 30, 2024, 7:39 a.m.