library(spatstat)
## Loading required package: nlme
## Loading required package: rpart
##
## spatstat 1.51-0 (nickname: 'Poetic Licence')
## For an introduction to spatstat, type 'beginner'
library(ggplot2)
library(nlme)
library(rpart)
##simulator run in r console and saved as object to load into r markdown
load(file="anemone_sim.rda")
plot(density(anemone_sim), main="Complete Spatial Randomness")
points(anemone_sim,pch=20)
env <- envelope(anemone_sim, Kest, nsim = 100) #Kernel density estimator of 100 points creating the shaded region
## Generating 100 simulations of CSR ...
## 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
## 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
## 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100.
##
## Done.
plot(env,main="Complete Spatial Randomness")
The Kernel density estimator revealed that at the farthest distances, the distribution of these simulated points are slightly more clumped then they would be if they had a pattern of complete spatial randomness. However, the majority of the plot is within the margin of what you would expect under CSR.
library(spatstat)
library(ggplot2)
load(file="clumped_sim.rda")
plot(density(clumped_sim),main="clumped")
points(clumped_sim,pch=20)
env2<-envelope(clumped_sim,Kest,nsim=100)
## Generating 100 simulations of CSR ...
## 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
## 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
## 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100.
##
## Done.
plot(env2,main="clumped")
The density plot right away shows these simulatred points have a more clustered pattern than CSR and the line for the point pattern distribution is far above the KDE expected for CSR.
load(file="uniform_sim.rda")
plot(density(uniform_sim), main="clumped then uniform")
points(uniform_sim,pch=20)
env3<-envelope(uniform_sim,Kest,nsim=100)
## Generating 100 simulations of CSR ...
## 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
## 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
## 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100.
##
## Done.
plot(env3,main="Clumped then uniform") ##clumped at close distances and uniform at far distances!!!
This point pattern is clumped at close distances and uniform at farther distances
load(file="uniform2_sim.rda")
plot(density(uniform2_sim),main="uniform")
points(uniform2_sim,pch=20)
env4<-envelope(uniform2_sim,Kest,nsim=100)
## Generating 100 simulations of CSR ...
## 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
## 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
## 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100.
##
## Done.
plot(env4,main="uniform")
This distribution is uniform and the line appears lower than the window expected for CSR, indicating uniform or repulsive patterns.
library(spatstat)
library(rpart)
data(anemones) #The data for these Beadlet anemones came form the north face of a single boulder in the high intertidal zone in Bretagne, France May 1976.Thsi appears to be a marked point pattern, with the size of circle point in the plot below corresponding to a size legend.
plot(anemones)
plot(density(anemones),main="Anemones by diameter")
env5<-envelope(anemones,Kest,nsim=100)
## Generating 100 simulations of CSR ...
## 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
## 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
## 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100.
##
## Done.
plot(env5,main="Anemones ")
Anemones appear to be repulsed at closer distances and then conform to CSR.Next lets try subsetting the data by marks based on their diameter
bigs<- subset(anemones, marks>5)#all anemones greater than 5cm in diameter
head(bigs)
## Marked planar point pattern: 6 points
## marks are numeric, of storage type 'integer'
## window: rectangle = [0, 280] x [0, 180] units
plot(envelope(bigs, fun = Kest, nsim= 10,verbose=FALSE),main="Big anemones")
smalls<-subset(anemones,marks<5)
head(smalls)
## Marked planar point pattern: 6 points
## marks are numeric, of storage type 'integer'
## window: rectangle = [0, 280] x [0, 180] units
plot(envelope(bigs,fun=Kest,nsim=10,verbose=FALSE))