Learn R Programming

DAAG (version 1.24)

align2D: Function to align points from ordination with known locations

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

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.

Value

fitlat

Fitted values of lat

fitlong

Fitted values of long

lat

Input values of lat

long

Input values of long

Details

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

Examples

Run this code
# NOT RUN {
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)
}
# }

Run the code above in your browser using DataLab