Title: | Spatial Covariance Functions |
---|---|
Description: | Spatial (cross-)covariance and related geostatistical tools: the nonparametric (cross-)covariance function , the spline correlogram, the nonparametric phase coherence function, local indicators of spatial association (LISA), (Mantel) correlogram, (Partial) Mantel test. |
Authors: | Ottar N. Bjornstad [aut, cre], Jun Cai [ctb] |
Maintainer: | Ottar N. Bjornstad <[email protected]> |
License: | GPL-3 |
Version: | 1.3-2 |
Built: | 2025-03-08 02:13:11 UTC |
Source: | https://github.com/objornstad/ncf |
Alternative summary method for class "Sncf2D".
cc.offset(object, xmax = NULL)
cc.offset(object, xmax = NULL)
object |
an object of class "Sncf2D", usually, as a result of a call to |
xmax |
the maximum distance to consider (default is no upper limit). |
An matrix of class "cc.offset" is returned with columns:
angle |
the cardinal angle (in degrees). |
distance |
the distances (in the positive direction) to the mode of the (cross-) correlation function (with 95% confidence bounds). |
correlation |
the correlation at the mode (with CI) for each of the cardinal angles. |
Sncf2D
, summary.Sncf2D
, plot.cc.offset
A vectorized function to calculate a correlation matrix for panels of data.
circ.cor2(x, y = NULL)
circ.cor2(x, y = NULL)
x |
a matrix. |
y |
an optional second matrix. |
Missing values are not allowed.
A correlation matrix is returned.
Jammalamadaka, S. Rao and SenGupta, A. (2001). Topics in Circular Statistics, Section 8.2, World Scientific Press, Singapore.
Called by various functions to calculate Pearson or angular correlation matrices.
cor2(x, y = NULL, circ = FALSE)
cor2(x, y = NULL, circ = FALSE)
x |
a matrix. |
y |
an optional second matrix. |
circ |
If TRUE, the observations are assumed to be angular (in radians), and circular correlation is used. If FALSE, Pearson product moment correlations is returned. |
An auxilliary function to ease the maintenance.
A correlation matrix is returned.
Jammalamadaka, S. Rao and SenGupta, A. (2001). Topics in Circular Statistics, Section 8.2, World Scientific Press, Singapore.
correlog
is the function to estimate spatial (cross-)correlograms. Either univariate or multivariate (time seres) for each site can be used.
correlog( x, y, z, w = NULL, increment, resamp = 999, latlon = FALSE, na.rm = FALSE, quiet = FALSE )
correlog( x, y, z, w = NULL, increment, resamp = 999, latlon = FALSE, na.rm = FALSE, quiet = FALSE )
x |
vector of length n representing the x coordinates (or longitude; see latlon). |
y |
vector of length n representing the y coordinates (or latitude). |
z |
vector of length n or matrix of dimension n x p representing p observation at each location. |
w |
an optional second variable with identical dimension to z (to estimate cross-correlograms). |
increment |
increment for the uniformly distributed distance classes. |
resamp |
the number of permutations under the null to assess level of significance. |
latlon |
If TRUE, coordinates are latitude and longitude. |
na.rm |
If TRUE, NA's will be dealt with through pairwise deletion of missing values. |
quiet |
If TRUE, the counter is suppressed during execution. |
The spatial (cross-)correlogram and Mantel (cross-)correlogram estimates the spatial dependence at discrete distance classes.
The region-wide similarity forms the reference line (the zero-line); the x-intercept is thus the distance at which object are no more similar than that expected by-chance-alone across the region.
If the data are univariate, the spatial dependence is measured by Moran's I. If it is multivariate, it is measured by the centred Mantel statistic. (Use correlog.nc
if the non-centered multivariate correlogram is desired).
Missing values are allowed – values are assumed missing at random.
An object of class "correlog" is returned, consisting of the following components:
correlation |
the value for the Moran (or Mantel) similarity. |
mean.of.class |
the actual average of the distances within each distance class. |
nlok |
the number of pairs within each distance class. |
x.intercept |
the interpolate x.intercept of Epperson (1993). |
p |
the permutation two-sided p-value for each distance-class. |
corr0 |
If a cross-correlogram is calculated, corr0 gives the empirical cross-correlation at distance zero. |
Ottar N. Bjornstad [email protected]
Bjornstad, O.N., Ims, R.A. & Lambin, X. (1999) Spatial population dynamics: Analysing patterns and processes of population synchrony. Trends in Ecology and Evolution, 11, 427-431. <doi:10.1016/S0169-5347(99)01677-8>
Bjornstad, O.N. & Falck, W. (2001) Nonparametric spatial covariance functions: estimation and testing. Environmental and Ecological Statistics, 8:53-70. <doi:10.1023/A:1009601932481>
Epperson, B.K. (1993) Recent advances in correlation studies of spatial patterns of genetic variation. Evolutionary Biology, 27, 95-155. <doi:10.1007/978-1-4615-2878-4_4>
plot.correlog
, spline.correlog
, correlog.nc
# first generate some sample data x <- expand.grid(1:20, 1:5)[, 1] y <- expand.grid(1:20, 1:5)[, 2] # z data from an exponential random field z <- cbind( rmvn.spa(x = x, y = y, p = 2, method = "exp"), rmvn.spa(x = x, y = y, p = 2, method = "exp") ) # w data from a gaussian random field w <- cbind( rmvn.spa(x = x, y = y, p = 2, method = "gaus"), rmvn.spa(x = x, y = y, p = 2, method = "gaus") ) # Spatial correlogram fit1 <- correlog(x = x, y = y, z = z[, 1], increment = 2, resamp = 0) ## Not run: plot(fit1) # Mantel correlogram fit2 <- correlog(x = x, y = y, z = z, increment = 2, resamp = 0) ## Not run: plot(fit2) # Mantel cross-correlogram fit3 <- correlog(x = x, y = y, z = z, w = w, increment = 2, resamp = 0) ## Not run: plot(fit3)
# first generate some sample data x <- expand.grid(1:20, 1:5)[, 1] y <- expand.grid(1:20, 1:5)[, 2] # z data from an exponential random field z <- cbind( rmvn.spa(x = x, y = y, p = 2, method = "exp"), rmvn.spa(x = x, y = y, p = 2, method = "exp") ) # w data from a gaussian random field w <- cbind( rmvn.spa(x = x, y = y, p = 2, method = "gaus"), rmvn.spa(x = x, y = y, p = 2, method = "gaus") ) # Spatial correlogram fit1 <- correlog(x = x, y = y, z = z[, 1], increment = 2, resamp = 0) ## Not run: plot(fit1) # Mantel correlogram fit2 <- correlog(x = x, y = y, z = z, increment = 2, resamp = 0) ## Not run: plot(fit2) # Mantel cross-correlogram fit3 <- correlog(x = x, y = y, z = z, w = w, increment = 2, resamp = 0) ## Not run: plot(fit3)
correlog.nc
is the function to estimate the non-centered (cross-)correlogram. The non-centered correlogram provides estimates of the spatial correlation for discrete distance classes. The function requires multiple observations at each location (use correlog
otherwise).
correlog.nc( x, y, z, w = NULL, increment, resamp = 999, na.rm = FALSE, latlon = FALSE, quiet = FALSE )
correlog.nc( x, y, z, w = NULL, increment, resamp = 999, na.rm = FALSE, latlon = FALSE, quiet = FALSE )
x |
vector of length n representing the x coordinates (or longitude; see latlon). |
y |
vector of length n representing the y coordinates (or latitude). |
z |
a matrix of dimension n x p representing p (>1) observation at each location. |
w |
an optional second variable with identical dimension to z (to estimate cross-correlograms). |
increment |
increment for the uniformly distributed distance classes. |
resamp |
the number of permutations under the null to assess level of significance. |
na.rm |
If TRUE, NA's will be dealt with through pairwise deletion of missing values. |
latlon |
If TRUE, coordinates are latitude and longitude. |
quiet |
If TRUE, the counter is suppressed during execution. |
The non-centered correlogram estimates spatial dependence at discrete distance classes. The method corresponds to the modified correlogram of Koenig & Knops(1998), but augmented to potentially estimate the cross-correlogram). The function requires multiple observations at each location. Missing values is allowed in the multivariate case (pairwise deletion will be used).
Missing values are allowed – values are assumed missing at random.
An object of class "correlog" is returned, consisting of the following components:
correlation |
the value for the Moran (or Mantel) similarity. |
mean.of.class |
the actual average of the distances within each distance class. |
nlok |
the number of pairs within each distance class. |
x.intercept |
the interpolate x.intercept of Epperson (1993). |
p |
the permutation p-value for each distance-class. |
corr0 |
If a cross-correlogram is calculated, corr0 gives the empirical within-patch cross-correlation. |
Ottar N. Bjornstad [email protected]
Bjornstad, O.N., Ims, R.A. & Lambin, X. (1999) Spatial population dynamics: Analysing patterns and processes of population synchrony. Trends in Ecology and Evolution, 11, 427-431. <doi:10.1016/S0169-5347(99)01677-8>
Koenig, W.D. & Knops, J.M.H. (1998) Testing for spatial autocorrelation in ecological studies. Ecography, 21, 423-429. <doi:10.1111/j.1600-0587.1998.tb00407.x>
# first generate some sample data x <- expand.grid(1:20, 1:5)[, 1] y <- expand.grid(1:20, 1:5)[, 2] # z data from an exponential random field z <- cbind( rmvn.spa(x = x, y = y, p = 2, method = "exp"), rmvn.spa(x = x, y = y, p = 2, method = "exp") ) # w data from a gaussian random field w <- cbind( rmvn.spa(x = x, y = y, p = 2, method = "gaus"), rmvn.spa(x = x, y = y, p = 2, method = "gaus") ) # noncentered (Mantel) correlogram fit1 <- correlog.nc(x = x, y = y, z = z, increment = 2, resamp = 499) ## Not run: plot(fit1)
# first generate some sample data x <- expand.grid(1:20, 1:5)[, 1] y <- expand.grid(1:20, 1:5)[, 2] # z data from an exponential random field z <- cbind( rmvn.spa(x = x, y = y, p = 2, method = "exp"), rmvn.spa(x = x, y = y, p = 2, method = "exp") ) # w data from a gaussian random field w <- cbind( rmvn.spa(x = x, y = y, p = 2, method = "gaus"), rmvn.spa(x = x, y = y, p = 2, method = "gaus") ) # noncentered (Mantel) correlogram fit1 <- correlog.nc(x = x, y = y, z = z, increment = 2, resamp = 499) ## Not run: plot(fit1)
Fourier filter to ensure positive semi-definite correlation functions. Called by various functions.
ff.filter(x)
ff.filter(x)
x |
a vector. |
A vector is returned whose Fourier-transform has no non-negative coefficients.
Called by various functions to calculate various intercepts.
gather(u, v, w, moran, df, xpoints, filter, fw)
gather(u, v, w, moran, df, xpoints, filter, fw)
u |
a vector. |
v |
a vector. |
w |
a vector. |
moran |
a matrix. |
df |
a scalar. |
xpoints |
a vector. |
filter |
a logical. |
fw |
a scalar |
An auxiliary function to ease maintenance.
A list is returned.
Great-circle distance function to calculate spatial distance from lat-long data. Called by various functions.
gcdist(x, y)
gcdist(x, y)
x |
vector of longitudes. |
y |
vector of latitudes. |
The distance in km is returned
This is the data in Bjornstad et al. (2002).
data(lbm)
data(lbm)
A data-frame with 135 rows and 40 columns. The first two are the x- and y-coordinates (in m), the following 38 represents the defoliation in years 1961 through 1998.
Bjornstad, O.N., Peltonen, M., Liebhold, A.M., and Baltensweiler, W. (2002) Waves of larch budmoth outbreaks in the European Alps. Science, 298, 1020-1023. <doi:10.1126/science.1075182>
lisa
is a function to estimate the local indicators of spatial association. The function assumes univariate data at each location. For multivariate data use lisa.nc
lisa(x, y, z, neigh, resamp = 999, latlon = FALSE, quiet = FALSE)
lisa(x, y, z, neigh, resamp = 999, latlon = FALSE, quiet = FALSE)
x |
vector of length n representing the x coordinates (or latitude; see latlon). |
y |
vector of length n representing the y coordinates (or longitude). |
z |
vector of n representing the observation at each location. |
neigh |
neighborhood size. |
resamp |
number of resamples under the NULL to generate p-values |
latlon |
If TRUE, coordinates are latitude and longitude. |
quiet |
If TRUE, the counter is suppressed during execution. |
This is the function to estimate the local indicators of spatial association modified form Anselin (1995). The statistic is the average autocorrelation within a neighborhood.
An object of class "lisa" is returned, consisting of the following components:
correlation |
the autocorrelation within the neighborhood (neigh) of each observation measured using Moran's I. |
p |
the permutation two-sided p-value for each observation. |
mean |
the mean of the observations inside each neighborhooddistance within each neighborhood. |
n |
the number of observations within each neighborhood. |
dmean |
the actual mean distance within each neighborhood. |
z |
the original observations |
coord |
a list with the x and y coordinates. |
Ottar N. Bjornstad [email protected]
Anselin, L. 1995. Local indicators of spatial association - LISA. Geographical Analysis 27:93-115. <doi:10.1111/j.1538-4632.1995.tb00338.x>
# first generate some sample data x <- expand.grid(1:20, 1:5)[, 1] y <- expand.grid(1:20, 1:5)[, 2] # z data from an exponential random field z <- rmvn.spa(x = x, y = y, p = 2, method = "gaus") # lisa analysis fit1 <- lisa(x = x, y = y, z = z, neigh = 3, resamp = 499) ## Not run: plot(fit1, neigh.mean=FALSE)
# first generate some sample data x <- expand.grid(1:20, 1:5)[, 1] y <- expand.grid(1:20, 1:5)[, 2] # z data from an exponential random field z <- rmvn.spa(x = x, y = y, p = 2, method = "gaus") # lisa analysis fit1 <- lisa(x = x, y = y, z = z, neigh = 3, resamp = 499) ## Not run: plot(fit1, neigh.mean=FALSE)
lisa.nc
is a function to estimate the (non-centred) multivariate local indicators of spatial association. The function requires multiple observations at each location. For single observations at each location use lisa
.
lisa.nc( x, y, z, neigh, na.rm = FALSE, resamp = 999, latlon = FALSE, quiet = FALSE )
lisa.nc( x, y, z, neigh, na.rm = FALSE, resamp = 999, latlon = FALSE, quiet = FALSE )
x |
vector of length n representing the x coordinates (or latitude; see latlon). |
y |
vector of length n representing the y coordinates (or longitude). |
z |
a matrix of dimension n x p representing p (>1) observation at each location. |
neigh |
neighborhood size. |
na.rm |
If TRUE, NA's will be dealt with through pairwise deletion of missing values. |
resamp |
number of resamples under the NULL to generate p-values |
latlon |
If TRUE, coordinates are latitude and longitude. |
quiet |
If TRUE, the counter is suppressed during execution. |
This is the function to estimate the (non-centered) local indicators of spatial association modified form Anselin (1995). 'correlation' is the average correlation within a neighborhood. The function requires multiple observations at each location.
Missing values are allowed – values are assumed missing at random, and pairwise complete observations will be used.
An object of class "lisa" is returned, consisting of the following components:
correlation |
the mean correlation within the neighborhood (neigh). |
p |
the permutation two-sided p-value for each distance-class. |
n |
the number of pairs within each neighborhood. |
dmean |
the actual mean of distance within each neighborhood. |
coord |
a list with the x and y coordinates. |
Ottar N. Bjornstad [email protected]
Anselin, L. 1995. Local indicators of spatial association - LISA. Geographical Analysis 27:93-115. <doi:10.1111/j.1538-4632.1995.tb00338.x>
# first generate some sample data x <- expand.grid(1:20, 1:5)[, 1] y <- expand.grid(1:20, 1:5)[,2] # z data from an exponential random field z <- cbind( rmvn.spa(x = x, y = y, p = 2, method = "exp"), rmvn.spa(x = x, y = y, p = 2, method = "exp") ) # lisa.nc analysis fit1 <- lisa.nc(x = x, y = y, z = z, neigh = 3) ## Not run: plot(fit1)
# first generate some sample data x <- expand.grid(1:20, 1:5)[, 1] y <- expand.grid(1:20, 1:5)[,2] # z data from an exponential random field z <- cbind( rmvn.spa(x = x, y = y, p = 2, method = "exp"), rmvn.spa(x = x, y = y, p = 2, method = "exp") ) # lisa.nc analysis fit1 <- lisa.nc(x = x, y = y, z = z, neigh = 3) ## Not run: plot(fit1)
mantel.correlog
is the function to calculate a Mantel (cross-)correlogram. The function requires two (or three) matrices.
mantel.correlog( dmat, zmat, wmat = NULL, increment, resamp = 999, quiet = FALSE )
mantel.correlog( dmat, zmat, wmat = NULL, increment, resamp = 999, quiet = FALSE )
dmat |
a matrix representing distance. |
zmat |
a matrix representing similarity. |
wmat |
an optional third matrix of similarities to calculate a Mantel cross-correlograms. |
increment |
increment for the uniformly distributed distance classes. |
resamp |
the number of permutations under the null to assess level of significance. |
quiet |
If TRUE, the counter is suppressed during execution. |
The function calculates Mantel (cross-)correlograms at discrete distance classes from two (or three) matrixes. The first is the matrix of distances and the second is a matrix of similarities. The optional third matrix is an additional similarity matrix to be used to calculate a Mantel cross-correlogram. Missing values are allowed – values are assumed missing at random.
An object of class "correlog" is returned, consisting of the following components:
correlation |
the value for the Moran (or Mantel) similarity. |
mean.of.class |
the actual average of the distances within each distance class. |
nlok |
the number of pairs within each distance class. |
x.intercept |
the interpolate x.intercept of Epperson (1993). |
p |
the permutation two-sided p-value for each distance-class. |
corr0 |
If a cross-correlogram is calculated, corr0 gives the empirical cross-correlation at distance zero. |
Ottar N. Bjornstad [email protected]
# first generate some sample data x <- expand.grid(1:20, 1:5)[, 1] y <- expand.grid(1:20, 1:5)[, 2] # z data from an exponential random field z <- cbind( rmvn.spa(x = x, y = y, p = 2, method = "exp"), rmvn.spa(x = x, y = y, p = 2, method = "exp") ) # w data from a gaussian random field w <- cbind(rmvn.spa( x = x, y = y, p = 2, method = "gaus"), rmvn.spa(x = x, y = y, p = 2, method = "gaus") ) # Make distance and similarity matrices zmat <- cor(t(z)) wmat <- cor(t(w)) dmat <- sqrt(outer(x, x, "-")^2 + outer(y, y, "-")^2) # Mantel correlogram fit1 <- mantel.correlog(dmat = dmat, zmat = zmat, increment = 2, quiet = TRUE, resamp = 0) ## Not run: plot(fit1) # Mantel cross-correlogram fit2 <- mantel.correlog(dmat = dmat, zmat = zmat, wmat = wmat, increment = 2, quiet = TRUE, resamp = 0) ## Not run: plot(fit2)
# first generate some sample data x <- expand.grid(1:20, 1:5)[, 1] y <- expand.grid(1:20, 1:5)[, 2] # z data from an exponential random field z <- cbind( rmvn.spa(x = x, y = y, p = 2, method = "exp"), rmvn.spa(x = x, y = y, p = 2, method = "exp") ) # w data from a gaussian random field w <- cbind(rmvn.spa( x = x, y = y, p = 2, method = "gaus"), rmvn.spa(x = x, y = y, p = 2, method = "gaus") ) # Make distance and similarity matrices zmat <- cor(t(z)) wmat <- cor(t(w)) dmat <- sqrt(outer(x, x, "-")^2 + outer(y, y, "-")^2) # Mantel correlogram fit1 <- mantel.correlog(dmat = dmat, zmat = zmat, increment = 2, quiet = TRUE, resamp = 0) ## Not run: plot(fit1) # Mantel cross-correlogram fit2 <- mantel.correlog(dmat = dmat, zmat = zmat, wmat = wmat, increment = 2, quiet = TRUE, resamp = 0) ## Not run: plot(fit2)
A simple function to do a permutation-based Mantel test. The data can either be two distance/similarity matrices or (x, y, z) data.
mantel.test( M1 = NULL, M2 = NULL, x = NULL, y = NULL, z = NULL, resamp = 999, latlon = FALSE, quiet = FALSE )
mantel.test( M1 = NULL, M2 = NULL, x = NULL, y = NULL, z = NULL, resamp = 999, latlon = FALSE, quiet = FALSE )
M1 |
similarity/distance matrix 1 |
M2 |
similarity/distance matrix 2 |
x |
vector of length n representing the x coordinates (or longitude; see latlon). |
y |
vector of length n representing the y coordinates (or latitude). |
z |
matrix of dimension n x p representing p observation at each location. |
resamp |
the number of resamples for the null distribution. |
latlon |
If TRUE, coordinates are latitude and longitude. |
quiet |
If TRUE, the counter is suppressed during execution. |
Typical usages are
mantel.test(M1, M2, x = NULL, y = NULL, z = NULL, resamp = 999, latlon = FALSE, quiet = FALSE) mantel.test(x, y, z, M1 = NULL, M2 = NULL, resamp = 999, latlon = FALSE, quiet = FALSE)
Missing values are treated through pairwise deletion.
An object of class "Mantel" is returned, consisting of a list with two components:
correlation |
the value for the Mantel correlation. |
p |
the randomization-based two-sided p-value. |
Ottar N. Bjornstad [email protected]
# first generate some sample data x <- expand.grid(1:20, 1:5)[, 1] y <- expand.grid(1:20, 1:5)[, 2] # z data from an exponential random field z <- cbind( rmvn.spa(x = x, y = y, p = 2, method = "exp"), rmvn.spa(x = x, y = y, p = 2, method = "exp") ) # the Mantel test mantel.test(x = x, y = y, z = z[, 1], resamp = 999)
# first generate some sample data x <- expand.grid(1:20, 1:5)[, 1] y <- expand.grid(1:20, 1:5)[, 2] # z data from an exponential random field z <- cbind( rmvn.spa(x = x, y = y, p = 2, method = "exp"), rmvn.spa(x = x, y = y, p = 2, method = "exp") ) # the Mantel test mantel.test(x = x, y = y, z = z[, 1], resamp = 999)
mSynch
is the function to estimate the mean (cross-)correlation in a spatiotemporal dataset as discussed in Bjornstad et al. (1999). The function requires multiple observations at each location.
mSynch(x, y = NULL, resamp = 999, na.rm = FALSE, circ = FALSE, quiet = FALSE)
mSynch(x, y = NULL, resamp = 999, na.rm = FALSE, circ = FALSE, quiet = FALSE)
x |
matrix of dimension n x p representing p observation at each location (i.e. each row is a time series). |
y |
optional matrix of dimension m x p representing p observation at each location (i.e. each row is a time series). If provided, the mean cross-correlation between the two panels is computed. |
resamp |
the number of resamples for the bootstrap or the null distribution. |
na.rm |
If TRUE, NA's will be dealt with through pairwise deletion of missing values for each pair of time series – it will dump if any one pair has less than two (temporally) overlapping observations. |
circ |
If TRUE, the observations are assumed to be angular (in radians), and circular correlation is used. |
quiet |
If TRUE, the counter is suppressed during execution. |
Missing values are allowed – values are assumed missing at random.
The circ argument computes a circular version of the Pearson's product moment correlation (see cor2
).
An object of class "mSynch" is returned, consisting of a list with two components:
real |
the regional average correlation. |
boot |
a vector of bootstrap resamples. |
Ottar N. Bjornstad [email protected]
Bjornstad, O.N., Ims, R.A. & Lambin, X. (1999) Spatial population dynamics: Analysing patterns and processes of population synchrony. Trends in Ecology and Evolution, 11, 427-431. <doi:10.1016/S0169-5347(99)01677-8>
# first generate some sample data x <- expand.grid(1:20, 1:5)[, 1] y <- expand.grid(1:20, 1:5)[, 2] # z data from an exponential random field z <- cbind( rmvn.spa(x = x, y = y, p = 2, method = "exp"), rmvn.spa(x = x, y = y, p = 2, method = "exp") ) # mean correlation analysis fit1 <- mSynch(x = z, resamp = 500) print(fit1)
# first generate some sample data x <- expand.grid(1:20, 1:5)[, 1] y <- expand.grid(1:20, 1:5)[, 2] # z data from an exponential random field z <- cbind( rmvn.spa(x = x, y = y, p = 2, method = "exp"), rmvn.spa(x = x, y = y, p = 2, method = "exp") ) # mean correlation analysis fit1 <- mSynch(x = z, resamp = 500) print(fit1)
A simple function to calculate permutation-based partial mantel tests for three matrices, the partial mantel test is calculated to test for relationships between M1 and M2 (M3) controlling for M3 (M2). syntax and logic follows Legendre and Legendre (1998) pp 557-558.
partial.mantel.test( M1, M2, M3, resamp = 999, method = "pearson", quiet = FALSE )
partial.mantel.test( M1, M2, M3, resamp = 999, method = "pearson", quiet = FALSE )
M1 |
similarity/distance matrix 1 |
M2 |
similarity/distance matrix 2 |
M3 |
similarity/distance matrix 3 |
resamp |
the number of resamples for the null distribution. |
method |
the method to be used for calculating the correlations. |
quiet |
If TRUE, the counter is suppressed during execution. |
Missing values are treated through pairwise deletion.
The method must be one of "pearson" (default), "spearman" or "kendall".
An object of class "partial.Mantel" is returned, consisting of a list with two components:
MantelR |
the vector of observed Mantel and partial Mantel correlations. |
p |
the vector of two-sided p-value under randomization (of M1). |
Ottar N. Bjornstad [email protected]
Legendre, P., and L. Legendre. 1998. Numerical Ecology, 2nd edition. Elsevier, Amsterdam
# first generate some sample data and dissimilarity matrices x <- rnorm(10) y <- rnorm(10) z <- rnorm(10) M1 <- sqrt(outer(x, x, "-")^2) M2 <- sqrt(outer(y, y, "-")^2) M3 <- sqrt(outer(z, z, "-")^2) partial.mantel.test(M1 = M1, M2 = M2, M3 = M3, resamp = 999)
# first generate some sample data and dissimilarity matrices x <- rnorm(10) y <- rnorm(10) z <- rnorm(10) M1 <- sqrt(outer(x, x, "-")^2) M2 <- sqrt(outer(y, y, "-")^2) M3 <- sqrt(outer(z, z, "-")^2) partial.mantel.test(M1 = M1, M2 = M2, M3 = M3, resamp = 999)
plot method for class "cc.offset".
## S3 method for class 'cc.offset' plot(x, dmax = NULL, inches = NULL, ...)
## S3 method for class 'cc.offset' plot(x, dmax = NULL, inches = NULL, ...)
x |
an object of class "cc.offset", usually, as a result of applying |
dmax |
the maximal distance for radial plot. If NULL, the maximum distance in the data will be used. |
inches |
the size of the symbols.If NULL, default is 0.1. |
... |
other arguments |
A radial symbol plot results. The radius represents the distance to peak correlation (the mode) of the correlation function (in the positive direction). The size of the symbol represents the magnitude of the correlation at the mode for the given cardinal direction.
cc.offset
, Sncf2D
, plot.Sncf2D
‘plot’ method for class "correlog".
## S3 method for class 'correlog' plot(x, ...)
## S3 method for class 'correlog' plot(x, ...)
x |
an object of class "correlog", usually, as a result of a call to |
... |
other arguments |
A spatial or Mantel (cross-correlogram) is plotted.
If a permutation test was performed, values significant at a nominal (two-sided) 5%-level will be represented by filled circles and non-significant values by open circles.
‘plot’ method for class "lisa".
## S3 method for class 'lisa' plot(x, neigh.mean = FALSE, add = FALSE, inches = 0.2, ...)
## S3 method for class 'lisa' plot(x, neigh.mean = FALSE, add = FALSE, inches = 0.2, ...)
x |
an object of class "lisa", usually, as a result of a call to |
neigh.mean |
If TRUE, size of symbols represents average observation in each neighborhood; If FALSE, size of symbols represents the original observation |
add |
If TRUE, a lisa-plot will be added to a pre-existing plot. |
inches |
scales the size of the symbols |
... |
other arguments |
A bubble-plot of observations against spatial coordinates is produced. Above mean values are signified by red circles. Below mean values are signified by black squares.
If a permutation test was performed, observations for which the associated LISA statistic is significant at a nominal (two-sided) 5%-level will be represented by filled symbols and non-significant values by open symbols. Thus spatial hot-spots are represented by red filled circles and cold-spots by black filled squares.
'plot' method for class "Sncf".
## S3 method for class 'Sncf' plot(x, ylim = c(-1, 1), add = FALSE, ...)
## S3 method for class 'Sncf' plot(x, ylim = c(-1, 1), add = FALSE, ...)
x |
an object of class "Sncf", usually, as a result of a call to |
ylim |
limits for the y-axis (default: -1, 1). |
add |
If TRUE the plot is added on to the previous graph. |
... |
other arguments |
A plot of the nonparametric spatial covariance function (with CI's if bootstraps are available)
'plot' method for class "Sncf.cov".
## S3 method for class 'Sncf.cov' plot(x, ...)
## S3 method for class 'Sncf.cov' plot(x, ...)
x |
an object of class "Sncf.cov", usually, as a result of a call to |
... |
other arguments |
A plot of the nonparametric spatial covariance function (with CI's if bootstrapps are available)
plot method for class "Sncf2D".
## S3 method for class 'Sncf2D' plot(x, xmax = 0, ylim = c(-1, 1), detail = FALSE, ...)
## S3 method for class 'Sncf2D' plot(x, xmax = 0, ylim = c(-1, 1), detail = FALSE, ...)
x |
an object of class "Sncf2D", usually, as a result of a call to |
xmax |
the maximal distance to be plotted on the x-axis. If set to zero the maximum distance in the data will be used. |
ylim |
limits for the y-axis (default: -1, 1). |
detail |
If TRUE, a separate plot is made for each direction (including confidence envelopes; see |
... |
other arguments |
A plot or panel-plot results. These represents the xy-plot of distance against spatial (cross-)correlation for each cardinal direction.
‘plot’ method for class "spline.correlog".
## S3 method for class 'spline.correlog' plot(x, ylim = c(-1, 1), ...)
## S3 method for class 'spline.correlog' plot(x, ylim = c(-1, 1), ...)
x |
an object of class "spline.correlog", usually, as a result of a call to |
ylim |
limits for the y-axis (default: -1, 1). |
... |
other arguments |
A plot of the spline correlogram function against distance is produced. 95% pointwise confidence (or null) envelopes are superimposed (if available).
spline.correlog
, summary.spline.correlog
‘print’ method for class "mSynch".
## S3 method for class 'mSynch' print(x, verbose = FALSE, ...)
## S3 method for class 'mSynch' print(x, verbose = FALSE, ...)
x |
an object of class "mSynch", usually, as a result of a call to |
verbose |
If TRUE, a raw listing of the object is produced. If FALSE, a summary list is produced |
... |
other arguments |
If verbose is FALSE, a list summarizing the regional correlation is produced:
mean |
the regional mean correlation. |
Squantile |
the quantile distribution from the resampling for the regional correlation. |
'print' method for class "Sncf".
## S3 method for class 'Sncf' print(x, ...)
## S3 method for class 'Sncf' print(x, ...)
x |
an object of class "Sncf", usually, as a result of a call to |
... |
other arguments |
The function-call is printed to screen.
‘print’ method for class "Sncf2D".
## S3 method for class 'Sncf2D' print(x, ...)
## S3 method for class 'Sncf2D' print(x, ...)
x |
an object of class "Sncf2D", usually, as a result of a call to |
... |
other arguments |
The function-call is printed to screen.
‘print’ method for class "spline.correlog".
## S3 method for class 'spline.correlog' print(x, ...)
## S3 method for class 'spline.correlog' print(x, ...)
x |
an object of class "spline.correlog", usually, as a result of a call to |
... |
other arguments |
The function-call is printed to screen.
Function to generate spatially autocorrelated random normal variates using the eigendecomposition method. Spatial covariance can follow either and exponential or Gaussian model.
rmvn.spa(x, y, p, method = "exp", nugget = 1)
rmvn.spa(x, y, p, method = "exp", nugget = 1)
x |
vector of length n representing the x coordinates (or latitude; see latlon). |
y |
vector of length n representing the y coordinates (or longitude). |
p |
the range of the spatial models. |
method |
correlation function "exp" (exponential) or "gaus" (gaussian). Exponential is the default. |
nugget |
correlation at the origin (defaults to one) |
A target covariance matrix A between the n units is generated by calculating the distances between the locations and thereafter evaluating the covariance function in each pairwise distance. A vector, Z, of spatially correlated normal data with the target covariance is subsequently generated using the eigendecomposition method (Ripley, 1987).
A vector of spatially correlated random normal variates with zero mean and unit variance is returned
Ottar N. Bjornstad [email protected]
Ripley, B.D. (1987). Stochastic Simulation. Wiley.
Sncf
is the function to estimate the nonparametric (cross-)correlation function using a smoothing spline as an equivalent kernel. The function requires multiple observations at each location (use spline.correlog
otherwise).
Sncf( x, y, z, w = NULL, df = NULL, type = "boot", resamp = 1000, npoints = 300, save = FALSE, filter = FALSE, fw = 0, max.it = 25, xmax = FALSE, na.rm = FALSE, latlon = FALSE, circ = FALSE, quiet = FALSE )
Sncf( x, y, z, w = NULL, df = NULL, type = "boot", resamp = 1000, npoints = 300, save = FALSE, filter = FALSE, fw = 0, max.it = 25, xmax = FALSE, na.rm = FALSE, latlon = FALSE, circ = FALSE, quiet = FALSE )
x |
vector of length n representing the x coordinates (or longitude; see latlon). |
y |
vector of length n representing the y coordinates (or latitude). |
z |
matrix of dimension n x p representing p observation at each location. |
w |
an optional second matrix of dimension n x p for species 2 (to estimate the spatial cross-correlation function). |
df |
degrees of freedom for the spline. Default is sqrt(n). |
type |
takes the value "boot" (default) to generate a bootstrap distribution or "perm" to generate a null distribution for the estimator |
resamp |
the number of resamples for the bootstrap or the null distribution. |
npoints |
the number of points at which to save the value for the spline function (and confidence envelope / null distribution). |
save |
If TRUE, the whole matrix of output from the resampling is saved (a resamp x npoints dimensional matrix). |
filter |
If TRUE, the Fourier filter method of Hall and coworkers is applied to ensure positive semi-definiteness of the estimator. (more work may be needed on this.) |
fw |
If filter is TRUE, it may be useful to truncate the function at some distance w sets the truncation distance. when set to zero no truncation is done. |
max.it |
the maximum iteration for the Newton method used to estimate the intercepts. |
xmax |
If FALSE, the max observed in the data is used. Otherwise all distances greater than xmax is omitted. |
na.rm |
If TRUE, NA's will be dealt with through pairwise deletion of missing values for each pair of time series – it will dump if any one pair has less than two (temporally) overlapping observations. |
latlon |
If TRUE, coordinates are latitude and longitude. |
circ |
If TRUE, the observations are assumed to be angular (in radians), and circular correlation is used. |
quiet |
If TRUE, the counter is suppressed during execution. |
Missing values are allowed – values are assumed missing at random.
The circ argument computes a circular version of the Pearson's product moment correlation (see cor2
). This option is to calculate the 'nonparametric phase coherence function' (Grenfell et al. 2001)
An object of class "Sncf" is returned, consisting of the following components:
real |
the list of estimates from the data. |
$cbar |
the regional average correlation. |
$x.intercept |
the lowest value at which the function is = 0. If correlation is initially negative, the distance is given as negative. |
$e.intercept |
the lowest value at which the function 1/e. |
$y.intercept |
the extrapolated value at x=0 (nugget). |
$cbar.intercept |
distance at which regional average correlation is reach. |
$predicted$x |
the x-axes for the fitted covariance function. |
$predcited$y |
the values for the covariance function. |
boot |
a list with the analogous output from the bootstrap or null distribution. |
$summary |
gives the full vector of output for the x.intercept, y.intercept, e.intercept, cbar.intercept, cbar and a quantile summary for the resampling distribution. |
$boot |
If save=TRUE, the full raw matrices from the resampling is saved. |
max.distance |
the maximum spatial distance considered. |
Ottar N. Bjornstad [email protected]
Hall, P. and Patil, P. (1994) Properties of nonparametric estimators of autocovariance for stationary random fields. Probability Theory and Related Fields, 99:399-424. <doi:10.1007/BF01199899>
Hall, P., Fisher, N.I. and Hoffmann, B. (1994) On the nonparametric estimation of covariance functions. Annals of Statistics, 22:2115-2134 <doi:10.1214/aos/1176325774>.
Bjornstad, O.N. and Falck, W. (2001) Nonparametric spatial covariance functions: estimation and testing. Environmental and Ecological Statistics, 8:53-70 <doi:10.1023/A:1009601932481>.
Bjornstad, O.N., Ims, R.A. and Lambin, X. (1999) Spatial population dynamics: Analysing patterns and processes of population synchrony. Trends in Ecology and Evolution, 11:427-431 <doi:10.1016/S0169-5347(99)01677-8>.
Bjornstad, O. N., and J. Bascompte. (2001) Synchrony and second order spatial correlation in host-parasitoid systems. Journal of Animal Ecology 70:924-933 <doi:10.1046/j.0021-8790.2001.00560.x>.
Grenfell, B.T., Bjornstad, O.N., & Kappey, J. (2001) Travelling waves and spatial hierarchies in measles epidemics. Nature 414:716-723. <doi:10.1038/414716a>
# first generate some sample data x <- expand.grid(1:20, 1:5)[, 1] y <- expand.grid(1:20, 1:5)[, 2] # z data from an exponential random field z <- cbind( rmvn.spa(x = x, y = y, p = 2, method = "exp"), rmvn.spa(x = x, y = y, p = 2, method = "exp") ) # w data from a gaussian random field w <- cbind( rmvn.spa(x = x, y = y, p = 2, method = "gaus"), rmvn.spa(x = x, y = y, p = 2, method = "gaus") ) # multivariate nonparametric covariance function fit1 <- Sncf(x = x, y = y, z = z, resamp = 0) ## Not run: plot.Sncf(fit1) summary(fit1) # multivariate nonparametric cross-covariance function fit2 <- Sncf(x = x, y = y, z = z, w = w, resamp = 0) ## Not run: plot(fit2) summary(fit2)
# first generate some sample data x <- expand.grid(1:20, 1:5)[, 1] y <- expand.grid(1:20, 1:5)[, 2] # z data from an exponential random field z <- cbind( rmvn.spa(x = x, y = y, p = 2, method = "exp"), rmvn.spa(x = x, y = y, p = 2, method = "exp") ) # w data from a gaussian random field w <- cbind( rmvn.spa(x = x, y = y, p = 2, method = "gaus"), rmvn.spa(x = x, y = y, p = 2, method = "gaus") ) # multivariate nonparametric covariance function fit1 <- Sncf(x = x, y = y, z = z, resamp = 0) ## Not run: plot.Sncf(fit1) summary(fit1) # multivariate nonparametric cross-covariance function fit2 <- Sncf(x = x, y = y, z = z, w = w, resamp = 0) ## Not run: plot(fit2) summary(fit2)
Sncf.srf
is the function to estimate the nonparametric for spatio-temporal data from fully stationary random fields (i.e. marginal expectation and variance identical for all locations; use Sncf
otherwise).
Sncf.srf( x, y, z, w = NULL, avg = NULL, avg2 = NULL, corr = TRUE, df = NULL, type = "boot", resamp = 0, npoints = 300, save = FALSE, filter = FALSE, fw = 0, max.it = 25, xmax = FALSE, jitter = FALSE, quiet = FALSE )
Sncf.srf( x, y, z, w = NULL, avg = NULL, avg2 = NULL, corr = TRUE, df = NULL, type = "boot", resamp = 0, npoints = 300, save = FALSE, filter = FALSE, fw = 0, max.it = 25, xmax = FALSE, jitter = FALSE, quiet = FALSE )
x |
vector of length n representing the x coordinates (or longitude; see latlon). |
y |
vector of length n representing the y coordinates (or latitude). |
z |
matrix of dimension n x p representing p observation at each location. |
w |
an optional second matrix of dimension n x p for variable 2 (to estimate the spatial cross-correlation function). |
avg |
supplies the marginal expectation of the Markov random field; if TRUE, the sample mean (across the markovian field) is used. |
avg2 |
optionally supplies the marginal expectation of the Markov random field for optional variable 2; if TRUE, the sample mean is used. |
corr |
If TRUE, the covariance function is standardized by the marginal variance (across the Markovian field) to return a correlation function (alternatively the covariance function is returned). |
df |
degrees of freedom for the spline. Default is sqrt(n). |
type |
takes the value "boot" (default) to generate a bootstrap distribution or "perm" to generate a null distribution for the estimator |
resamp |
the number of resamples for the bootstrap or the null distribution. |
npoints |
the number of points at which to save the value for the spline function (and confidence envelope / null distribution). |
save |
If TRUE, the whole matrix of output from the resampling is saved (an resamp x npoints dimensional matrix). |
filter |
If TRUE, the Fourier filter method of Hall and coworkers is applied to ensure positive semidefiniteness of the estimator. (more work may be needed on this.) |
fw |
If filter is TRUE, it may be useful to truncate the function at some distance w sets the truncation distance. When set to zero no truncation is done. |
max.it |
the maximum iteration for the Newton method used to estimate the intercepts. |
xmax |
If FALSE, the max observed in the data is used. Otherwise all distances greater than xmax is omitted. |
jitter |
If TRUE, jitters the distance matrix, to avoid problems associated with fitting the function to data on regular grids. |
quiet |
If TRUE, the counter is suppressed during execution. |
If corr = F
, an object of class "Sncf.cov" is returned. Otherwise the class is "Sncf".
Sncf.srf
is a function to estimate the nonparametric (cross-)covariance function (as discussed in Bjornstad and Bascompte 2001) for data from a fully stationary random fields. I have found it useful to estimate the (cross-)covariance functions in synthetic data.
An object of class "Sncf" (or "Sncf.cov") is returned. See Sncf
for details.
Ottar N. Bjornstad [email protected]
Bjornstad, O. N., and J. Bascompte. (2001) Synchrony and second order spatial correlation in host-parasitoid systems. Journal of Animal Ecology 70:924-933. <doi:10.1046/j.0021-8790.2001.00560.x>
Sncf
, summary.Sncf
, plot.Sncf
, plot.Sncf.cov
# first generate some sample data x <- expand.grid(1:20, 1:5)[, 1] y <- expand.grid(1:20, 1:5)[, 2] # z data from an exponential random field z <- cbind( rmvn.spa(x = x, y = y, p = 2, method = "exp"), rmvn.spa(x = x, y = y, p = 2, method = "exp") ) # w data from a gaussian random field w <- cbind( rmvn.spa(x = x, y = y, p = 2, method = "gaus"), rmvn.spa(x = x, y = y, p = 2, method = "gaus") ) # multivariate nonparametric covariance function fit1 <- Sncf.srf(x = x, y = y, z = z, avg = NULL, corr = TRUE, resamp = 0) ## Not run: plot(fit1) summary(fit1) # multivariate nonparametric cross-covariance function (with known # marginal expectation of zero for both z and w fit2 <- Sncf.srf(x = x, y = y, z = z, w = w, avg = 0, avg2 = 0, corr = FALSE, resamp = 0) ## Not run: plot(fit2) summary(fit2)
# first generate some sample data x <- expand.grid(1:20, 1:5)[, 1] y <- expand.grid(1:20, 1:5)[, 2] # z data from an exponential random field z <- cbind( rmvn.spa(x = x, y = y, p = 2, method = "exp"), rmvn.spa(x = x, y = y, p = 2, method = "exp") ) # w data from a gaussian random field w <- cbind( rmvn.spa(x = x, y = y, p = 2, method = "gaus"), rmvn.spa(x = x, y = y, p = 2, method = "gaus") ) # multivariate nonparametric covariance function fit1 <- Sncf.srf(x = x, y = y, z = z, avg = NULL, corr = TRUE, resamp = 0) ## Not run: plot(fit1) summary(fit1) # multivariate nonparametric cross-covariance function (with known # marginal expectation of zero for both z and w fit2 <- Sncf.srf(x = x, y = y, z = z, w = w, avg = 0, avg2 = 0, corr = FALSE, resamp = 0) ## Not run: plot(fit2) summary(fit2)
Sncf2D
is the function to estimate the anisotropic nonparametric correlation function in 8 (or arbitrary) directions (North - Southeast). Correlation functions are calculated for each different bearing. The function requires multiple observations at each location. (use spline.correlog2D
otherwise).
Sncf2D( x, y, z, w = NULL, df = NULL, type = "boot", resamp = 1000, npoints = 300, save = FALSE, max.it = 25, xmax = FALSE, na.rm = FALSE, jitter = FALSE, quiet = FALSE, angle = c(0, 22.5, 45, 67.5, 90, 112.5, 135, 157.5) )
Sncf2D( x, y, z, w = NULL, df = NULL, type = "boot", resamp = 1000, npoints = 300, save = FALSE, max.it = 25, xmax = FALSE, na.rm = FALSE, jitter = FALSE, quiet = FALSE, angle = c(0, 22.5, 45, 67.5, 90, 112.5, 135, 157.5) )
x |
vector of length n representing the x coordinates. |
y |
vector of length n representing the y coordinates. |
z |
matrix of dimension n x p representing p observation at each location. |
w |
an optional second matrix of dimension n x p for variable 2 (to estimate spatial or lagged cross-correlation functions). |
df |
degrees of freedom for the spline. Default is sqrt(n). |
type |
takes the value "boot" (default) to generate a bootstrap distribution or "perm" to generate a null distribution for the estimator |
resamp |
the number of resamples for the bootstrap or the null distribution. |
npoints |
the number of points at which to save the value for the spline function (and confidence envelope / null distribution). |
save |
If TRUE, the whole matrix of output from the resampling is saved (an resamp x npoints dimensional matrix). |
max.it |
the maximum iteration for the Newton method used to estimate the intercepts. |
xmax |
If FALSE, the max observed in the data is used. Otherwise all distances greater than xmax is omitted. |
na.rm |
If TRUE, NA's will be dealt with through pairwise deletion of missing values for each pair of time series – it will dump if any one pair has less than two (temporally) overlapping observations. |
jitter |
If TRUE, jitters the distance matrix, to avoid problems associated with fitting the function to data on regular grids |
quiet |
If TRUE, the counter is suppressed during execution. |
angle |
specifies number of cardinal directions and angles for which to calculate correlation functions. Default are 8 directions between 0 and 180. |
Correlation functions are calculated on projected distances onto the different bearings so ALL data are used for each direction. The (obsolete?) oldncf2D
used the alternative of slicing up the data like pieces of a pie.
Latitude-longitude coordinates can NOT be used.
Missing values are allowed - values are assumed missing at random.
I have implemented an optional argument: jitter
if TRUE this jitters the distance matrix, to avoid some problems I've had with spline-smoothing data from regular grid-data.
An object of class "Sncf2D" is returned, consisting of a list of estimates for each cardinal direction :
real |
the list of estimates from the data. |
$cbar |
the regional average correlation. |
$x.intercept |
the lowest value at which the function is = 0. If correlation is initially negative, the distance is given as negative. |
$e.intercept |
the lowest value at which the function 1/e. |
$y.intercept |
the extrapolated value at x=0 (nugget). |
$cbar.intercept |
distance at which regional average correlation is reach. |
$predicted$x |
the x-axes for the fitted covariance function. |
$predcited$y |
the values for the covariance function. |
boot |
a list with the analogous output from the bootstrap or null distribution. |
$summary |
gives the full vector of output for the x.intercept, y.intercept, e.intercept, cbar.intercept, and the cbar and a quantile summary for the resampling distribution. |
$boot |
If save=TRUE, the full raw matrices from the resampling is saved. |
angle |
a vector with the cardinal directions. |
max.distance |
the maximum spatial distance. |
The function to estimate the anisotropic nonparametric (cross-)correlation function in arbitrary directions. In particular it was developed to calculate the lagged cross-correlation function (Bjornstad et al. 2002).
Ottar N. Bjornstad [email protected]
Bjornstad, O. N., M. Peltonen, A. M. Liebhold, and W. Baltensweiler. 2002. Waves of larch budmoth outbreaks in the European Alps. Science 298:1020-1023. <doi:10.1126/science.1075182>
summary.Sncf2D
, plot.Sncf2D
, cc.offset
, Sncf
, spline.correlog2D
# first generate some sample data x <- expand.grid(1:20, 1:5)[, 1] y <- expand.grid(1:20, 1:5)[, 2] # z data from an exponential random field z <- cbind( rmvn.spa(x = x, y = y, p = 2, method = "exp"), rmvn.spa(x = x, y = y, p = 2, method = "exp") ) # anisotorpic nonparametric covariance function at 30 and 60 degrees fit1 <- Sncf2D(x = x, y = y, z = z, resamp = 0, angle = c(30, 60)) ## Not run: plot(fit1) summary(fit1) # What distance is the peak in correlation cc.offset(fit1)
# first generate some sample data x <- expand.grid(1:20, 1:5)[, 1] y <- expand.grid(1:20, 1:5)[, 2] # z data from an exponential random field z <- cbind( rmvn.spa(x = x, y = y, p = 2, method = "exp"), rmvn.spa(x = x, y = y, p = 2, method = "exp") ) # anisotorpic nonparametric covariance function at 30 and 60 degrees fit1 <- Sncf2D(x = x, y = y, z = z, resamp = 0, angle = c(30, 60)) ## Not run: plot(fit1) summary(fit1) # What distance is the peak in correlation cc.offset(fit1)
spatial.plot
is a quick function to visualize spatial data using bubble plots
spatial.plot(x, y, z, ctr = TRUE, add = FALSE, inches = 0.2, ...)
spatial.plot(x, y, z, ctr = TRUE, add = FALSE, inches = 0.2, ...)
x |
vector of length n representing the x coordinates. |
y |
vector of length n representing the y coordinates. |
z |
vector of n representing the observation at each location. |
ctr |
If TRUE, observations will be centered before plotting (zero-sized symbols represents average observations); if FALSE, the original observations are used. |
add |
If TRUE, a lisa-plot will be added to a pre-existing plot. |
inches |
scales the size of the symbols |
... |
other arguments |
This is a simple function to visualize spatial data. Positive (or above average) observations are shown by red circles, Negative (or below average) observations are shown as black squares. For hot/coldspot analysis using Local indicators of spatial association use lisa
.
A bubble-plot of the spatial data is produced.
Ottar N. Bjornstad [email protected]
Ripley, B.D. (1987). Stochastic Simulation. Wiley.
# first generate some sample data x <- expand.grid(1:20, 1:5)[, 1] y <- expand.grid(1:20, 1:5)[, 2] # z data from an exponential random field z <- rmvn.spa(x = x, y = y, p = 2, method = "gaus") # plot data ## Not run: spatial.plot(x = x, y = y, z = z, ctr = FALSE)
# first generate some sample data x <- expand.grid(1:20, 1:5)[, 1] y <- expand.grid(1:20, 1:5)[, 2] # z data from an exponential random field z <- rmvn.spa(x = x, y = y, p = 2, method = "gaus") # plot data ## Not run: spatial.plot(x = x, y = y, z = z, ctr = FALSE)
spline.correlog
is the function to estimate the spline (cross-)correlogram from spatial data. Either univariate or multivariate (time seres) for each site can be used.
spline.correlog( x, y, z, w = NULL, df = NULL, type = "boot", resamp = 1000, npoints = 300, save = FALSE, filter = FALSE, fw = 0, max.it = 25, xmax = FALSE, latlon = FALSE, na.rm = FALSE, quiet = FALSE )
spline.correlog( x, y, z, w = NULL, df = NULL, type = "boot", resamp = 1000, npoints = 300, save = FALSE, filter = FALSE, fw = 0, max.it = 25, xmax = FALSE, latlon = FALSE, na.rm = FALSE, quiet = FALSE )
x |
vector of length n representing the x coordinates (or longitude; see latlon). |
y |
vector of length n representing the y coordinates (or latitude). |
z |
vector of length n or matrix of dimension n x p representing p observation at each location. |
w |
an optional second variable with identical dimension to z (to estimate cross-correlograms). |
df |
degrees of freedom for the spline. Default is sqrt(n). |
type |
takes the value "boot" (default) to generate a bootstrap distribution or "perm" to generate a null distribution |
resamp |
the number of resamples for the bootstrap or the null distribution. |
npoints |
the number of points at which to save the value for the spline function (and confidence envelope / null distribution). |
save |
If TRUE, the whole matrix of output from the resampling is saved (a resamp x npoints dimensional matrix). |
filter |
If TRUE, the Fourier filter method of Hall and coworkers is applied to ensure positive semidefiniteness of the estimator. |
fw |
If filter is TRUE, it may be useful to truncate the function at some distance fw sets the truncation distance. When set to zero, no truncation is done. |
max.it |
the maximum iteration for the Newton method used to estimate the intercepts. |
xmax |
If FALSE, the max observed in the data is used. Otherwise all distances greater than xmax is omitted. |
latlon |
If TRUE, coordinates are latitude and longitude. |
na.rm |
If TRUE, NA's will be dealt with through pairwise deletion of missing values. |
quiet |
If TRUE, the counter is suppressed during execution. |
If observations are univariate the spline (cross-)correlogram represents the generalization of the spatial (cross-)correlogram; if observations are multivariate the spline (cross-)correlogram represents the generalization of the Mantel (cross-)correlogram.
The spline (cross-)correlogram differs from the spatial correlogram (and Mantel correlogram) in that it estimated spatial dependence as a continuous functions of distance (rather than binning into distance classes). The spline correlogram differs from the nonparametric (cross-)correlation function in that the zero-correlation reference line in the former corresponds to the region-wide correlation reference line in the latter. The x-intercept in the spline correlogram is the distance at which object are no more similar than that expected by-chance-alone across the region.
Missing values are allowed – values are assumed missing at random.
An object of class "spline.correlog" is returned, consisting of the following components:
real |
the list of estimates from the data. |
$x.intercept |
the lowest value at which the function is = 0. If correlation is initially negative, the distance is given as negative. |
$e.intercept |
the lowest value at which the function 1/e. |
$y.intercept |
the extrapolated value at x=0 (nugget). |
$predicted$x |
the x-axes for the fitted covariance function. |
$predcited$y |
the values for the covariance function. |
boot |
a list with the analogous output from the bootstrap or null distribution. |
$summary |
gives the full vector of output for the x.intercept, y.intercept, e.intercept, and a quantile summary for the resampling distribution. |
$boot |
If save=TRUE, the full raw matrices from the resampling is saved. |
max.distance |
the maximum spatial distance considered. |
Ottar N. Bjornstad [email protected]
Bjornstad, O.N. & Falck, W. (2001) Nonparametric spatial covariance functions: estimation and testing. Environmental and Ecological Statistics, 8:53-70. <doi:10.1023/A:1009601932481>
summary.spline.correlog
, plot.spline.correlog
, Sncf
, spline.correlog2D
, correlog
# first generate some sample data x <- expand.grid(1:20, 1:5)[, 1] y <- expand.grid(1:20, 1:5)[, 2] # z data from an exponential random field z <- cbind( rmvn.spa(x = x, y = y, p = 2, method = "exp"), rmvn.spa(x = x, y = y, p = 2, method = "exp") ) # w data from a gaussian random field w <- cbind( rmvn.spa(x = x, y = y, p = 2, method = "gaus"), rmvn.spa(x = x, y = y, p = 2, method = "gaus") ) # univariate spline correlogram fit1 <- spline.correlog(x = x, y = y, z = z[, 1], resamp = 100) ## Not run: plot.spline.correlog(fit1) summary(fit1) # multivariate spline correlogram fit2 <- spline.correlog(x = x, y = y, z = z, resamp = 100) ## Not run: plot.spline.correlog(fit2) summary(fit2) # multivariate spline cross-correlogram fit3 <- spline.correlog(x = x, y = y, z = z, w = w, resamp = 100) ## Not run: plot.spline.correlog(fit3) summary(fit3)
# first generate some sample data x <- expand.grid(1:20, 1:5)[, 1] y <- expand.grid(1:20, 1:5)[, 2] # z data from an exponential random field z <- cbind( rmvn.spa(x = x, y = y, p = 2, method = "exp"), rmvn.spa(x = x, y = y, p = 2, method = "exp") ) # w data from a gaussian random field w <- cbind( rmvn.spa(x = x, y = y, p = 2, method = "gaus"), rmvn.spa(x = x, y = y, p = 2, method = "gaus") ) # univariate spline correlogram fit1 <- spline.correlog(x = x, y = y, z = z[, 1], resamp = 100) ## Not run: plot.spline.correlog(fit1) summary(fit1) # multivariate spline correlogram fit2 <- spline.correlog(x = x, y = y, z = z, resamp = 100) ## Not run: plot.spline.correlog(fit2) summary(fit2) # multivariate spline cross-correlogram fit3 <- spline.correlog(x = x, y = y, z = z, w = w, resamp = 100) ## Not run: plot.spline.correlog(fit3) summary(fit3)
spline.correlog2D
is the function to estimate the anisotropic nonparametric correlation function in 8 (or arbitrary) directions (North - Southeast) for univariate data. Correlation functions are calculated for each different bearing. The function assumes univariate observations at each location. (use Sncf2D
otherwise).
spline.correlog2D( x, y, z, w = NULL, df = NULL, type = "boot", resamp = 1000, npoints = 300, save = FALSE, max.it = 25, xmax = FALSE, na.rm = FALSE, jitter = FALSE, quiet = FALSE, angle = c(0, 22.5, 45, 67.5, 90, 112.5, 135, 157.5) )
spline.correlog2D( x, y, z, w = NULL, df = NULL, type = "boot", resamp = 1000, npoints = 300, save = FALSE, max.it = 25, xmax = FALSE, na.rm = FALSE, jitter = FALSE, quiet = FALSE, angle = c(0, 22.5, 45, 67.5, 90, 112.5, 135, 157.5) )
x |
vector of length n representing the x coordinates. |
y |
vector of length n representing the y coordinates. |
z |
vector of length n representing the observation at each location. |
w |
an optional second vector of length n for variable 2 (to estimate spatial or lagged cross-correlation functions). |
df |
degrees-of-freedom for the spline. Default is sqrt(n). |
type |
takes the value "boot" (default) to generate a bootstrap distribution or "perm" to generate a null distribution for the estimator |
resamp |
the number of resamples for the bootstrap or the null distribution. |
npoints |
the number of points at which to save the value for the spline function (and confidence envelope / null distribution). |
save |
If TRUE, the whole matrix of output from the resampling is saved (an resamp x npoints dimensional matrix). |
max.it |
the maximum iteration for the Newton method used to estimate the intercepts. |
xmax |
If FALSE, the max observed in the data is used. Otherwise all distances greater than xmax is omitted. |
na.rm |
If TRUE, NA's will be dealt with through pairwise deletion of missing values for each pair of time series – it will dump if any one pair has less than two (temporally) overlapping observations. |
jitter |
If TRUE, jitters the distance matrix to avoid problems associated with fitting the function to data on regular grids. |
quiet |
If TRUE, the counter is suppressed during execution. |
angle |
specifies number of cardinal directions and angles for which to calculate correlation functions. Default are 8 directions between 0 and 180. |
see Sncf2D
An object of class "Sncf2D" is returned. See Sncf2D
for details.
The function to estimate the UNIvariate anisotropic nonparametric (cross-)correlation function in arbitrary directions. In particular it was developed to calculate the univariate lagged cross-correlation function used in (Humston et al. 2005). Note that this 2D spline correlogram does the anisotropic analysis NOT by doing the angle-with-tolerance-wedge-style of Oden and Sokal (1986) but by projecting the the spatial coordinates of all locations on a sequence of cardinal angles (a la Sncf2D). Hence, all data points are used every time, it is only their relative distances that are changed. For example {0, 0} and {0, 10} are distance zero in the zero-degree direction but at distance 10 in the 90-degree direction.
Oden, N.L. and Sokal, R.R. 1986. Directional autocorrelation: an extension of spatial correlograms to two dimensions. Systematic Zoology 35: 608-617. <doi:10.2307/2413120> @references Humston, R., Mortensen, D. and Bjornstad, O.N. 2005. Anthropogenic forcing on the spatial dynamics of an agricultural weed: the case of the common sunflower. Journal of Applied Ecology 42: 863-872. <doi:10.1111/j.1365-2664.2005.01066.x>
'summary' method for class "Sncf".
## S3 method for class 'Sncf' summary(object, ...)
## S3 method for class 'Sncf' summary(object, ...)
object |
an object of class "Sncf", usually, as a result of a call to |
... |
other arguments |
A list summarizing the nonparametric (cross-)covariance function is returned.
Regional.synch |
the regional mean (cross-)correlation. |
Squantile |
the quantile distribution from the resampling for the regional correlation. |
estimates |
a vector of benchmark statistics: |
$x |
is the lowest value at which the function is = 0. If correlation is initially negative, the distance calculated appears as a negative measure. |
$e |
is the lowest value at which the function is <= 1/e. |
$y |
is the extrapolated value at x=0. |
$cbar |
is the shortest distance at which function is = regional mean correlation. |
quantiles |
a matrix summarizing the quantiles in the bootstrap (or null) distributions of the benchmark statistics. |
Summary method for class "Sncf2D".
## S3 method for class 'Sncf2D' summary(object, ...)
## S3 method for class 'Sncf2D' summary(object, ...)
object |
an object of class "Sncf2D", usually, as a result of a call to |
... |
other arguments |
A list summarizing the nonparametric covariance function in each cardinal direction results, each with the entires as in summary.Sncf
.
Sncf2D
, cc.offset
, summary.Sncf
‘summary’ method for class "spline.correlog".
## S3 method for class 'spline.correlog' summary(object, ...)
## S3 method for class 'spline.correlog' summary(object, ...)
object |
an object of class "spline.correlog", usually, as a result of a call to |
... |
other arguments |
A list summarizing the spline correlogram is returned.
estimates |
a vector of benchmark statistics: |
$x |
is the lowest value at which the function is = 0. If correlation is initially negative, the distance calculated appears as a negative measure. |
$e |
is the lowest value at which the function is <= 1/e. |
$y |
is the extrapolated value at x=0. |
quantiles |
a matrix summarizing the quantiles in the bootstrap (or null) distributions of the benchmark statistics. |
spline.correlog
, plot.spline.correlog