I am trying to obtain the mean value of the marks in each point counting all the points available at certain distance around each point and including the point from where we are measuring.
I have used markmean() {spatstats} with a buffer but I am unsure if it is doing what I want to do.
Here a simple example of what I am trying to do:
library(spatstat)
p <- c(1:25) #points ID
x <- c(4,4,4,4,4,3,3,3,3,3,2,2,2,2,2,1,1,1,1,1,0,0,0,0,0) #x location
y <- c(0,1,2,3,4,0,1,2,3,4,0,1,2,3,4,0,1,2,3,4,0,1,2,3,4) #y location
i <- c(0,0,0,0,0,0,0,0,0,0,0,0,60,40,0,0,0,0,0,0,0,0,0,0,0) #mark or value in each point
w <- owin(c(0,4), c(0,4))# window needed to create ppp
table <- data.frame(p,x,y,i)
ppptable.Mark <- ppp( table$x, table$y,
marks = table$i,
window = w )
meanmarkstable <- markmean (ppptable.Mark, sigma=1, at="points")
tableresults <- cbind(table,meanmarkstable )
The spatial point look something like this:
Point distribution with IDs and marks (marks are in point 13=60,in point 14=40, for the rest of the points the mark is 0 Of course my real data does not follow a regular pattern, so the distance between points is variable.
I would expect that for the point 13 with sigma 1, the markmean is: (60+40+0+0+0)/5= 20 or that for the point 7 the mark mean is: (60+0+0+0+0)/5= 12.
But following the above code I get:
p x y i meanmarkstable
1 1 4 0 0 0.5588339
2 2 4 1 0 1.8035799
3 3 4 2 0 3.3992581
4 4 4 3 0 3.2959390
5 5 4 4 0 2.1132312
6 6 3 0 0 1.6559496
7 7 3 1 0 5.5518658
8 8 3 2 0 10.5182801
9 9 3 3 0 10.1597853
10 10 3 4 0 6.2832065
11 11 2 0 0 2.5529727
12 12 2 1 0 8.6038936
13 13 2 2 60 4.7103612
14 14 2 3 40 7.6160733
15 15 2 4 0 10.0581368
16 16 1 0 0 1.6560550
17 17 1 1 0 5.5599181
18 18 1 2 0 10.6956613
19 19 1 3 0 11.0335128
20 20 1 4 0 7.7616822
21 21 0 0 0 0.5589243
22 22 0 1 0 1.8099875
23 23 0 2 0 3.5421055
24 24 0 3 0 4.0856978
25 25 0 4 0 2.1128894
Do you know why I am getting these results? How would you calculate correctly the mean of the marks around each point within certain buffer?
Thank you very much in advance for your time and help!