ppm
,
evaluate the spatial trend or the conditional intensity of the model
at new locations.## S3 method for class 'ppm':
predict(object, window, ngrid=NULL, locations=NULL,
covariates=NULL, type="trend", \dots, check=TRUE, repair=TRUE)
ppm
. An object of
class "ppm"
(see ppm.object
)."owin"
)
delimiting the locations where predictions
should be computed. Defaults to the window of the
original data used to fit the model object
.window
where the predictions should be computed.
An integer, or an integer vector of length 2,
specifying the number of grid points in the $y$ and $x$
directions. (Incompatingrid
)"trend"
for the spatial trend,
"cif"
or "lambda"
for the conditional intensity,
and "se"
fobject
. If there is any possibility that this object
has been restored from a dump file, or has otherwise lost track of
the environment where it was originally compuobject
, if it is found to be damaged.locations
is given and is a data frame:
a vector of predicted values for the spatial locations
(and marks, if required) given in locations
. If ngrid
is given, or if locations
is given
and is a binary image mask:
If object
is an unmarked point process,
the result is a pixel image object (of class "im"
, see
im.object
) containing the predictions.
If object
is a multitype point process,
the result is a list of pixel images, containing the predictions
for each type at the same grid of locations.
The ``predicted values'' are either values of the spatial trend
(if type="trend"
), values of the conditional intensity
(if type="cif"
or type="lambda"
), or
estimates of standard error for the fitted spatial trend
(if type="se"
).
predict.glm
so that prediction is wrong if the trend formula in
object
involves terms in ns()
,
bs()
or poly()
.
This is a weakness of predict.glm
itself!
Error messages may be very opaque,
as they tend to come from deep in the workings of
predict.glm
.
If you are passing the covariates
argument
and the function crashes,
it is advisable to start by checking that all the conditions
listed above are satisfied.ppm
. This
returns an object of class "ppm"
representing
the fitted point process model (see ppm.object
).
The parameter estimates in this fitted model can be read off
simply by printing the ppm
object.
The spatial trend and conditional intensity of the
fitted model are evaluated using this function predict.ppm
.The default action is to create a rectangular grid of points in the observation window of the data point pattern, and evaluate the spatial trend at these locations.
The argument type
specifies the values that are computed:
[object Object],[object Object],[object Object]
Note that the ``spatial trend'' is the same as the intensity function
if the fitted model object
is a Poisson point process.
However, if the model is not a Poisson process, then the
``spatial trend'' is the (exponentiated) first order potential
and not the intensity of the process. [For example if we fit the
stationary Strauss process with parameters
$\beta$ and $\gamma$,
then the spatial trend is constant and equal to $\beta$,
while the intensity is a smaller value that is not easy to
compute. ]
The spatial locations where predictions are required,
are determined by the (incompatible)
arguments ngrid
and locations
.
ngrid
is present, then
predictions are performed at a rectangular
grid of locations in the windowwindow
.
The result of prediction will be a pixel image or images.locations
is present, then predictions
will be performed at the spatial locations given by
this dataset. These may be an arbitrary list of spatial locations,
or they may be a rectangular grid.
The result of prediction will be either a numeric vector
or a pixel image or images.ngrid
norlocations
is given, thenngrid
is assumed. It defaults to 50.locations
may be a data frame or list
specifying arbitrary locations,
or a binary image mask (an object of class "owin"
with type "mask"
) specifying (a subset of) a rectangular
grid of locations. If locations
is a data frame or list, then it must contain
vectors locations$x
and locations$y
specifying the
$x,y$ coordinates of the prediction locations. Additionally, if
the model is a marked point process, then locations
must also contain
a factor locations$marks
specifying the marks of the
prediction locations. These vectors must have equal length.
The result of prediction will be a vector of predicted values,
of the same length.
If locations
is a binary image mask, then prediction will be
performed at each pixel in this binary image where the pixel value
is TRUE
(in other words, at each pixel that is inside the
window). If the fitted model is an unmarked point process, then the
result of prediction will be an image. If the fitted model is a
marked point process, then prediction will
be performed for each possible value of the mark at each such
location, and the result of prediction will be a
list of images, one for each mark value.
The argument covariates
gives the values of any spatial covariates
at the prediction locations.
If the trend formula in the fitted model
involves spatial covariates (other than
the Cartesian coordinates x
, y
)
then covariates
is required.
The format and use of covariates
are analogous to those of the
argument of the same name in ppm
.
It is either a data frame or a list of images.
If covariates
is a list of images, then
the names of the entries should correspond to
the names of covariates in the model formula trend
.
Each entry in the list must be an image object (of class "im"
,
see im.object
).
The software will look up
the pixel values of each image at the quadrature points.
If covariates
is a data frame, then the
i
th row of covariates
is assumed to contain covariate data for the i
th location.
When locations
is a data frame,
this just means that each row of covariates
contains the
covariate data for the location specified in the corresponding row of
locations
. When locations
is a binary image
mask, the row covariates[i,]
must correspond to the location
x[i],y[i]
where x = as.vector(raster.x(locations))
and y = as.vector(raster.y(locations))
.
Note that if you only want to use prediction in order to
generate a plot of the predicted values,
it may be easier to use plot.ppm
which calls
this function and plots the results.
ppm
,
ppm.object
,
plot.ppm
,
print.ppm
,
fitted.ppm
data(cells)
m <- ppm(cells, ~ polynom(x,y,2), Strauss(0.05))
trend <- predict(m, type="trend")
image(trend)
points(cells)
cif <- predict(m, type="cif")
persp(cif)
data(japanesepines)
mj <- ppm(japanesepines, ~harmonic(x,y,2))
se <- predict(mj, type="se")
# prediction at arbitrary locations
predict(mj, locations=data.frame(x=0.3, y=0.4))
X <- runifpoint(5, japanesepines$window)
predict(mj, locations=X)
predict(mj, locations=X, type="se")
# multitype
data(amacrine)
ma <- ppm(amacrine, ~marks,
MultiStrauss(c("off","on"),matrix(0.06, 2, 2)))
predict(ma)
predict(ma, type="cif")
predict(ma, locations=data.frame(x=0.8, y=0.5,marks="on"), type="cif")
Run the code above in your browser using DataLab