0

I have a data frame

df <- data.frame(x = rep(seq(1:10), 10), y = rep(seq(1:10), each = 10), diameter = rnorm(100, 0.3, 0.03), height = rnorm(100, 0.2, 001))

that I want to convert to the pppfile by means of the ppp of spatstat package. I want that the diameter and height variables are marks and I can not do this. I tried f.ex this

pp1<-ppp(df$x, df$y,  marks = data.frame(df %>% select(diameter, height)))

but does not work.

The output I want to have is similar to the data file finepines that is attached to the spatstat package

> finpines
Marked planar point pattern: 126 points
Mark variables: diameter, height 
window: rectangle = [-5, 5] x [-8, 2] metres
Mateusz1981
  • 1,817
  • 17
  • 33
  • Please elaborate a little more on your statement "but does not work". Thank you. – nilsole Oct 10 '16 at 10:12
  • The warning message described in my answer has been a topic here before: http://stackoverflow.com/questions/18025517/point-patterns-in-spatstat#comment26367832_18025517 – nilsole Oct 10 '16 at 10:15

2 Answers2

5

You need to define the observation window before you can define a planar point pattern ppp since we need to know both where points were observed and where there were no points. E.g. the intensity of the process is the average number of points per area so we need to know the area of the study region.

In your example I will assume the study region (observation window) is [0, 11] x [0, 11]. Then you can do:

library(spatstat)
df <- data.frame(x = rep(seq(1:10), 10),
                 y = rep(seq(1:10), each = 10),
                 diameter = rnorm(100, 0.3, 0.03),
                 height = rnorm(100, 0.2, 001))
W <- owin( c(0, 11), c(0,11) )
pp1 <- as.ppp( df, W = W)
Ege Rubak
  • 4,347
  • 1
  • 10
  • 18
0

You may try this, but I cannot judge whether you can accept this warning:

Warning message: In ppp(df$x, df$y, marks = data.frame(df %>% select(diameter, height))) : 99 points were rejected as lying outside the specified window

library(spatstat)
library(dplyr)
df <- data.frame(x = rep(seq(1:10), 10), y = rep(seq(1:10), each = 10), diameter = rnorm(100, 0.3, 0.03), height = rnorm(100, 0.2, 001))
pp1<-ppp(df$x, df$y,  marks = data.frame(df %>% select(diameter, height)))

The output is:

> pp1
Marked planar point pattern: 1 point
Mark variables: diameter, height 
window: rectangle = [0, 1] x [0, 1] units
*** 99 illegal points stored in attr(,“rejects”) ***
nilsole
  • 1,663
  • 2
  • 12
  • 28