Title: | Functions for Spatial Point Pattern Analysis |
---|---|
Description: | Some wrappers, functions and data sets for for spatial point pattern analysis (mainly based on 'spatstat'), used in the book "Introduccion al Analisis Espacial de Datos en Ecologia y Ciencias Ambientales: Metodos y Aplicaciones" and in the papers by De la Cruz et al. (2008) <doi:10.1111/j.0906-7590.2008.05299.x> and Olano et al. (2009) <doi:10.1051/forest:2008074>. |
Authors: | Marcelino de la Cruz Rot, with contributions of Philip M. Dixon and Jose M. Blanco-Moreno |
Maintainer: | Marcelino de la Cruz Rot <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.1-17 |
Built: | 2024-12-21 06:36:02 UTC |
Source: | CRAN |
dixon2002
is a wrapper to the functions of Dixon (2002) to test spatial segregation for several species by analyzing the
counts of the nearest neighbour contingency table for a marked point pattern.
dixon2002(datos, nsim = 99)
dixon2002(datos, nsim = 99)
datos |
|
nsim |
number of simulations for the randomization approximation of the p-values. |
A measure of segregation describes the tendency of one species to be associated with itself or with other species. Dixon (2002) proposed a measure of the segregation of species i in a multiespecies spatial pattern as:
where is the number of individuals of species i,
is the frequency of species i as neighbor of especies i and
is the total
number of locations. Values of
larger than 0 indicate that species i is segregated; the larger the value of
, the more extreme the segregation.
Values of
less than 0 indicate that species i is is found as neighbor of itself less than expected under random labelling.
Values of
close to 0 are consistent with random labelling of the neighbors of species i.
Dixon (2002) also proposed a pairwise segregation index for the off-diagonal elements of the contingency table:
is larger than 0 when
, the frequency of neighbors of species j around points of species i, is larger than expected under random
labelling and less than 0 when
is smaller than expected under random labelling.
As a species/neighbor-specific test, Dixon(2002) proposed the statistic
where j may be the same as i and is the expected count in the contingency table. It has an asymptotic normal distribution with mean 0
and variance 1; its asymptotic p-value can be obtained from the numerical evaluation of the cumulative normal distribution; when the sample size is small, a p-value on the observed counts in each cell (
) may be obtained by simulation, i.e, by condicting a randomization test.
An overall test of random labelling (i.e. a test that all counts in the x
nearest-neighbor contingency table are equal to their expected counts) is based
on the quadratic form
where is the vector of all cell counts in the contingency table,
is the variance-covariance matrix of those counts and
is a generalized inverse of
. Under the null hypothesis of random labelling of points,
has a asymptotic Chi-square distribution with
degrees of freedom (if the sample sizes are small its distribution should be estimated using Monte-Carlo simulation). P-values are computed from the probability of observing
equal or larger values of
.
The overall statistic
can be partitioned into
species-specific test statistics
. Each
test if the frequencies of the neighbors
of species i are similar to the expected frequencies if the points were randomly labelled. Because the
are not independent Chi-square statistics, they do not
sum to the overall
.
A list with the following components:
ON |
Observed nearest neighbor counts in table format. From row sp to column sp. |
EN |
Expected nearest neighbor counts in table format. |
Z |
Z-score for testing whether the observed count equals the expected count. |
S |
Segregation measure. |
pZas |
P-values based on the asymptotic normal distribution of the Z statistic. |
pNr |
If nsim !=0, p-values of the observed counts in each cell based on the randomization distribution. |
C |
Overall test of random labelling. |
Ci |
Species-specific test of random labelling. |
pCas |
P-value of the overall test from the asymptotic chi-square distribution with the appropriate degrees of freedom. |
pCias |
P-values of the species-specific tests from the asymptotic chi-square distribution with the appropriate degrees of freedom. |
pCr |
If nsim !=0, p-value of the overall test from the randomization distribution. |
pCir |
If nsim !=0, p-values of the species-specific tests from the randomization distribution. |
tablaZ |
table with ON, EN, Z, S, pZas and pNr in pretty format, as in the table II of Dixon (2002). |
tablaC |
table with C, Ci, pCas,pCias, pCr and pCir in pretty format, as in the table IV of Dixon (2002). |
The and
statistics asume that the spatial nearest-neighbor process is stationary, at least to second order,
i.e., have the same sign in every part of the entire plot. A biologically heterogeneous process will violate this asumption.
Philip M. Dixon . Marcelino de la Cruz wrote the wrapper code for the ecespa
version.
Dixon, P.M. 2002. Nearest-neighbor contingency table analysis of spatial segregation for several species. Ecoscience, 9 (2): 142-151. doi:10.1080/11956860.2002.11682700.
K012
for another segregation test, based in the differences of univariate and bivariate -functions. A faster version of this function, with code implemented in FORTRAN it is available in function
dixon
in dixon.
data(swamp) dixon2002(swamp,nsim=99)
data(swamp) dixon2002(swamp,nsim=99)
This is a summary of the features of ecespa by way of examples of its main functions.
Marcelino de la Cruz Rot, with contributions of Philip M. Dixon and Jose M. Blanco-Moreno and heavily borrowing Baddeley's & Turner's spatstat code.
De la Cruz, M. 2006. Introducción al análisis de datos mapeados o algunas de las (muchas) cosas que puedo hacer si tengo coordenadas. Ecosistemas 15 (3): 19-39.
De la Cruz, M. 2008. Métodos para analizar datos puntuales. En: Introducción al Análisis Espacial de Datos en Ecología y Ciencias Ambientales: Métodos y Aplicaciones (eds. Maestre, F. T., Escudero, A. y Bonet, A.), pp 76-127. Asociación Española de Ecología Terrestre, Universidad Rey Juan Carlos y Caja de Ahorros del Mediterráneo, Madrid.
De la Cruz, M., Romao, R.L., Escudero, A. and Maestre, F.T. 2008. Where do seedlings go? A spatio-temporal analysis of early mortality in a semiarid specialist. Ecography, 31(6): 720-730. doi:10.1111/j.0906-7590.2008.05299.x.
Diggle, P. J. 2003. Statistical analysis of spatial point patterns. Arnold, London.
Dixon, P.M. 2002. Nearest-neighbor contingency table analysis of spatial segregation for several species. Ecoscience, 9 (2): 142-151. doi:10.1080/11956860.2002.11682700.
Dixon, P. M. 2002. Ripley's K function. In The encyclopedia of environmetrics (eds. El-Shaarawi, A.H. & Piergorsch, W.W.), pp. 1976-1803. John Wiley & Sons Ltd, NY.
Escudero, A., Romao, R.L., De la Cruz, M. & Maestre, F. 2005. Spatial pattern and neighbour effects on Helianthemum squamatum seedlings in a Mediterranean gypsum community. Journal of Vegetation Science, 16: 383-390. doi:10.1111/j.1654-1103.2005.tb02377.x.
Getis, A. and Franklin, J. 1987. Second-order neighbourhood analysis of mapped point patterns. Ecology 68: 473-477. doi:10.2307/1938452.
Loosmore, N.B. and Ford, E.D. (2006) Statistical inference using the G or K point pattern spatial statistics. Ecology 87, 1925-1931. doi:10.1890/0012-9658(2006)87[1925:SIUTGO]2.0.CO;2.
Lotwick,H.W. & Silverman, B. W. 1982. Methods for analysing spatial processes of several types of points. Journal of the Royal Statistical Society B, 44: 406-413. doi:10.1111/j.2517-6161.1982.tb01221.x.
Olano, J.M., Laskurain, N.A., Escudero, A. and De la Cruz, M. 2009. Why and where adult trees die in a secondary temperate forest? The role of neighbourhood. Annals of Forest Science, 66: 105. doi:10.1051/forest:2008074.
Penttinen, A. 2006. Statistics for Marked Point Patterns. In The Yearbook of the Finnish Statistical Society, pp. 70-91.
Rey-Benayas, J.M., de la Montaña, E., Pérez-Camacho, L., de la Cruz, M., Moreno, D., Parejo, J.L. and Suárez-Seoane, S. 2010. Inter-annual dynamics and spatial congruence of a nocturnal bird assemblage inhabiting a Mediterranean agricultural mosaic. Ardeola,57(2): 303-320.
Syrjala, S. E. 1996. A statistical test for a difference between the spatial distributions of two populations. Ecology 77: 75-80. doi:10.2307/2265656.
Waagepetersen, R. P. 2007. An estimating function approach to inference for inhomogeneous Neymann-Scott processes. Biometrics 63: 252-258. doi:10.1111/j.1541-0420.2006.00667.x.
## Not run: ############################################# ### Transfom easily data from a data.frame into the ppp format ### of spatstat: data(fig1) plot(fig1) #typical xyplot fig1.ppp <- haz.ppp (fig1) fig1.ppp plot(fig1.ppp) # point pattern plot of spatstat ############################################# ### Summarize the joint pattern of points and marks at different scales ### with the normalized mark-weighted K-function (Penttinen, 2006). ### Compare this function in two consecutive cohorts of Helianthemum ### squamatum seedlings: ## Figure 3.10 of De la Cruz (2008): data(seedlings1) data(seedlings2) s1km <- Kmm(seedlings1, r=1:100) s2km <- Kmm(seedlings2, r=1:100) plot(s1km, ylime=c(0.6,1.2), lwd=2, maine="", xlabe="r(cm)") plot(s2km, lwd=2, lty=2, add=T ) abline(h=1, lwd=2, lty=3) legend(x=60, y=1.2, legend=c("Hs_C1", "Hs_C2", "H0"), lty=c(1, 2, 3), lwd=c(3, 2, 2), bty="n") ## A pointwise test of normalized Kmm == 1 for seedlings1: s1km.test <- Kmm(seedlings1, r=1:100, nsim=99) plot(s1km.test, xlabe="r(cm)") ############################################# ### Explore the local relationships between marks and locations (e.g. size ### of one cohort of H. squamatum seedlings). Map the marked point pattern ### to a random field for visual inspection, with the normalized mark-sum ### measure (Penttinen, 2006). data(seedlings1) seed.m <- marksum(seedlings1, R=25) plot(seed.m, what="marksum", sigma = 5) # raw mark-sum measure; sigma is bandwith for smoothing plot(seed.m, what="pointsum", sigma = 5) # point sum measure plot(seed.m, what="normalized", dimyx=200, contour=TRUE, sigma = 5) # normalized mark-sum measure # the same with added grid plot(seed.m, what="normalized", dimyx=200, contour=TRUE, sigma = 5, grid=TRUE) ############################################# ### Test against the null model of "independent labelling", ### i.e. test asociation/repulsion between a "fixed" pattern (e.g. adult ### H. squamatum plants) and a "variable" pattern (e.g. of surviving and ### dead seedlings), with 2.5% and 97.5% envelopes of 999 random ### labellings (De la Cruz & al. 2008). data(Helianthemum) cosa <- K012(Helianthemum, fijo="adultHS", i="deadpl", j="survpl", r=seq(0,200,le=201), nsim=999, nrank=25, correction="isotropic") plot(cosa$k01, sqrt(./pi)-r~r, col=c(3, 1, 3), lty=c(3, 1, 3), las=1, ylab=expression(L[12]), xlim=c(0, 200), main="adult HS vs. dead seedlings", legend=FALSE) plot(cosa$k02, sqrt(./pi)-r~r, col=c(3, 1, 3), lty=c(3, 1, 3), las=1, ylab=expression(L[12]), xlim=c(0, 200), main="adult HS vs. surviving seedlings", legend=FALSE) ############################################# ### Test differences of agregation and segregation between two patterns, ### e.g. surviving and dying H. squamatum seedlings (De la Cruz & al. 2008). data(Helianthemum) cosa12 <- K1K2(Helianthemum, j="deadpl", i="survpl", r=seq(0,200,le=201), nsim=999, nrank=1, correction="isotropic") plot(cosa12$k1k2, lty=c(2, 1, 2), col=c(2, 1, 2), xlim=c(0, 200), main= "survival- death",ylab=expression(K[1]-K[2]), legend=FALSE) plot(cosa12$k1k12, lty=c(2, 1, 2), col=c(2, 1, 2), xlim=c(0, 200), main="segregation of surviving seedlings",ylab=expression(K[1]-K[12]), legend=FALSE) plot(cosa12$k2k12, lty=c(2, 1, 2), col=c(2, 1, 2), xlim=c(0, 200), main= "segregation of dying seedlings",ylab=expression(K[2]-K[12]), legend=FALSE) ############################################# ### Test 'univariate' and 'bivariate' point patterns ### against non-Poisson (in-)homogeneous models ### (De la Cruz and Escudero, submited). data(urkiola) ##################### ## univariate example # get univariate pp I.ppp <- split.ppp(urkiola)$birch # estimate inhomogeneous intensity function I.lam <- predict (ppm(I.ppp, ~polynom(x,y,2)), type="trend", ngrid=200) # Compute and plot envelopes to Kinhom, simulating from an Inhomogeneous # Poisson Process: I2.env <- envelope( I.ppp,Kinhom, lambda=I.lam, correction="trans", nsim=99, simulate=expression(rpoispp(I.lam))) plot(I2.env, sqrt(./pi)-r~r, xlab="r (metres)", ylab= "L (r)", col=c(1,3,2,2),legend=FALSE) # It seems that there is short scale clustering; let's fit an Inhomogeneous # Poisson Cluster Process: I.ki <- ipc.estK(mippp=I.ppp, lambda=I.lam, correction="trans") # Compute and plot envelopes to Kinhom, simulating from the fitted IPCP: Ipc.env <- Ki(I.ki, correction="trans", nsim=99, ngrid=200) plot (Ipc.env, xlab="r (metres)", ylab= "L (r)") ##################### ## bivariate example: test independence between birch and quercus in Urkiola J.ppp <- split.ppp(urkiola)$oak # We want to simulate oak from a homogeneous Poisson model: J.ppm <- ppm(J.ppp, trend=~1, interaction=Poisson() ) IJ.env <- Kci (mod1=I.ki, mod2=J.ppm, nsim=99) plot(IJ.env, type=12) plot(IJ.env, type=21) ############################################# ### Simulate envelopes from the fitted values of a logistic model, ### as in Olano et al. (2009) data(quercusvm) # read fitted values from logistic model: probquercus <-c(0.99955463, 0.96563477, 0.97577094, 0.97327199, 0.92437309, 0.84023396, 0.94926682, 0.89687281, 0.99377915, 0.74157478, 0.95491518, 0.72366493, 0.66771787, 0.77330148, 0.67569082, 0.9874892, 0.7918891, 0.73246803, 0.81614635, 0.66446411, 0.80077908, 0.98290508, 0.54641754, 0.53546689, 0.73273626, 0.7347013, 0.65559655, 0.89481468, 0.63946334, 0.62101995, 0.78996371, 0.93179582, 0.80160346, 0.82204428, 0.90050059, 0.83810669, 0.92153079, 0.47872421, 0.24697004, 0.50680935, 0.6297911, 0.46374812, 0.65672284, 0.87951682, 0.35818237, 0.50932432, 0.92293014, 0.48580241, 0.49692053, 0.52290553, 0.7317549, 0.32445982, 0.30300865, 0.73599359, 0.6206056, 0.85777043, 0.65758613, 0.50100406, 0.31340849, 0.22289286, 0.40002879, 0.29567678, 0.56917817, 0.56866864, 0.27718552, 0.4910667, 0.47394411, 0.40543788, 0.29571349, 0.30436276, 0.47859015, 0.31754526, 0.42131675, 0.37468782, 0.73271225, 0.26786274, 0.59506388, 0.54801851, 0.38983575, 0.64896835, 0.37282031, 0.67624306, 0.29429766, 0.29197755, 0.2247629, 0.40697843, 0.17022391, 0.26528042, 0.24373722, 0.26936163, 0.13052254, 0.19958585, 0.18659692, 0.36686678, 0.47263005, 0.39557661, 0.68048997, 0.74878567, 0.88352322, 0.93851375) ################################ ## Envelopes for an homogeneous point pattern: cosap <- Kinhom.log(A=quercusvm, lifemark="0", nsim=99, prob=probquercus) plot(cosap) ################################ ## Envelopes for an inhomogeneous point pattern: ## First, fit an inhomogeneous Poisson model to alive trees : quercusalive <- unmark(quercusvm[quercusvm$marks == 0]) mod2 <- ppm(quercusalive, ~polynom(x,y,2)) ## Now use mod2 to estimate lambda for K.inhom: cosapm <- Kinhom.log(A=quercusvm, lifemark="0", prob=probquercus, nsim=99, mod=mod2) plot(cosapm) ############################################# ### Test segregation based on the counts in the contingency table ### of nearest neighbors in a multitype point pattern (Dixon, 2002) data(swamp) dixon2002(swamp,nsim=99) ############################################# ### Fit the Poisson cluster point process to a point pattern with ### the method of minimum contrast (Diggle 2003). data(gypsophylous) # Estimate K function ("Kobs"). gyps.env <- envelope(gypsophylous, Kest, correction="iso", nsim=99) plot(gyps.env, sqrt(./pi)-r~r, ylab="L(r)", legend=FALSE) # Fit Poisson Cluster Process. The limits of integration # rmin and rmax are setup to 0 and 60, respectively. cosa.pc <- pc.estK(Kobs = gyps.env$obs[gyps.env$r<=60], r = gyps.env$r[gyps.env$r<=60]) # Add fitted Kclust function to the plot. lines(gyps.env$r,sqrt(Kclust(gyps.env$r, cosa.pc$sigma2,cosa.pc$rho)/pi)-gyps.env$r, lty=2, lwd=3, col="purple") # A kind of pointwise test of the gypsophylous pattern been a realisation # of the fitted model, simulating with sim.poissonc and using function J (Jest). gyps.env.sim <- envelope(gypsophylous, Jest, nsim=99, simulate=expression(sim.poissonc(gypsophylous, sigma=sqrt(cosa.pc$sigma2), rho=cosa.pc$rho))) plot(gyps.env.sim, main="",legendpos="bottomleft") ############################################# ### Compute Syrjala's test for the difference between the spatial ### distributions of two populations, as in Rey-Benayas et al. ### (submited) data(syr1); data(syr2); data(syr3) plot(syrjala.test(syr1, syr2, nsim=999)) plot(syrjala.test(syr1, syr3, nsim=999)) ## End(Not run)
## Not run: ############################################# ### Transfom easily data from a data.frame into the ppp format ### of spatstat: data(fig1) plot(fig1) #typical xyplot fig1.ppp <- haz.ppp (fig1) fig1.ppp plot(fig1.ppp) # point pattern plot of spatstat ############################################# ### Summarize the joint pattern of points and marks at different scales ### with the normalized mark-weighted K-function (Penttinen, 2006). ### Compare this function in two consecutive cohorts of Helianthemum ### squamatum seedlings: ## Figure 3.10 of De la Cruz (2008): data(seedlings1) data(seedlings2) s1km <- Kmm(seedlings1, r=1:100) s2km <- Kmm(seedlings2, r=1:100) plot(s1km, ylime=c(0.6,1.2), lwd=2, maine="", xlabe="r(cm)") plot(s2km, lwd=2, lty=2, add=T ) abline(h=1, lwd=2, lty=3) legend(x=60, y=1.2, legend=c("Hs_C1", "Hs_C2", "H0"), lty=c(1, 2, 3), lwd=c(3, 2, 2), bty="n") ## A pointwise test of normalized Kmm == 1 for seedlings1: s1km.test <- Kmm(seedlings1, r=1:100, nsim=99) plot(s1km.test, xlabe="r(cm)") ############################################# ### Explore the local relationships between marks and locations (e.g. size ### of one cohort of H. squamatum seedlings). Map the marked point pattern ### to a random field for visual inspection, with the normalized mark-sum ### measure (Penttinen, 2006). data(seedlings1) seed.m <- marksum(seedlings1, R=25) plot(seed.m, what="marksum", sigma = 5) # raw mark-sum measure; sigma is bandwith for smoothing plot(seed.m, what="pointsum", sigma = 5) # point sum measure plot(seed.m, what="normalized", dimyx=200, contour=TRUE, sigma = 5) # normalized mark-sum measure # the same with added grid plot(seed.m, what="normalized", dimyx=200, contour=TRUE, sigma = 5, grid=TRUE) ############################################# ### Test against the null model of "independent labelling", ### i.e. test asociation/repulsion between a "fixed" pattern (e.g. adult ### H. squamatum plants) and a "variable" pattern (e.g. of surviving and ### dead seedlings), with 2.5% and 97.5% envelopes of 999 random ### labellings (De la Cruz & al. 2008). data(Helianthemum) cosa <- K012(Helianthemum, fijo="adultHS", i="deadpl", j="survpl", r=seq(0,200,le=201), nsim=999, nrank=25, correction="isotropic") plot(cosa$k01, sqrt(./pi)-r~r, col=c(3, 1, 3), lty=c(3, 1, 3), las=1, ylab=expression(L[12]), xlim=c(0, 200), main="adult HS vs. dead seedlings", legend=FALSE) plot(cosa$k02, sqrt(./pi)-r~r, col=c(3, 1, 3), lty=c(3, 1, 3), las=1, ylab=expression(L[12]), xlim=c(0, 200), main="adult HS vs. surviving seedlings", legend=FALSE) ############################################# ### Test differences of agregation and segregation between two patterns, ### e.g. surviving and dying H. squamatum seedlings (De la Cruz & al. 2008). data(Helianthemum) cosa12 <- K1K2(Helianthemum, j="deadpl", i="survpl", r=seq(0,200,le=201), nsim=999, nrank=1, correction="isotropic") plot(cosa12$k1k2, lty=c(2, 1, 2), col=c(2, 1, 2), xlim=c(0, 200), main= "survival- death",ylab=expression(K[1]-K[2]), legend=FALSE) plot(cosa12$k1k12, lty=c(2, 1, 2), col=c(2, 1, 2), xlim=c(0, 200), main="segregation of surviving seedlings",ylab=expression(K[1]-K[12]), legend=FALSE) plot(cosa12$k2k12, lty=c(2, 1, 2), col=c(2, 1, 2), xlim=c(0, 200), main= "segregation of dying seedlings",ylab=expression(K[2]-K[12]), legend=FALSE) ############################################# ### Test 'univariate' and 'bivariate' point patterns ### against non-Poisson (in-)homogeneous models ### (De la Cruz and Escudero, submited). data(urkiola) ##################### ## univariate example # get univariate pp I.ppp <- split.ppp(urkiola)$birch # estimate inhomogeneous intensity function I.lam <- predict (ppm(I.ppp, ~polynom(x,y,2)), type="trend", ngrid=200) # Compute and plot envelopes to Kinhom, simulating from an Inhomogeneous # Poisson Process: I2.env <- envelope( I.ppp,Kinhom, lambda=I.lam, correction="trans", nsim=99, simulate=expression(rpoispp(I.lam))) plot(I2.env, sqrt(./pi)-r~r, xlab="r (metres)", ylab= "L (r)", col=c(1,3,2,2),legend=FALSE) # It seems that there is short scale clustering; let's fit an Inhomogeneous # Poisson Cluster Process: I.ki <- ipc.estK(mippp=I.ppp, lambda=I.lam, correction="trans") # Compute and plot envelopes to Kinhom, simulating from the fitted IPCP: Ipc.env <- Ki(I.ki, correction="trans", nsim=99, ngrid=200) plot (Ipc.env, xlab="r (metres)", ylab= "L (r)") ##################### ## bivariate example: test independence between birch and quercus in Urkiola J.ppp <- split.ppp(urkiola)$oak # We want to simulate oak from a homogeneous Poisson model: J.ppm <- ppm(J.ppp, trend=~1, interaction=Poisson() ) IJ.env <- Kci (mod1=I.ki, mod2=J.ppm, nsim=99) plot(IJ.env, type=12) plot(IJ.env, type=21) ############################################# ### Simulate envelopes from the fitted values of a logistic model, ### as in Olano et al. (2009) data(quercusvm) # read fitted values from logistic model: probquercus <-c(0.99955463, 0.96563477, 0.97577094, 0.97327199, 0.92437309, 0.84023396, 0.94926682, 0.89687281, 0.99377915, 0.74157478, 0.95491518, 0.72366493, 0.66771787, 0.77330148, 0.67569082, 0.9874892, 0.7918891, 0.73246803, 0.81614635, 0.66446411, 0.80077908, 0.98290508, 0.54641754, 0.53546689, 0.73273626, 0.7347013, 0.65559655, 0.89481468, 0.63946334, 0.62101995, 0.78996371, 0.93179582, 0.80160346, 0.82204428, 0.90050059, 0.83810669, 0.92153079, 0.47872421, 0.24697004, 0.50680935, 0.6297911, 0.46374812, 0.65672284, 0.87951682, 0.35818237, 0.50932432, 0.92293014, 0.48580241, 0.49692053, 0.52290553, 0.7317549, 0.32445982, 0.30300865, 0.73599359, 0.6206056, 0.85777043, 0.65758613, 0.50100406, 0.31340849, 0.22289286, 0.40002879, 0.29567678, 0.56917817, 0.56866864, 0.27718552, 0.4910667, 0.47394411, 0.40543788, 0.29571349, 0.30436276, 0.47859015, 0.31754526, 0.42131675, 0.37468782, 0.73271225, 0.26786274, 0.59506388, 0.54801851, 0.38983575, 0.64896835, 0.37282031, 0.67624306, 0.29429766, 0.29197755, 0.2247629, 0.40697843, 0.17022391, 0.26528042, 0.24373722, 0.26936163, 0.13052254, 0.19958585, 0.18659692, 0.36686678, 0.47263005, 0.39557661, 0.68048997, 0.74878567, 0.88352322, 0.93851375) ################################ ## Envelopes for an homogeneous point pattern: cosap <- Kinhom.log(A=quercusvm, lifemark="0", nsim=99, prob=probquercus) plot(cosap) ################################ ## Envelopes for an inhomogeneous point pattern: ## First, fit an inhomogeneous Poisson model to alive trees : quercusalive <- unmark(quercusvm[quercusvm$marks == 0]) mod2 <- ppm(quercusalive, ~polynom(x,y,2)) ## Now use mod2 to estimate lambda for K.inhom: cosapm <- Kinhom.log(A=quercusvm, lifemark="0", prob=probquercus, nsim=99, mod=mod2) plot(cosapm) ############################################# ### Test segregation based on the counts in the contingency table ### of nearest neighbors in a multitype point pattern (Dixon, 2002) data(swamp) dixon2002(swamp,nsim=99) ############################################# ### Fit the Poisson cluster point process to a point pattern with ### the method of minimum contrast (Diggle 2003). data(gypsophylous) # Estimate K function ("Kobs"). gyps.env <- envelope(gypsophylous, Kest, correction="iso", nsim=99) plot(gyps.env, sqrt(./pi)-r~r, ylab="L(r)", legend=FALSE) # Fit Poisson Cluster Process. The limits of integration # rmin and rmax are setup to 0 and 60, respectively. cosa.pc <- pc.estK(Kobs = gyps.env$obs[gyps.env$r<=60], r = gyps.env$r[gyps.env$r<=60]) # Add fitted Kclust function to the plot. lines(gyps.env$r,sqrt(Kclust(gyps.env$r, cosa.pc$sigma2,cosa.pc$rho)/pi)-gyps.env$r, lty=2, lwd=3, col="purple") # A kind of pointwise test of the gypsophylous pattern been a realisation # of the fitted model, simulating with sim.poissonc and using function J (Jest). gyps.env.sim <- envelope(gypsophylous, Jest, nsim=99, simulate=expression(sim.poissonc(gypsophylous, sigma=sqrt(cosa.pc$sigma2), rho=cosa.pc$rho))) plot(gyps.env.sim, main="",legendpos="bottomleft") ############################################# ### Compute Syrjala's test for the difference between the spatial ### distributions of two populations, as in Rey-Benayas et al. ### (submited) data(syr1); data(syr2); data(syr3) plot(syrjala.test(syr1, syr2, nsim=999)) plot(syrjala.test(syr1, syr3, nsim=999)) ## End(Not run)
The three different point patterns in the figure 3.1 of De la Cruz (2008)
data(fig1) data(fig2) data(fig3)
data(fig1) data(fig2) data(fig3)
A data frame with 87 observations on the following 2 variables.
x
x coordinate
y
y coordinate
De la Cruz, M. 2008. Métodos para analizar datos puntuales. En: Introducción al Análisis Espacial de Datos en Ecología y Ciencias Ambientales: Métodos y Aplicaciones (eds. Maestre, F. T., Escudero, A. y Bonet, A.), pp 76-127. Asociación Española de Ecología Terrestre, Universidad Rey Juan Carlos y Caja de Ahorros del Mediterráneo, Madrid.
## Not run: data(fig1) data(fig2) data(fig3) # transform to ppp format of spatstat with function haz.ppp: fig1.ppp <- haz.ppp(fig1) fig2.ppp <- haz.ppp(fig2) fig3.ppp <- haz.ppp(fig3) #Analyses as in Fig.3.2 of De la Cruz (2008). First, compute function K: cosa1 <- Kest(fig1.ppp) # Plot different estimators. # Fig. 3.2a: par("mar"=par("mar")+c(0,1,0,0)) plot(cosa1, col=c(1,0,0,1), lwd=c(2,2,2,2), lty=c(1,1,1,2), main="") # Fig. 3.2b: plot(cosa1, sqrt(./pi)-r~r, col=c(1,0,0,1), lwd=c(2,2,2,2), lty=c(1,1,1,2), main="", ylab="L(r)") # Fig. 3.2c: plot(cosa1, .-(pi*r^2)~r, col=c(1,0,0,1), lwd=c(2,2,2,2), lty=c(1,1,1,2), main="", ylab=expression(K(r)-pi*r^2)) # Fig. 3.2d: plot(cosa1,(./(pi*r^2))-1~r, col=c(1,0,0,1), lwd=c(2,2,2,2), lty=c(1,1,1,2), main="", ylab=expression((K(r)/pi*r^2)-1)) ## Analyses as in fig. 3.7 of De la Cruz (2008). ## First, compute function K and pointwise envelopes: cosa1.env <- envelope(fig1.ppp, Kest) cosa2.env <- envelope(fig2.ppp, Kest) cosa3.env <- envelope(fig3.ppp, Kest) ## Plot function L with pointwise envelopes: plot(cosa1.env,sqrt(./pi)-r~r, lwd=c(1,1,2,2), lty=c(1,1,3,3), col=c(1,1,1,1), xlab="r", ylab="L(r)", main="", ylim=c(-2,2)) ## Add simultaneous envelopes of Ripley (+-1.68 *sqrt(A)/N): abline(h=1.68*sqrt(area.owin(fig1.ppp$window))/fig1.ppp$n, lty=2, lwd=2) abline(h=-1.68*sqrt(area.owin(fig1.ppp$window))/fig1.ppp$n, lty=2, lwd=2) ## Plot function L with pointwise envelopes: plot(cosa2.env,sqrt(./pi)-r~r, lwd=c(1,1,2,2), lty=c(1,1,3,3), col=c(1,1,1,1), xlab="r", ylab="L(r)", main="") ## Add simultaneous envelopes of Ripley: abline(h=1.68*sqrt(area.owin(fig2.ppp$window))/fig2.ppp$n, lty=2, lwd=2) abline(h=-1.68*sqrt(area.owin(fig2.ppp$window))/fig2.ppp$n, lty=2, lwd=2) ## Plot function L with pointwise envelopes: plot(cosa3.env,sqrt(./pi)-r~r, lwd=c(1,1,2,2), lty=c(1,1,3,3), col=c(1,1,1,1), xlab="r", ylab="L(r)", main="") ## Add simultaneous envelopes of Ripley: abline(h=1.68*sqrt(area.owin(fig3.ppp$window))/fig3.ppp$n, lty=2, lwd=2) abline(h=-1.68*sqrt(area.owin(fig3.ppp$window))/fig3.ppp$n, lty=2, lwd=2) ## End(Not run)
## Not run: data(fig1) data(fig2) data(fig3) # transform to ppp format of spatstat with function haz.ppp: fig1.ppp <- haz.ppp(fig1) fig2.ppp <- haz.ppp(fig2) fig3.ppp <- haz.ppp(fig3) #Analyses as in Fig.3.2 of De la Cruz (2008). First, compute function K: cosa1 <- Kest(fig1.ppp) # Plot different estimators. # Fig. 3.2a: par("mar"=par("mar")+c(0,1,0,0)) plot(cosa1, col=c(1,0,0,1), lwd=c(2,2,2,2), lty=c(1,1,1,2), main="") # Fig. 3.2b: plot(cosa1, sqrt(./pi)-r~r, col=c(1,0,0,1), lwd=c(2,2,2,2), lty=c(1,1,1,2), main="", ylab="L(r)") # Fig. 3.2c: plot(cosa1, .-(pi*r^2)~r, col=c(1,0,0,1), lwd=c(2,2,2,2), lty=c(1,1,1,2), main="", ylab=expression(K(r)-pi*r^2)) # Fig. 3.2d: plot(cosa1,(./(pi*r^2))-1~r, col=c(1,0,0,1), lwd=c(2,2,2,2), lty=c(1,1,1,2), main="", ylab=expression((K(r)/pi*r^2)-1)) ## Analyses as in fig. 3.7 of De la Cruz (2008). ## First, compute function K and pointwise envelopes: cosa1.env <- envelope(fig1.ppp, Kest) cosa2.env <- envelope(fig2.ppp, Kest) cosa3.env <- envelope(fig3.ppp, Kest) ## Plot function L with pointwise envelopes: plot(cosa1.env,sqrt(./pi)-r~r, lwd=c(1,1,2,2), lty=c(1,1,3,3), col=c(1,1,1,1), xlab="r", ylab="L(r)", main="", ylim=c(-2,2)) ## Add simultaneous envelopes of Ripley (+-1.68 *sqrt(A)/N): abline(h=1.68*sqrt(area.owin(fig1.ppp$window))/fig1.ppp$n, lty=2, lwd=2) abline(h=-1.68*sqrt(area.owin(fig1.ppp$window))/fig1.ppp$n, lty=2, lwd=2) ## Plot function L with pointwise envelopes: plot(cosa2.env,sqrt(./pi)-r~r, lwd=c(1,1,2,2), lty=c(1,1,3,3), col=c(1,1,1,1), xlab="r", ylab="L(r)", main="") ## Add simultaneous envelopes of Ripley: abline(h=1.68*sqrt(area.owin(fig2.ppp$window))/fig2.ppp$n, lty=2, lwd=2) abline(h=-1.68*sqrt(area.owin(fig2.ppp$window))/fig2.ppp$n, lty=2, lwd=2) ## Plot function L with pointwise envelopes: plot(cosa3.env,sqrt(./pi)-r~r, lwd=c(1,1,2,2), lty=c(1,1,3,3), col=c(1,1,1,1), xlab="r", ylab="L(r)", main="") ## Add simultaneous envelopes of Ripley: abline(h=1.68*sqrt(area.owin(fig3.ppp$window))/fig3.ppp$n, lty=2, lwd=2) abline(h=-1.68*sqrt(area.owin(fig3.ppp$window))/fig3.ppp$n, lty=2, lwd=2) ## End(Not run)
Computes and plots the neighbourhood density function, a local version of the -function defined by Getis and Franklin (1987).
getis(mippp, nx = 30, ny = 30, R = 10) ## S3 method for class 'ecespa.getis' plot(x, type="k", dimyx=NULL, xy=NULL, eps=NULL, color=NULL, contour=TRUE, points=TRUE,...)
getis(mippp, nx = 30, ny = 30, R = 10) ## S3 method for class 'ecespa.getis' plot(x, type="k", dimyx=NULL, xy=NULL, eps=NULL, color=NULL, contour=TRUE, points=TRUE,...)
mippp |
A point pattern. An object with the |
nx |
Grid dimensions (for estimation) in the x-side. |
ny |
Grid dimensions (for estimation) in the y-side. |
R |
Radius. The distance argument r at which the function |
x |
Result of applying |
type |
Type of local statistics to be ploted. One of |
color |
A list of colors such as that generated by |
dimyx |
pixel array dimensions, will be passed to (i.e. see details in) |
xy |
pixel coordinates, will be passed to (i.e. see details in) |
eps |
width and height of pixels, will be passed to (i.e. see details in) |
contour |
Logical; if TRUE, add a contour to current plot. |
points |
Logical; if TRUE, add the point pattern to current plot. |
... |
Additional graphical parameters passed to |
Getis and Franklin (1987) proposed the neigbourhood density function, a local version of Ripley's - function.
Given a spatial point pattern
, the neigbourhood density function associated with the ith point in
is computed by
where the sum is over all points j != i that lie within a distance r of the ith point, a is the area of the observation window,
n is the number of points in , and e[i,j] is the isotropic edge correction term (as described in
Kest
). The value of L[i](r) can also
be interpreted as one of the summands that contributes to the global estimate of the -function.
The command getis
actually computes the local -function using
Kcross
. As the main objective of getis
is to map the local density function,
as sugested by Gestis and Franklin (1987: 476) a grid of points (whose density is controled by nx
and ny
), is used to accurately estimate the
functions in empty or sparse areas. The S3 method plot.ecespa.getis
plots the spatial distribution of the local or
function or other related local statistics, such as
, the number of neighbor points [=
] or the deviations from the expected value of local
under CSR [=
]. It some of the arguments
dimyx
, xy
or eps
is provided it will use the function
interp.im
in spatstat
package to interpolate the results;otherwise it will plot the estimated values at the origial grid points.
getis
gives an object of class ecespa.getis
, bassically a list with the following elements:
x |
x coordinates of pattern points (ahead) and grid points. |
y |
y coordinates of pattern points (ahead) and grid points. |
klocal |
Estimate of local |
klocalgrid |
Estimate of local |
R |
Distance |
nx |
Density of the estimating grid in the x-side. |
ny |
Density of the estimating grid in the x-side. |
dataname |
Name of the ppp object analysed. |
ppp |
Original point pattern. |
plot.ecespa.getis
plots an interpolated map of the selected local statistics
As plot.ecespa.getis
interpolates over rectangular grid of points, it is not apropriate to map irregular windows. In those cases, Smooth.ppp
of spatstat
can be used to interpolate the local statistics (see examples).
Marcelino de la Cruz Rot
Getis, A. and Franklin, J. 1987. Second-order neighbourhood analysis of mapped point patterns. Ecology 68: 473-477. doi:10.2307/1938452.
localK
, a different approach in spatstat.
## Compare with fig. 5b of Getis & Franklin (1987: 476): data(ponderosa) #ponderosa12 <- getis(ponderosa, nx = 30, ny = 30, R = 12) ponderosa12 <- getis(ponderosa, nx = 20, ny = 20, R = 12) plot(ponderosa12, type = "l", dimyx=256) ## Not run: ## Plot the same, using Smooth.ppp in spatstat ponderosa.12 <- setmarks(ponderosa, ponderosa12$klocal) Z <- Smooth(ponderosa.12, sigma=5, dimyx=256) plot(Z, col=topo.colors(128), main="smoothed neighbourhood density") contour(Z, add=TRUE) points(ponderosa, pch=16, cex=0.5) ## Example with irregular window: data(letterR) X <- rpoispp(50, win=letterR) X.g <- getis(X, R=0.2) plot(X.g,dimyx=c(200,100)) ## Plot the same, using Smooth.ppp in spatstat X2 <- setmarks(X, X.g$klocal) Z <- Smooth(X2, sigma=0.05, dimxy=256) plot(Z, col=topo.colors(128), main="smoothed neighbourhood density") contour(Z, add=TRUE) points(X, pch=16, cex=0.5) ## End(Not run)
## Compare with fig. 5b of Getis & Franklin (1987: 476): data(ponderosa) #ponderosa12 <- getis(ponderosa, nx = 30, ny = 30, R = 12) ponderosa12 <- getis(ponderosa, nx = 20, ny = 20, R = 12) plot(ponderosa12, type = "l", dimyx=256) ## Not run: ## Plot the same, using Smooth.ppp in spatstat ponderosa.12 <- setmarks(ponderosa, ponderosa12$klocal) Z <- Smooth(ponderosa.12, sigma=5, dimyx=256) plot(Z, col=topo.colors(128), main="smoothed neighbourhood density") contour(Z, add=TRUE) points(ponderosa, pch=16, cex=0.5) ## Example with irregular window: data(letterR) X <- rpoispp(50, win=letterR) X.g <- getis(X, R=0.2) plot(X.g,dimyx=c(200,100)) ## Plot the same, using Smooth.ppp in spatstat X2 <- setmarks(X, X.g$klocal) Z <- Smooth(X2, sigma=0.05, dimxy=256) plot(Z, col=topo.colors(128), main="smoothed neighbourhood density") contour(Z, add=TRUE) points(X, pch=16, cex=0.5) ## End(Not run)
Locations of plants in a gypsophylous plant community in Central Spain. These are part of the data collected by Romao (2003) that have been analyzed several times (Escudero et al. 2005, De la Cruz 2006). The coordinates of the plans are given in cm.
data(gypsophylous)
data(gypsophylous)
An object of class "ppp" of spatstat
representing the point pattern of plants locations. See ppp.object
for details of the format.
Romao, R.L. 2003. Estructura espacial de comunidades de gipsófitos: interacciones bióticas y constricciones abióticas. Tesis Doctoral. Universidad Politécnica de Madrid.
De la Cruz, M. 2006. Introducción al análisis de datos mapeados o algunas de las (muchas) cosas que puedo hacer si tengo coordenadas. Ecosistemas 15 (3): 19-39.
Escudero, A., Romao, R.L., De la Cruz, M. & Maestre, F. 2005. Spatial pattern and neighbour effects on Helianthemum squamatum seedlings in a Mediterranean gypsum community. Journal of Vegetation Science, 16: 383-390. doi:10.1111/j.1654-1103.2005.tb02377.x.
## Not run: data(gypsophylous) plot(gypsophylous) ## End(Not run)
## Not run: data(gypsophylous) plot(gypsophylous) ## End(Not run)
ppp maker for the impatient layman
haz.ppp(W)
haz.ppp(W)
W |
a data frame or matrix with two or three columns (coordinate x, coordinate y, and mark of the point) |
This naive function easily transform your xy data to the format required by spatstat (version <2.0). It establishes the window of observation as the rectangle defined by the xy range. It asumes that the first two columns are coordinates x and y, and the third (if any) gives the marks of the points.
A point pattern with the format of spatstat v. < 2.0
This window is an underestimate of the real sampling window of the observed points. For a less biassed estimate, use function ripras
in spatstat.
Marcelino de la Cruz
data(fig1) plot(fig1) #typical xyplot fig1.ppp <- haz.ppp (fig1) fig1.ppp plot(fig1.ppp) # point pattern plot of spatstat
data(fig1) plot(fig1) #typical xyplot fig1.ppp <- haz.ppp (fig1) fig1.ppp plot(fig1.ppp) # point pattern plot of spatstat
Locations of H. squamatum adult plants and seedlings in a 6 m x 7 m plot over gypsum soil in Chinchón (near Madrid, Spain). These are part of the data collected by Romao (2003) that have been analyzed several times (Escudero et al.2005, De la Cruz 2006, De la Cruz et al. in press. ). The coordinates of the plans are given in cm.
data(Helianthemum)
data(Helianthemum)
An object of class "ppp" of spatstat
representing the point pattern of plants locations marked by their type. See ppp.object
for details of the format.The dataset has 866 points with the following levels:
adult H. squamatum plants
dying H. squamatum seedlings
surviving H. squamatum seedlings
Romao, R.L. 2003. Estructura espacial de comunidades de gipsófitos: interacciones bióticas y constricciones abióticas. Tesis Doctoral. Universidad Politécnica de Madrid.
De la Cruz, M. 2006. Introducción al análisis de datos mapeados o algunas de las (muchas) cosas que puedo hacer si tengo coordenadas. Ecosistemas 15 (3): 19-39.
De la Cruz, M., Romao, R.L., Escudero, A. and Maestre, F.T. 2008. Where do seedlings go? A spatio-temporal analysis of early mortality in a semiarid specialist. Ecography,31(6): 720-730. doi:10.1111/j.0906-7590.2008.05299.x.
Escudero, A., Romao, R.L., De la Cruz, M. & Maestre, F. 2005. Spatial pattern and neighbour effects on Helianthemum squamatum seedlings in a Mediterranean gypsum community. Journal of Vegetation Science, 16: 383-390. doi:10.1111/j.1654-1103.2005.tb02377.x.
data(Helianthemum) plot(Helianthemum)
data(Helianthemum) plot(Helianthemum)
Fits the (In)homogeneous Poisson Cluster point process to a point pattern dataset by the Method of Minimum Contrast.
ipc.estK(mippp, lambda = NULL, correction = "iso", r = NULL, sigma2 = NULL, rho = NULL, q = 1/4, p = 2) ## S3 method for class 'ecespa.minconfit' plot(x, type="L", add=FALSE, xlim=NULL, ylim=NULL, lwd=c(1,1), lty=c(1,2), col=c(1,2), main=NULL, ...)
ipc.estK(mippp, lambda = NULL, correction = "iso", r = NULL, sigma2 = NULL, rho = NULL, q = 1/4, p = 2) ## S3 method for class 'ecespa.minconfit' plot(x, type="L", add=FALSE, xlim=NULL, ylim=NULL, lwd=c(1,1), lty=c(1,2), col=c(1,2), main=NULL, ...)
mippp |
Point pattern to which the (I)PCP will be fitted. A point pattern with the |
lambda |
Optional. Values of the estimated intensity function as a pixel image (object of class " |
correction |
A character item selecting any of the options "border", "bord.modif", "isotropic", "Ripley" or
"translate". It specifies the edge correction(s) to be applied in the computation of the |
r |
Numeric vector. The values of the argument |
sigma2 |
Optional. Starting value for the parameter |
rho |
Optional. Starting value for the parameter |
q |
|
p |
|
x |
An object of class 'ecespa.minconfit', resulting of applying |
type |
Type of function to be ploted. If type="L", function |
add |
Logical. Should the curves be added to another plot? |
xlim |
Vector setting the limits of the x-axis. |
ylim |
Vector setting the limits of the y-axis. |
lwd |
Vector (length=2) setting the line width for ploting the two functions. |
lty |
Vector (length=2) setting the line type for ploting the two functions. |
col |
Vector (length=2) setting the line color for ploting the two functions. |
main |
Optional. Text to appear as a title of the plot. |
... |
Additional graphical parameters passed to |
The algorithm fits the (inhomogeneous) Poisson cluster point process (PCP) to a point pattern, by finding the parameters of the (inhomogeneous) Poisson cluster model
which give the closest match between the theoretical K function of the Poisson cluster process and the observed
K function. For a concise explanation of the PCP see pc.estK
. For a more detailed explanation of the Method of Minimum Contrast, see mincontrast
in spatstat or Diggle (2003: 86).
The inhomogeneous PCP can be thought of as a thinned process of an homogeneous PCP, where the spatially varying thinning probability
is related to the spatially varying intensity function
as
(Waagepetersen, 2007).
As the inhomogeneous K function for the IPCP coincides with the (homogeneous) K function for the corresponding homogeneous PCP,
the parameters of the underlying homomgeneous PCP can be estimated as those that give the closest match between the theoretical K function
for the homogeneous PCP and the empirical inhomogeneous K function for the observed IPCP.
This Poisson cluster process can be simulated with rIPCP
.
ipc.estK
gives an object of class 'ecespa.minconfit
', basically a list with the following components:
sigma2 |
Parameter |
rho |
Parameter |
d.theta |
Minimized value of the contrast criterion |
Kobs |
Values of the observed K-function. |
Kfit |
Values of the fitted K-function. |
r |
Sequence of distances at which |
data |
Original point pattern. |
lambda |
Original intensity function. |
dataname |
Name of the original point pattern. |
lambdaname |
Name of the original intensity function image. |
q |
|
p |
|
Marcelino de la Cruz Rot , inspired by some code of Philip M. Dixon
Diggle, P. J. 2003. Statistical analysis of spatial point patterns. Arnold, London.
Waagepetersen, R. P. 2007. An estimating function approach to inference for inhomogeneous Neymann-Scott processes. Biometrics 63: 252-258. doi:10.1111/j.1541-0420.2006.00667.x.
some functions in spatstat: mincontrast
for a more general implementation of the method of mimimum contrast;
matclust.estK
and lgcp.estK
fit other appropriate processes for clustered patterns.
##################### ## Same example as in pc.estK data(gypsophylous) # set the number of simulations (nsim=199 or larger for real analyses) # and resolution for lambda (ngrid=200 or larger for real analyses) nsim<- 19 ngrid <- 50 ## Estimate K function ("Kobs"). gyps.env <- envelope(gypsophylous, Kest, correction="iso", nsim=nsim) plot(gyps.env, sqrt(./pi)-r~r, legend=FALSE) ## Fit Poisson Cluster Process. The limits of integration ## rmin and rmax are setup to 0 and 60, respectively. cosa.pc2 <- ipc.estK(gypsophylous, r = gyps.env$r[gyps.env$r<=60]) ## Add fitted Kclust function to the plot. plot(cosa.pc2, add=TRUE, lwd=c(3,3)) ## A kind of pointwise test of the gypsophylous pattern been a realisation ## of the fitted model, simulating with rIPCP and using function J (Jest). gyps.env.sim2 <- envelope(gypsophylous, Jest, nsim=nsim, simulate=expression(rIPCP(cosa.pc2))) plot(gyps.env.sim2, main="",legendpos="bottomleft") ## Not run: ##################### ## Inhomogeneous example data(urkiola) ##################### ## univariate case # get univariate pp I.ppp <- split.ppp(urkiola)$birch # estimate inhomogeneous intensity function I.lam <- predict (ppm(I.ppp, ~polynom(x,y,2)), type="trend", ngrid=ngrid) # Compute and plot envelopes to Kinhom, simulating from an Inhomogeneous # Poisson Process: I2.env <- envelope( I.ppp,Kinhom, lambda=I.lam, correction="trans", nsim=nsim, simulate=expression(rpoispp(I.lam))) plot(I2.env, sqrt(./pi)-r~r, xlab="r (metres)", ylab= "L (r)", col=c(1,3,2,2),legend=FALSE) # It seems that there is short scale clustering; let's fit an Inhomogeneous # Poisson Cluster Process: I.ki <- ipc.estK(mippp=I.ppp, lambda=I.lam, correction="trans") # Compute and plot envelopes to Kinhom, simulating from the fitted IPCP: Ipc.env <- Ki(I.ki, correction="trans", nsim=nsim, ngrid=ngrid) plot (Ipc.env, xlab="r (metres)", ylab= "L (r)") ##################### ## bivariate case: test independence between birch and quercus in Urkiola J.ppp <- split.ppp(urkiola)$oak # We want to simulate oak from a homogeneous Poisson model: J.ppm <- ppm(J.ppp, trend=~1, interaction=Poisson() ) IJ.env <- Kci (mod1=I.ki, mod2=J.ppm, nsim=nsim) plot(IJ.env, type=12) plot(IJ.env, type=21) ## End(Not run)
##################### ## Same example as in pc.estK data(gypsophylous) # set the number of simulations (nsim=199 or larger for real analyses) # and resolution for lambda (ngrid=200 or larger for real analyses) nsim<- 19 ngrid <- 50 ## Estimate K function ("Kobs"). gyps.env <- envelope(gypsophylous, Kest, correction="iso", nsim=nsim) plot(gyps.env, sqrt(./pi)-r~r, legend=FALSE) ## Fit Poisson Cluster Process. The limits of integration ## rmin and rmax are setup to 0 and 60, respectively. cosa.pc2 <- ipc.estK(gypsophylous, r = gyps.env$r[gyps.env$r<=60]) ## Add fitted Kclust function to the plot. plot(cosa.pc2, add=TRUE, lwd=c(3,3)) ## A kind of pointwise test of the gypsophylous pattern been a realisation ## of the fitted model, simulating with rIPCP and using function J (Jest). gyps.env.sim2 <- envelope(gypsophylous, Jest, nsim=nsim, simulate=expression(rIPCP(cosa.pc2))) plot(gyps.env.sim2, main="",legendpos="bottomleft") ## Not run: ##################### ## Inhomogeneous example data(urkiola) ##################### ## univariate case # get univariate pp I.ppp <- split.ppp(urkiola)$birch # estimate inhomogeneous intensity function I.lam <- predict (ppm(I.ppp, ~polynom(x,y,2)), type="trend", ngrid=ngrid) # Compute and plot envelopes to Kinhom, simulating from an Inhomogeneous # Poisson Process: I2.env <- envelope( I.ppp,Kinhom, lambda=I.lam, correction="trans", nsim=nsim, simulate=expression(rpoispp(I.lam))) plot(I2.env, sqrt(./pi)-r~r, xlab="r (metres)", ylab= "L (r)", col=c(1,3,2,2),legend=FALSE) # It seems that there is short scale clustering; let's fit an Inhomogeneous # Poisson Cluster Process: I.ki <- ipc.estK(mippp=I.ppp, lambda=I.lam, correction="trans") # Compute and plot envelopes to Kinhom, simulating from the fitted IPCP: Ipc.env <- Ki(I.ki, correction="trans", nsim=nsim, ngrid=ngrid) plot (Ipc.env, xlab="r (metres)", ylab= "L (r)") ##################### ## bivariate case: test independence between birch and quercus in Urkiola J.ppp <- split.ppp(urkiola)$oak # We want to simulate oak from a homogeneous Poisson model: J.ppm <- ppm(J.ppp, trend=~1, interaction=Poisson() ) IJ.env <- Kci (mod1=I.ki, mod2=J.ppm, nsim=nsim) plot(IJ.env, type=12) plot(IJ.env, type=21) ## End(Not run)
Given a "fixed" point pattern and some process that asign labels (I,J) to another "variable" point pattern,
K012
estimates the combined bivariate K function between the fixed pattern and every type of the
variable pattern, and test that they are independent (i.e. that the labels are randomly assigned,
irrespectively of the fixed pattern).
K012(X, fijo, i, j, nsim = 99, nrank = 1, r = NULL, correction = "isotropic")
K012(X, fijo, i, j, nsim = 99, nrank = 1, r = NULL, correction = "isotropic")
X |
Multitype marked point pattern. An object with the |
fijo |
Number or character string identifying the mark value of the "fixed" pattern in X |
i |
Number or character string identifying the mark value of the I pattern in X |
j |
Number or character string identifying the mark value of the J pattern in X |
nsim |
Number of simulated point patterns to be generated when computing the envelopes. |
nrank |
Integer. Rank of the envelope value amongst the |
r |
Numeric vector. The values of the argument r at which the K functions should be evaluated. |
correction |
A character item selecting any of the options "border", "bord.modif", "isotropic", "Ripley" or "translate". It specifies the edge correction(s) to be applied. |
This test was developped to answer some questions about the spatial pattern of survival and
mortality of seedlings and its relationships with adult plants in a plant community (De la Cruz et al. 2008).
In order to evaluate the spatial structures of seedlings fates (survive or die), the null hypothesis of random labelling (Cuzick & Edwards 1990, Dixon 2002)
would be the appropriate one. This kind of pattern is the result of two hierarchical processes: a first one that generates the pattern of points (seedlings)
and other that assign "labels" (i.e. "die", "survive") to the points. On the other hand, to analyze the relationships between the spatial pattern of
emerging seedlings and the pattern of adult plants (two patterns that have been generated independently), independence would be the appropriate
null hypothesis (Goreaud & Pellisier 2003). However, testing the relationship between the pattern of seedling fates and the pattern of adult plants does
not completely fit any of the mentioned hypotheses because, although the pattern of adult plants and the pattern of, e.g., dead seedlings are generated
independently, their relationship is conditioned by the dependence of the fate "dead" on the locations of emerging seedlings. This implies that
one can not apply the usual technique of toroidal shifting one pattern over the other to test the independence hypothesis.
Instead one must permute the label of the focal fate (i.e. survive, die) over the global pattern of seedlings points,
keeping the locations and labels of adults fixed. This is the method that K012
uses to build the envelopes. The bivariate K functions are
computed with the Lotwick's and Silverman's (1982) combined estimator (Kmulti.ls
).
A list with two elements.
k01 |
Bivariate K function of the fixed point pattern and the I variable type, with simulation envelopes |
k02 |
Bivariate K function of the fixed point pattern and the J variable type, with simulation envelopes |
Each of the above elements is a fv.object
, essentially a data.frame
with the following items:
r |
the values of the argument r at which the functions kave been estimated |
hi |
upper envelope of simulations |
lo |
lower envelope of simulations |
together with the observed corrected estimate of the combined bivariate K function ( iso
, trans
, border
, etc).
Marcelino de la Cruz
Cuzick, J. and Edwards, R. 1990. Spatial clustering for inhomogeneous populations (with discussion). Journal of the Royal Statistical Society B 52: 73-104.
De la Cruz, M. 2006. Introducción al análisis de datos mapeados o algunas de las (muchas) cosas que puedo hacer si tengo coordenadas. Ecosistemas 15 (3): 19-39.
De la Cruz, M., Romao, R.L., Escudero, A. and Maestre, F.T. 2008. Where do seedlings go? A spatio-temporal analysis of early mortality in a semiarid specialist. Ecography, 31(6): 720-730. doi:10.1111/j.0906-7590.2008.05299.x.
Dixon, P. M. 2002. Ripley's K function. In The encyclopedia of environmetrics (eds. El-Shaarawi, A.H. & Piergorsch, W.W.), pp. 1976-1803. John Wiley & Sons Ltd, NY.
Goreaud, F. and Pelissier, R. 2003. Avoiding misinterpretation of biotic interactions with the intertype K12-function: population independence vs. random labelling hypotheses. J. Veg. Sci. 14: 681-692.
Lotwick, H. W. & Silverman, B. W. 1982. Methods for analysing spatial processes of several types of points. Journal of the Royal Statistical Society B 44: 406-413.
dixon2002
for another segregation test, based in the contingency table of counts of nearest neigbors in a marked point pattern.
data(Helianthemum) # To get 2.5% and 97.5% envelopes of 999 random labelings. ## as in fig. 10 of De la Cruz (2006), change nsim= 999 and nrank=25 nsim <-19 nrank <-1 ## Test asociation/repulsion between the fixed pattern of adult ## H. squamatum plants and the "variable" pattern of surviving and ## dead seedlings, cosa <- K012(Helianthemum, fijo="adultHS", i="deadpl", j="survpl", r=seq(0,200,le=201), nsim=nsim, nrank=nrank, correction="isotropic") plot(cosa$k01, sqrt(./pi)-r~r, col=c(3, 1, 3), lty=c(3, 1, 3), las=1, ylab=expression(L[12]), xlim=c(0, 200), main="adult HS vs. dead seedlings") plot(cosa$k02, sqrt(./pi)-r~r, col=c(3, 1, 3), lty=c(3, 1, 3), las=1, ylab=expression(L[12]), xlim=c(0, 200), main="adult HS vs. surviving seedlings")
data(Helianthemum) # To get 2.5% and 97.5% envelopes of 999 random labelings. ## as in fig. 10 of De la Cruz (2006), change nsim= 999 and nrank=25 nsim <-19 nrank <-1 ## Test asociation/repulsion between the fixed pattern of adult ## H. squamatum plants and the "variable" pattern of surviving and ## dead seedlings, cosa <- K012(Helianthemum, fijo="adultHS", i="deadpl", j="survpl", r=seq(0,200,le=201), nsim=nsim, nrank=nrank, correction="isotropic") plot(cosa$k01, sqrt(./pi)-r~r, col=c(3, 1, 3), lty=c(3, 1, 3), las=1, ylab=expression(L[12]), xlim=c(0, 200), main="adult HS vs. dead seedlings") plot(cosa$k02, sqrt(./pi)-r~r, col=c(3, 1, 3), lty=c(3, 1, 3), las=1, ylab=expression(L[12]), xlim=c(0, 200), main="adult HS vs. surviving seedlings")
Given two point patterns I and J, K1K2
computes the differences between
both univariate -functions (i.e.
) as well as the differences between
the univariate and the bivariate
-function (i.e.
and
).
It also computes simulation envelopes to test that that the observed differences are within the
range expected asuming the random labelling hypothesis.
K1K2(X, i, j, nsim = 99, nrank = 1, r = NULL, correction = "isotropic")
K1K2(X, i, j, nsim = 99, nrank = 1, r = NULL, correction = "isotropic")
X |
Multitype marked point pattern. An object with the |
i |
Number or character string identifying the mark value of the I pattern in X. |
j |
Number or character string identifying the mark value of the J pattern in X. |
nsim |
Number of simulated point patterns to be generated when computing the envelopes. |
nrank |
Integer. Rank of the envelope value amongst the |
r |
Numeric vector. The values of the argument |
correction |
A character item selecting any of the options "border", "bord.modif", "isotropic", "Ripley" or "translate". It specifies the edge correction(s) to be applied. |
The indiscriminate use of the raw bivariate functions (mainly the or the
-bivariate functions) in ecological studies for testing the association/ repulsion
between different point patterns waste some of the most interesting properties of the
-function. One of them is that under the random labelling hypothesis
every individual pattern would be a random thinning of the corresponding bivariate pattern and therefore
(Diggle 2003).
Dixon (2002) sugested that some differences of these functions could provide provide interesting ecological information. For example,
,
has an expected value of 0 for all
distances under random labelling and evaluates the differences in the intensity of aggregation of the two point patterns
(e.g., in the example bellow, the pattern of drought and herbivory deaths). Other relevant function is
) and the complementary
)
which evaluate the degree of segregation of every individual pattern, i.e. if every point of the pattern is more -or less- surrounded by other points of the same type
than would be expected under the random labelling hypothesis.
K1K2
uses , the combined estimator of Lotwick and Silverman (a weigthed mean of
and
) as computed by
Kmulti.ls
.
A list with three elements.
k1k2 |
Difference between |
k1k12 |
Difference between |
k2k12 |
Difference between |
Each of the above elements is a fv.object
, essentially a data.frame
with the following items:
r |
The values of the argument r at which the functions have been estimated. |
hi |
Upper envelope of simulations. |
D |
The respective difference function |
lo |
Lower envelope of simulations. |
Marcelino de la Cruz
De la Cruz, M. 2006. Introducción al análisis de datos mapeados o algunas de las (muchas) cosas que puedo hacer si tengo coordenadas. Ecosistemas 15 (3): 19-39.
De la Cruz, M., Romao, R.L., Escudero, A. and Maestre, F.T. 2008. Where do seedlings go? A spatio-temporal analysis of early mortality in a semiarid specialist. Ecography,31(6): 720-730. doi:10.1111/j.0906-7590.2008.05299.x.
Diggle, P.J. 2003. Statistical analysis of spatial point patterns. Arnold, London.
Dixon, P. M. 2002. Ripley's K function. In The encyclopedia of environmetrics (eds. El-Shaarawi, A.H. & Piergorsch, W.W.), pp. 1976-1803. John Wiley & Sons Ltd, NY.
data(Helianthemum) # set the number of simulations (nsim=199 or larger for real analyses) nsim<- 19 cosa12 <- K1K2(Helianthemum, j="deadpl", i="survpl", r=seq(0,200,le=201), nsim=nsim, correction="isotropic") ## plots of figure 9 in De la Cruz (2006) (they where made with nsim=999) plot(cosa12$k1k2, lty=c(2, 1, 2), col=c(2, 1, 2), xlim=c(0, 200), main= "survival- death") plot(cosa12$k1k12, lty=c(2, 1, 2), col=c(2, 1, 2), xlim=c(0, 200), main="segregation of surviving seedlings") plot(cosa12$k2k12, lty=c(2, 1, 2), col=c(2, 1, 2), xlim=c(0, 200), main= "segregation of dying seedlings", legend=FALSE)
data(Helianthemum) # set the number of simulations (nsim=199 or larger for real analyses) nsim<- 19 cosa12 <- K1K2(Helianthemum, j="deadpl", i="survpl", r=seq(0,200,le=201), nsim=nsim, correction="isotropic") ## plots of figure 9 in De la Cruz (2006) (they where made with nsim=999) plot(cosa12$k1k2, lty=c(2, 1, 2), col=c(2, 1, 2), xlim=c(0, 200), main= "survival- death") plot(cosa12$k1k12, lty=c(2, 1, 2), col=c(2, 1, 2), xlim=c(0, 200), main="segregation of surviving seedlings") plot(cosa12$k2k12, lty=c(2, 1, 2), col=c(2, 1, 2), xlim=c(0, 200), main= "segregation of dying seedlings", legend=FALSE)
Functions to automate testing of 'univariate' and 'bivariate' point pattern hypothesis against non-Poisson (in-)homogeneous models.
Kci(mod1, mod2, correction="trans", nsim=99, ngrid=200, nrep=1e+05, r=NULL, simu="both", spctype=1) Ki(mod1, correction="trans", nsim=99, ngrid=200, nrep=1e+05, r=NULL, spctype=1) ## S3 ploth method for objects of class 'ecespa.kci': ## S3 method for class 'ecespa.kci' plot(x, type=1, q=0.025, kmean=TRUE, add=FALSE, maine=NULL, xlabe=NULL, ylabe=NULL, xlime=NULL, ylime=NULL, lty=c(1,2,3), col=c(1,2,3), lwd=c(1,1,1), ...)
Kci(mod1, mod2, correction="trans", nsim=99, ngrid=200, nrep=1e+05, r=NULL, simu="both", spctype=1) Ki(mod1, correction="trans", nsim=99, ngrid=200, nrep=1e+05, r=NULL, spctype=1) ## S3 ploth method for objects of class 'ecespa.kci': ## S3 method for class 'ecespa.kci' plot(x, type=1, q=0.025, kmean=TRUE, add=FALSE, maine=NULL, xlabe=NULL, ylabe=NULL, xlime=NULL, ylime=NULL, lty=c(1,2,3), col=c(1,2,3), lwd=c(1,1,1), ...)
mod1 |
Fitted model. An object of class |
mod2 |
Fitted model. An object of class |
correction |
A character item selecting any of the options "border", "bord.modif", or "translate". It specifies the edge correction to be applied when computing K-functions. |
nsim |
Number of simulated point patterns to be generated when computing the envelopes. |
ngrid |
Dimensions (ngrid by ngrid) of a rectangular grid of locations where |
nrep |
Total number of steps (proposals) of Metropolis-Hastings algorithm that should be run by |
r |
Numeric vector. The values of the argument |
simu |
A character item indicating if both models will be simulated for the computation of the envelopes ( |
spctype |
Type of 'pre-thinning' method employed by |
x |
An object of class 'ecespa.kci'. The result of runing |
type |
What to plot. One of 1 (K1), 2 (K2), 12 (K12), 21 (K21), 112 (K1-K12) or 221 (K2-K21). |
q |
Quantile for selecting the simulation envelopes. |
kmean |
Logical. Should the mean of the simulated envelopes be ploted? |
add |
Logical. Should the kci.plot be added to a previous plot? |
maine |
Title to add to the plot. |
xlabe |
Text or expression to label the x-axis. |
ylabe |
Text or expression to label the y-axis. |
xlime |
Max and min coordinates for the x-axis. |
ylime |
Max and min coordinates for the y-axis. |
lty |
Vector with the line type for the estimated Kmm function, the simulated envelopes and the mean of the simulated envelopes. |
col |
Vector with the color for the estimated K-function, the simulated envelopes and the mean of the simulated envelopes. |
lwd |
Vector with the line width for the estimated K-function, the simulated envelopes and the mean of the simulated envelopes. |
... |
Additional graphical parameters passed to plot. |
These functions are designed to automate the testing of 'univariate' and(/or) 'bivariate' point pattern hypotheses (based on K-functions) against non-Poisson (in-)homogeneous
models. These non-Poisson (in-)homogeneous models should have been fitted with pseudolikelihood tools (spatstat
ppm
function)
or with minimum contrast methods (ecespa.minconfit
).
Function Ki
is designed to test 'univariate' hypotheses. It will compute the (in-)homogeneous K-function (using spatstat
Kinhom
function)
of the point pattern to which the ppm
or ecespa.minconfit
model has beeen fitted and will compute 'envelopes' simulating from the fitted model.
The computed envelopes can be considered as a pointwise test of the point pattern been a realisation of the fitted model.
Function Kci
is designed to test 'bivariate' hypotheses. It will compute the (in-)homogeneous cross K-function
(using spatstat
Kcross.inhom
function) and will compute envelopes simulating from the fitted models.
As, when dealing with inhomogeneos patterns !=
,
Kci
will compute both functions. If simu = "both"
(default option),
Kci
will simulate from mod2
to test K12 and from mod1
to test K21. If simu != "both"
, only mod2
will be simulated. This option
may be useful when only K12 is of interest. Function Kci
will also compute univariate (in-) homogeneous K-functions and envelopes for each individual point pattern.
The S3 ploth method will plot the selected K-function and envelopes (actually, it will plot the most usual L-function = ).
The appropriate K function can be selected with the argument
type
. If type = 1
(default option), it will plot the univariate K function
(of the analized model in Ki
or of the first model [mod1] in Kci
). If type = 2
, it will plot the univariate K function of the second model
(mod2 in Kci
). When type = 12
or type = 21
, it will plot respectively K12 or K21.
Options type = 112
or type = 221
will graph a kind of 'segregation test' (see K1K2
), and will represent de differences
K1-K12, K2-K21 and their envelopes.
Both Kci
and Ki
return an object of class 'ecespa.kci'
, basically a list with the following items:
r |
Numeric vector. The values of the argument |
kia |
Numeric vector. Observed (in-)homogeneous K function for |
kib |
Numeric vector. Observed (in-)homogeneous K function for |
kci.ab.o |
Numeric vector. Observed (in-) homogeneous cross K-function (K12) for |
kci.ba.o |
Numeric vector. Observed (in-) homogeneous cross K-function (K21) for |
kci.ab.s |
Matrix of simulated (in-) homogeneous cross K-function (K12) for |
kci.ba.s |
Matrix of simulated (in-) homogeneous cross K-function (K21) for |
kib.s |
Matrix of simulated (in-)homogeneous K function for |
kia.s |
Matrix of simulated (in-)homogeneous K function for |
datanamea |
Name of |
datanameb |
Name of |
modnamea |
Name of model |
modnameb |
Name of model |
type |
Type of analysis. "Kci" or "Ki". |
As this implementation involves the use of images as the means of evaluation of the (inhomogeneous) spatial trend, and a mask based on those images will be used as the point pattern window, the "Ripley's" or "isotropic" edge correction can not be employed.
It is usual that during the simulation process some warnings are produced. They are related to some simulated points being rejected as lying outside the specified window.
Even when one of the two point patterns is assumed to be homogeneous Poisson (and, apparently not worth of fitting any model), an homogeneous
Poisson model can be easily fitted and passed to Kci
with ppm
. See the examples.
Marcelino de la Cruz Rot
De la Cruz, M. and Escudero, A. 2008. Null models and tools for multivariate heterogeneous point patterns. Submitted.
De Soto, L., Olano, J.M., Rozas, V. and De la Cruz, M. 2009. Release of Juniperus thurifera woodlands from herbivore-mediated arrested succession in Spain. Applied Vegetation Science, 13: 1525. doi:10.1111/j.1654-109X.2009.01045.x
data(urkiola) # set the number of simulations (nsim=199 or larger for real analyses) nsim<- 5 ##################### ## univariate case # get univariate pp I.ppp <- split.ppp(urkiola)$birch # estimate inhomogeneous intensity function I.lam <- predict (ppm(I.ppp, ~polynom(x,y,2)), type="trend", ngrid=200) # Compute and plot envelopes to Kinhom, simulating from an Inhomogeneous # Poisson Process: I2.env <- envelope( I.ppp,Kinhom, lambda=I.lam, correction="trans", nsim=nsim, simulate=expression(rpoispp(I.lam))) plot(I2.env, sqrt(./pi)-r~r, xlab="r (metres)", ylab= "L (r)", col=c(1,3,2,2),legend=FALSE) # It seems that there is short scale clustering; let's fit an Inhomogeneous # Poisson Cluster Process: I.ki <- ipc.estK(mippp=I.ppp, lambda=I.lam, correction="trans") # Compute and plot envelopes to Kinhom, simulating from the fitted IPCP: Ipc.env <- Ki(I.ki, correction="trans", nsim=nsim, ngrid=200) plot (Ipc.env, xlab="r (metres)", ylab= "L (r)") ## Not run: ##################### ## bivariate case: test independence between birch and quercus in Urkiola J.ppp <- split.ppp(urkiola)$oak # We want to simulate oak from a homogeneous Poisson model: J.ppm <- ppm(J.ppp, trend=~1, interaction=Poisson() ) IJ.env <- Kci (mod1=I.ki, mod2=J.ppm, nsim=nsim) plot(IJ.env, type=12) plot(IJ.env, type=21) ## End(Not run)
data(urkiola) # set the number of simulations (nsim=199 or larger for real analyses) nsim<- 5 ##################### ## univariate case # get univariate pp I.ppp <- split.ppp(urkiola)$birch # estimate inhomogeneous intensity function I.lam <- predict (ppm(I.ppp, ~polynom(x,y,2)), type="trend", ngrid=200) # Compute and plot envelopes to Kinhom, simulating from an Inhomogeneous # Poisson Process: I2.env <- envelope( I.ppp,Kinhom, lambda=I.lam, correction="trans", nsim=nsim, simulate=expression(rpoispp(I.lam))) plot(I2.env, sqrt(./pi)-r~r, xlab="r (metres)", ylab= "L (r)", col=c(1,3,2,2),legend=FALSE) # It seems that there is short scale clustering; let's fit an Inhomogeneous # Poisson Cluster Process: I.ki <- ipc.estK(mippp=I.ppp, lambda=I.lam, correction="trans") # Compute and plot envelopes to Kinhom, simulating from the fitted IPCP: Ipc.env <- Ki(I.ki, correction="trans", nsim=nsim, ngrid=200) plot (Ipc.env, xlab="r (metres)", ylab= "L (r)") ## Not run: ##################### ## bivariate case: test independence between birch and quercus in Urkiola J.ppp <- split.ppp(urkiola)$oak # We want to simulate oak from a homogeneous Poisson model: J.ppm <- ppm(J.ppp, trend=~1, interaction=Poisson() ) IJ.env <- Kci (mod1=I.ki, mod2=J.ppm, nsim=nsim) plot(IJ.env, type=12) plot(IJ.env, type=21) ## End(Not run)
Computes simulation envelopes for (in-)homogeneous K-function simulating from a vector of probabilitiesn.
Kinhom.log (A, lambda=NULL, mod=NULL, lifemark="0", prob=NULL, r=NULL, nsim=99, correction="trans", ngrid=200)
Kinhom.log (A, lambda=NULL, mod=NULL, lifemark="0", prob=NULL, r=NULL, nsim=99, correction="trans", ngrid=200)
A |
A marked point pattern with the |
lambda |
Optional. Values of the estimated intensity function as a pixel image (object of class
" |
mod |
A fitted model. An object of class |
lifemark |
Level of the marks of |
prob |
Numeric vector, with length equal to the number of points of |
r |
Numeric vector. The values of the argument |
nsim |
Number of simulated point patterns to be generated when computing the envelopes. |
correction |
A character item selecting any of the options "border", "bord.modif", or "translate". It specifies the edge correction to be applied when computing K-functions. |
ngrid |
Dimensions (ngrid by ngrid) of a rectangular grid of locations where |
This function is a wrapper to compute the critical envelopes for Monte Carlo test of goodness-of-fit of (in-)homogeneous K functions, simulating from the fittted values of a logistic model (i.e. a binomial GLM with logit link) fitted to the marks ("failure", "success") of a "binomially"-marked point pattern. This is particularly interesting in plant ecology when considering alternatives to the random mortality hypothesis (Kenkel 1988). This hypothesis is usually tested building Monte Carlo envelopes from the "succesful" patterns resulting from a random labelling of a "binomially"-marked point pattern (this is equivalent to a random thinning of the whole pattern irrespective of the marks). As tree mortality is rarely random but instead can be modelled as a function of a certain number of covariates, the most natural alternative to the random mortality hypothesis is the logistic mortality hypothesis, that can be tested thinning the original pattern of trees with retention probabilities defined by the fitted values of a logistic model (Batista and Maguire 1998, Olano et al. 2008).
Kinhom.log
will compute the envelopes by thinning the unmarked point pattern A
with retention probabilities prob
. If no
prob
vector is provided, all points will be thinned with the same probability ( number of "live" points / number of points ), i.e. Kinhom.log
will compute random thinning envelopes.
Kinhom.log
will compute envelopes both to homogeneous and inhomogeneous K functions. If no lambda
or mode
arguments
are provided, Kinhom.log
assumes that the original pattern is homogeneous and will use a constant lambda
to compute the inhomogeneous K
(i.e. it will compute the homogeneous K). The most convenient use with inhomogeneous point patterns is to provide the argument mod
with an inhomogeneous Poisson model fitted to the original pattern of 'live' points (with spatstat function ppm
; see the examples).
This model will be used to compute (and to update in the simulations) the inhomogeneous trend (i.e. the "lambda") of the patterns.
If the argument lambda
is provided but not mod
, these lambda will be used as a covariate to fit an inhomogeneous Poisson model that
will be used to compute (and to update in the simulations) the inhomogeneous spatial trend.
Kinhom.log
will produce an object of class 'ecespa.kci' that can be easily ploted (see the examples).
This is accomplished by the S3 ploth method plot.ecespa.kci
; it will plot the K-function and its envelopes
(actually, it will plot the most usual L-function = ).
Kinhom.log
returns an object of class ecespa.kci
, basically a list with the following items:
r |
Numeric vector. The values of the argument |
kia |
Numeric vector. Observed (in-)homogeneous K function. |
kia.s |
Matrix of simulated (in-)homogeneous K functions. |
datanamea |
Name of point pattern |
modnamea |
Name of model |
type |
Type of analysis. Always "Kinhom.log". |
probname |
Name of the vector of fitted retention probabilities |
modtrend |
Spatial trend (formula) of the model |
nsim |
Number of simulations. |
As this implementation involves the use of images as the means of evaluation of the (inhomogeneous) spatial trend, and a mask based on those images will be used as the point pattern window, the "Ripley's" or "isotropic" edge correction can not be employed.
Marcelino de la Cruz Rot
Batista, J.L.F. and Maguire, D.A. 1998. Modelling the spatial structure of tropical forests. For. Ecol. Manag., 110: 293-314.
Kenkel, N.C. 1988. Pattern of self-thinning in Jack Pine: testing the random mortality hypothesis. Ecology, 69: 1017-1024.
Olano, J.M., Laskurain, N.A., Escudero, A. and De la Cruz, M. 2009. Why and where adult trees die in a secondary temperate forest? The role of neighbourhood. Annals of Forest Science, 66: 105. doi:10.1051/forest:2008074.
data(quercusvm) # set the number of simulations (nsim=199 or larger for real analyses) nsim<- 19 # read fitted values from logistic model: probquercus <-c(0.99955463, 0.96563477, 0.97577094, 0.97327199, 0.92437309, 0.84023396, 0.94926682, 0.89687281, 0.99377915, 0.74157478, 0.95491518, 0.72366493, 0.66771787, 0.77330148, 0.67569082, 0.9874892, 0.7918891, 0.73246803, 0.81614635, 0.66446411, 0.80077908, 0.98290508, 0.54641754, 0.53546689, 0.73273626, 0.7347013, 0.65559655, 0.89481468, 0.63946334, 0.62101995, 0.78996371, 0.93179582, 0.80160346, 0.82204428, 0.90050059, 0.83810669, 0.92153079, 0.47872421, 0.24697004, 0.50680935, 0.6297911, 0.46374812, 0.65672284, 0.87951682, 0.35818237, 0.50932432, 0.92293014, 0.48580241, 0.49692053, 0.52290553, 0.7317549, 0.32445982, 0.30300865, 0.73599359, 0.6206056, 0.85777043, 0.65758613, 0.50100406, 0.31340849, 0.22289286, 0.40002879, 0.29567678, 0.56917817, 0.56866864, 0.27718552, 0.4910667, 0.47394411, 0.40543788, 0.29571349, 0.30436276, 0.47859015, 0.31754526, 0.42131675, 0.37468782, 0.73271225, 0.26786274, 0.59506388, 0.54801851, 0.38983575, 0.64896835, 0.37282031, 0.67624306, 0.29429766, 0.29197755, 0.2247629, 0.40697843, 0.17022391, 0.26528042, 0.24373722, 0.26936163, 0.13052254, 0.19958585, 0.18659692, 0.36686678, 0.47263005, 0.39557661, 0.68048997, 0.74878567, 0.88352322, 0.93851375) ################################ ## Envelopes for an homogeneous point pattern: cosap <- Kinhom.log(A=quercusvm, lifemark="0", prob=probquercus, nsim=nsim) plot(cosap) ################################ ## Envelopes for an inhomogeneous point pattern: ## First, fit an inhomogeneous Poisson model to alive trees : quercusalive <- unmark(quercusvm[quercusvm$marks == 0]) mod2 <- ppm(quercusalive, ~polynom(x,y,2)) ## Now use mod2 to estimate lambda for K.inhom: cosapm <- Kinhom.log(A=quercusvm, lifemark="0", prob=probquercus, nsim=nsim, mod=mod2) ################################ ## An example of homogeneous random thinning: cosa <- Kinhom.log(A=quercusvm, lifemark="0", nsim=nsim) plot(cosa)
data(quercusvm) # set the number of simulations (nsim=199 or larger for real analyses) nsim<- 19 # read fitted values from logistic model: probquercus <-c(0.99955463, 0.96563477, 0.97577094, 0.97327199, 0.92437309, 0.84023396, 0.94926682, 0.89687281, 0.99377915, 0.74157478, 0.95491518, 0.72366493, 0.66771787, 0.77330148, 0.67569082, 0.9874892, 0.7918891, 0.73246803, 0.81614635, 0.66446411, 0.80077908, 0.98290508, 0.54641754, 0.53546689, 0.73273626, 0.7347013, 0.65559655, 0.89481468, 0.63946334, 0.62101995, 0.78996371, 0.93179582, 0.80160346, 0.82204428, 0.90050059, 0.83810669, 0.92153079, 0.47872421, 0.24697004, 0.50680935, 0.6297911, 0.46374812, 0.65672284, 0.87951682, 0.35818237, 0.50932432, 0.92293014, 0.48580241, 0.49692053, 0.52290553, 0.7317549, 0.32445982, 0.30300865, 0.73599359, 0.6206056, 0.85777043, 0.65758613, 0.50100406, 0.31340849, 0.22289286, 0.40002879, 0.29567678, 0.56917817, 0.56866864, 0.27718552, 0.4910667, 0.47394411, 0.40543788, 0.29571349, 0.30436276, 0.47859015, 0.31754526, 0.42131675, 0.37468782, 0.73271225, 0.26786274, 0.59506388, 0.54801851, 0.38983575, 0.64896835, 0.37282031, 0.67624306, 0.29429766, 0.29197755, 0.2247629, 0.40697843, 0.17022391, 0.26528042, 0.24373722, 0.26936163, 0.13052254, 0.19958585, 0.18659692, 0.36686678, 0.47263005, 0.39557661, 0.68048997, 0.74878567, 0.88352322, 0.93851375) ################################ ## Envelopes for an homogeneous point pattern: cosap <- Kinhom.log(A=quercusvm, lifemark="0", prob=probquercus, nsim=nsim) plot(cosap) ################################ ## Envelopes for an inhomogeneous point pattern: ## First, fit an inhomogeneous Poisson model to alive trees : quercusalive <- unmark(quercusvm[quercusvm$marks == 0]) mod2 <- ppm(quercusalive, ~polynom(x,y,2)) ## Now use mod2 to estimate lambda for K.inhom: cosapm <- Kinhom.log(A=quercusvm, lifemark="0", prob=probquercus, nsim=nsim, mod=mod2) ################################ ## An example of homogeneous random thinning: cosa <- Kinhom.log(A=quercusvm, lifemark="0", nsim=nsim) plot(cosa)
This is a functional data summary for marked point patterns that measures the joint pattern of points and marks at different scales determined by .
Kmm(mippp, r = 1:10, nsim=NULL) ## S3 method for ploting objects of class 'ecespa.kmm': ## S3 method for class 'ecespa.kmm' plot(x, type="Kmm.n", q=0.025, xlime=NULL, ylime=NULL, maine=NULL, add=FALSE, kmean=TRUE, ylabe=NULL, xlabe=NULL, lty=c(1,2,3), col=c(1,2,3), lwd=c(1,1,1), ...)
Kmm(mippp, r = 1:10, nsim=NULL) ## S3 method for ploting objects of class 'ecespa.kmm': ## S3 method for class 'ecespa.kmm' plot(x, type="Kmm.n", q=0.025, xlime=NULL, ylime=NULL, maine=NULL, add=FALSE, kmean=TRUE, ylabe=NULL, xlabe=NULL, lty=c(1,2,3), col=c(1,2,3), lwd=c(1,1,1), ...)
mippp |
A marked point pattern. An object with the |
r |
Sequence of distances at which |
nsim |
Number of simulated point patterns to be generated when computing the envelopes. |
x |
An object of class 'ecespa.kmm'. The result of applying |
type |
Type of mark-weighted K-function to plot. One of |
q |
Quantile for selecting the simulation envelopes. |
xlime |
Max and min coordinates for the x-axis. |
ylime |
Max and min coordinates for the y-axis. |
maine |
Title to add to the plot. |
add |
Logical. Should the kmm.object be added to a previous plot? |
kmean |
Logical. Should the mean of the simulated Kmm envelopes be ploted? |
ylabe |
Text or expression to label the y-axis. |
xlabe |
Text or expression to label the x-axis. |
lty |
Vector with the line type for the estimated Kmm function, the simulated envelopes and the mean of the simulated envelopes. |
col |
Vector with the color for the estimated Kmm function, the simulated envelopes and the mean of the simulated envelopes. |
lwd |
Vector with the line width for the estimated Kmm function, the simulated envelopes and the mean of the simulated envelopes. |
... |
Additional graphical parameters passed to plot. |
Penttinnen (2006) defines , the mark-weighted
-function of a stationary marked point process
,
so that
where is the intensity of the process,
i.e. the expected number of points of
per unit area,
denotes expectation (given that there is a point at the origin);
and
are the marks attached to every two points of the process separated by a distance
and
is the mean mark. It measures the joint pattern of marks and points at the scales determmined by
. If all the marks are set to 1,
then
equals the expected number of additional random points within
a distance
of a typical random point of
, i.e.
becomes the conventional Ripley's
-function for unmarked point processes.
As the
-function measures clustering or regularity among the points regardless of the marks, one can separate clustering of marks with the
normalized weighted K-function
If the process is independently marked, equals
so the
normalized mark-weighted
-function will equal 1 for all distances
.
If nsim != NULL
, Kmm
computes 'simulation envelopes' from the simulated point patterns. These are simulated from nsim
random permutations
of the marks over the points coordinates. This is a kind of pointwise test of or
for a given
.
Kmm
returns an object of class 'ecespa.kmm'
, basically a list with the following items:
dataname |
Name of the analyzed point pattern. |
r |
Sequence of distances at which |
nsim |
Number of simulations for computing the envelopes, or |
kmm |
Mark-weighted |
kmm.n |
Normalized mark-weighted |
kmmsim |
Matrix of simulated mark-weighted |
kmmsim.n |
Matrix of simulated normalized mark-weighted |
This implementation estimates without any correction of border effects, so it must be used with caution. However, as
is
also estimed without correction it migth compensate the border effects on the normalized
-function.
Marcelino de la Cruz Rot
De la Cruz, M. 2008. Métodos para analizar datos puntuales. En: Introducción al Análisis Espacial de Datos en Ecología y Ciencias Ambientales: Métodos y Aplicaciones (eds. Maestre, F. T., Escudero, A. y Bonet, A.), pp 76-127. Asociación Española de Ecología Terrestre, Universidad Rey Juan Carlos y Caja de Ahorros del Mediterráneo, Madrid.
Penttinen, A. 2006. Statistics for Marked Point Patterns. In The Yearbook of the Finnish Statistical Society, pp. 70-91.
## Figure 3.10 of De la Cruz (2008): # change r to r=1:100 r = seq(1,100, by=5) data(seedlings1) data(seedlings2) s1km <- Kmm(seedlings1, r=r) s2km <- Kmm(seedlings2, r=r) plot(s1km, ylime=c(0.6,1.2), lwd=2, maine="", xlabe="r(cm)") plot(s2km, lwd=2, lty=2, add=TRUE ) abline(h=1, lwd=2, lty=3) legend(x=60, y=1.2, legend=c("Hs_C1", "Hs_C2", "H0"), lty=c(1, 2, 3), lwd=c(3, 2, 2), bty="n") ## Not run: ## A pointwise test of normalized Kmm == 1 for seedlings1: s1km.test <- Kmm(seedlings1, r=1:100, nsim=99) plot(s1km.test, xlabe="r(cm)") ## End(Not run)
## Figure 3.10 of De la Cruz (2008): # change r to r=1:100 r = seq(1,100, by=5) data(seedlings1) data(seedlings2) s1km <- Kmm(seedlings1, r=r) s2km <- Kmm(seedlings2, r=r) plot(s1km, ylime=c(0.6,1.2), lwd=2, maine="", xlabe="r(cm)") plot(s2km, lwd=2, lty=2, add=TRUE ) abline(h=1, lwd=2, lty=3) legend(x=60, y=1.2, legend=c("Hs_C1", "Hs_C2", "H0"), lty=c(1, 2, 3), lwd=c(3, 2, 2), bty="n") ## Not run: ## A pointwise test of normalized Kmm == 1 for seedlings1: s1km.test <- Kmm(seedlings1, r=1:100, nsim=99) plot(s1km.test, xlabe="r(cm)") ## End(Not run)
For a multitype point pattern, calculates the combined estimator of the bivariate and
functions.
Kmulti.ls(X, I, J, r = NULL, corre = "isotropic")
Kmulti.ls(X, I, J, r = NULL, corre = "isotropic")
X |
Multitype marked point pattern. An object with the |
I |
Subset index specifying the points of the first pattern. |
J |
Subset index specifying the points of the second pattern. |
r |
Numeric vector. The values of the argument r at which the multitype K function |
corre |
A character item selecting any of the options "border", "bord.modif", "isotropic", "Ripley" or
"translate", as described in |
As a consequence of edge effects, the estimators and
of the same bivariate pattern could differ.
is the combined estimator defined by Lotwick and Silverman (1982) as
and
being respectively the number of points in
and
.
An object of class "fv" (see fv.object
). Essentially a data frame containing numeric columns
r |
The values of the argument r at which the function |
.
theo |
The theoretical value of |
.
together with a column or columns named "border", "bord.modif", "iso" and/or "trans", according to the selected edge corrections.
These columns contain estimates of the function obtained by the edge corrections named.
Kmulti.ls
is a wrapper for a convenient use of the Kmulti
function of spatstat.
Please refer to its help page for additional documentation.
Marcelino de la Cruz
Lotwick,H.W. & Silverman, B. W. 1982. Methods for analysing spatial processes of several types of points. Journal of the Royal Statistical Society B, 44: 406-413. doi:10.1111/j.2517-6161.1982.tb01221.x.
data(amacrine) plot(Kmulti.ls(amacrine, I=amacrine$marks=="on", J=amacrine$marks=="off", corre="isotropic"), sqrt(./pi)-r~r, main="") # compare with Kmulti plot(Kmulti(amacrine, I=amacrine$marks=="on", J=amacrine$marks=="off"), sqrt(iso/pi)-r~r, add=TRUE, col=3) plot(Kmulti(amacrine, J=amacrine$marks=="on", I=amacrine$marks=="off"), sqrt(iso/pi)-r~r, add=TRUE, col=4)
data(amacrine) plot(Kmulti.ls(amacrine, I=amacrine$marks=="on", J=amacrine$marks=="off", corre="isotropic"), sqrt(./pi)-r~r, main="") # compare with Kmulti plot(Kmulti(amacrine, I=amacrine$marks=="on", J=amacrine$marks=="off"), sqrt(iso/pi)-r~r, add=TRUE, col=3) plot(Kmulti(amacrine, J=amacrine$marks=="on", I=amacrine$marks=="off"), sqrt(iso/pi)-r~r, add=TRUE, col=4)
Performs the Loosmore and Ford (2006) test or the Maximum Absolute Deviation test for a spatial point pattern.
LF.gof(X, rmin=NULL, rmax=NULL, na.rm=TRUE)
LF.gof(X, rmin=NULL, rmax=NULL, na.rm=TRUE)
X |
An object resulting from the function |
rmin |
Minimum value of the function argument r over which the maximum absolute deviation, or the integral, will be computed for the test. |
rmax |
Maximum value of the function argument r over which the maximum absolute deviation, or the integral, will be computed for the test. |
na.rm |
Should NA's be removed to compute the integral? |
These function perform a tests for goodness-of-fit of a point pattern dataset to a point process model, based on Monte Carlo simulation from the model. The simulations should have been previously computed with the function envelope
, applied with the argument savefuns=TRUE
in order to save all the simulated functions, required for the computation of the test.
The test, popularized in the ecological field by Loosmore and Ford (2006) is also described in Diggle (2003, page 14), and according to Baddeley and Turner (2005) also in Diggle (1986) and Cressie (1991, page 667, equation (8.5.42)).
If the arguments rmin
and rmax
are set to NULL
, the integral of the GoF statistics will be computed over the complete range of r values.
A list with the following components:
The GoF statistic, i.e., the value of the integral over the range of r's
The p-value of the test
Number of NA
values for each r. It helps to evaluate the reliability of the computed u's, specially for small r's
Marcelino de la Cruz
Cressie, N.A.C. (1991) Statistics for spatial data. John Wiley and Sons, 1991.
Diggle, P. J. (1986). Displaced amacrine cells in the retina of a rabbit : analysis of a bivariate spatial point pattern. J. Neuroscience Methods 18, 115-125.
Diggle, P.J. (2003) Statistical analysis of spatial point patterns, Second edition. Arnold.
Loosmore, N.B. and Ford, E.D. (2006) Statistical inference using the G or K point pattern spatial statistics. Ecology 87, 1925-1931. doi:10.1890/0012-9658(2006)87[1925:SIUTGO]2.0.CO;2.
dclf.test
for an alternative implementation of the test in spatstat.
An exploratory data analysis technique for marked point patterns. The marked point pattern is mapped to a random field for visual inspection.
marksum(mippp, R = 10, nx = 30, ny = 30) ## S3 method for ploting objects of class 'ecespa.marksum': ## S3 method for class 'ecespa.marksum' plot(x, what="normalized", contour=FALSE, grid=FALSE, ribbon=TRUE,col=NULL ,main=NULL,xlab="",ylab="",...)
marksum(mippp, R = 10, nx = 30, ny = 30) ## S3 method for ploting objects of class 'ecespa.marksum': ## S3 method for class 'ecespa.marksum' plot(x, what="normalized", contour=FALSE, grid=FALSE, ribbon=TRUE,col=NULL ,main=NULL,xlab="",ylab="",...)
mippp |
A marked point pattern. An object with the |
R |
Radius. The distance argument r at which the mark-sum measure should be computed |
nx |
Grid density (for estimation) in the x-side. |
ny |
Grid density (for estimation) in the y-side. |
x |
An object of class |
what |
What to plot. One of |
contour |
Logical; if |
grid |
Logical; if |
ribbon |
Logical; if |
col |
Color table to use for the map ( see help file on image for details). |
main |
Text or expression to add as a title to the plot. |
xlab |
Text or expression to add as a label to axis x. |
ylab |
Text or expression to add as a label to axis y. |
... |
Additional parameters to |
Penttinen (2006) defines the mark-sum measure as a smoothed summary measuring locally the contribution of points and marks. For any fixed location within the
observational window and a distance
, the mark-sum measure
equals the sum of the marks of the points within the circle of radius
with centre in
. The point-sum measure
is defined by him as the sum of points within the circle of radius
with centre
in
, and describes the contribution of points locally near
. The normalized mark-sum measure describes the contribution of marks
near
and is defined (Penttinen, 2006) as
This implementation of marksum
estimates the mark-sum and the point-sum measures in a grid of points whose density is defined by nx
and
ny
.
marksum
gives an object of class 'ecespa.marksum'
; basically a list with the following elements:
normalized |
Normalized mark-sum measure estimated in the grid points. |
marksum |
Raw mark-sum measure estimated in the grid points. |
pointsum |
Point-sum measure estimated in the grid points. |
minus |
Point-sum of the grid points. For advanced use only. |
grid |
Grid of points. |
nx |
Density of the estimating grid in the x-side. |
ny |
Density of the estimating grid in the x-side. |
dataname |
Name of the ppp object analysed. |
R |
Radius. The distance argument r at which the mark-sum measure has been computed. |
window |
Window of the point pattern. |
plot.ecespa.marksum
plots the selected mark-sum measure.
Marcelino de la Cruz Rot
Penttinen, A. 2006. Statistics for Marked Point Patterns. In The Yearbook of the Finnish Statistical Society, pp. 70-91.
getis
, related to the point-sum measure, and markstat
for designing different implementations.
data(seedlings1) seed.m <- marksum(seedlings1, R=25) # raw mark-sum measure; sigma is bandwith for smoothing plot(seed.m, what="marksum", sigma = 5) # point sum measure plot(seed.m, what="pointsum", sigma = 5) # normalized mark-sum measure plot(seed.m, what="normalized", dimyx=200, contour=TRUE, sigma = 5) # the same with added grid and normalized mark-sum measure plot(seed.m, what="normalized", dimyx=200, contour=TRUE, sigma = 5, grid=TRUE)
data(seedlings1) seed.m <- marksum(seedlings1, R=25) # raw mark-sum measure; sigma is bandwith for smoothing plot(seed.m, what="marksum", sigma = 5) # point sum measure plot(seed.m, what="pointsum", sigma = 5) # normalized mark-sum measure plot(seed.m, what="normalized", dimyx=200, contour=TRUE, sigma = 5) # the same with added grid and normalized mark-sum measure plot(seed.m, what="normalized", dimyx=200, contour=TRUE, sigma = 5, grid=TRUE)
Computes the p-value for a two-sided hypothesis test following Dixon's (2002:145) description of the method of Agresti & Min (2001).
p2colasr(Z)
p2colasr(Z)
Z |
|
P-value of the two-sided hypothesis test
This function is usually not to be called by the user. It is internally used by dixon2002
.
Marcelino de la Cruz Rot
Agresti, A. & Min, Y. 2001. On small-sample confidence intervals
for parameters in discrete distributions. Biometrics, 57: 963-971.
Dixon, P.M. 2002. Nearest-neighbor contingency table analysis
of spatial segregation for several species. Ecoscience, 9(2): 142-151.
Fits the Poisson Cluster point process to a point pattern dataset by the Method of Minimum Contrast.
pc.estK(Kobs, r, sigma2 = NULL, rho = NULL) Kclust(r, sigma2, rho)
pc.estK(Kobs, r, sigma2 = NULL, rho = NULL) Kclust(r, sigma2, rho)
Kobs |
Empirical |
r |
Sequence of distances at which function |
sigma2 |
Optional. Starting value for the parameter |
rho |
Optional. Starting value for the parameter |
The algorithm fits the Poisson cluster point process to a point pattern, by finding the parameters of the Poisson cluster model
which give the closest match between the theoretical K function of the Poisson cluster process and the observed
K function. For a more detailed explanation of the Method of Minimum Contrast, see mincontrast
in spatstat or Diggle (2003: 86).
The Poisson cluster processes are defined by the following postulates (Diggle 2003):
PCP1 | Parent events form a Poisson process with intensity . |
PCP2 | Each parent produces a random number of offspring, according to a probability distribution |
|
|
PCP3 | The positions of the offspring relative to their parents are distributed according to a bivariate pdf . |
This implementation asumes that the probability distribution of offspring per parent is a Poisson distribution and
that the position of each offspring relative to its parent follows a radially symetric Gaussian distribution with pdf
The theoretical -function of this Poisson cluster process is (Diggle, 2003):
The command Kclust
computes the theoretical -function of this Poisson cluster process and
can be used to find some initial estimates of
and
. In any case, the optimization usually finds the
correct parameters even without starting values for these parameters.
This Poisson cluster process can be simulated with sim.poissonc
.
sigma2 |
Parameter |
rho |
Parameter |
The exponents and
of the contrast criterion (see
mincontrast
) are fixed
respectively to and
. The
and
limits of integration of the
contrast criterion are set up by the sequence of values of
and
passed to
pc.estK
.
Marcelino de la Cruz Rot, inspired by some code of Philip M. Dixon
Diggle, P. J. 2003. Statistical analysis of spatial point patterns. Arnold, London.
ipc.estK
for fitting the inhomogeneous Poisson cluster process; some functions in spatstat
( matclust.estK
and lgcp.estK
) fit other appropriate processes for clustered patterns;
mincontrast
performs a more general implementation of the method of mimimum contrast.
data(gypsophylous) # set the number of simulations (nsim=199 or larger for real analyses) nsim<- 19 ## Estimate K function ("Kobs"). gyps.env <- envelope(gypsophylous, Kest, correction="iso", nsim=nsim) plot(gyps.env, sqrt(./pi)-r~r, legend=FALSE) ## Fit Poisson Cluster Process. The limits of integration ## rmin and rmax are setup to 0 and 60, respectively. cosa.pc <- pc.estK(Kobs = gyps.env$obs[gyps.env$r<=60], r = gyps.env$r[gyps.env$r<=60]) ## Add fitted Kclust function to the plot. lines(gyps.env$r,sqrt(Kclust(gyps.env$r, cosa.pc$sigma2,cosa.pc$rho)/pi)-gyps.env$r, lty=2, lwd=3, col="purple") ## A kind of pointwise test of the gypsophylous pattern been a realisation ## of the fitted model, simulating with sim.poissonc and using function J (Jest). gyps.env.sim <- envelope(gypsophylous, Jest, nsim=nsim, simulate=expression(sim.poissonc(gypsophylous, sigma=sqrt(cosa.pc$sigma2), rho=cosa.pc$rho))) plot(gyps.env.sim, main="",legendpos="bottomleft")
data(gypsophylous) # set the number of simulations (nsim=199 or larger for real analyses) nsim<- 19 ## Estimate K function ("Kobs"). gyps.env <- envelope(gypsophylous, Kest, correction="iso", nsim=nsim) plot(gyps.env, sqrt(./pi)-r~r, legend=FALSE) ## Fit Poisson Cluster Process. The limits of integration ## rmin and rmax are setup to 0 and 60, respectively. cosa.pc <- pc.estK(Kobs = gyps.env$obs[gyps.env$r<=60], r = gyps.env$r[gyps.env$r<=60]) ## Add fitted Kclust function to the plot. lines(gyps.env$r,sqrt(Kclust(gyps.env$r, cosa.pc$sigma2,cosa.pc$rho)/pi)-gyps.env$r, lty=2, lwd=3, col="purple") ## A kind of pointwise test of the gypsophylous pattern been a realisation ## of the fitted model, simulating with sim.poissonc and using function J (Jest). gyps.env.sim <- envelope(gypsophylous, Jest, nsim=nsim, simulate=expression(sim.poissonc(gypsophylous, sigma=sqrt(cosa.pc$sigma2), rho=cosa.pc$rho))) plot(gyps.env.sim, main="",legendpos="bottomleft")
Locations of alive and dead oak trees (Quercus robur) in a secondary wood in Urkiola Natural Park (Basque country, north of Spain). This is part of a more extensive dataset collected and analysed by Laskurain (2008). The coordinates of the trees are given in meters.
data(quercusvm)
data(quercusvm)
An object of class "ppp" representing the point pattern of tree locations. Entries include
Cartesian x-coordinate of tree.
Cartesian y-coordinate of tree.
factor with two levels indicating the status of each tree (1 = "alive", 0 = "dead").
See ppp
for details of the format of a ppp object.
Laskurain, N. A. (2008) Dinámica espacio-temporal de un bosque secundario en el Parque Natural de Urkiola (Bizkaia). Tesis Doctoral. Universidad del País Vasco /Euskal Herriko Unibertsitatea.
Generate a random point pattern, a simulated realisation of the Inhomogeneous Poisson Cluster Process.
rIPCP(x, lambda = NULL, type = 1, lmax = NULL, win = owin(c(0, 1), c(0, 1)), ...)
rIPCP(x, lambda = NULL, type = 1, lmax = NULL, win = owin(c(0, 1), c(0, 1)), ...)
x |
an object of class |
lambda |
Optional. Values of the estimated intensity function as a pixel image (object of class "im" of |
type |
Type of 'prethining' employed in the simulation. See details. |
lmax |
Optional. Upper bound on the values of lambda. |
win |
Optional. Window of the simulated pattern. |
... |
Optional. Arguments passed to |
This function simulates the Inhomogeneous Poisson Cluster process from an object of class 'ecespa.minconfit'
, resulting from fitting an IPCP to some 'original' point pattern
using the function ipc.estK
. Following the approach of Waagepetersen (2007), the simulation involves a first step in which an homogeneous aggregated pattern
is simulated (from the fitted parameters of the 'ecespa.minconfit'
object, using function rThomas
of spatstat
) and a second one in which
the homogeneous pattern is thinned with a spatially varying thinning probability f (s) proportional to the spatially varying intensity, i.e. f (s) = lambda(s) / max[lambda(s)].
To obtain a 'final' density similar to that of the original point pattern, a "prethinning" must be performed. There are two alternatives. If the argument 'type'
is set equal to '1',
the expected number of points per cluster (mu parameter of rThomas
is thinned as mu <- mu.0 / mean[f(s)], where mu.0 is the
mean number of points per cluster of the original pattern. This alternative produces point patterns most similar to the 'original'. If the argument 'type'
is set equal to '2',
the fitted intensity of the Poisson process of cluster centres (kappa parameter of rThomas
, i.e. the intensity of 'parent' points) is thinned
as kappa <- kappa / mean[f(s)]. This alternative produces patterns more uniform than the 'original' and it is provided only for experimental purposes.
A point pattern, with the format of the ppp
objects of spatstat
.
Marcelino de la Cruz Rot
Waagepetersen, R. P. 2007. An estimating function approach to inference for inhomogeneous Neymann-Scott processes. Biometrics 63: 252-258. doi:10.1111/j.1541-0420.2006.00667.x.
sim.poissonc
to simulate homogeneous PCP; rNeymanScott
and rThomas
in spatstat are the basis of this function
data(gypsophylous) plot(gypsophylous) ## It 'seems' that the pattern is clustered, so ## fit a Poisson Cluster Process. The limits of integration ## rmin and rmax are setup to 0 and 60, respectively. cosa.pc2 <- ipc.estK(gypsophylous, r = seq(0, 60, by=0.2)) ## Create one instance of the fitted PCP: pointp <- rIPCP( cosa.pc2) plot(pointp) ##################### ## Inhomogeneous example data(urkiola) # get univariate pp I.ppp <- split.ppp(urkiola)$birch plot(I.ppp) #estimate inhomogeneous intensity function I.lam <- predict (ppm(I.ppp, ~polynom(x,y,2)), type="trend", ngrid=200) # It seems that there is short scale clustering; lets fit an IPCP: I.ki <- ipc.estK(mippp=I.ppp, lambda=I.lam, correction="trans") ## Create one instance of the fitted PCP: pointpi <- rIPCP( I.ki) plot(pointpi)
data(gypsophylous) plot(gypsophylous) ## It 'seems' that the pattern is clustered, so ## fit a Poisson Cluster Process. The limits of integration ## rmin and rmax are setup to 0 and 60, respectively. cosa.pc2 <- ipc.estK(gypsophylous, r = seq(0, 60, by=0.2)) ## Create one instance of the fitted PCP: pointp <- rIPCP( cosa.pc2) plot(pointp) ##################### ## Inhomogeneous example data(urkiola) # get univariate pp I.ppp <- split.ppp(urkiola)$birch plot(I.ppp) #estimate inhomogeneous intensity function I.lam <- predict (ppm(I.ppp, ~polynom(x,y,2)), type="trend", ngrid=200) # It seems that there is short scale clustering; lets fit an IPCP: I.ki <- ipc.estK(mippp=I.ppp, lambda=I.lam, correction="trans") ## Create one instance of the fitted PCP: pointpi <- rIPCP( I.ki) plot(pointpi)
Marked point patterns of two consecutive cohorts of seedlings of H. squamatum growing in a gypsophylous plant community in Central Spain. The datasets contains the locations of the seedlings marked with their heigth. Both the coordinates and the heigth of the seedlings are given in cm.
data(seedlings1) data(seedlings2)
data(seedlings1) data(seedlings2)
seedlings1
and seedlings2
are objects of class "ppp" representing the point pattern of seedling locations marked by their heights. See ppp.object
for details of the format.
Romao, R.L. 2003. Estructura espacial de comunidades de gipsófitos: interacciones bióticas y constricciones abióticas. Tesis Doctoral. Universidad Politécnica de Madrid.
De la Cruz, M. 2006. Introducción al análisis de datos mapeados o algunas de las (muchas) cosas que puedo hacer si tengo coordenadas. Ecosistemas 15 (3): 19-39.
Escudero, A., Romao, R.L., De la Cruz, M. & Maestre, F. 2005. Spatial pattern and neighbour effects on Helianthemum squamatum seedlings in a Mediterranean gypsum community. Journal of Vegetation Science, 16: 383-390. doi:10.1111/j.1654-1103.2005.tb02377.x.
## Not run: data(seedlings1) plot(seedlings1) ## End(Not run)
## Not run: data(seedlings1) plot(seedlings1) ## End(Not run)
Generate a random point pattern, a simulated realisation of the Poisson Cluster Process
sim.poissonc(x.ppp, rho, sigma)
sim.poissonc(x.ppp, rho, sigma)
x.ppp |
Point pattern whose window and intensity will be simulated. An object with the
|
rho |
Parameter |
sigma |
Parameter |
The Poisson cluster processes are defined by the following postulates (Diggle 2003):
PCP1 | Parent events form a Poisson process with intensity . |
PCP2 | Each parent produces a random number of offspring, according to a probability distribution |
|
|
PCP3 | The positions of the offspring relative to their parents are distributed according to a bivariate pdf . |
This implementation asumes that the probability distribution of offspring per parent is a Poisson distribution and
that the position of each offspring relative to its parent follows a radially symetric Gaussian distribution with pdf
The simulated point pattern (an object of class "ppp
").
This implementation simulates only point patterns within rectangular windows. Use ipc.estK
to fit and
rIPCP
(or the spatstat
functions) to simulate point patterns within irregular windows.
This function can use the results of pc.estK
to simulate point patterns from a fitted model.
Be careful as the paramted returned by pc.estK
is while
sim.poissonc
takes
its square root, i.e. .
Marcelino de la Cruz Rot
Diggle, P.J. 2003. Statistical analysis of spatial point patterns. Arnold, London.
rIPCP
to simulate inhomogeneous PCP; rNeymanScott
and rThomas
in spatstat
data(gypsophylous) # set the number of simulations (nsim=199 or larger for real analyses) nsim<- 39 ## Estimate K function ("Kobs"). gyps.env <- envelope(gypsophylous, Kest, correction="iso", nsim=nsim) plot(gyps.env, sqrt(./pi)-r~r, legend=FALSE) ## Fit Poisson Cluster Process. The limits of integration ## rmin and rmax are setup to 0 and 60, respectively. cosa.pc <- pc.estK(Kobs = gyps.env$obs[gyps.env$r<=60], r = gyps.env$r[gyps.env$r<=60]) ## Add fitted Kclust function to the plot. lines(gyps.env$r,sqrt(Kclust(gyps.env$r, cosa.pc$sigma2,cosa.pc$rho)/pi)-gyps.env$r, lty=2, lwd=3, col="purple") ## A kind of pointwise test of the pattern gypsophilous been a realisation ## of the fitted model, simulating with sim.poissonc and using function J (Jest). gyps.env.sim <- envelope(gypsophylous, Jest, nsim=nsim, simulate=expression(sim.poissonc(gypsophylous, sigma=sqrt(cosa.pc$sigma2), rho=cosa.pc$rho))) plot(gyps.env.sim, main="")
data(gypsophylous) # set the number of simulations (nsim=199 or larger for real analyses) nsim<- 39 ## Estimate K function ("Kobs"). gyps.env <- envelope(gypsophylous, Kest, correction="iso", nsim=nsim) plot(gyps.env, sqrt(./pi)-r~r, legend=FALSE) ## Fit Poisson Cluster Process. The limits of integration ## rmin and rmax are setup to 0 and 60, respectively. cosa.pc <- pc.estK(Kobs = gyps.env$obs[gyps.env$r<=60], r = gyps.env$r[gyps.env$r<=60]) ## Add fitted Kclust function to the plot. lines(gyps.env$r,sqrt(Kclust(gyps.env$r, cosa.pc$sigma2,cosa.pc$rho)/pi)-gyps.env$r, lty=2, lwd=3, col="purple") ## A kind of pointwise test of the pattern gypsophilous been a realisation ## of the fitted model, simulating with sim.poissonc and using function J (Jest). gyps.env.sim <- envelope(gypsophylous, Jest, nsim=nsim, simulate=expression(sim.poissonc(gypsophylous, sigma=sqrt(cosa.pc$sigma2), rho=cosa.pc$rho))) plot(gyps.env.sim, main="")
Locations and botanical classification of trees in a plot in the Savannah River. Locations are given in metres, rounded to the nearest 0.1 metre. The data come from a 1-ha (200 m x 50 m) plot in the Savannah River Site, South Carolina, USA. The 734 mapped stems included 156 Carolina ash (Fraxinus caroliniana), 215 Water tupelo (Nyssa aquatica), 205 Swamp tupelo (Nyssa sylvatica), 98 Bald cypress (Taxodium distichum) and 60 stems of 8 additional species. Although the plots were set up by Bill Good and their spatial patterns described in Good and Whipple(1982), the plots have been maintained and resampled by Rebecca Sharitz and her colleagues of the Savannah River Ecology Laboratory. There are slightly different versions of the Good plot data. Every time the plots are resampled, some errors are corrected. This is mostly a concern for the biologists. The different versions are very similar; they are all very good examples of a marked spatial point pattern.
data(swamp)
data(swamp)
A data frame with 734 observations on the following 3 variables.
x
Cartesian x-coordinate of tree
y
Cartesian y-coordinate of tree
sp
a factor with levels indicating the species of each tree:
FX
|
Carolina ash (Fraxinus caroliniana) |
NS
|
Swamp tupelo (Nyssa sylvatica) |
NX
|
Water tupelo (Nyssa aquatica) |
TD
|
Bald cypress (Taxodium distichum) |
OT
|
Other species |
Dixon, P.M. 2002. Nearest-neighbor contingency table analysis of spatial segregation for several species. Ecoscience, 9 (2): 142-151. doi:10.1080/11956860.2002.11682700.
Good, , B. J. & Whipple, S.A. 1982. Tree spatial patterns: South Carolina bottomland and swamp forest. Bulletin of the Torrey Botanical Club, 109: 529-536.
Jones et al. 1994. Tree population dynamics in seven South Carolina mixed-species forests. Bulletin of the Torrey Botanical Club, 121:360-368.
data(swamp) plot(swamp$x,swamp$y, col=as.numeric(swamp$sp),pch=19, xlab="",ylab="",main="Swamp forest")
data(swamp) plot(swamp$x,swamp$y, col=as.numeric(swamp$sp),pch=19, xlab="",ylab="",main="Swamp forest")
Computes a two-sample Cramer-von Mises (and Kolmogorov-Smirnov) type test for a difference between the spatial distributions of two populations. It is designed to be sensitive to differences in the way the populations are distributed across the study area but insensitive to differences in abundance between the two populations.
syrjala0(coords, var1, var2, nsim, R=FALSE) syrjala(coords = NULL, var1 = NULL, var2 = NULL, nperm = 999) syrjala.test(ppp1, ppp2, nsim = 999) ## S3 method for class 'syrjala.test' plot(x, coline=1, ...) ## S3 method for class 'ecespa.syrjala' plot(x, ...)
syrjala0(coords, var1, var2, nsim, R=FALSE) syrjala(coords = NULL, var1 = NULL, var2 = NULL, nperm = 999) syrjala.test(ppp1, ppp2, nsim = 999) ## S3 method for class 'syrjala.test' plot(x, coline=1, ...) ## S3 method for class 'ecespa.syrjala' plot(x, ...)
coords |
A |
var1 |
The first numeric variable |
var2 |
The second numeric variable. |
nperm |
Number of permutations. |
nsim |
Number of permutations. |
R |
Logical. Should be computed using R approach? |
ppp1 |
A marked point pattern, with the |
ppp2 |
A marked point pattern, with the |
x |
An object of class ' |
coline |
color for drawing the statistic's line in the plot. |
... |
Graphical parameters passed to |
The null hypothesis of Syrjala's test is that across the study area, the normalized distributions of the two populations are the same (Syrjala, 1996). Population density data are collected at sampling locations on two populations.
Let
denote the coordinates of the
sampling location (
);
let
denote the sample density at the
sampling location of the
population.
To construct a test that is independent of the population sizes, the observed density data is first normalized:
where is the sum of
observations across the
sampling locations.
The value of the cumulative distribution function at the location
for the
population, denoted
,
is the sum of all normalized density observations,
, whose location
is such that
and
. The statistic proposed by Syrjala to test the null hypothesis is the square of the difference
between the cumulative distribution functions of the two populations, summed over all sampling locations,
that is
As is not invariant with respect to the 'corner' of the rectangle enclosing the study area that is chosen as the origin of the coordinate sytem,
is computed four times, one with each corner as the origin, and the average
is employed as the test statistic.
The level of significance of the observed
is determined from its position in the ordered set of test statistic values from all
pairwise
permutations (that is approximated from a large number of randomly selected permutations).
Functions syrjala
or syrjala0
(with the argument R=FALSE
) return an object of class 'syrjala.test
'.
Functions syrjala.test
or syrjala0
(with the argument R=TRUE
) return an object of class 'ecespa.syrjala
'.
In Both cases, the result is a list with the following elements:
cvm.obs |
(class syrjala.test). The observed (averaged) |
cvm.sim |
(class syrjala.test). A numeric vector with the |
ks.obs |
(class syrjala.test). The observed (averaged) |
ks.sim |
(class syrjala.test). A numeric vector with the |
datanames |
(class syrjala.test). A character vector with the names of the two patterns, the spatial congruence of which is been analyzed. |
nperm |
(class syrjala.test). The number of permutations employed in the test (not counting the original data). |
psi.obs |
(class ecespa.syrjala).The observed (averaged) |
psi.sim |
(class ecespa.syrjala). A vector with the |
datanames |
(class ecespa.syrjala). A vector with the names of the two point patterns whose spatial congruence is been analyzed. |
nsim |
(class ecespa.syrjala). The number of permutations employed in the test. |
Both S3 plot methods plot an histogram with the distribution of the simulated 's statistics and draws the observed
as a vertical line.
The test requires both populations being sampled in exactly the same sampling locations.
Althoug this implementation employs ppp
's as the supporting data format, this kind of data are not spatial point patterns.
They cannot be analysed with the usual tools employed for marked point patterns.
syrjala
or syrjala0
(with the argument R=FALSE
) implement a Fortran version of Syrjala's test. They run considerably faster
than the "whole-R" implementation of syrjala.test
or syrjala0
(with the argument R=TRUE
). This last implementation is supplied for illustrative purposes and to
maintain compability with previous versions of package ecespa
. One can use function haz.ppp
to easily build the ppp
objects from a data.frame
with only three columns (x-coordinate,
y-coordinate and abundance).
This function has been employed to compute Syrjala's test in Rey-Benayas et al. (2008).
Jose M. Blanco-Moreno [email protected] for the Fortran implementation of Syrjala's original QBasic function, Marcelino de la Cruz Rot for the R version, the wrapping functions and the documentation
Rey-Benayas, J.M., de la Montaña, E., Pérez-Camacho, L., de la Cruz, M., Moreno, D., Parejo, J.L. and Suárez-Seoane, S. 2010. Inter-annual dynamics and spatial congruence of a nocturnal bird assemblage inhabiting a Mediterranean agricultural mosaic. Ardeola,57(2): 303-320.
Syrjala, S. E. 1996. A statistical test for a difference between the spatial distributions of two populations. Ecology 77: 75-80. doi:10.2307/2265656.
data(syr1); data(syr2); data(syr3) coords <- data.frame(x=syr1$x, y=syr1$y); var1<- syr1$marks; var2<- syr2$marks (stest<-syrjala(coords, var1, var2, 9999)) plot(stest) ## Not run: plot(syrjala.test(syr1, syr2, nsim=999)) plot(syrjala.test(syr1, syr3, nsim=999)) syrjala0(coords, var1, var2, 9999) syrjala0(coords, var1, var2, 999, R=TRUE) coords <- expand.grid(x=1:10,y=1:10) var1 <- runif(100) var2 <- runif(100) syrjala(coords, var1, var2, 9999) ## End(Not run)
data(syr1); data(syr2); data(syr3) coords <- data.frame(x=syr1$x, y=syr1$y); var1<- syr1$marks; var2<- syr2$marks (stest<-syrjala(coords, var1, var2, 9999)) plot(stest) ## Not run: plot(syrjala.test(syr1, syr2, nsim=999)) plot(syrjala.test(syr1, syr3, nsim=999)) syrjala0(coords, var1, var2, 9999) syrjala0(coords, var1, var2, 999, R=TRUE) coords <- expand.grid(x=1:10,y=1:10) var1 <- runif(100) var2 <- runif(100) syrjala(coords, var1, var2, 9999) ## End(Not run)
Artificial data to exemplify Syrjala's test.
data(syr1) data(syr2) data(syr3)
data(syr1) data(syr2) data(syr3)
syr1
, syr2
and syr3
are marked point patterns
of class "ppp" representing the coordinates of some sampling locations, 'marked' by
the value of some parameters (e.g. density of individuals) measured on them. See ppp.object
for details of the format. On the other hand, one can use function haz.ppp
to easily build ppp
objects
appropriate for use with syrjala.test
.
data(syr1)
data(syr1)