Code
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
str(lansing)
## List of 6
## $ window :List of 4
## ..$ type : chr "rectangle"
## ..$ xrange: num [1:2] 0 1
## ..$ yrange: num [1:2] 0 1
## ..$ units :List of 3
## .. ..$ singular : chr "foot"
## .. ..$ plural : chr "feet"
## .. ..$ multiplier: num 924
## .. ..- attr(*, "class")= chr "unitname"
## ..- attr(*, "class")= chr "owin"
## $ n : int 2251
## $ x : num [1:2251] 0.078 0.076 0.051 0.015 0.03 0.102 0.135 0.121 0.04 0.065 ...
## $ y : num [1:2251] 0.091 0.266 0.225 0.366 0.426 0.474 0.498 0.489 0.596 0.608 ...
## $ markformat: chr "vector"
## $ marks : Factor w/ 6 levels "blackoak","hickory",..: 1 1 1 1 1 1 1 1 1 1 ...
## - attr(*, "class")= chr "ppp"
names(lansing)
## [1] "window" "n" "x" "y" "markformat"
## [6] "marks"
mytest <- quadrat.test(ants)
## Warning: Some expected counts are small; chi^2 approximation may be inaccurate
plot(mytest)
code
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)
Code
mytest
##
## Chi-squared test of CSR using quadrat counts
##
## data: ants
## X2 = 18.512, df = 23, p-value = 0.5417
## alternative hypothesis: two.sided
##
## Quadrats: 24 tiles (irregular windows)
Code
resids <- residuals(mytest)
hist(resids,
main = "Histogram of Quadrat Residuals",
xlab = "Residuals (Observed - Expected)",
col = "lightblue", border = "black")
Code
levels(marks(ants))
## [1] "Cataglyphis" "Messor"
ants_split <- split(ants)
results <- lapply(ants_split, quadrat.test)
## Warning: Some expected counts are small; chi^2 approximation may be inaccurate
## Warning: Some expected counts are small; chi^2 approximation may be inaccurate
results
## $Cataglyphis
##
## Chi-squared test of CSR using quadrat counts
##
## data: X[[i]]
## X2 = 33.133, df = 23, p-value = 0.1575
## alternative hypothesis: two.sided
##
## Quadrats: 24 tiles (irregular windows)
##
## $Messor
##
## Chi-squared test of CSR using quadrat counts
##
## data: X[[i]]
## X2 = 15.153, df = 23, p-value = 0.2219
## alternative hypothesis: two.sided
##
## Quadrats: 24 tiles (irregular windows)
Code
ants_nn <- nndist(ants, k = 1:100)
ants_ann <- colMeans(ants_nn)
sim_ppp <- rpoispp(500)
sim_nn <- nndist(sim_ppp, k = 1:100)
sim_ann <- colMeans(sim_nn)
plot(1:length(sim_ann), sim_ann,
xlab = "Neighbor Order (k)",
ylab = "Average Nearest Neighbor Distance",
main = "ANN Values for Ants vs CSR",
type = "b", pch = 19)
points(1:length(ants_ann), ants_ann, pch = 5, col = "red")
lines(1:length(ants_ann), ants_ann, col = "red", lty = 2)
legend("bottomright",
legend = c("CSR (random)", "Ants dataset"),
pch = c(19, 5), col = c("black", "red"), lty = c(1, 2))
Code
envelope(lansing, Gcross, nsim = 99, i = 'maple', j = 'hickory') |> plot()
## Generating 99 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.
##
## Done.
envelope(lansing, Kcross, nsim = 99, i = 'maple', j = 'hickory') |> plot()
## Generating 99 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.
##
## Done.
envelope(lansing, pcfcross, nsim = 99, i = 'maple', j = 'hickory') |> plot()
## Generating 99 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.
##
## Done.
Code
envelope(ants, Gcross, nsim = 50, i = 'Cataglyphis', j = 'Messor') |> plot()
## Generating 50 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.
##
## Done.
envelope(ants, Kcross, nsim = 50, i = 'Cataglyphis', j = 'Messor') |> plot()
## Generating 50 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.
##
## Done.
envelope(ants, pcfcross, nsim = 50, i = 'Cataglyphis', j = 'Messor') |> plot()
## Generating 50 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.
##
## Done.
Code
E <- envelope(longleaf, markcorr, nsim=99)
## Generating 99 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.
##
## Done.
plot(E)
Code
anemones
## Marked planar point pattern: 231 points
## marks are numeric, of storage type 'integer'
## window: rectangle = [0, 280] x [0, 180] units
E_anem <- envelope(anemones, markcorr, nsim = 99)
## Generating 99 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.
##
## Done.
plot(E_anem)