Part A

plot(rpoispp(500))

1. Illustrate two alternate ways of accomplishing the same result as above, using related but different syntax.

rpoispp(500)%>%plot

plot(rpoispp(500))

myobj=rpoispp(500)
plot(myobj)

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

2. What does add=T do in the above lines of code?

It adds contour lines to the random plot point.

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

3. What do the numbers within the square mean?

The numbers within the square mean represent the number of points randomly distributed into each square. For example, the 8 in the top left corner signifies 8 data points. Since it is a 10 x 10 plot, there are 100 squares that contain any given represented number of data points.

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 = 386.33, df = 399, p-value = 0.6673
## alternative hypothesis: two.sided
## 
## Quadrats: 20 by 20 grid of tiles

4. Repeat this operation 3 times and create a table reporting your a) number of points, b) number of grid cells, c) P-values, and d) interpret your P-values.

Number of Points Number of Grid Cells P-Values Interpret P-Values
500 400 0.4564 High probability that the observed pattern could occur under conditions of Complete Spatial Randomness
500 400 0.5165 High probability that the observed pattern could occur under conditions of Complete Spatial Randomness
500 400 0.1626 High probability that the observed pattern could occur under conditions of Complete Spatial Randomness
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 = 104.48, df = 63, p-value = 0.001595
## alternative hypothesis: two.sided
## 
## Quadrats: 8 by 8 grid of tiles
plot(density(pp))
plot(pp, pch = 1, add = TRUE)

5. Repeat this operation 3 times. Report and interpret your P-values.

  1. P-value = 0.1604
    1. Accept the null: High probability that the observed pattern would occur.
  2. P-value = 0.2176
    1. Accept the null: High probability that the observed pattern would occur.
  3. P-value = 0.0001511
    1. Reject the null: Low probability that the observed pattern would occur.

6. Try different numbers of the grid cells in your quadrat test. Does this affect your interpretation of the P-values obtained?

pp <- rpoispp(function(x,y) {200*x + 200*y})
quadrat.test(pp, nx=5, ny=5)
## 
##  Chi-squared test of CSR using quadrat counts
## 
## data:  pp
## X2 = 69.039, df = 24, p-value = 6.108e-06
## alternative hypothesis: two.sided
## 
## Quadrats: 5 by 5 grid of tiles
plot(density(pp))
plot(pp, pch = 1, add = TRUE)

p-value = 0.0009035

pp <- rpoispp(function(x,y) {200*x + 200*y})
quadrat.test(pp, 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:  pp
## X2 = 444, df = 399, p-value = 0.1187
## alternative hypothesis: two.sided
## 
## Quadrats: 20 by 20 grid of tiles
plot(density(pp))
plot(pp, pch = 1, add = TRUE)

p-value = 0.445

pp <- rpoispp(function(x,y) {200*x + 200*y})
quadrat.test(pp, nx=2, ny=2)
## 
##  Chi-squared test of CSR using quadrat counts
## 
## data:  pp
## X2 = 29.248, df = 3, p-value = 3.973e-06
## alternative hypothesis: two.sided
## 
## Quadrats: 2 by 2 grid of tiles
plot(density(pp))
plot(pp, pch = 1, add = TRUE)

p-value = 5.942e-05

Based on my three tests, the small grid sizes like 5x5 and 2x2 gave me very small p-values while the larger grid (20x20) gave me a high p-value. This might mean that my point pattern is not homogeneous Poisson.

Part B

plot(split(lansing))

7. What is the area in sq. ft. of the study region for the lansing data?

924 ft x 924 ft = 853,776 sq ft

8. What is the total number of trees in the lansing dataset?

2251 trees

9. What are the most and least abundant trees in the lansing dataset (ignoring “misc”)?

species_counts <- table(marks(lansing))
most_abundant <- names(which.max(species_counts))
least_abundant <- names(which.min(species_counts))
species_counts
## 
## blackoak  hickory    maple     misc   redoak whiteoak 
##      135      703      514      105      346      448

Most abundant trees are hickory followed by maple and least abundant are black oak followed by red oak.

10. Characterize the pattern for each of the a) two most abundant species, and for b) the least abundant species (ignore “misc”) as either random, aggregated, or dispersed based only on your visual interpretation of the plots you generated using plot, density, contoue, quadrat count, or hist(quadrat_count()).

Most Abundant

hickory <- split(lansing)$hickory
plot(density(hickory))
contour(density(hickory), add=T)
plot(hickory, add=T)

Aggregated dispersion

maple <- split(lansing)$maple
plot(density(maple))
contour(density(maple), add=T)
plot(maple, add=T)

Aggregated dispersion

Least Abundant

blackoak <- split(lansing)$blackoak
plot(density(blackoak))
contour(density(blackoak), add=T)
plot(blackoak, add=T)

Aggregated dispersion

redoak <- split(lansing)$redoak
plot(density(redoak))
contour(density(redoak), add=T)
plot(redoak, add=T)

Random dispersion

11. Perform a quadrat analysis (quadrat test) for a) each of the two most common tree types and b) the least common tree type (ignoring “misc”). Interpret your P-values.

hickory <- split(lansing)$hickory
quadrat.test(hickory, nx = 924, ny = 924)
## Warning: Some expected counts are small; chi^2 approximation may be inaccurate
## 
##  Chi-squared test of CSR using quadrat counts
## 
## data:  hickory
## X2 = 855502, df = 853775, p-value = 0.1864
## alternative hypothesis: two.sided
## 
## Quadrats: 924 by 924 grid of tiles

1a) Hickory, P-value = 0.1864

Accept the null, high probability that the observed pattern would occur.

maple <- split(lansing)$maple
quadrat.test(maple, nx = 924, ny = 924)
## Warning: Some expected counts are small; chi^2 approximation may be inaccurate
## 
##  Chi-squared test of CSR using quadrat counts
## 
## data:  maple
## X2 = 863228, df = 853775, p-value = 5.667e-13
## alternative hypothesis: two.sided
## 
## Quadrats: 924 by 924 grid of tiles

1b) Maple, P-value = 5.667e-13

Reject the null, very unlikely that the observed pattern would occur.

blackoak <- split(lansing)$blackoak
quadrat.test(blackoak, nx = 924, ny = 924)
## Warning: Some expected counts are small; chi^2 approximation may be inaccurate
## 
##  Chi-squared test of CSR using quadrat counts
## 
## data:  blackoak
## X2 = 853641, df = 853775, p-value = 0.9187
## alternative hypothesis: two.sided
## 
## Quadrats: 924 by 924 grid of tiles

2a) Black Oak, P-value = 0.9187

Accept the null, high probability that the observed pattern would occur.

redoak <- split(lansing)$redoak
quadrat.test(redoak, nx = 924, ny = 924)
## Warning: Some expected counts are small; chi^2 approximation may be inaccurate
## 
##  Chi-squared test of CSR using quadrat counts
## 
## data:  redoak
## X2 = 858365, df = 853775, p-value = 0.0004534
## alternative hypothesis: two.sided
## 
## Quadrats: 924 by 924 grid of tiles

2b) Red Oak, P-value = 0.0004534

Reject the null, very unlikely that the observed pattern would occur.

12. Run several quadrat tests for “hickory” using different quadrat numbers. Is the interpretation of your results robust to variation in quadrat size?

hickory <- split(lansing)$hickory
quadrat.test(hickory, nx = 30, ny = 30)
## Warning: Some expected counts are small; chi^2 approximation may be inaccurate
## 
##  Chi-squared test of CSR using quadrat counts
## 
## data:  hickory
## X2 = 1313.4, df = 899, p-value < 2.2e-16
## alternative hypothesis: two.sided
## 
## Quadrats: 30 by 30 grid of tiles
hickory <- split(lansing)$hickory
quadrat.test(hickory, nx = 500, ny = 500)
## Warning: Some expected counts are small; chi^2 approximation may be inaccurate
## 
##  Chi-squared test of CSR using quadrat counts
## 
## data:  hickory
## X2 = 253564, df = 249999, p-value = 5.182e-07
## alternative hypothesis: two.sided
## 
## Quadrats: 500 by 500 grid of tiles
hickory <- split(lansing)$hickory
quadrat.test(hickory, nx = 2000, ny = 2000)
## Warning: Some expected counts are small; chi^2 approximation may be inaccurate
## 
##  Chi-squared test of CSR using quadrat counts
## 
## data:  hickory
## X2 = 4010677, df = 4e+06, p-value = 0.0001619
## alternative hypothesis: two.sided
## 
## Quadrats: 2000 by 2000 grid of tiles

All three tests I ran changing the quadrat tests did not seem to have super vast differences in their p-values, nor did they seem robust. In all three scenarios I got a p-value that was less than 0.05, meaning I would reject the null hypothesis every time.

Part C

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

13. Illustrate two other ways you can do this.

#plot(colMeans(nndist(rpoispp(500), 1:500)))
#plot(colMeans(nndist(rpoispp(500), k=1:500)))

“It can also be helpful to look at a histogram of nearest neighbor distances:”

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

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

14. What does the plot suggest about the pattern of maple trees in this landscape?

This plot suggests that the random null mean-nearest-neighbor plot follows a similar pattern to the actual nearest neighbor plot for the maple data.

The cells dataset has 42 points so I chose to replace k with 40.

plot(apply(nndist(rpoispp(500), k=40: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 = 40:100)
  ann_values <- colMeans(nn_distances)
  points(1:length(ann_values), ann_values, 
       pch = 5)                         #Open squares for points

15. What does the plot suggest about the pattern of cells?

The plot suggests that the pattern of cells is not randomly distributed.

plot(Gest(rpoispp(500)))

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

hickory <- split(lansing)$hickory
G_env <- 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)

16. Does the data wander beyond the bounds of the confidence band? If so, above or below? Does this graph suggest randomness, clumping or aversion in the hickory data?

The data wanders above the bounds of the confidence bands at around 0.010 on the x-axis until about 0.020. This means that the data points are closer together than expected under CSR. It suggests clumping in the hickory data.

17. Does the data wander beyond the bounds of the confidence band? If so, above or below? Does this graph suggest randomness, clumping or aversion in the blackoak data?

blackoak <- split(lansing)$blackoak
G_env <- 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)

Same as hickory, the black oak data wanders above the bounds of the confidence bands from about 0.015 to about 0.06. This means that the data points are closer together than expected under CSR. It suggests clumping in the black oak data.

#install.packages("spatstat.data")
data(cells)
G_env <- 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)

18. Does the data wander beyond the bounds of the confidence band? If so, above or below? Does this graph suggest randomness, clumping or aversion in the cells data?

This data wanders below the bounds of the confidence bands from 0.0 on the x-axis to about 0.12. This means that the points are further apart than expected under Complete Spatial Randomness, so the cells are more spread out than random.

data(longleaf)
G_env <- 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)

19. Does the data wander beyond the bounds of the confidence band? If so, above or below? Does this graph suggest randomness, clumping or aversion in the longleaf data?

The data wanders above the bounds of the confidence band from around 0.6 m on the x-axis to about 5 m. This means that the data points are closer together than expected under CSR. It suggests clumping in the longleaf data.