Title: | Methods for Computing Spatial, Temporal, and Spatiotemporal Statistics |
---|---|
Description: | Methods for computing spatial, temporal, and spatiotemporal statistics as described in Gouhier and Guichard (2014) [https://doi.org/10.1111/2041-210X.12188]. These methods include empirical univariate, bivariate and multivariate variograms; fitting variogram models; phase locking and synchrony analysis; generating autocorrelated and cross-correlated matrices. |
Authors: | Tarik C. Gouhier |
Maintainer: | Tarik C. Gouhier <[email protected]> |
License: | GPL (>=2) |
Version: | 0.3.8 |
Built: | 2024-10-31 21:07:36 UTC |
Source: | https://github.com/tgouhier/synchrony |
Methods for computing spatial, temporal, and spatiotemporal statistics as described in Gouhier and Guichard (2014) [https://doi.org/10.1111/2041-210X.12188]. These methods include empirical univariate, bivariate and multivariate variograms; fitting variogram models; phase locking and synchrony analysis; generating autocorrelated and cross-correlated matrices.
Package: | synchrony |
Type: | Package |
Version: | 0.3.8 |
Date: | 2019-12-05 |
License: | GPL (>=2) |
URL: | https://github.com/tgouhier/synchrony |
LazyLoad: | yes |
Tarik C. Gouhier ([email protected])
Maintainer: Tarik C. Gouhier ([email protected])
Bjornstad, O. N., and W. Falck. 2001. Nonparametric spatial covariance functions: Estimation and testing. Environmental and Ecological Statistics 8:53-70.
Bjornstad, O. N., R. A. Ims, and X. Lambin. 1999. Spatial population dynamics: analyzing patterns and processes of population synchrony. Trends in Ecology & Evolution 14:427-432.
Buonaccorsi, J. P., J. S. Elkinton, S. R. Evans, and A. M. Liebhold. 2001. Measuring and testing for spatial synchrony. Ecology 82:1668-1679.
Cazelles, B., and L. Stone. 2003. Detection of imperfect population synchrony in an uncertain world. Journal of Animal Ecology 72:953-968.
Fortin, M. J., and M. R. T. Dale. 2005. Spatial Analysis: A Guide for Ecologists. Cambridge University Press.
Gouhier, T. C., and F. Guichard. 2007. Local disturbance cycles and the maintenance of spatial heterogeneity across scales in marine metapopulations. Ecology 88:647-657.
Gouhier, T. C., F. Guichard, and A. Gonzalez. 2010. Synchrony and stability of food webs in metacommunities. The American Naturalist 175:E16-E34.
Gouhier, T. C., F. Guichard, and B. A. Menge. 2010. Ecological processes can synchronize marine population dynamics over continental scales. Proceedings of the National Academy of Sciences 107:8281-8286.
Loreau, M., and C. de Mazancourt. 2008. Species synchrony and its drivers: Neutral and nonneutral community dynamics in fluctuating environments. The American Naturalist 172:E48-E66.
Purves, D. W., and R. Law. 2002. Fine-scale spatial structure in a grassland community: quantifying the plant's eye view. Journal of Ecology 90:121-129.
Vasseur, D. A. 2007. Environmental colour intensifies the Moran effect when population dynamics are spatially heterogeneous. Oikos 116:1726-1736.
Zar, J. H. 1999. Biostatistical Analysis, Fourth edition. Prentice-Hall, Inc., Upper Saddle River, NJ.
# Compute phase synchrony t1=runif(100) t2=runif(100) sync=phase.sync(t1, t2) # Distribution of phase difference hist(sync$deltaphase$mod_phase_diff_2pi) # Compute concordant peaks p=peaks(t1, t2, nrands=100) # Find proportion of time steps where both time series peak together p$peaks # Plot (null) distribution of proportion of time steps where both time # series peak together hist(p$rand) # p-value of observed value p$pval # Compute Kendall's W data(bird.traits) (w=kendall.w(bird.traits)) # Community matrix for 20 species undergoing random fluctuations comm.rand=matrix(runif(100), nrow=5, ncol=20) community.sync(comm.rand, nrands=10) # Community matrix for 20 species undergoing synchronized fluctuations comm.corr=matrix(rep(comm.rand[,1], 20), nrow=5, ncol=20) community.sync(comm.corr, nrands=10)
# Compute phase synchrony t1=runif(100) t2=runif(100) sync=phase.sync(t1, t2) # Distribution of phase difference hist(sync$deltaphase$mod_phase_diff_2pi) # Compute concordant peaks p=peaks(t1, t2, nrands=100) # Find proportion of time steps where both time series peak together p$peaks # Plot (null) distribution of proportion of time steps where both time # series peak together hist(p$rand) # p-value of observed value p$pval # Compute Kendall's W data(bird.traits) (w=kendall.w(bird.traits)) # Community matrix for 20 species undergoing random fluctuations comm.rand=matrix(runif(100), nrow=5, ncol=20) community.sync(comm.rand, nrands=10) # Community matrix for 20 species undergoing synchronized fluctuations comm.corr=matrix(rep(comm.rand[,1], 20), nrow=5, ncol=20) community.sync(comm.corr, nrands=10)
Contains the wing length, tail length, and bill length from 12 birds
data(bird.traits)
data(bird.traits)
A data frame with 12 observations (birds) on the following 3 variables.
wing.length
a numeric vector containing wing length in cm
tail.length
a numeric vector containing tail length in cm
bill.length
a numeric vector containing bill length in cm
Dataset from Zar (1999; page 444)
Zar, J. H. 1999. Biostatistical Analysis, Fourth edition. Prentice-Hall, Inc., Upper Saddle River, NJ.
data(bird.traits) (w=kendall.w(bird.traits))
data(bird.traits) (w=kendall.w(bird.traits))
Compute community-wide synchrony and its the significance via Monte Carlo randomizations. If all species fluctuate in perfect unison, the community-wide synchrony will be 1. If species undergo uncorrelated fluctuations, the community-wide synchrony will be 1/S. The Monte Carlo randomizations are performed by shuffling the columns of the community matrix independently. This function also returns the mean correlation between the columns of the matrix.
community.sync (data, nrands = 0, method = c("pearson", "kendall", "spearman"), alternative = c("greater", "less"), type = 1, quiet = FALSE, ...)
community.sync (data, nrands = 0, method = c("pearson", "kendall", "spearman"), alternative = c("greater", "less"), type = 1, quiet = FALSE, ...)
data |
community matrix in wide format where each row contains the abundance at each time step and each column corresponds to a different species. |
nrands |
number of randomizations to perform (default is 0) |
method |
Method to compute mean correlation between columns?
Options include |
alternative |
Alternative hypothesis. Options are
|
type |
Randomization method. The |
quiet |
Suppress progress bar when set to |
... |
Other parameters to |
Loreau and de Mazancourt (2008) show that community-wide synchrony can be quantified
by computing the temporal variance
of the community time series
and the sum of the temporal standard deviation of the time series
across all species
such that:
Returns a named list containing:
obs |
the observed community synchrony |
meancorr |
the mean correlation between the columns of the matrix |
rands |
the community synchrony value the randomizations.
This variable is only returned if |
pval |
p-value of observed community synchrony.
This variable is only returned if |
alternative |
Alternative hypothesis. This variable is only returned if |
Tarik C. Gouhier ([email protected])
Loreau, M., and C. de Mazancourt. 2008. Species synchrony and its drivers: Neutral and nonneutral community dynamics in fluctuating environments. The American Naturalist 172:E48-E66.
Purves, D. W., and R. Law. 2002. Fine-scale spatial structure in a grassland community: quantifying the plant's eye view. Journal of Ecology 90:121-129.
# Community matrix for 20 species undergoing random fluctuations comm.rand=matrix(runif(100), nrow=5, ncol=20) community.sync(comm.rand, nrands=20)$pval # Community matrix for 20 species undergoing synchronized fluctuations comm.corr=matrix(rep(comm.rand[,1], 20), nrow=5, ncol=20) community.sync(comm.corr, nrands=20)$pval # On "real" data data(bird.traits) community.sync(bird.traits, nrands=20)$pval
# Community matrix for 20 species undergoing random fluctuations comm.rand=matrix(runif(100), nrow=5, ncol=20) community.sync(comm.rand, nrands=20)$pval # Community matrix for 20 species undergoing synchronized fluctuations comm.corr=matrix(rep(comm.rand[,1], 20), nrow=5, ncol=20) community.sync(comm.corr, nrands=20)$pval # On "real" data data(bird.traits) community.sync(bird.traits, nrands=20)$pval
Calculate distance between all pairs of sites
coord2dist (coords, is.latlon = TRUE, lower.tri = TRUE)
coord2dist (coords, is.latlon = TRUE, lower.tri = TRUE)
coords |
|
is.latlon |
are coordinates latitudes/longitudes? Default is |
lower.tri |
Return lower triangular part of the distance matrix? Default is |
Returns the distance between all pairs of sites
Tarik C. Gouhier ([email protected])
coords=rbind(c(32, -125), c(43, -130)) # Compute great circle distance coord2dist(coords)
coords=rbind(c(32, -125), c(43, -130)) # Compute great circle distance coord2dist(coords)
Find local minima and maxima of a time series
find.minmax (timeseries)
find.minmax (timeseries)
timeseries |
time series in matrix format ( |
Returns a named list containing:
mins |
|
maxs |
|
Tarik C. Gouhier ([email protected])
t1=runif(100) min.max=find.minmax(t1) min.max$maxs plot (t1, t="l") points (min.max$mins, col="blue", bg="blue", pch=19) points (min.max$maxs, col="red", bg="red", pch=19)
t1=runif(100) min.max=find.minmax(t1) min.max$maxs plot (t1, t="l") points (min.max$mins, col="blue", bg="blue", pch=19) points (min.max$maxs, col="red", bg="red", pch=19)
Compute Kendall's coefficient of concordance (W)
kendall.w (data, nrands = 0, type = 1, quiet = FALSE)
kendall.w (data, nrands = 0, type = 1, quiet = FALSE)
data |
matrix in wide format where each row represents a different sample and each column represents a different variable. |
nrands |
Number of randomizations to perform to determine significance. Default is 0. |
type |
Randomization method. The |
quiet |
Suppress progress bar when set to |
Kendall's W is a non-parametric statistic that ranges from 0 to 1 and measures
the level of agreement between multiple variables. When the number of observations ,
its significance can be determined by using a
distribution with
.
Legendre (2005) shows that the
test is always too conservative (low power)
compared to the randomization test. Hence, both tests have been made available in
this function. The Monte Carlo randomizations are performed by shuffling the
columns of the community matrix independently (Legendre 2005).
Returns a named list containing:
w.uncorrected |
Kendall's W uncorrected for tied ranks |
w.corrected |
Kendall's W corrected for tied ranks |
pval |
p-value of Kendall's W |
spearman.corr |
Spearman's ranked correlation |
pval.rand |
p-value of Kendall's W based on randomization test.
This variable is only returned if |
rands |
randomizations. This variable is only returned if |
Tarik C. Gouhier ([email protected])
Buonaccorsi, J. P., J. S. Elkinton, S. R. Evans, and A. M. Liebhold. 2001. Measuring and testing for spatial synchrony. Ecology 82:1668-1679.
Gouhier, T. C., and F. Guichard. 2007. Local disturbance cycles and the maintenance of spatial heterogeneity across scales in marine metapopulations. Ecology 88:647-657.
Gouhier, T. C., F. Guichard, and A. Gonzalez. 2010. Synchrony and stability of food webs in metacommunities. The American Naturalist 175:E16-E34.
Legendre, P. 2005. Species associations: the Kendall coefficient of concordance revisited. Journal of Agricultural, Biological, and Environmental Statistics 10:226-245.
Purves, D. W., and R. Law. 2002. Fine-scale spatial structure in a grassland community: quantifying the plant's eye view. Journal of Ecology 90:121-129.
Zar, J. H. 1999. Biostatistical Analysis, Fourth edition. Prentice-Hall, Inc., Upper Saddle River, NJ.
data(bird.traits) (w=kendall.w(bird.traits))
data(bird.traits) (w=kendall.w(bird.traits))
Calculate distance between a pair of coordinates
latlon2dist (coords)
latlon2dist (coords)
coords |
4-element vector of coordinates with format: |
Returns the great circle distance distance between the pair of coordinates
Tarik C. Gouhier ([email protected])
coords=c(32, -125, 43, -130) # Compute great circle distance latlon2dist(coords)
coords=c(32, -125, 43, -130) # Compute great circle distance latlon2dist(coords)
Compute mean column-wise correlation and determine its significance via Monte Carlo randomizations. The Monte Carlo randomizations are performed by shuffling the columns of the community matrix independently.
meancorr (data, nrands = 0, alternative = c("two.tailed", "greater", "less"), method = c("pearson", "kendall", "spearman"), type = 1, quiet = FALSE, ...)
meancorr (data, nrands = 0, alternative = c("two.tailed", "greater", "less"), method = c("pearson", "kendall", "spearman"), type = 1, quiet = FALSE, ...)
data |
community matrix in wide format where each row contains the abundance at each time step and each column corresponds to a different species. |
nrands |
number of randomizations to perform (default is 0) |
alternative |
Alternative hypothesis. Options include |
method |
Method to compute correlation? Options include |
type |
Randomization method. The |
quiet |
Suppress progress bar when set to |
... |
Other parameters to |
Returns a named list containing:
obs |
the observed mean correlation |
rands |
the mean correlation for each randomization.
This variable is only returned if |
pval |
p-value of observed mean correlation.
This variable is only returned if |
alternative |
Alternative hypothesis.
This variable is only returned if |
method |
Method used to compute the mean correlation. |
Tarik C. Gouhier ([email protected])
Purves, D. W., and R. Law. 2002. Fine-scale spatial structure in a grassland community: quantifying the plant's eye view. Journal of Ecology 90:121-129.
# Community matrix for 20 species undergoing random fluctuations comm.rand=matrix(runif(100), nrow=5, ncol=20) meancorr(comm.rand, nrands=20)$pval # Community matrix for 20 species undergoing synchronized fluctuations comm.corr=matrix(rep(comm.rand[,1], 20), nrow=5, ncol=20) meancorr(comm.corr, nrands=20)$pval # On "real" data data(bird.traits) meancorr(bird.traits, nrands=20)$pval
# Community matrix for 20 species undergoing random fluctuations comm.rand=matrix(runif(100), nrow=5, ncol=20) meancorr(comm.rand, nrands=20)$pval # Community matrix for 20 species undergoing synchronized fluctuations comm.corr=matrix(rep(comm.rand[,1], 20), nrow=5, ncol=20) meancorr(comm.corr, nrands=20)$pval # On "real" data data(bird.traits) meancorr(bird.traits, nrands=20)$pval
Find the proportion of local minima/maxima common to both time series and compute its significance via Monte Carlo randomizations
peaks (t1, t2, nrands = 0, type = 1, quiet = FALSE)
peaks (t1, t2, nrands = 0, type = 1, quiet = FALSE)
t1 |
time series 1 in matrix format ( |
t2 |
time series 2 in matrix format ( |
nrands |
number of randomizations. Default is |
type |
Randomization method. The |
quiet |
Suppress progress bar when set to |
Returns a named list containing:
pval |
p-value computed by randomly shuffling both time series |
rands |
proportion of local minima/maxima common to both time series for each randomization |
obs |
proportion of local minima/maxima common to both time series in the observed dataset |
index |
indices of local minima/maxima common to both time series in the observed dataset |
Tarik C. Gouhier ([email protected])
Buonaccorsi, J. P., J. S. Elkinton, S. R. Evans, and A. M. Liebhold. 2001. Measuring and testing for spatial synchrony. Ecology 82:1668-1679.
Purves, D. W., and R. Law. 2002. Fine-scale spatial structure in a grassland community: quantifying the plant's eye view. Journal of Ecology 90:121-129.
t1=runif(100) t2=runif(100) (p=peaks(t1, t2))
t1=runif(100) t2=runif(100) (p=peaks(t1, t2))
Create two time series with specific autocorrelation , cross-correlation
, mean
ts.mean
, and standard deviation ts.sd
using the
phase partnered algorithm described by Vasseur (2007)
phase.partnered (n = 2000, rho = 1, gamma = 1, sigma = 0.1, mu = 0)
phase.partnered (n = 2000, rho = 1, gamma = 1, sigma = 0.1, mu = 0)
n |
number of time steps in time series. Default is |
rho |
cross-correlation between the two time series ( |
gamma |
autocorrelation of each time series. Gamma ( |
sigma |
standard deviation of both time series. Default is |
mu |
mean of both time series. Default is |
Returns a named list containing the following:
rho |
Cross-correlation of the time series |
gamma |
Autocorrelation of the time series |
sigma |
Standard deviation of the time series |
mu |
Mean of the time series |
timeseries |
|
Tarik C. Gouhier ([email protected])
Gouhier, T. C., F. Guichard, and A. Gonzalez. 2010. Synchrony and stability of food webs in metacommunities. The American Naturalist 175:E16-E34.
Vasseur, D. A. 2007. Environmental colour intensifies the Moran effect when population dynamics are spatially heterogeneous. Oikos 116:1726-1736.
# Positively cross-correlated white noise pos.corr=phase.partnered(n = 100, rho = 0.7, gamma = 0) # Negatively cross-correlated white noise neg.corr=phase.partnered(n = 100, rho = -1, gamma = 0) par(mfrow=c(2,1)) matplot (pos.corr$timeseries, t="l", lty=1) matplot (neg.corr$timeseries, t="l", lty=1)
# Positively cross-correlated white noise pos.corr=phase.partnered(n = 100, rho = 0.7, gamma = 0) # Negatively cross-correlated white noise neg.corr=phase.partnered(n = 100, rho = -1, gamma = 0) par(mfrow=c(2,1)) matplot (pos.corr$timeseries, t="l", lty=1) matplot (neg.corr$timeseries, t="l", lty=1)
Compute the phase synchrony between two quasi-periodic time series by quantifying their phase difference at each time step
phase.sync (t1, t2, nrands = 0, mod = 1, method = c("markov", "fft"), nbreaks = 10, mins = FALSE, quiet = FALSE)
phase.sync (t1, t2, nrands = 0, mod = 1, method = c("markov", "fft"), nbreaks = 10, mins = FALSE, quiet = FALSE)
t1 |
time series 1 in matrix format ( |
t2 |
time series 2 in matrix format ( |
nrands |
number of randomizations to perform (default is 0) |
mod |
flag to indicate whether to compute phase difference modulus |
method |
method to generate surrogate time series for Monte Carlo simulations.
This can be set to |
nbreaks |
number of bins to use to group the values in the time series.
Default is |
quiet |
Suppress progress bar when set to |
mins |
use local minima instead of local maxima to compute and the interpolate the phase. Default is
|
Two time series are phase-locked if the relationship between their phases remains constant over time. This function computes the phase of successive local maxima or minima for each time series and then uses linear interpolation to find the phase at time steps that fall between local maxima/minima. A histogram can be used to determine if the distribution of the phase difference at each time step is uniform (indicating no phase locking) or has a clear peak (indicating phase locking).
Returns a list containing Q.obs
, pval
, rands
,
phases1
, phases2
, deltaphase
, and icdf
:
Q.obs |
Phase synchrony ranging from 0 (no phase synchrony) to 1 (full phase synchrony) |
pval |
p-value of observed phase synchrony based on randomization test |
rands |
Monte Carlo randomizations |
phases1 |
|
phases2 |
|
deltaphase |
|
icdf |
Inverse cumulative distribution of Q values obtained from Monte Carlo randomizatons |
Tarik C. Gouhier ([email protected])
Cazelles, B., and L. Stone. 2003. Detection of imperfect population synchrony in an uncertain world. Journal of Animal Ecology 72:953–968.
Theiler, J., S. Eubank, A. Longtin, B. Galdrikian, and J. Doyne Farmer. 1992. Testing for nonlinearity in time series: the method of surrogate data. Physica D: Nonlinear Phenomena 58:77–94.
t1=runif(100) t2=runif(100) # Compute and interpolate phases using successive local minima sync.mins=phase.sync(t1, t2, mins=TRUE) # Compute and interpolate phases using successive local maxima sync.maxs=phase.sync(t1, t2) # Plot distribution of phase difference hist(sync.mins$deltaphase$mod_phase_diff_2pi)
t1=runif(100) t2=runif(100) # Compute and interpolate phases using successive local minima sync.mins=phase.sync(t1, t2, mins=TRUE) # Compute and interpolate phases using successive local maxima sync.maxs=phase.sync(t1, t2) # Plot distribution of phase difference hist(sync.mins$deltaphase$mod_phase_diff_2pi)
Contains the mean annual chl-a concentration, sea surface temperature, upwelling currents, and mussel abundance at 48 intertidal sites along the West Coast of the United States from 2000-2003.
data(pisco.data)
data(pisco.data)
A data frame with 192 observations on the following 7 variables.
latitude
latitude (degrees North)
longitude
longitude (degrees West)
chl
mean annual remote sensed chlorophyll-a concentration
sst
mean annual remote sensed sea surface temperature
upwelling
mean annual remote sensed upwelling currents
mussel_abund
mean annual mussel cover (Mytilus californianus)
year
sampling year
Gouhier, T. C., F. Guichard, and B. A. Menge. 2010. Ecological processes can synchronize marine population dynamics over continental scales. Proceedings of the National Academy of Sciences 107:8281-8286.
data(pisco.data)
data(pisco.data)
synchrony
objects
Plot synchrony
objects
## S3 method for class 'synchrony' plot(x, main = "", xlab = "Values from randomizations", ylab = "Frequency", line.col = "red", lty = 2, lwd = 1, col = "grey", ...)
## S3 method for class 'synchrony' plot(x, main = "", xlab = "Values from randomizations", ylab = "Frequency", line.col = "red", lty = 2, lwd = 1, col = "grey", ...)
x |
|
main |
main title of the figure |
xlab |
xlabel of the figure. Default is "Values from randomizations" |
ylab |
ylabel of the figure. Default is "Frequency" |
line.col |
color of the vertical line indicating the value observed in the data. Default is "red" |
lty |
line type. Default is 2 or dashed |
lwd |
line width. Default is 1 |
col |
color of the bars. Default is grey |
... |
other graphical parameters. |
Tarik C. Gouhier ([email protected])
comm.rand=matrix(runif(100), nrow=5, ncol=20) comm.rand.sync=community.sync(comm.rand, nrands=20) plot(comm.rand.sync)
comm.rand=matrix(runif(100), nrow=5, ncol=20) comm.rand.sync=community.sync(comm.rand, nrands=20) plot(comm.rand.sync)
vario
objects
Plot vario
objects
## S3 method for class 'vario' plot(x, xlab = "Lag distance", ylab = NULL, ylim = NULL, xtype = c("mean.bin.dist", "bins"), rug = FALSE, ci = FALSE, pch = 21, col.sig="black", col.nonsig="black", bg.sig="black", bg.nonsig = "white", alpha = 0.05, ...)
## S3 method for class 'vario' plot(x, xlab = "Lag distance", ylab = NULL, ylim = NULL, xtype = c("mean.bin.dist", "bins"), rug = FALSE, ci = FALSE, pch = 21, col.sig="black", col.nonsig="black", bg.sig="black", bg.nonsig = "white", alpha = 0.05, ...)
x |
|
xlab |
xlabel of the figure. Default is "Lag distance" |
ylab |
ylabel of the figure. Default is |
ylim |
y-range. Default is |
xtype |
Use either the discrete bin classes ( |
rug |
Plot rug indicating the density of data points? Default is |
ci |
Plot two-tailed (1- |
pch |
Type of points to use when plotting the variogram. Default is 21 |
col.sig |
Border color of points for significant values. Default is black |
col.nonsig |
Border color of points for non-significant values. Default is black |
bg.sig |
Background color of points for significant values. Default is black |
bg.nonsig |
Background color of points for non-significant values. Default is black |
alpha |
Significance level. Default is 0.05 |
... |
other graphical parameters. |
Tarik C. Gouhier ([email protected])
data(pisco.data) d=subset(pisco.data, subset=year==2000, select=c("latitude", "longitude", "sst")) semiv=vario(data=d) moran=vario(data=d, type="moran", nrand=100) geary=vario(data=d, type="geary", nrand=100) par(mfrow=c(3,1)) plot(semiv) plot(moran, bg.sig="blue") plot(geary, bg.sig="red")
data(pisco.data) d=subset(pisco.data, subset=year==2000, select=c("latitude", "longitude", "sst")) semiv=vario(data=d) moran=vario(data=d, type="moran", nrand=100) geary=vario(data=d, type="geary", nrand=100) par(mfrow=c(3,1)) plot(semiv) plot(moran, bg.sig="blue") plot(geary, bg.sig="red")
variofit
objects
Plot variofit
objects
## S3 method for class 'variofit' plot(x, xlab = "Lag distance", ylab = "Variogram", col.pts = "black", col.line = "red", pch = 21, ...)
## S3 method for class 'variofit' plot(x, xlab = "Lag distance", ylab = "Variogram", col.pts = "black", col.line = "red", pch = 21, ...)
x |
|
xlab |
xlabel of the figure. Default is "Lag distance" |
ylab |
ylabel of the figure. Default is "Variogram" |
col.pts |
Border color of the points. Default is black |
col.line |
Color of the fitted variogram. Default is red |
pch |
Type of points to use when plotting the variogram. Default is 21 |
... |
other graphical parameters. |
Tarik C. Gouhier ([email protected])
# Environmental variogram data(pisco.data) d=subset(pisco.data, subset=year==2000, select=c("latitude", "longitude", "upwelling")) semiv=vario(data=d) mod.sph=vario.fit(semiv$vario, semiv$mean.bin.dist) plot(mod.sph)
# Environmental variogram data(pisco.data) d=subset(pisco.data, subset=year==2000, select=c("latitude", "longitude", "upwelling")) semiv=vario(data=d) mod.sph=vario.fit(semiv$vario, semiv$mean.bin.dist) plot(mod.sph)
Create surrogate time series with the same short-term time correlation and overall temporal pattern as the original time series using the Markov process described by Cazelles and Stones (2003)
surrogate.ts (ts, distr.ts = NULL, trans.ts = NULL, nbreaks = 10)
surrogate.ts (ts, distr.ts = NULL, trans.ts = NULL, nbreaks = 10)
ts |
time series in matrix format ( |
distr.ts |
binning of time series values. This parameter must be specified
if |
trans.ts |
transition matrix from bin |
nbreaks |
number of bins to use to group the time series values. Default is |
The values of the time series are grouped into
nbreak
equally-sized bins.
The transition matrix describing the probability of
belonging to
bin
based on
belonging to bin
is defined using the relative
frequencies of the data such that:
. The surrogate time series is then constructed
by randomly selecting a starting value and randomly selecting the next value from the proper bin
based on the transition matrix. This process is repeated until the surrogate time series has
the same length as the original time series.
Returns a named list containing:
surr.ts |
surrogate time series in matrix format |
trans |
transition matrix |
distr |
binning of time series values |
Tarik C. Gouhier ([email protected])
Cazelles, B., and L. Stone. 2003. Detection of imperfect population synchrony in an uncertain world. Journal of Animal Ecology 72:953-968.
t1=runif(100) surr.t1=surrogate.ts(ts=t1) plot(t1, t="l") lines(surr.t1$surr.ts, col="red")
t1=runif(100) surr.t1=surrogate.ts(ts=t1) plot(t1, t="l") lines(surr.t1$surr.ts, col="red")
Compute the empirical variogram and determine its significance via Monte Carlo randomizations
vario (n.bins = 20, size.bins = NULL, extent = 0.5, data, data2 = NULL, is.latlon = TRUE, is.centered = FALSE, nrands = 0, type = c("semivar", "cov", "pearson", "spearman", "kendall", "moran", "geary"), alternative = c("one.tailed", "two.tailed"), mult.test.corr = c("none", "holm", "hochberg", "bonferroni"), regional = c("all", "extent"), quiet = FALSE)
vario (n.bins = 20, size.bins = NULL, extent = 0.5, data, data2 = NULL, is.latlon = TRUE, is.centered = FALSE, nrands = 0, type = c("semivar", "cov", "pearson", "spearman", "kendall", "moran", "geary"), alternative = c("one.tailed", "two.tailed"), mult.test.corr = c("none", "holm", "hochberg", "bonferroni"), regional = c("all", "extent"), quiet = FALSE)
n.bins |
Number of bins or lag distances. This argument is only used when
|
size.bins |
Size of bins in units of distance (e.g., km). When specified, this argument overrides
|
extent |
Proportion of the spatial extent of the data over which to compute the variogram. Default is 0.5 to limit potentially spurious results due to the limited number of data points at large lag distances. |
data |
|
data2 |
|
is.latlon |
Are coordinates latitudes/longitudes? Default is |
is.centered |
Should the variogram be centered by subtracting the regional mean
from each value? If so, the zero-line represents the regional mean. Default is |
nrands |
Number of randomizations to determine statistical significance of variogram. Default is 0. |
type |
Type of variogram to compute. Default is |
alternative |
Conduct a one-tailed or a two-tailed test? Note that the statistical test
is to determine whether the local value within each lag distance is different from the regional
mean. If the variogram is centered, the null hypothesis is that the local values are equal to zero.
If the variogram is not centered, the null hypothesis is that the local values are equal to the
regional mean. Default is |
mult.test.corr |
Correct for multiple tests? Default is |
regional |
Should the regional average be computed for the entire dataset ( |
quiet |
Suppress progress bar when set to |
This function can be used to compute univariate correlograms using Moran's I,
Geary's C, and the covariance function or variograms using the semivariance function.
Multivariate (Mantel) correlograms can also be computed using the covariance function,
Pearson's, Spearman's or Kendall's correlation coefficients. Cross-correlograms/variograms
between data1
and data2
can be computed with the covariance function,
Pearson's, Spearman's or Kendall's correlation coefficients for multivariate
variograms and Moran's I, Geary's C, the covariance function, or semivariance
for univariate variograms.
Returns a named list containing the following variables:
bins |
Center of each lag/bin |
mean.bin.dist |
Mean distance of each lag/bin |
vario |
Variogram values in each lag/bin |
npoints |
Number of pairs of points in each lag/bin |
metric |
Type of variogram computed |
is.centered |
Is the variogram centered? |
regional.mean |
Regional mean value |
pvals |
p-value for each lag/bin.
This variable is only returned if |
rands |
|
alternative |
One-tailed or two-tailed test?
This variable is only returned if |
mult.test.corr |
Correct for multiple tests?
This variable is only returned if |
is.multivar |
Was the analysis performed on multivariate data? |
Tarik C. Gouhier ([email protected])
Bjornstad, O. N., and W. Falck. 2001. Nonparametric spatial covariance functions: Estimation and testing. Environmental and Ecological Statistics 8:53-70.
Bjornstad, O. N., R. A. Ims, and X. Lambin. 1999. Spatial population dynamics: analyzing patterns and processes of population synchrony. Trends in Ecology & Evolution 14:427-432.
Fortin, M. J., and M. R. T. Dale. 2005. Spatial Analysis: A Guide for Ecologists. Cambridge University Press.
data(pisco.data) d=subset(pisco.data, subset=year==2000, select=c("latitude", "longitude", "sst")) semiv=vario(data=d) moran=vario(data=d, type="moran", nrands=100) par(mfrow=c(2,1), mar=c(4.2, 4, 1, 1)) plot(semiv$mean.bin.dist, semiv$vario, xlab="Lag distance (km)", ylab="Semivariance") plot(moran$mean.bin.dist, moran$vario, xlab="Lag distance (km)", ylab="Moran's I", t="l") points(moran$mean.bin.dist[moran$pvals >= 0.05], moran$vario[moran$pvals >= 0.05], bg="white", pch=21) points(moran$mean.bin.dist[moran$pvals < 0.05], moran$vario[moran$pvals < 0.05], bg="black", pch=21) abline(h=0, lty=2) # Compute spatial synchrony d.upw=subset(pisco.data, select=c("latitude", "longitude", "year", "upwelling")) d.cov=subset(pisco.data, select=c("latitude", "longitude", "year", "mussel_abund")) # Reshape the data d.upw.wide=reshape(data=d.upw, idvar=c("latitude", "longitude"), timevar=c("year"), direction="wide") d.cov.wide=reshape(data=d.cov, idvar=c("latitude", "longitude"), timevar=c("year"), direction="wide") # Generate variograms v.upw=vario(n.bins=12, data=d.upw.wide, type="pearson", extent=1, nrands=999) v.cov=vario(n.bins=12, data=d.cov.wide, type="pearson", extent=1, nrands=999) ## Fit variograms v.cov.per=vario.fit(v.cov$vario, v.cov$mean.bin.dist, type="period", start.vals=list(a=1, b=3, c=0)) v.upw.lin=vario.fit(v.upw$vario, v.upw$mean.bin.dist, type="linear") par(mfrow=c(2,1)) plot(v.cov, xlab="Lag distance (km)", bg.sig="red", col.nonsig="red", main="Mussel cover", rug=TRUE, ylim=c(-0.3, 0.3)) lines(v.cov$mean.bin.dist, v.cov.per$fit, col="red") plot(v.upw, xlab="Lag distance (km)", bg.sig="blue", col.nonsig="blue", main="Upwelling", rug=TRUE) lines(v.upw$mean.bin.dist, v.upw.lin$fit, col="blue")
data(pisco.data) d=subset(pisco.data, subset=year==2000, select=c("latitude", "longitude", "sst")) semiv=vario(data=d) moran=vario(data=d, type="moran", nrands=100) par(mfrow=c(2,1), mar=c(4.2, 4, 1, 1)) plot(semiv$mean.bin.dist, semiv$vario, xlab="Lag distance (km)", ylab="Semivariance") plot(moran$mean.bin.dist, moran$vario, xlab="Lag distance (km)", ylab="Moran's I", t="l") points(moran$mean.bin.dist[moran$pvals >= 0.05], moran$vario[moran$pvals >= 0.05], bg="white", pch=21) points(moran$mean.bin.dist[moran$pvals < 0.05], moran$vario[moran$pvals < 0.05], bg="black", pch=21) abline(h=0, lty=2) # Compute spatial synchrony d.upw=subset(pisco.data, select=c("latitude", "longitude", "year", "upwelling")) d.cov=subset(pisco.data, select=c("latitude", "longitude", "year", "mussel_abund")) # Reshape the data d.upw.wide=reshape(data=d.upw, idvar=c("latitude", "longitude"), timevar=c("year"), direction="wide") d.cov.wide=reshape(data=d.cov, idvar=c("latitude", "longitude"), timevar=c("year"), direction="wide") # Generate variograms v.upw=vario(n.bins=12, data=d.upw.wide, type="pearson", extent=1, nrands=999) v.cov=vario(n.bins=12, data=d.cov.wide, type="pearson", extent=1, nrands=999) ## Fit variograms v.cov.per=vario.fit(v.cov$vario, v.cov$mean.bin.dist, type="period", start.vals=list(a=1, b=3, c=0)) v.upw.lin=vario.fit(v.upw$vario, v.upw$mean.bin.dist, type="linear") par(mfrow=c(2,1)) plot(v.cov, xlab="Lag distance (km)", bg.sig="red", col.nonsig="red", main="Mussel cover", rug=TRUE, ylim=c(-0.3, 0.3)) lines(v.cov$mean.bin.dist, v.cov.per$fit, col="red") plot(v.upw, xlab="Lag distance (km)", bg.sig="blue", col.nonsig="blue", main="Upwelling", rug=TRUE) lines(v.upw$mean.bin.dist, v.upw.lin$fit, col="blue")
Fit model to the empirical variogram
vario.fit (vario, bins, weights = rep(1, length(vario)), type = c("spherical", "gaussian", "nugget", "linear", "exponential", "sill", "periodic", "hole"), start.vals = list(c0 = 0, c1 = max(vario), a = max(bins)/4, b=0.1, c=0.1), control = list(maxit=10000))
vario.fit (vario, bins, weights = rep(1, length(vario)), type = c("spherical", "gaussian", "nugget", "linear", "exponential", "sill", "periodic", "hole"), start.vals = list(c0 = 0, c1 = max(vario), a = max(bins)/4, b=0.1, c=0.1), control = list(maxit=10000))
vario |
Empirical variogram from |
bins |
Bins or lag distances from |
weights |
Vector of weights of the same length as |
type |
Type of variogram model to fit to the data. Default is |
start.vals |
Named list containing the start values for the variogram model:
|
control |
optional parameter for the |
Return a named list containing the following variables:
vario |
Empirical variogram values |
bins |
Empirical variogram bins/lag distances |
AIC |
AIC score of the model fit: |
RMSE |
Root Mean Square Error of the model fit: |
params |
Named list containing the best model parameter estimates |
fit |
Predicted variogram values from the model fit |
nls.success |
did |
convergence |
did |
Selecting proper initial values is critical for fitting a reasonable model to the
empirical variogram. If these values are off, nls
will fail and fall-back
functions will be used to determine the best parameter values that minimize the
Root Mean Square Error (RMSE).
Tarik C. Gouhier ([email protected])
# Load data data(pisco.data) # Environmental variogram d=subset(pisco.data, subset=year==2000, select=c("latitude", "longitude", "upwelling")) semiv=vario(data=d) plot(semiv, xlab="Lag distance (km)") mod.sph=vario.fit(semiv$vario, semiv$mean.bin.dist) # Weighted least squares fit based on the number of points mod.exp=vario.fit(semiv$vario, semiv$mean.bin.dist, weights=semiv$npoints/sum(semiv$npoints), type="expo") mod.gau=vario.fit(semiv$vario, semiv$mean.bin.dist, type="gauss") mod.lin=vario.fit(semiv$vario, semiv$mean.bin.dist, type="lin") lines(semiv$mean.bin.dist, mod.sph$fit, col="red") lines(semiv$mean.bin.dist, mod.exp$fit, col="black") lines(semiv$mean.bin.dist, mod.gau$fit, col="blue") lines(semiv$mean.bin.dist, mod.lin$fit, col="green") legend(x="topleft", legend=paste(c("Spherical AIC:", "Exponential AIC:", "Gaussian AIC:", "Linear AIC:"), c(format(mod.sph$AIC, dig=2), format(mod.exp$AIC, dig=2), format(mod.gau$AIC, dig=2), format(mod.lin$AIC, dig=2))), lty=1, col=c("red", "black", "blue", "green"), bty="n") # Correlogram cover=subset(pisco.data, subset=year==2000, select=c("latitude", "longitude", "mussel_abund")) moran=vario(data=cover, type="moran") mod.hol=vario.fit(moran$vario, moran$mean.bin.dist, type="hole", start.vals=list(c0=0.6, a=25, c1=0.01)) mod.per=vario.fit(moran$vario, moran$mean.bin.dist, type="period", start.vals=list(a=1, b=3, c=0)) mod.lin=vario.fit(moran$vario, moran$mean.bin.dist, type="linear") plot(moran, xlab="Lag distance (km)", ylim=c(-0.6, 0.8)) lines(moran$mean.bin.dist, mod.per$fit, col="red") lines(moran$mean.bin.dist, mod.hol$fit, col="black") lines(moran$mean.bin.dist, mod.lin$fit, col="blue") legend(x="topleft", legend=paste(c("Periodic AIC:", "Hole AIC:", "Linear AIC:"), c(format(mod.per$AIC, dig=2), format(mod.hol$AIC, dig=2), format(mod.lin$AIC, dig=2))), lty=1, col=c("red", "black", "blue"), bty="n")
# Load data data(pisco.data) # Environmental variogram d=subset(pisco.data, subset=year==2000, select=c("latitude", "longitude", "upwelling")) semiv=vario(data=d) plot(semiv, xlab="Lag distance (km)") mod.sph=vario.fit(semiv$vario, semiv$mean.bin.dist) # Weighted least squares fit based on the number of points mod.exp=vario.fit(semiv$vario, semiv$mean.bin.dist, weights=semiv$npoints/sum(semiv$npoints), type="expo") mod.gau=vario.fit(semiv$vario, semiv$mean.bin.dist, type="gauss") mod.lin=vario.fit(semiv$vario, semiv$mean.bin.dist, type="lin") lines(semiv$mean.bin.dist, mod.sph$fit, col="red") lines(semiv$mean.bin.dist, mod.exp$fit, col="black") lines(semiv$mean.bin.dist, mod.gau$fit, col="blue") lines(semiv$mean.bin.dist, mod.lin$fit, col="green") legend(x="topleft", legend=paste(c("Spherical AIC:", "Exponential AIC:", "Gaussian AIC:", "Linear AIC:"), c(format(mod.sph$AIC, dig=2), format(mod.exp$AIC, dig=2), format(mod.gau$AIC, dig=2), format(mod.lin$AIC, dig=2))), lty=1, col=c("red", "black", "blue", "green"), bty="n") # Correlogram cover=subset(pisco.data, subset=year==2000, select=c("latitude", "longitude", "mussel_abund")) moran=vario(data=cover, type="moran") mod.hol=vario.fit(moran$vario, moran$mean.bin.dist, type="hole", start.vals=list(c0=0.6, a=25, c1=0.01)) mod.per=vario.fit(moran$vario, moran$mean.bin.dist, type="period", start.vals=list(a=1, b=3, c=0)) mod.lin=vario.fit(moran$vario, moran$mean.bin.dist, type="linear") plot(moran, xlab="Lag distance (km)", ylim=c(-0.6, 0.8)) lines(moran$mean.bin.dist, mod.per$fit, col="red") lines(moran$mean.bin.dist, mod.hol$fit, col="black") lines(moran$mean.bin.dist, mod.lin$fit, col="blue") legend(x="topleft", legend=paste(c("Periodic AIC:", "Hole AIC:", "Linear AIC:"), c(format(mod.per$AIC, dig=2), format(mod.hol$AIC, dig=2), format(mod.lin$AIC, dig=2))), lty=1, col=c("red", "black", "blue"), bty="n")
Compute the empirical variogram values for each bin
vario.func (x, y, glob.mean, glob.sd, glob.N, is.multivar = FALSE, type = c("semivar", "cov", "pearson", "spearman", "kendall", "moran", "geary"))
vario.func (x, y, glob.mean, glob.sd, glob.N, is.multivar = FALSE, type = c("semivar", "cov", "pearson", "spearman", "kendall", "moran", "geary"))
x |
First set of sites within bin/lag distance |
y |
Second set of sites within bin/lag distance |
glob.mean |
Global mean |
glob.sd |
Global standard deviation |
glob.N |
Global number of points |
is.multivar |
Is the data multivariate? Default is |
type |
Type of variogram to compute. Default is |
Return the value.
Tarik C. Gouhier ([email protected])
# Internal function used by vario
# Internal function used by vario