Problem 1

plot(rpoispp(500))

Alternate Way 1

pp <- rpoispp(500)
plot(pp)

Alternate Way 2

with(list(pp = rpoispp(500)), plot(pp))

Problem 2

pp <- rpoispp(500)
plot(density(pp))
contour(density(pp), 
        add=T)
plot(pp, add=T)

Add=T includes the density heat map and contour lines. Without add=T, it would appear like the plain plot in Problem 1.

Problem 3

plot(quadratcount(pp, nx = 10, ny = 10))

This displays the number of events found in a grid of equally-sized sampling areas. The numbers inside the squares represent how many events are found in that particular sampling area.

Problem 4

Testing for complete spatial randomness:

quadrat.test(rpoispp(500), nx = 20, ny = 20)
## Warning: Some expected counts are small; chi^2 approximation may be inaccurate
## 
##  Chi-squared test of CSR using quadrat counts
## 
## data:  rpoispp(500)
## X2 = 381.34, df = 399, p-value = 0.5412
## alternative hypothesis: two.sided
## 
## Quadrats: 20 by 20 grid of tiles
N Points N Grid Cells P-Values P Interpretation
368.6 400 0.2797 Random
394.66 400 0.8961 Random
415.43 400 0.5502 Random

Problem 5/6

pp <- rpoispp(function(x,y) 
  {200*x + 200*y}) 
quadrat.test(pp, nx=8, ny=8) 
## Warning: Some expected counts are small; chi^2 approximation may be inaccurate
## 
##  Chi-squared test of CSR using quadrat counts
## 
## data:  pp
## X2 = 88.897, df = 63, p-value = 0.03504
## alternative hypothesis: two.sided
## 
## Quadrats: 8 by 8 grid of tiles
plot(density(pp)) 
plot(pp, pch = 1, add = TRUE)

P-Value P Interpretation
5.432e-07 Clustering/Not Random
0.0003312 Clustering/Not Random
0.004137 Clustering/Not Random

As the number of grid cells in my quadrat test increases (15x15, 50x50, 100x100), the P-Values also increase, meaning an increase in spatial randomness.

Problem 7

plot(split(lansing))

The lansing study area is 924 x 924 (853,776) square feet.

Problem 8

There are 2251 trees in the lansing data set.

Problem 9

In the lansing data set, Blackoak trees are the least abundant and hickory trees are the most abundant.

Problem 10

Hickory:

hickory <- split(lansing)$hickory

plot(density(hickory))
contour(density(hickory), add = TRUE)

Maple:

maple <- split(lansing)$maple

plot(density(maple))
contour(density(maple), add = TRUE)

Redoak:

redoak <- split(lansing)$redoak

plot(density(redoak))
contour(density(redoak), add = TRUE)

Blackoak:

blackoak <- split(lansing)$blackoak

plot(density(blackoak))
contour(density(blackoak), add = TRUE)

The patterns for the most abundant species (hickory and maple) and the least abundant species (redoak and blackoak) are all aggregated or clustered.

Problem 11

Hickory:

quadrat.test(hickory, nx = 8, ny = 8)
## 
##  Chi-squared test of CSR using quadrat counts
## 
## data:  hickory
## X2 = 318.91, df = 63, p-value < 2.2e-16
## alternative hypothesis: two.sided
## 
## Quadrats: 8 by 8 grid of tiles

Maple

quadrat.test(maple, nx = 8, ny = 8)
## 
##  Chi-squared test of CSR using quadrat counts
## 
## data:  maple
## X2 = 352.12, df = 63, p-value < 2.2e-16
## alternative hypothesis: two.sided
## 
## Quadrats: 8 by 8 grid of tiles

Redoak

quadrat.test(redoak, nx = 8, ny = 8)
## 
##  Chi-squared test of CSR using quadrat counts
## 
## data:  redoak
## X2 = 141.95, df = 63, p-value = 1.01e-07
## alternative hypothesis: two.sided
## 
## Quadrats: 8 by 8 grid of tiles

Maple

quadrat.test(blackoak, nx = 8, ny = 8)
## Warning: Some expected counts are small; chi^2 approximation may be inaccurate
## 
##  Chi-squared test of CSR using quadrat counts
## 
## data:  blackoak
## X2 = 182.16, df = 63, p-value = 3.27e-13
## alternative hypothesis: two.sided
## 
## Quadrats: 8 by 8 grid of tiles

Quadratic Test Table

Tree P-Value P Interpretation
Hickory 0.0001055 Clustered/Not Random
Maple 2.2e-16 Clustered/Not Random
Redoak 1.01e-07 Clustered/Not Random
Blackoak 3.27e-13 Clustered/Not Random

Problem 12

quadrat.test(hickory, nx = 5, ny = 5)
## 
##  Chi-squared test of CSR using quadrat counts
## 
## data:  hickory
## X2 = 233.45, df = 24, p-value < 2.2e-16
## alternative hypothesis: two.sided
## 
## Quadrats: 5 by 5 grid of tiles
quadrat.test(hickory, nx = 20, ny = 20)
## Warning: Some expected counts are small; chi^2 approximation may be inaccurate
## 
##  Chi-squared test of CSR using quadrat counts
## 
## data:  hickory
## X2 = 766.7, df = 399, p-value < 2.2e-16
## alternative hypothesis: two.sided
## 
## Quadrats: 20 by 20 grid of tiles
quadrat.test(hickory, nx = 50, ny = 50)
## Warning: Some expected counts are small; chi^2 approximation may be inaccurate
## 
##  Chi-squared test of CSR using quadrat counts
## 
## data:  hickory
## X2 = 2906.5, df = 2499, p-value = 4.082e-08
## alternative hypothesis: two.sided
## 
## Quadrats: 50 by 50 grid of tiles

The results are not robust to quadrat size, as different grid resolutions lead to different conclusions. Rather, they suggest that hickory trees exhibit scale-dependent clustering, which is picked up at some quadrat sizes but not at others.

Problem 13

plot(apply(nndist(rpoispp(500), k=1:500), 2, FUN = mean))

Alternate Way 1

pp <- rpoispp(500)
nn <- nndist(pp, k = 1:500)
plot(colMeans(nn), type = "l",
     xlab = "k-th neighbor", ylab = "Mean distance")

Alternate Way 2

pp <- rpoispp(500)
means <- sapply(1:500, function(k) mean(nndist(pp, k = k)))
plot(1:500, means, type = "l",
     xlab = "k-th neighbor", ylab = "Mean distance")

Frequency histogram of nearest neighbor distances:

hist(apply(nndist(rpoispp(500), k=1:500), 2, FUN = mean))

Problem 14

plot(apply(nndist(rpoispp(500), k=1:100), 2, FUN = mean),
       xlab = "Neighbor Order (k)",
       ylab = "Average Nearest Neighbor Distance",
       main = "ANN Values for Different Neighbor Orders",
       type = "b",                 # Plot points connected by lines
       pch = 19)                   # Solid circles for points
  nn_distances <- nndist(split(lansing)$maple, k = 1:100)
  ann_values <- colMeans(nn_distances)
  points(1:length(ann_values), ann_values,
       pch = 5)                         #Open squares for points

Since the two curves of both the random (null) mean-nearest-neighbor plot and the nearest neighbor plot are so similar, it means the maple trees in this landscape are likely randomly distributed.

Problem 15

n <- npoints(cells)
pp <- rpoispp(n)
plot(apply(nndist(pp, k = 1:n), 2, mean))
nn_distances <- nndist(cells, k = 1:n)
lines(1:n, colMeans(nn_distances), col = "red")

Problem 16

plot(Gest(rpoispp(500)))

pp <- rpoispp(function(x,y) {200*x + 200*y})
plot(Gest(pp))

 G_env <- envelope(rpoispp(500), Gest, nsim = 95, alpha  = 0.05)
## Generating 95 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.
## 
## Done.
  plot(G_env)

G_env_hickory <- envelope(hickory, Gest, nsim = 95, alpha = 0.05)
## Generating 95 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.
## 
## Done.
plot(G_env_hickory, main = "Hickory: G-function with CSR envelope")

The data does wander outside of the confidence band. It hovers above, meaning the graph suggests some clustering.

Problem 17

G_env_blackoak <- envelope(blackoak, Gest, nsim = 95, alpha = 0.05)
## Generating 95 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.
## 
## Done.
plot(G_env_blackoak, main = "Blackoak: G-function with CSR envelope")

The data does wander outside of the confidence band. It hovers above, meaning the graph suggests some clustering.

Problem 18

G_env_cells <- envelope(cells, Gest, nsim = 95, alpha = 0.05)
## Generating 95 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.
## 
## Done.
plot(G_env_cells, main = "Blackoak: G-function with CSR envelope")

The data does wander outside of the confidence band. It erratically hovers far below, meaning the graph strongly suggests dispersion.

Problem 19

G_env_longleaf <- envelope(longleaf, Gest, nsim = 95, alpha = 0.05)
## Generating 95 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.
## 
## Done.
plot(G_env_longleaf, main = "Longleaf: G-function with CSR envelope")

The data does wander outside of the confidence band. It hovers above, meaning the graph suggests some clustering.