spatstat sub-selection

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

spatstat sub-selection

Tom_R
Fellow Users,

In Spatstat, if you have a ppp object with, say 100 points, how do you create another ppp containing a random selection, N, of the original?

You can tell the function 'rthin' to make a sub-selection of points, i.e. "every point is removed with probability 0.5" but you CAN'T set N exactly...

I'm sure this should be easy...

Ta!

Tom
Reply | Threaded
Open this post in threaded view
|

Re: spatstat sub-selection

Joris FA Meys
You can't specify it in rthin, which I can understand for the simple
reason that this violates the independence of the sampling. If you put
a fixed limit on your resampling, the chance of being selected depends
on when some point is selected.

You could do it by hacking the object :

rthin.exact <- function(x,n){
    l <- x$n
    i <- sample(1:l,n,replace=F)
    x$n <- n
    x$x <- x$x[i]
    x$y <- x$y[i]
    return(x)
}

data(redwood)
plot(redwood, main="thinning")

  # keep 30 points
  Y <- rthin.exact(redwood, 30)
  points(Y, col="green", cex=1.4)

Cheers
Joris

On Sun, Jun 6, 2010 at 12:26 AM, Tom_R <[hidden email]> wrote:

>
> Fellow Users,
>
> In Spatstat, if you have a ppp object with, say 100 points, how do you
> create another ppp containing a random selection, N, of the original?
>
> You can tell the function 'rthin' to make a sub-selection of points, i.e.
> "every point is removed with probability 0.5" but you CAN'T set N exactly...
>
> I'm sure this should be easy...
>
> Ta!
>
> Tom
> --
> View this message in context: http://r.789695.n4.nabble.com/spatstat-sub-selection-tp2244619p2244619.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



--
Ghent University
Faculty of Bioscience Engineering
Department of Applied mathematics, biometrics and process control

tel : +32 9 264 59 87
[hidden email]
-------------------------------
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.