intgen.idw {phylin}R Documentation

Interpolation of genetic distances to a a grid of points.

Description

Interpolations of a matrix containing genetic distances using the Inverse Distance Weighting (IDW) algorithm. It generates a matrix of interpolated values for each grid cell and for each sample.

Usage

intgen.idw(d.real, d.gen, method = "Shepard", p = 2, R = 2, N = 15)

Arguments

d.real

distance matrix between sampled locals (columns) and locals where interpolation is to be executed (rows). Names should correspond to genetic distances matrix.

d.gen

genetic distances matrix. Names should correspond to real distances matrix, but not necessarily in the same order.

method

Method to calculate weights for idw. Should be "Shepard" (default), "Modified", "Neighbours", or distinctive abreviations of each. See details section for additional help on each method.

p

The power to use in weight calculation.

R

Radius to use with Modified Shepard method.

N

Maximum number of neighbours to use with Shepard with neighbours.

Details

The IDW interpolation algorithm is commonly used to interpolate genetic data over a spatial grid. This function provides a simple interface to interpolate such data with three methods:

  1. Shepard: weights are the inverse of the distance between the interpolation location x and the sample points x_i, raised to the power p

    w(x) = \frac{1}{d(x, x_i)^p}

  2. Modified Shepard: distances are weighted with a search radius r to calculate the interpolation weights

    w(x) = \left(\frac{r-d(x, x_i)}{r.d(x, xi)}\right)^p

  3. Shepard with neighbours: A maximum ammount of N neighbours is allowed to the weight calculation following Shepard method.

The functions 'intgen.idw' and 'idw' are similar but whereas the first interpolate all samples to a grid-based coordinates, the second interpolates a single set of values. Although 'idw' can be used to generate the same results, the 'intgen.idw' should be faster (see the examples).

Value

This function returns a matrix containing all interpolated values for each locality (rows) and for each sample (columns)

Author(s)

Pedro Tarroso <ptarroso@cibio.up.pt>

References

Fortin, M. -J. and Dale, M. (2006) Spatial Analysis: A guide for Ecologists. Cambridge: Cambridge University Press.

Isaaks, E. H. and Srivastava, R. M. (1989) An Introduction to applied geostatistics. New York: Oxford University Press.

Legendre, P. and Legendre, L. (1998) Numerical ecology. 2nd english edition. Amesterdam: Elsevier

See Also

idw

Examples

    data(vipers)
    data(d.gen)
    data(grid)

    # create a matrix of distances from sample points (columns) to all
    # grid pixels
    rd <- geo.dist(grid, vipers[,1:2])

    #interpolate with idw
    result <- intgen.idw(rd, d.gen)

    #plot the 12 random interpolations
    layout(matrix(c(1:12), 4,3))

    for (i in sample(1:nrow(vipers), 12))
    {
        dt <- data.frame(grid, int=result[,i])
        # when samples are given with real coordinates, aspect of image 
        # should be maintained with asp=1 to plot properly. 
        image(sort(unique(grid[,1])), sort(unique(grid[,2])), 
              xtabs(int~x+y, dt), xlab='Longitude', ylab='Latitude', 
              main=colnames(result)[i])
        cex <- (d.gen[,i]-min(d.gen[,i]))/(max(d.gen[,i])-min(d.gen[,i]))
        points(vipers[,1:2], cex=cex+0.5)
    }

## Not run: 
    # Compare 'idw' with 'intgen.idw' to generate the same results.
    # NOTE: it may take a few minutes to run.
    result2 <- matrix(NA, nrow=nrow(grid), ncol=nrow(vipers))
    for (i in 1:nrow(vipers)) {
        values <- d.gen[i,]
        intpl <- idw(values, vipers[,1:2], grid)
        result2[,i] <- intpl[,1]
    }
    colnames(result2) <- rownames(vipers)

    # compare all items in the two matrices to check equality:
    all(result == result2)

## End(Not run)

[Package phylin version 2.0.2 Index]