align2D: Function to align points from ordination with known locations

Description Usage Arguments Details Value Note Author(s) Examples

View source: R/align2D.R

Description

Find the linear transformation which, applied to one set of points in the ($x$, $y$) plane, gives the best match in a least squares sense to a second set of points.

Usage

1
align2D(lat, long, x1, x2, wts=NULL)

Arguments

lat

Latitude or other co-ordinate of point to align to

long

Longitude or other co-ordinate of point to align to

x1

First coordinate of point to align

x2

First coordinate of point to align

wts

If non-NULL, specifies weights for the points.

Details

Achieves the best match, in a least squares sense, between an ordination and known locations in two-dimensionaL space.

Value

fitlat

Fitted values of lat

fitlong

Fitted values of long

lat

Input values of lat

long

Input values of long

Note

An ordination that is designed to reproduce distances between points is specified only to within an arbitrary rotation about the centroid. What linear transformation of the points ($x1$, $x2$) given by the ordination gives the best match to the known co-ordinates?

Author(s)

John H Maindonald

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
if(require(DAAG)&require(oz)){
aupts <- cmdscale(audists)
xy <- align2D(lat = aulatlong$latitude, long = aulatlong$longitude,
              x1 = aupts[, 1], x2 = aupts[, 2], wts = NULL)
oz()
fitcoords <- align2D(lat=aulatlong$latitude,
                      long=aulatlong$longitude,
                      x1=aupts[,1], x2 = aupts[,2],
                      wts=NULL)
x <-with(fitcoords,
         as.vector(rbind(lat, fitlat, rep(NA,length(lat)))))
y <-with(fitcoords,
         as.vector(rbind(long, fitlong, rep(NA,length(long)))))
points(aulatlong, col="red", pch=16, cex=1.5)
lines(x, y, col="gray40", lwd=3)
}

## The function is currently defined as
function(lat, long, x1, x2, wts=NULL){
    ## Get best fit in space of (latitude, longitude)
    if(is.null(wts))wts <- rep(1,length(x1))
    fitlat <- predict(lm(lat ~ x1+x2, weights=wts))
    fitlong <- predict(lm(long ~ x1+x2, weights=wts))
    list(fitlat = fitlat, fitlong=fitlong, lat=lat, long=long)
}

jhmaindonald/DAAG documentation built on May 3, 2019, 3:13 p.m.