intgen.idw: Interpolation of genetic distances to a a grid of points.

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/intgen.idw.R

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

1
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) = 1/d(x, xi)^p

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

    w(x) = ((r-d(x, xi)) / (r*d(x, xi)))^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

 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
    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)

phylin documentation built on Dec. 12, 2019, 5:07 p.m.