distance {sphet} | R Documentation |
Distance measures available in distance
Description
Reads points coordinates and generates objects of class distance.matrix
Usage
distance(coord, region.id = NULL, output = TRUE,
type = c("NN", "distance", "inverse"),
measure = c("euclidean", "gcircle", "chebyshev", "braycur", "canberra"),
nn = 6, cutoff = FALSE, miles = TRUE, R = NULL, shape.name = NULL, region.id.name = NULL,
firstline = FALSE, file.name = NULL)
Arguments
coord |
a matrix with the (X,Y)-coordinates of the points. The first column can be the region.id variable giving the ordering of the observations |
region.id |
variable that defines the ordering of the observations |
output |
when TRUE (default) writes the object to a file |
type |
one of |
measure |
one of |
nn |
the number of nearest neighbors |
cutoff |
If type is |
miles |
If TRUE (default), distances are in miles, otherwise in Km. (See |
R |
deprecated, |
shape.name |
The name of the shape file. See Details |
region.id.name |
The name of the |
firstline |
If |
file.name |
If |
Details
Writes distance matrices
The object created is similar to the content of a 'GWT'
file. The output file can be of any format.
In particular, it could be a 'GWT'
file. When firstline
is TRUE
, an header line is added to the 'GWT'
file.
The first element is simply a place holder, the second is the number of observations. The name of the shape file
and of the id variable can be specified by the options shape.name
and region.id.name
respectively.
The function performs a series of test on the region.id
variable. If a region.id
variable is not specified and
coord
only has two columns, a sequence from 1 to the number of observations is generated and
used as identification variable. If region.id
is specified
and the first column of coord
contains an id variable they should be the same.
The distance measures implemented in sphet
are:
-
'euclidean'
:\sqrt{\sum{(x_i - y_i)^2}}
-
'chebyshev'
:max(|x_i - y_i|)
-
'braycur'
:\frac{\sum{|x_i - y_i|}}{\sum{|x_i + y_i|}}
-
'canberra'
:\frac{\sum{|x_i - y_i|}}{\sum{|x_i| + |y_i|}}
-
'gcircle'
: seespDists
, which uses an approximation to the WGS84 spheroid.
Value
A matrix
of three columns: from
, to
, and distance
Author(s)
Gianfranco Piras gpiras@mac.com
Examples
set.seed("1234")
X <- runif(100, 0, 70)
Y <- runif(100, -30, 20)
coord1 <- cbind(seq(1,100), X, Y)
thm2 <- distance(coord1, region.id = NULL,
output = FALSE, type = "NN", nn = 6)
thm2 <- distance(coord1, region.id = NULL, output = FALSE, type = "distance", cutoff = 1)