Dear Adrian and Rolf,

Thank you for solving this problem fast.

Best regards,

Thierry

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium
+ 32 2 525 02 51
+ 32 54 43 61 85
Thierry.Onkelinx@inbo.be<mailto:Thierry.Onkelinx@inbo.be>
www.inbo.be<http://www.inbo.be/>

To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey

Van: Adrian.Baddeley@csiro.au [mailto:Adrian.Baddeley@csiro.au]
Verzonden: maandag 16 januari 2012 4:55
Aan: r.turner@auckland.ac.nz; ONKELINX, Thierry
CC: r-sig-geo@stat.math.ethz.ch
Onderwerp: RE: Unexpected output from distfun

Yes, this is correct.

There is a bug in nncross: the value of nncross(X,Y) may be incorrect if X and Y do not have the same window.
This affects distfun.ppp and it may also affect areaGain, areaLoss, AreaInter.

Rolf's fix is correct. For efficiency it would be better to take the value of 'huge' in nncross to be

     diameter(union.owin(as.rectangle(X), as.rectangle(Y)))

i.e. using as.rectangle(X) instead of as.owin(X) to avoid geometry computations.

This will be fixed in the next version of spatstat (1.25-2) to be released this week

Thanks for drawing this to our attention

Adrian Baddeley


________________________________
From: Rolf Turner [mailto:r.turner@auckland.ac.nz]
Sent: Sunday, 15 January 2012 11:16 AM
To: ONKELINX, Thierry
Cc: r-sig-geo@stat.math.ethz.ch; Baddeley, Adrian (CMIS, Floreat)
Subject: Re: Unexpected output from distfun

Okay --- I think I've tracked it down.  The problem is (I believe) with the value
of "huge" in the nncross() function --- which just isn't huge enough.  It was taken
to be the diameter of X$window, which could in fact be quite small relative to
the distances between the points of X and the points of Y (and will in fact be
*zero* when applying the function returned by distfun() if the argument to
distfun() has only one point).

I've amended nncross() to take "huge" to be the diameter of

    union.owin(X$window,Y$window)

This seems to work ... although there may be a better strategy.  (Over to you,
Adrian).

I have attached my amended version of nncross, which you can source into
you can use until a release of "spatstat" containing this, or a more appropriate fix
comes out.

Note that you need to do

    assignInNamespace("nncross",nncross,"spatstat")

after sourcing in nncross.R, otherwise distfun() will use the "old" version of nncross
rather than the amended one.  And you have to (psigh!) do the assignInNamespace()
thing each time you start a new R session, in order to get the right nncross() function
being called.

    cheers,

        Rolf Turner

On 15/01/12 11:55, ONKELINX, Thierry wrote:
Dear all,

I'm not getting the output I'm expecting when using distfun() from the spatstat package. Any idea what is going wrong?

Best regards,

Thierry

library(spatstat)
w <- owin(xrange = c(-10, 10), yrange = c(-10, 10))
P <- ppp(x = 0, y = 0, window = w)
P1 <- ppp(x = 1, y = 0, window = w)
P2 <- ppp(x = 1:2, y = c(1, 1), window = w)
P3 <- ppp(x = 2:1, y = c(2, 2), window = w)
f <- distfun(P)
f2 <- distfun(P2)
fo <- list(f(P1), f(P2), f(P3))
fo2 <- list(f2(P), f2(P1), f2(P3))

> fo
[[1]]
[1] 0

[[2]]
[1] 1 1

[[3]]
[1] 1 1

> fo2
[[1]]
[1] 0

[[2]]
[1] 0

[[3]]
[1] 1 1

> sessionInfo()
R version 2.14.1 (2011-12-22)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=nl_BE.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=nl_BE.UTF-8        LC_COLLATE=nl_BE.UTF-8
 [5] LC_MONETARY=nl_BE.UTF-8    LC_MESSAGES=nl_NL.UTF-8
 [7] LC_PAPER=C                 LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=nl_BE.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] spatstat_1.25-1 deldir_0.0-16   mgcv_1.7-12

loaded via a namespace (and not attached):
[1] grid_2.14.1    lattice_0.20-3 Matrix_1.0-3   nlme_3.1-102


	[[alternative HTML version deleted]]

