# 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

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:

*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**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**Shepard with neighbours*: A maximum ammount of*N*neighbours is allowed to the weight calculation following Shepard method.

### 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 | ```
data(vipers)
data(d.gen)
data(grid)
# create a matrix of distances from sample points (columns) to all
# grid pixels
rd <- real.dist(vipers[,1:2], grid)
#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)
}
``` |