after running as.ppp(), all points lying outside the window

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

after running as.ppp(), all points lying outside the window

Musa, Kamarul Imran
Dear all,

I was trying to plot 1135 points using spatstat package. The data points were in the CSV file, and I would like to convert them to a ppp object so I can run relrisk().  Unfortunately, after running as.ppp(), I received a warning message and when plotted, all the points were lying outside the rectangle window. I have been looking for answers elsewhere but could not find the right one for me, so I hope if anyone can help, then I would be grateful.

The file is in the dropbox folder (https://www.dropbox.com/s/90yxvd5cwnvbty8/stroke_typhoid_RSO2.csv?dl=0) for those interested to download. But the codes and results that I have run are listed below:

1) When I run str(), it gives these:

> str(str_typ)
'data.frame': 1135 obs. of  3 variables:
 $ mark: int  1 2 2 2 2 2 2 1 2 2 ...
 $ x   : int  388992 422451 429127 430811 432153 432153 432306 432862 432887 433456 ...
 $ y   : int  516003 575800 627691 629927 624186 624186 617470 638829 615294 607246 ...

2) The summary returns these:

> summary(str_typ)
      mark             x                          y        
 Min.   :1.000   Min.   :388992      Min.   :516003  
 1st Qu.:1.000   1st Qu.:467048   1st Qu.:660183  
 Median :1.000   Median :474740   Median :669192  
 Mean   :1.303   Mean   :473189   Mean   :664687  
 3rd Qu.:2.000   3rd Qu.:481698   3rd Qu.:676389  
 Max.   :2.000   Max.   :503274   Max.   :689283  

3) To create the Window, I used this:

Win <- owin(c(388992,503274), c(516002,689283))

4) Then, I run as.ppp()
 
> str_typ2 <- as.ppp(str_typ, W = Win)
Warning message:
1135 points were rejected as lying outside the specified window

5) When I run plot()
> plot(str_typ2)
Warning message:
In plot.ppp(str_typ2) : 1135 illegal points also plotted

6) What I could see is that all points were lying outside the rectangle box.

Best regards,
Kamarul
USM, Malaysia



         
_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: after running as.ppp(), all points lying outside the window

Barry Rowlingson
On Wed, Apr 5, 2017 at 8:27 AM, Musa, Kamarul Imran
<[hidden email]> wrote:
> str_typ2 <- as.ppp(str_typ, W = Win)

as.ppp is using the first two columns of your data frame for
coordinates, the first one in yours is the mark!

So you have:

 > str_typ = data.frame(mark=sample(2,1135,TRUE), x=runif(1135,388992,
503274), y=runif(1135, 516003, 689283))
 > Win <- owin(c(388992,503274), c(516002,689283))
 > str_typ2 <- as.ppp(str_typ, W = Win)
Warning message:
1135 points were rejected as lying outside the specified window

But do the data frame with x,y,mark and it works:

 > str_typ = data.frame(x=runif(1135,388992, 503274), y=runif(1135,
516003, 689283), mark=sample(2,1135,TRUE))
 > str_typ2 <- as.ppp(str_typ, W = Win)

Probably better to use `ppp()` to construct a marked `ppp` object:

  str_typ2 <- ppp(x=str_typ$x, y=str_typ$y, marks=str_typ$mark, window=Win)

Note the window argument is `window=` here, in other places in
`spatstat` its `W` or `Win` or other things!

Barry

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: after running as.ppp(), all points lying outside the window

Musa, Kamarul Imran
Dear Barry,

It works! I must make sure that the coordinates are correctly specified and positioned. And that I need to use 'window' and not 'W' in the arguments. Really appreciate your help.

Regards,
Kamarul

________________________________________
From: [hidden email] [[hidden email]] on behalf of Barry Rowlingson [[hidden email]]
Sent: Wednesday, April 05, 2017 5:46 PM
To: Musa, Kamarul Imran
Cc: [hidden email]
Subject: Re: [R-sig-Geo] after running as.ppp(), all points lying outside the window

On Wed, Apr 5, 2017 at 8:27 AM, Musa, Kamarul Imran
<[hidden email]> wrote:
> str_typ2 <- as.ppp(str_typ, W = Win)

as.ppp is using the first two columns of your data frame for
coordinates, the first one in yours is the mark!

So you have:

 > str_typ = data.frame(mark=sample(2,1135,TRUE), x=runif(1135,388992,
503274), y=runif(1135, 516003, 689283))
 > Win <- owin(c(388992,503274), c(516002,689283))
 > str_typ2 <- as.ppp(str_typ, W = Win)
Warning message:
1135 points were rejected as lying outside the specified window

But do the data frame with x,y,mark and it works:

 > str_typ = data.frame(x=runif(1135,388992, 503274), y=runif(1135,
516003, 689283), mark=sample(2,1135,TRUE))
 > str_typ2 <- as.ppp(str_typ, W = Win)

Probably better to use `ppp()` to construct a marked `ppp` object:

  str_typ2 <- ppp(x=str_typ$x, y=str_typ$y, marks=str_typ$mark, window=Win)

Note the window argument is `window=` here, in other places in
`spatstat` its `W` or `Win` or other things!

Barry

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