[R] envelope in spatstat
Turner Rolf
r.turner at auckland.ac.nz
Thu Apr 15 08:29:59 CEST 2010
Comments in-ine below.
Tom Richardson wrote:
Hi R users,
This query is regarding the use of the 'envelope' function in Spatstat.
My data can be represented as a point process with CONTINUOUS marks:
points <- ppp(x=x,y=y, marks=m, window= wind)
However the marks are alignments (lines), and so have to be treated
differently to normal scalar marks. Hence to create a mcf object with the
appropriate test function for alignment marks, I input 'func' (below)
suggested by Stoyan & Penttinen (1989):
func <- function(m1,m2) { sin(abs(m1-m2))^2}
mcf <- markcorr(points, func, normalise = TRUE, method="density")
So far, so good.
Really? You must have modified the markcorr() function then. In the current
release of spatstat (1.18-2) markcorr() throws an errror if the marks are a
data frame. As they must effectively be if the marks are line segments. Or
even ``lines''. You need two parameters to specify a line, four to specify a line
segment.
I also don't get what your function ``func()'' is actually doing. If m1 and m2 represent
line segments (or even lines) sin(abs(m1-m2))^2 is a vector, not a scalar as is needed by
markcorr().
If the marks really are scalars, then it is mysterious to me how they represent lines.
I am not familiar with the Stoyan and Penttinen paper to which you refer, and cannot get
access to it at this moment; perhaps things are all explained therein.
However, usinf 'envelope' and 'rlabel' I would like to
check if the pattern in the data is lost when randomly relabeling the mark
for each point. If the test function, 'func' were the usual G(m1,m2)=m1*m2,
then the following would work:
E <- envelope(points, markcorr, nsim=20,
simulate=expression(rlabel(points)))
Howeve, in the above 'markcorr' calculates G(m1,m2)=m1*m2 by default. So
need to specify the test function to be G(m1,m2)= sin(abs(m1-m2))^2.
According to the spatstat manual (p177), I may need to 'cook up' a specific
function, like this:
Kdif = function(X, ..., i) {
Kidot = Kdot(X, ..., i = i)
K = Kest(X, ...)
dif = eval.fv(Kidot - K)
return(dif)
}
E = envelope(lansing, Kdif, i='blackoak',
simulate=expression(rlabel(lansing)))
So how do I tell 'envelope' that I want to specify the mark correlation
test function ??
Be that as it may; let us assume that you have some sort of numeric marks,
so that func(m1,m2){sin(abs(m1-m2))^2} is a scalar and thereby makes sense.
And you want to use func() as the value of ``f'' in markcorr(). And you want
to do envelope() to the resulting markcorr().
Do the following:
# Generate toy data:
set.seed(42)
X <- rpoispp(100)
marks(X) <- rnorm(X$n)
# Cook up your ``specific function'':
mcspecial <- function(X,r=NULL){
markcorr(X,f=function(m1,m2){sin(abs(m1-m2))^2},r=r)
}
# Now do the envelope:
Env <- envelope(X,fun=mcspecial,simulate=expression(rlabel(X)))
cheers,
Rolf Turner
######################################################################
Attention:
This e-mail message is privileged and confidential. If you are not the
intended recipient please delete the message and notify the sender.
Any views or opinions presented are solely those of the author.
This e-mail has been scanned and cleared by MailMarshal
www.marshalsoftware.com
######################################################################
More information about the R-help
mailing list