library(spatstat)
## Warning: package 'spatstat' was built under R version 4.3.2
## Loading required package: spatstat.data
## Warning: package 'spatstat.data' was built under R version 4.3.2
## Loading required package: spatstat.geom
## Warning: package 'spatstat.geom' was built under R version 4.3.2
## spatstat.geom 3.2-8
## Loading required package: spatstat.random
## Warning: package 'spatstat.random' was built under R version 4.3.2
## spatstat.random 3.2-2
## Loading required package: spatstat.explore
## Warning: package 'spatstat.explore' was built under R version 4.3.2
## Loading required package: nlme
## spatstat.explore 3.2-5
## Loading required package: spatstat.model
## Warning: package 'spatstat.model' was built under R version 4.3.2
## Loading required package: rpart
## spatstat.model 3.2-8
## Loading required package: spatstat.linnet
## Warning: package 'spatstat.linnet' was built under R version 4.3.2
## spatstat.linnet 3.1-3
## 
## spatstat 3.0-7 
## For an introduction to spatstat, type 'beginner'
data("ants")
ants
## Marked planar point pattern: 97 points
## Multitype, with levels = Cataglyphis, Messor 
## window: polygonal boundary
## enclosing rectangle: [-25, 803] x [-49, 717] units (one unit = 0.5 feet)
plot(ants)
title("Ants")

plot(split(ants))

Metode Kuadran

quad1 = quadratcount(split(ants))
plot(quad1)

catag<-quad1[[1]]
mess<-quad1[[2]]
Obs<-matrix(NA,2,2)
rownames(Obs)<-c("A","0")
colnames(Obs)<-c("B","0")
Obs[1,1]<-sum(((catag>0)+(mess>0))==2) #ab
Obs[2,1]<-sum(((catag>0)-(mess>0))==1) #a0
Obs[1,2]<-sum(((catag>0)-(mess>0))==-1) #0b
Obs[2,2]<-sum(((catag>0)+(mess>0))==0) #00
Tes<-chisq.test(Obs)
## Warning in chisq.test(Obs): Chi-squared approximation may be incorrect
chisqhitung<-sum((Obs-Tes$expected)^2/Tes$expected)
chistabel<-qchisq(0.05,df=1,lower.tail=F)
p_valuechi<-pchisq(chisqhitung,1,lower.tail=F)
chisq.test(Obs, correct = F)
## Warning in chisq.test(Obs, correct = F): Chi-squared approximation may be
## incorrect
## 
##  Pearson's Chi-squared test
## 
## data:  Obs
## X-squared = 11.2, df = 1, p-value = 0.000818

Berarti cukup bukti untuk menolak H0 sehingga dapat disimpulkan sebaran spasial antara kedua spesies tidak saling bebas, atau saling berkorelasi.

Metode K-function

unique(ants$marks)
## [1] Messor      Cataglyphis
## Levels: Cataglyphis Messor
Kh <- Kdot(ants, "Messor")
plot(Kh)

Diagnostic plot for independence between mesor and other species

f1 <- function(X) { marks(X) == "Messor"}
f2 <- function(X) { marks(X) == "Cataglyphis"}
K <- Kmulti(ants,f1,f2)
plot(K)

plot(envelope(ants, Kdot,
i="Messor",
nsim=99,
fix.n=T, fix.marks=T))
## Generating 99 simulations of CSR with fixed number of points of each type  ...
## 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.
## 
## Done.

Antara species messor dengan cataglyphis

plot(envelope(ants, Kmulti,
I=f1, J=f2, nsim=99,
fix.n=T, fix.marks=T))
## Generating 99 simulations of CSR with fixed number of points of each type  ...
## 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.
## 
## Done.

Akan dilakukan uji MAD (Mean Absolute Deviation)

mad.test(ants, Kcross, i="Messor", j="Cataglyphis", nsim=99,
fix.n=T, fix.marks=T)
## Generating 99 simulations of CSR with fixed number of points of each type  ...
## 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.
## 
## Done.
## 
##  Maximum absolute deviation test of CSR
##  Monte Carlo test based on 99 simulations with fixed number of points of
##  each type
##  Summary function: "K"["Messor", "Cataglyphis"](r)
##  Reference function: theoretical
##  Alternative: two.sided
##  Interval of distance values: [0, 191.5] units (one unit = 0.5 feet)
##  Test statistic: Maximum absolute deviation
##  Deviation = observed minus theoretical
## 
## data:  ants
## mad = 5161, rank = 78, p-value = 0.78

Lansing Wood Data

data("lansing")
lansing
## Marked planar point pattern: 2251 points
## Multitype, with levels = blackoak, hickory, maple, misc, redoak, whiteoak 
## window: rectangle = [0, 1] x [0, 1] units (one unit = 924 feet)
summary(lansing)
## Marked planar point pattern:  2251 points
## Average intensity 2251 points per square unit (one unit = 924 feet)
## 
## *Pattern contains duplicated points*
## 
## Coordinates are given to 3 decimal places
## i.e. rounded to the nearest multiple of 0.001 units (one unit = 924 feet)
## 
## Multitype:
##          frequency proportion intensity
## blackoak       135 0.05997335       135
## hickory        703 0.31230560       703
## maple          514 0.22834300       514
## misc           105 0.04664594       105
## redoak         346 0.15370950       346
## whiteoak       448 0.19902270       448
## 
## Window: rectangle = [0, 1] x [0, 1] units
## Window area = 1 square unit
## Unit of length: 924 feet
plot(lansing)

plot(split(lansing))

plot(density(split(lansing)), ribbon = T)

hick = split(lansing)$hickory
plot(hick)

Metode Kuadran

z <-(quadratcount(split(lansing)))
plot(z)

Kh. <- Kdot(lansing,"hickory")
plot(Kh.)