Hi Dr Baddeley,

I have a spatstat query (below & attached .txt). I thought to email you first, rather than R-Help or R-Sig-Geo as (I think?) we're supposed to ask the package maintainers first...

I wonder if you could please take a look at the code below & offer your thoughts or suggestions?

My query regards the creation of a randomised multitype ppp when different marks have different sizes. The presence of marks with particular sizes introduces geometrical constraints into the randomisation procedure because i don't want any overlaps between the points.

Many thanks in advance!!
Tom Richardson


### Load data
multitype_ppp <- ppp(x=x,y=y, marks=type)    ##
A <- ppp(x=x[type==A],y=y[type==A])  ##  radii for type A ~ 0.6
B <- ppp(x=x[type==B],y=y[type==B])  ##  radii for type B ~ 1.64
# etc.... there are other types- excluded here for clarity

## create intensity map for the multitype_ppp & also for those points of type A

lambda_dot <- as.im(adaptive.density(multitype_ppp, correction = c("translate"), nrep=100, f=0.5 ))
lambda_I   <- as.im(adaptive.density(A, nrep=50, f=0.1  ))

########### Random Labelling, for K-dot function ############################### ########### Under random labelling, Ki•(r) = K(r), where K, is the summary ##### ########### function for the point process without marks ######################

KDIFF <- function (X, ..., i)
        {
Kidot <- Kdot.inhom(X, ..., i= i, lambdaI=lambda_I , lambdadot=lambda_dot)
        Kinh      <- Kinhom    (X, ...,       lambda=lambda_dot  )
        dif       <- eval.fv  (Kidot - Kinh)
        return(dif)
        }

## Create 95% C.I. envelope for to test random-labelling hypothesis of "type_A-to-any"

envelopes_A <- envelope(multitype_ppp, KDIFF, i="mark_A", nsim = 39, simulate = expression(rlabel(multitype_ppp)))

## THE END ###

The command "simulate=expression(rlabel(multitype_ppp))" reallocates the identities (A or B) amongst all points in 'multitype_ppp'. This would be suitable if the marks were something like 'red'/'blue', or 'on'/'off'. However, in my data the marks are the radii of the objects (0.6 & 1.64 mm). Thus simply shuffling the marks amongst the x,y, coordinates in this way sometimes results in the disc associated with each point overlapping other discs! This is not realistic. Therefore I need an alternative procedure to generate a randomised multitype_ppp based on the original, but without overlaps.

I thought of the following:

## intesnity maps again:
lambda_dot <- as.im(adaptive.density(multitype_ppp, correction = c("translate"), nrep=100, f=0.5 ))
lambda_A   <- as.im(adaptive.density(A, nrep=50, f=0.5  ))
lambda_B   <- as.im(adaptive.density(B, nrep=50, f=0.5  ))

## create inhomogeneous ppp's for A & B basaed on the original ones, in which there are no A-A or B-B overlaps Hard_A <- ppm(points, ~ polynom(x,y,2) + Z , covariates=list(Z=lambda_A), Hardcore(0.6) )
## create a ppp in which there are no overlaps between points of type B
Hard_B <- ppm(points, ~ polynom(x,y,2) + Z , covariates=list(Z=lambda_B), Hardcore(1.64) )
## Now combine them
multitype_ppp2 <- superimpose(Hard_A, Hard_B)

HOWEVER, this does not exclude the possibility that there will be A-B & B-A overlaps !

Alternatively one could use rshift until the minimum A-B NND is >= 0.6+1.64. However, if rshift has to be performed multiple times, the resulting point patterns may have quite different underlying intensity maps, i.e. they will no longer be representative samples from lambda_A or lambda_B !!

Basically, I'm stuck...




Hi Dr Baddeley,

I hope you are well. I have a spatstat query
I wonder if you could take a  look at the below. My query regards the creation 
of a randomised multitype ppp when different marks have different sizes. The 
presence of marks with particular sizes introduces geometrical constraints into 
the randomisation procedure because i don't want any overlaps between the 
points.
Many tahnks in advance!!
Tom Richardson

### Load data
multitype_ppp <- ppp(x=x,y=y, marks=type)       ## 
A <- ppp(x=x[type==A],y=y[type==A])     ##  radii for type A ~ 0.6
B <- ppp(x=x[type==B],y=y[type==B])     ##  radii for type B ~ 1.64
# etc.... there are other types- excluded here for clarity

## create intensity map for the multitype_ppp & also for those points of type A

lambda_dot <- as.im(adaptive.density(multitype_ppp, correction = 
c("translate"), nrep=50, f=0.1  ))
lambda_I   <- as.im(adaptive.density(A, nrep=50, f=0.5  ))

########### Random Labelling, for K-dot function ###############################
########### Under random labelling, Ki�(r) = K(r), where K, is the summary #####
########### function for the point process without marks  ######################

KDIFF <- function (X, ..., i)
        {
        Kidot     <- Kdot.inhom(X, ..., i= i, lambdaI=lambda_I , 
lambdadot=lambda_dot)
        Kinh      <- Kinhom    (X, ...,       lambda=lambda_dot  )
        dif       <- eval.fv  (Kidot - Kinh)
        return(dif)
        }

## Create 95% C.I. envelope for to test random-labelling hypothesis of 
"type_A-to-any"

envelopes_A <- envelope(multitype_ppp, KDIFF, i="mark_A", nsim = 39,  simulate 
= expression(rlabel(multitype_ppp)))

## THE END ###

The command "simulate=expression(rlabel(multitype_ppp))" reallocates the 
identities (A or B) amongst all points in 'multitype_ppp'. This would be 
suitable if the marks were something like 'red'/'blue', or 'on'/'off'. However, 
in my data the marks are the radii of the objects (0.6 & 1.64 mm). Thus simply 
shuffling the marks amongst the x,y, coordinates in this way sometimes results 
in the disc associated with each point overlapping other discs! This is not 
realistic. Therefore I need an alternative  procedure to generate a randomised 
multitype_ppp based on the original, but without overlaps. 

I thought of the following:

## intesnity maps again: 
lambda_dot <- as.im(adaptive.density(multitype_ppp, correction = 
c("translate"), nrep=50, f=0.1  ))
lambda_A   <- as.im(adaptive.density(A, nrep=50, f=0.1  ))
lambda_B   <- as.im(adaptive.density(B, nrep=50, f=0.1  ))

## create inhomogeneous ppp's for A & B basaed on the original ones, in which 
there are no A-A or B-B overlaps
Hard_A   <- ppm(points, ~ polynom(x,y,2) + Z , covariates=list(Z=lambda_A), 
Hardcore(0.6) )
## create a ppp in which there are no overlaps between points of type B
Hard_B   <- ppm(points, ~ polynom(x,y,2) + Z , covariates=list(Z=lambda_B), 
Hardcore(1.64) )
## Now combine them
multitype_ppp2 <- superimpose(Hard_A, Hard_B)

However, this does not exclude the possibility that there will be A-B & B-A 
overlaps ! 

Alternatively one could use rshift until the minimum A-B NND is >= 0.6+1.64. 
However, if rshift has to be performed multiple times, the resulting point 
patterns may have quite different underlying intensity maps, i.e. they will no 
longer be representative samples from lambda_A or lambda_B !!

Basically, I'm stuck...



_______________________________________________
R-sig-Geo mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to