# NOT RUN {
# See ?global_envelope_test for more examples
## Testing complete spatial randomness (CSR)
#-------------------------------------------
if(require("spatstat", quietly=TRUE)) {
pp <- unmark(spruces)
# }
# NOT RUN {
nsim <- 2499 # Number of simulations
# }
# NOT RUN {
# }
# NOT RUN {
# Generate nsim simulations under CSR, calculate L-function for the data and simulations
env <- envelope(pp, fun="Lest", nsim=nsim, savefuns=TRUE, correction="translate",
simulate=expression(runifpoint(ex=pp)))
# The rank envelope test
res <- rank_envelope(env)
# Plot the result.
# - The central curve is now obtained from env[['theo']], which is the
# value of the L-function under the null hypothesis (L(r) = r).
plot(res)
# or (requires R library ggplot2)
plot(res, plot_style="ggplot2")
## Advanced use:
# Choose the interval of distances [r_min, r_max] (at the same time create a curve_set from 'env')
curve_set <- crop_curves(env, r_min=1, r_max=7)
# For better visualisation, take the L(r)-r function
curve_set <- residual(curve_set, use_theo=TRUE)
# Do the rank envelope test
res <- rank_envelope(curve_set); plot(res, plot_style="ggplot2")
}
# }
Run the code above in your browser using DataLab