| Title: | Compare Spatial Structure of Hotspots with Neutral Models |
|---|---|
| Description: | Analyses whether the statistical properties of a spatial pattern of hotspots may be reproduced with a simple neutral model. |
| Authors: | Mark Padgham [aut, cre] |
| Maintainer: | Mark Padgham <[email protected]> |
| License: | GPL-3 |
| Version: | 0.0.0.012 |
| Built: | 2026-05-22 08:37:25 UTC |
| Source: | https://github.com/mpadge/hotspotr |
Fits a neutral model to an observed series of hotspot values in terms of standard deviation of environmental variables, spatial autocorrelation parameters, and number of iterations of spatial autocorrelation.
fit_hotspot_model( z, nbs, wts, ac_type = "moran", ntests = 100, verbose = FALSE, plot = FALSE )fit_hotspot_model( z, nbs, wts, ac_type = "moran", ntests = 100, verbose = FALSE, plot = FALSE )
z |
Vector of observed values to be tested |
nbs |
An |
wts |
Weighting factors for each neighbour; must have same length as nbs. Uniform weights used if not given. |
ac_type |
type of autocorrelation statistic to use in tests
( |
ntests |
Number of repeats of neutral model used to calculate mean rank–scale distribution |
verbose |
If TRUE, dump progress details to screen |
plot |
If TRUE, produces a plot of rank–scale distributions |
A vector of three values as estimated by the neutral model:
sd0 = standard deviation of normal distribution
alpha = temporal autocorrelation coefficient
niters = number of iterations of spatial autocorrelation
Fitting these neutral models is not a standard optimisation problem
because the models are very noisy. Although optim with
method="SANN" may be used, it often generates extremely large values
for alpha (for example, > 10). DEoptim could also be applied,
yet in generally does not explore anything useful—if given starting
parameters, it will generally remain exactly in that place.
The approach employed here reflects the comment of https://stat.ethz.ch/pipermail/r-help/2015-May/428751.html through simply producing regular series, fitting loess models, and taking the corresponding minima.
## Not run: xy <- cbind (rep (seq (size), each=size), rep (seq (size), size)) dhi <- 1 # for rook; dhi=1.5 for queen nbs <- spdep::dnearneigh (xy, 0, dhi) z <- runif (length (nbs)) test <- fit_hotspot_model (z=z, nbs=dat$nbs, alpha=0.1, sd=0.1, ntests=100) ## End(Not run)## Not run: xy <- cbind (rep (seq (size), each=size), rep (seq (size), size)) dhi <- 1 # for rook; dhi=1.5 for queen nbs <- spdep::dnearneigh (xy, 0, dhi) z <- runif (length (nbs)) test <- fit_hotspot_model (z=z, nbs=dat$nbs, alpha=0.1, sd=0.1, ntests=100) ## End(Not run)
Uses the parameters returned by fit_hotspot_model to generate
rank-scale distributions both of raw values and associated spatial
autocorrelation statistics.
generate_hotspot_model( n, alpha = 0.1, sd0 = 0.1, ac_type = "moran", niters = 1, plot = FALSE )generate_hotspot_model( n, alpha = 0.1, sd0 = 0.1, ac_type = "moran", niters = 1, plot = FALSE )
n |
Number of observations to generate |
alpha |
Strength of spatial autocorrelation |
sd0 |
Standard deviation of truncated normal distribution used to model environmental variation (with mean of 1) |
ac_type |
Type of autocorrelation statistic to use in tests
( |
niters |
Number of successive layers of spatial autocorrelation |
plot |
If TRUE, produces a plot of rank–scale distributions |
A matrix of two columns containing sorted and scaled versions of
z = raw values
ac = associated spatial autocorrelation statistics
Analyses whether the statistical properties of a spatial pattern of hotspots may be reproduced with a simple neutral model.
ives2d
|
Simulate model of Ives & Klopfer (Ecology 1997) |
neutral2d
|
Neutral model in two dimensions |
run_tests
|
Test observed data with range of possible (1-D & 2-D) models |
test2d
|
Test observed data against a two dimensional neutral model |
Maintainer: Mark Padgham [email protected]
Useful links:
Implements neutral model of hotspot values and associated autocorrelation
statustics. Current version is a simply internal R loop, while
neutral_hotspots_ntests is a parallel version of exactly the same
thing.
neutral_hotspots( nbs, wts, alpha = 0.1, sd0 = 0.1, ac_type = "moran", niters = 1, log_scale = TRUE, ntests = 100, parallel = FALSE, seed )neutral_hotspots( nbs, wts, alpha = 0.1, sd0 = 0.1, ac_type = "moran", niters = 1, log_scale = TRUE, ntests = 100, parallel = FALSE, seed )
nbs |
An |
wts |
Weighting factors for each neighbour; must have same length as nbs. Uniform weights used if not given. |
alpha |
strength of spatial autocorrelation |
sd0 |
Standard deviation of truncated normal distribution used to model environmental variation (with mean of 1) |
ac_type |
Type of autocorrelation statistic to use in tests
( |
niters |
Number of successive layers of spatial autocorrelation |
log_scale |
If TRUE, raw hotspot values are log-transformed |
ntests |
Number of tests over which to generate an average result |
parallel |
If true, the tests are conducted using the |
seed |
Random seed |
A vector of hotspot values sorted from high to low
ives
# First set up a grid of rectangular neighbours size <- 10 xy <- cbind (rep (seq (size), each=size), rep (seq (size), size)) dhi <- 1 # for rook; dhi=1.5 for queen nbs <- spdep::dnearneigh (xy, 0, dhi) dat <- neutral_hotspots (nbs, ntests=1000)# First set up a grid of rectangular neighbours size <- 10 xy <- cbind (rep (seq (size), each=size), rep (seq (size), size)) dhi <- 1 # for rook; dhi=1.5 for queen nbs <- spdep::dnearneigh (xy, 0, dhi) dat <- neutral_hotspots (nbs, ntests=1000)
Implements neutral model of hotspot values and associated autocorrelation
statustics. Current version is a simply internal R loop, while
neutral_hotspots_ntests is a parallel version of exactly the same
thing.
neutral_hotspots2( nbs, wts, alpha = 0.1, sd0 = 0.1, ac_type = "moran", niters = 1, log_scale = TRUE, ntests = 100, seed )neutral_hotspots2( nbs, wts, alpha = 0.1, sd0 = 0.1, ac_type = "moran", niters = 1, log_scale = TRUE, ntests = 100, seed )
nbs |
An |
wts |
Weighting factors for each neighbour; must have same length as nbs. Uniform weights used if not given. |
alpha |
strength of spatial autocorrelation |
sd0 |
Standard deviation of truncated normal distribution used to model environmental variation (with mean of 1) |
ac_type |
Type of autocorrelation statistic to use in tests
( |
niters |
Number of successive layers of spatial autocorrelation |
log_scale |
If TRUE, raw hotspot values are log-transformed |
ntests |
Number of tests over which to generate an average result |
seed |
Random seed |
A vector of hotspot values sorted from high to low
ives
# First set up a grid of rectangular neighbours size <- 10 xy <- cbind (rep (seq (size), each=size), rep (seq (size), size)) dhi <- 1 # for rook; dhi=1.5 for queen nbs <- spdep::dnearneigh (xy, 0, dhi) dat <- neutral_hotspots (nbs, ntests=1000)# First set up a grid of rectangular neighbours size <- 10 xy <- cbind (rep (seq (size), each=size), rep (seq (size), size)) dhi <- 1 # for rook; dhi=1.5 for queen nbs <- spdep::dnearneigh (xy, 0, dhi) dat <- neutral_hotspots (nbs, ntests=1000)
First order statistic for normal distribution.
order_one(sigma, n, ntrials = 1000)order_one(sigma, n, ntrials = 1000)
sigma |
Standard deviation of normal distribution |
n |
Number of samples of normal distribution |
ntrials |
Number of trials over which to average order statistics |
First order statistic
Tests observed data (z) against a series of neutral models
p_values( z, nbs, wts, sd0 = 0.1, alpha = 0.1, niters = 1, ntests = 1000, ac_type = "moran", log_scale = FALSE, plot = FALSE, verbose = FALSE )p_values( z, nbs, wts, sd0 = 0.1, alpha = 0.1, niters = 1, ntests = 1000, ac_type = "moran", log_scale = FALSE, plot = FALSE, verbose = FALSE )
z |
Vector of observed values to be tested |
nbs |
An |
wts |
Weighting factors for each neighbour; must have same length as nbs. Uniform weights used if not given. |
sd0 |
Standard deviation of truncated normal distribution used to model environmental variation (with mean of 1) |
alpha |
Strength of spatial autocorrelation |
niters |
Number of successive layers of spatial autocorrelation |
ntests |
Number of tests to run, with statistics calculated from the
mean of |
ac_type |
type of autocorrelation statistic to use in tests
( |
log_scale |
If TRUE, raw hotspot values are log-transformed |
plot |
If TRUE, plot mean and observed distributions of z and associated autocorrelation statistics |
verbose |
If TRUE, dump progress details to screen |
Nothing (dumps statistics to screen)
Averages results of a number of neutral models
rs_dist_diff( nbs, wts, alpha = 0.1, sd0 = 0.1, niters = 1, ntests = 1000, ac_type = "moran", log_scale = TRUE, mean_stats )rs_dist_diff( nbs, wts, alpha = 0.1, sd0 = 0.1, niters = 1, ntests = 1000, ac_type = "moran", log_scale = TRUE, mean_stats )
nbs |
An |
wts |
Weighting factors for each neighbour; must have same length as nbs. Uniform weights used if not given. |
alpha |
Strength of spatial autocorrelation |
sd0 |
Standard deviation of truncated normal distribution used to model environmental variation (with mean of 1) |
niters |
Number of sequential iterations of spatial autocorrelation |
ntests |
Number of repeats of neutral model used to calculate mean rank–scale distribution |
ac_type |
type of autocorrelation statistic to use in tests
( |
log_scale |
If TRUE, raw hotspot values are log-transformed |
mean_stats |
Mean rank–scale distributions returned from
|
A vector of hotspot values sorted from high to low
ives