简体   繁体   中英

plot residuals in spatstat without overlaying points

This might be very simple but I have spent quite a lot of time trying to figure it out without any luck, maybe anyone can help me.

I have point pattern model fitted through the ppm() function in spatstat, (reproducible code below) and when I plot the residuals it automatically plots the points over the residuals image, which makes it very difficult to see anything. Does anyone know how to avoid it?

code:

library(spatstat)
pattern <- rpoispp(300)
cov <- rnoise(rgen = rnorm, dimyx=32, mean=2, sd=1, w = pattern$window)
fit <- ppm(pattern ~ cov)
res <- residuals.ppm(fit, type = "raw")
plot(res, how = "imagecontour")

The data points are not being "over-plotted" on top of the residuals: the residual measure includes an 'atom' of mass at each data point, together with a smooth density, so the plot is correct.

If the problem is that you can't see the detail because the symbols representing the atoms are too large, then you could just reduce the scale of these symbols, using one of the arguments markscale or maxsize which will be passed to plot.ppp .

Then again, if there are a lot of data points, you might be better to just smooth the residual measure. If res is the residual measure you calculated, then try plot(Smooth(res)) . See the help for Smooth.msr for further information.

If you really need to extract the smooth density component of the residual measure, you could follow Ege's advice, or alternatively use with.msr . For example

with(res, Smooth(qlocations %mark% density)) 

gives an image representing the continuous component of the residual measure.

These comments only apply for the raw residuals, where all atoms have equal mass 1. For other types of residuals, the atoms have unequal masses, and it becomes more important to display them.

Well the residual for a point process model is really a signed measure which has both a discrete part (concentrated at the observed locations) and a continuous part. If you only plot the continuous part you are not really plotting the residual...

Of course it is a valid point that you want to plot only the continuous part, and an easy way to obtain this is to pass type = "n" to plot.msr which sends it to plot.ppp . However, this still gives you a strange symbolmap on the left hand side.

Alternatively, you can use the internal spatstat function augment.msr which adds a pixel image to the residual object, and then use that image for plotting (beware that using an internal function is not guaranteed to work in future versions of spatstat ):

library(spatstat)
pattern <- rpoispp(300)
cov <- rnoise(rgen = rnorm, dimyx=32, mean=2, sd=1, w = pattern$window)
fit <- ppm(pattern ~ cov)
res <- residuals.ppm(fit, type = "raw")
plot(res, how = "imagecontour")
res <- augment.msr(res)
den <- attr(res, "smoothdensity")
plot(den)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM