Title: | Functions for Kriging and Point Pattern Analysis |
---|---|
Description: | Functions for kriging and point pattern analysis. |
Authors: | Brian Ripley [aut, cre, cph], Roger Bivand [ctb], William Venables [cph] |
Maintainer: | Brian Ripley <[email protected]> |
License: | GPL-2 | GPL-3 |
Version: | 7.3-17 |
Built: | 2024-12-01 08:44:04 UTC |
Source: | CRAN |
Compute analysis of variance tables for one or more
fitted trend surface model objects; where anova.trls
is
called with multiple objects, it passes on the arguments to
anovalist.trls
.
## S3 method for class 'trls' anova(object, ...) anovalist.trls(object, ...)
## S3 method for class 'trls' anova(object, ...) anovalist.trls(object, ...)
object |
A fitted trend surface model object from |
... |
Further objects of the same kind |
anova.trls
and anovalist.trls
return objects corresponding
to their printed tabular output.
Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth edition. Springer.
library(stats) data(topo, package="MASS") topo0 <- surf.ls(0, topo) topo1 <- surf.ls(1, topo) topo2 <- surf.ls(2, topo) topo3 <- surf.ls(3, topo) topo4 <- surf.ls(4, topo) anova(topo0, topo1, topo2, topo3, topo4) summary(topo4)
library(stats) data(topo, package="MASS") topo0 <- surf.ls(0, topo) topo1 <- surf.ls(1, topo) topo2 <- surf.ls(2, topo) topo3 <- surf.ls(3, topo) topo4 <- surf.ls(4, topo) anova(topo0, topo1, topo2, topo3, topo4) summary(topo4)
Compute spatial correlograms of spatial data or residuals.
correlogram(krig, nint, plotit = TRUE, ...)
correlogram(krig, nint, plotit = TRUE, ...)
krig |
trend-surface or kriging object with columns |
nint |
number of bins used |
plotit |
logical for plotting |
... |
parameters for the plot |
Divides range of data into nint
bins, and computes the covariance for
pairs with separation in each bin, then divides by the variance.
Returns results for bins with 6 or more pairs.
x
and y
coordinates of the correlogram, and cnt
, the number of pairs
averaged per bin.
Plots the correlogram if plotit = TRUE
.
Ripley, B. D. (1981) Spatial Statistics. Wiley.
Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth edition. Springer.
data(topo, package="MASS") topo.kr <- surf.ls(2, topo) correlogram(topo.kr, 25) d <- seq(0, 7, 0.1) lines(d, expcov(d, 0.7))
data(topo, package="MASS") topo.kr <- surf.ls(2, topo) correlogram(topo.kr, 25) d <- seq(0, 7, 0.1) lines(d, expcov(d, 0.7))
Spatial covariance functions for use with surf.gls
.
expcov(r, d, alpha = 0, se = 1) gaucov(r, d, alpha = 0, se = 1) sphercov(r, d, alpha = 0, se = 1, D = 2)
expcov(r, d, alpha = 0, se = 1) gaucov(r, d, alpha = 0, se = 1) sphercov(r, d, alpha = 0, se = 1, D = 2)
r |
vector of distances at which to evaluate the covariance |
d |
range parameter |
alpha |
proportion of nugget effect |
se |
standard deviation at distance zero |
D |
dimension of spheres. |
vector of covariance values.
Ripley, B. D. (1981) Spatial Statistics. Wiley.
Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth edition. Springer.
data(topo, package="MASS") topo.kr <- surf.ls(2, topo) correlogram(topo.kr, 25) d <- seq(0, 7, 0.1) lines(d, expcov(d, 0.7))
data(topo, package="MASS") topo.kr <- surf.ls(2, topo) correlogram(topo.kr, 25) d <- seq(0, 7, 0.1) lines(d, expcov(d, 0.7))
Forms the average of a series of (usually simulated) K-functions.
Kaver(fs, nsim, ...)
Kaver(fs, nsim, ...)
fs |
full scale for K-fn |
nsim |
number of simulations |
... |
arguments to simulate one point process object |
list with components x
and y
of the average K-fn on L-scale.
Ripley, B. D. (1981) Spatial Statistics. Wiley.
Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth edition. Springer.
towns <- ppinit("towns.dat") par(pty="s") plot(Kfn(towns, 40), type="b") plot(Kfn(towns, 10), type="b", xlab="distance", ylab="L(t)") for(i in 1:10) lines(Kfn(Psim(69), 10)) lims <- Kenvl(10,100,Psim(69)) lines(lims$x,lims$lower, lty=2, col="green") lines(lims$x,lims$upper, lty=2, col="green") lines(Kaver(10,25,Strauss(69,0.5,3.5)), col="red")
towns <- ppinit("towns.dat") par(pty="s") plot(Kfn(towns, 40), type="b") plot(Kfn(towns, 10), type="b", xlab="distance", ylab="L(t)") for(i in 1:10) lines(Kfn(Psim(69), 10)) lims <- Kenvl(10,100,Psim(69)) lines(lims$x,lims$lower, lty=2, col="green") lines(lims$x,lims$upper, lty=2, col="green") lines(Kaver(10,25,Strauss(69,0.5,3.5)), col="red")
Computes envelope (upper and lower limits) and average of simulations of K-fns
Kenvl(fs, nsim, ...)
Kenvl(fs, nsim, ...)
fs |
full scale for K-fn |
nsim |
number of simulations |
... |
arguments to produce one simulation |
list with components
x |
distances |
lower |
min of K-fns |
upper |
max of K-fns |
aver |
average of K-fns |
Ripley, B. D. (1981) Spatial Statistics. Wiley.
Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth edition. Springer.
towns <- ppinit("towns.dat") par(pty="s") plot(Kfn(towns, 40), type="b") plot(Kfn(towns, 10), type="b", xlab="distance", ylab="L(t)") for(i in 1:10) lines(Kfn(Psim(69), 10)) lims <- Kenvl(10,100,Psim(69)) lines(lims$x,lims$lower, lty=2, col="green") lines(lims$x,lims$upper, lty=2, col="green") lines(Kaver(10,25,Strauss(69,0.5,3.5)), col="red")
towns <- ppinit("towns.dat") par(pty="s") plot(Kfn(towns, 40), type="b") plot(Kfn(towns, 10), type="b", xlab="distance", ylab="L(t)") for(i in 1:10) lines(Kfn(Psim(69), 10)) lims <- Kenvl(10,100,Psim(69)) lines(lims$x,lims$lower, lty=2, col="green") lines(lims$x,lims$upper, lty=2, col="green") lines(Kaver(10,25,Strauss(69,0.5,3.5)), col="red")
Actually computes .
Kfn(pp, fs, k=100)
Kfn(pp, fs, k=100)
pp |
a list such as a pp object, including components |
fs |
full scale of the plot |
k |
number of regularly spaced distances in (0, |
relies on the domain D having been set by ppinit
or ppregion
.
A list with components
x |
vector of distances |
y |
vector of L-fn values |
k |
number of distances returned – may be less than |
dmin |
minimum distance between pair of points |
lm |
maximum deviation from L(t) = t |
Ripley, B. D. (1981) Spatial Statistics. Wiley.
Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth edition. Springer.
ppinit
, ppregion
, Kaver
, Kenvl
towns <- ppinit("towns.dat") par(pty="s") plot(Kfn(towns, 10), type="s", xlab="distance", ylab="L(t)")
towns <- ppinit("towns.dat") par(pty="s") plot(Kfn(towns, 10), type="s", xlab="distance", ylab="L(t)")
Retrieves the rectangular domain (xl, xu)
(yl, yu)
from the
underlying C
code.
ppgetregion()
ppgetregion()
A vector of length four with names c("xl", "xu", "yl", "yu")
.
Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth edition. Springer.
Read a file in standard format and create a point process object.
ppinit(file)
ppinit(file)
file |
string giving file name |
The file should contain
the number of points
a header (ignored)
xl xu yl yu scale
x y (repeated n times)
class "pp"
object with components x
, y
,
xl
, xu
, yl
, yu
Calls ppregion
to set the domain.
Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth edition. Springer.
towns <- ppinit("towns.dat") par(pty="s") plot(Kfn(towns, 10), type="b", xlab="distance", ylab="L(t)")
towns <- ppinit("towns.dat") par(pty="s") plot(Kfn(towns, 10), type="b", xlab="distance", ylab="L(t)")
Pseudo-likelihood estimation of a Strauss spatial point process.
pplik(pp, R, ng=50, trace=FALSE)
pplik(pp, R, ng=50, trace=FALSE)
pp |
a pp object |
R |
the fixed parameter |
ng |
use a |
trace |
logical? Should function evaluations be printed? |
estimate for c
in the interval .
Ripley, B. D. (1988) Statistical Inference for Spatial Processes. Cambridge.
Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth edition. Springer.
pines <- ppinit("pines.dat") pplik(pines, 0.7)
pines <- ppinit("pines.dat") pplik(pines, 0.7)
Sets the rectangular domain (xl, xu)
(yl, yu)
.
ppregion(xl = 0, xu = 1, yl = 0, yu = 1)
ppregion(xl = 0, xu = 1, yl = 0, yu = 1)
xl |
Either |
xu , yl , yu
|
otheri limits of the rectangle if given separately. |
none
initializes variables in the C
subroutines.
Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth edition. Springer.
Predicted values based on trend surface model object
## S3 method for class 'trls' predict(object, x, y, ...)
## S3 method for class 'trls' predict(object, x, y, ...)
object |
Fitted trend surface model object returned by |
x |
Vector of prediction location eastings (x coordinates) |
y |
Vector of prediction location northings (y coordinates) |
... |
further arguments passed to or from other methods. |
predict.trls
produces a vector of predictions corresponding
to the prediction locations. To display the output with image
or contour
, use trmat
or convert the returned vector
to matrix form.
Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth edition. Springer.
data(topo, package="MASS") topo2 <- surf.ls(2, topo) topo4 <- surf.ls(4, topo) x <- c(1.78, 2.21) y <- c(6.15, 6.15) z2 <- predict(topo2, x, y) z4 <- predict(topo4, x, y) cat("2nd order predictions:", z2, "\n4th order predictions:", z4, "\n")
data(topo, package="MASS") topo2 <- surf.ls(2, topo) topo4 <- surf.ls(4, topo) x <- c(1.78, 2.21) y <- c(6.15, 6.15) z2 <- predict(topo2, x, y) z4 <- predict(topo4, x, y) cat("2nd order predictions:", z2, "\n4th order predictions:", z4, "\n")
Evaluate Kriging surface over a grid.
prmat(obj, xl, xu, yl, yu, n)
prmat(obj, xl, xu, yl, yu, n)
obj |
object returned by |
xl |
limits of the rectangle for grid |
xu |
ditto |
yl |
ditto |
yu |
ditto |
n |
use |
list with components x
, y
and z
suitable for contour
and image
.
Ripley, B. D. (1981) Spatial Statistics. Wiley.
Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth edition. Springer.
data(topo, package="MASS") topo.kr <- surf.gls(2, expcov, topo, d=0.7) prsurf <- prmat(topo.kr, 0, 6.5, 0, 6.5, 50) contour(prsurf, levels=seq(700, 925, 25))
data(topo, package="MASS") topo.kr <- surf.gls(2, expcov, topo, d=0.7) prsurf <- prmat(topo.kr, 0, 6.5, 0, 6.5, 50) contour(prsurf, levels=seq(700, 925, 25))
Simulate Binomial spatial point process.
Psim(n)
Psim(n)
n |
number of points |
relies on the region being set by ppinit
or ppregion
.
list of vectors of x
and y
coordinates.
uses the random number generator.
Ripley, B. D. (1981) Spatial Statistics. Wiley.
Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth edition. Springer.
towns <- ppinit("towns.dat") par(pty="s") plot(Kfn(towns, 10), type="s", xlab="distance", ylab="L(t)") for(i in 1:10) lines(Kfn(Psim(69), 10))
towns <- ppinit("towns.dat") par(pty="s") plot(Kfn(towns, 10), type="s", xlab="distance", ylab="L(t)") for(i in 1:10) lines(Kfn(Psim(69), 10))
Evaluate Kriging standard error of prediction over a grid.
semat(obj, xl, xu, yl, yu, n, se)
semat(obj, xl, xu, yl, yu, n, se)
obj |
object returned by |
xl |
limits of the rectangle for grid |
xu |
ditto |
yl |
ditto |
yu |
ditto |
n |
use |
se |
standard error at distance zero as a multiple of the supplied covariance. Otherwise estimated, and it assumed that a correlation function was supplied. |
list with components x, y and z suitable for contour
and image
.
Ripley, B. D. (1981) Spatial Statistics. Wiley.
Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth edition. Springer.
data(topo, package="MASS") topo.kr <- surf.gls(2, expcov, topo, d=0.7) prsurf <- prmat(topo.kr, 0, 6.5, 0, 6.5, 50) contour(prsurf, levels=seq(700, 925, 25)) sesurf <- semat(topo.kr, 0, 6.5, 0, 6.5, 30) contour(sesurf, levels=c(22,25))
data(topo, package="MASS") topo.kr <- surf.gls(2, expcov, topo, d=0.7) prsurf <- prmat(topo.kr, 0, 6.5, 0, 6.5, 50) contour(prsurf, levels=seq(700, 925, 25)) sesurf <- semat(topo.kr, 0, 6.5, 0, 6.5, 30) contour(sesurf, levels=c(22,25))
Simulates SSI (sequential spatial inhibition) point process.
SSI(n, r)
SSI(n, r)
n |
number of points |
r |
inhibition distance |
uses the region set by ppinit
or ppregion
.
list of vectors of x
and y
coordinates
uses the random number generator.
will never return if r
is too large and it cannot place
n
points.
Ripley, B. D. (1981) Spatial Statistics. Wiley.
Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth edition. Springer.
towns <- ppinit("towns.dat") par(pty = "s") plot(Kfn(towns, 10), type = "b", xlab = "distance", ylab = "L(t)") lines(Kaver(10, 25, SSI(69, 1.2)))
towns <- ppinit("towns.dat") par(pty = "s") plot(Kfn(towns, 10), type = "b", xlab = "distance", ylab = "L(t)") lines(Kaver(10, 25, SSI(69, 1.2)))
Simulates Strauss spatial point process.
Strauss(n, c=0, r)
Strauss(n, c=0, r)
n |
number of points |
c |
parameter |
r |
inhibition distance |
Uses spatial birth-and-death process for 4n
steps, or for 40n
steps
starting from a binomial pattern on the first call from an other function.
Uses the region set by ppinit
or ppregion
.
list of vectors of and
coordinates
uses the random number generator
Ripley, B. D. (1981) Spatial Statistics. Wiley.
Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth edition. Springer.
towns <- ppinit("towns.dat") par(pty="s") plot(Kfn(towns, 10), type="b", xlab="distance", ylab="L(t)") lines(Kaver(10, 25, Strauss(69,0.5,3.5)))
towns <- ppinit("towns.dat") par(pty="s") plot(Kfn(towns, 10), type="b", xlab="distance", ylab="L(t)") lines(Kaver(10, 25, Strauss(69,0.5,3.5)))
Fits a trend surface by generalized least-squares.
surf.gls(np, covmod, x, y, z, nx = 1000, ...)
surf.gls(np, covmod, x, y, z, nx = 1000, ...)
np |
degree of polynomial surface |
covmod |
function to evaluate covariance or correlation function |
x |
x coordinates or a data frame with columns |
y |
y coordinates |
z |
z coordinates. Will supersede |
nx |
Number of bins for table of the covariance. Increasing adds accuracy, and increases size of the object. |
... |
parameters for |
list with components
beta |
the coefficients |
x |
|
y |
|
z |
and others for internal use only. |
Ripley, B. D. (1981) Spatial Statistics. Wiley.
Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth edition. Springer.
trmat
, surf.ls
, prmat
, semat
, expcov
, gaucov
, sphercov
library(MASS) # for eqscplot data(topo, package="MASS") topo.kr <- surf.gls(2, expcov, topo, d=0.7) trsurf <- trmat(topo.kr, 0, 6.5, 0, 6.5, 50) eqscplot(trsurf, type = "n") contour(trsurf, add = TRUE) prsurf <- prmat(topo.kr, 0, 6.5, 0, 6.5, 50) contour(prsurf, levels=seq(700, 925, 25)) sesurf <- semat(topo.kr, 0, 6.5, 0, 6.5, 30) eqscplot(sesurf, type = "n") contour(sesurf, levels = c(22, 25), add = TRUE)
library(MASS) # for eqscplot data(topo, package="MASS") topo.kr <- surf.gls(2, expcov, topo, d=0.7) trsurf <- trmat(topo.kr, 0, 6.5, 0, 6.5, 50) eqscplot(trsurf, type = "n") contour(trsurf, add = TRUE) prsurf <- prmat(topo.kr, 0, 6.5, 0, 6.5, 50) contour(prsurf, levels=seq(700, 925, 25)) sesurf <- semat(topo.kr, 0, 6.5, 0, 6.5, 30) eqscplot(sesurf, type = "n") contour(sesurf, levels = c(22, 25), add = TRUE)
Fits a trend surface by least-squares.
surf.ls(np, x, y, z)
surf.ls(np, x, y, z)
np |
degree of polynomial surface |
x |
x coordinates or a data frame with columns |
y |
y coordinates |
z |
z coordinates. Will supersede |
list with components
beta |
the coefficients |
x |
|
y |
|
z |
and others for internal use only. |
Ripley, B. D. (1981) Spatial Statistics. Wiley.
Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth edition. Springer.
library(MASS) # for eqscplot data(topo, package="MASS") topo.kr <- surf.ls(2, topo) trsurf <- trmat(topo.kr, 0, 6.5, 0, 6.5, 50) eqscplot(trsurf, type = "n") contour(trsurf, add = TRUE) points(topo) eqscplot(trsurf, type = "n") contour(trsurf, add = TRUE) plot(topo.kr, add = TRUE) title(xlab= "Circle radius proportional to Cook's influence statistic")
library(MASS) # for eqscplot data(topo, package="MASS") topo.kr <- surf.ls(2, topo) trsurf <- trmat(topo.kr, 0, 6.5, 0, 6.5, 50) eqscplot(trsurf, type = "n") contour(trsurf, add = TRUE) points(topo) eqscplot(trsurf, type = "n") contour(trsurf, add = TRUE) plot(topo.kr, add = TRUE) title(xlab= "Circle radius proportional to Cook's influence statistic")
This function provides the basic quantities which are used in
forming a variety of diagnostics for checking the quality of
regression fits for trend surfaces calculated by surf.ls
.
trls.influence(object) ## S3 method for class 'trls' plot(x, border = "red", col = NA, pch = 4, cex = 0.6, add = FALSE, div = 8, ...)
trls.influence(object) ## S3 method for class 'trls' plot(x, border = "red", col = NA, pch = 4, cex = 0.6, add = FALSE, div = 8, ...)
object , x
|
Fitted trend surface model from |
div |
scaling factor for influence circle radii in |
add |
add influence plot to existing graphics if |
border , col , pch , cex , ...
|
additional graphical parameters |
trls.influence
returns a list with components:
r |
raw residuals as given by |
hii |
diagonal elements of the Hat matrix |
stresid |
standardised residuals |
Di |
Cook's statistic |
Unwin, D. J., Wrigley, N. (1987) Towards a general-theory of control point distribution effects in trend surface models. Computers and Geosciences, 13, 351–355.
Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth edition. Springer.
surf.ls
, influence.measures
, plot.lm
library(MASS) # for eqscplot data(topo, package = "MASS") topo2 <- surf.ls(2, topo) infl.topo2 <- trls.influence(topo2) (cand <- as.data.frame(infl.topo2)[abs(infl.topo2$stresid) > 1.5, ]) cand.xy <- topo[as.integer(rownames(cand)), c("x", "y")] trsurf <- trmat(topo2, 0, 6.5, 0, 6.5, 50) eqscplot(trsurf, type = "n") contour(trsurf, add = TRUE, col = "grey") plot(topo2, add = TRUE, div = 3) points(cand.xy, pch = 16, col = "orange") text(cand.xy, labels = rownames(cand.xy), pos = 4, offset = 0.5)
library(MASS) # for eqscplot data(topo, package = "MASS") topo2 <- surf.ls(2, topo) infl.topo2 <- trls.influence(topo2) (cand <- as.data.frame(infl.topo2)[abs(infl.topo2$stresid) > 1.5, ]) cand.xy <- topo[as.integer(rownames(cand)), c("x", "y")] trsurf <- trmat(topo2, 0, 6.5, 0, 6.5, 50) eqscplot(trsurf, type = "n") contour(trsurf, add = TRUE, col = "grey") plot(topo2, add = TRUE, div = 3) points(cand.xy, pch = 16, col = "orange") text(cand.xy, labels = rownames(cand.xy), pos = 4, offset = 0.5)
Evaluate trend surface over a grid.
trmat(obj, xl, xu, yl, yu, n)
trmat(obj, xl, xu, yl, yu, n)
obj |
object returned by |
xl |
limits of the rectangle for grid |
xu |
ditto |
yl |
ditto |
yu |
ditto |
n |
use |
list with components x
, y
and z
suitable for contour
and image
.
Ripley, B. D. (1981) Spatial Statistics. Wiley.
Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth edition. Springer.
data(topo, package="MASS") topo.kr <- surf.ls(2, topo) trsurf <- trmat(topo.kr, 0, 6.5, 0, 6.5, 50)
data(topo, package="MASS") topo.kr <- surf.ls(2, topo) trsurf <- trmat(topo.kr, 0, 6.5, 0, 6.5, 50)
Compute spatial (semi-)variogram of spatial data or residuals.
variogram(krig, nint, plotit = TRUE, ...)
variogram(krig, nint, plotit = TRUE, ...)
krig |
trend-surface or kriging object with columns |
nint |
number of bins used |
plotit |
logical for plotting |
... |
parameters for the plot |
Divides range of data into nint
bins, and computes the average squared
difference for pairs with separation in each bin. Returns results for
bins with 6 or more pairs.
x
and y
coordinates of the variogram and cnt
,
the number of pairs averaged per bin.
Plots the variogram if plotit = TRUE
Ripley, B. D. (1981) Spatial Statistics. Wiley.
Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth edition. Springer.
data(topo, package="MASS") topo.kr <- surf.ls(2, topo) variogram(topo.kr, 25)
data(topo, package="MASS") topo.kr <- surf.ls(2, topo) variogram(topo.kr, 25)