=— title: “Lab-Practice 3” author: “Kendall Ellis” date: “2025-09-11” output: html_document —
plot(rpoispp(500))
# Illustrate two alternate ways of accomplishing the same result as the above, i. e. using related but different syntax.
pp1 <- rpoispp(function(x,y){500*x+500*y})
plot(pp1)
pp2 <- rpoispp(function(x,y){500*x*x+500*y*y})
plot(pp2)
pp <- rpoispp(500)
plot(density(pp))
contour(density(pp), add=T)
plot(pp, add=T)
# What does add=T do in the above lines of code?
Answer: add=T is representing a color map, most likely of temperature or intensity related to the contours.
plot(quadratcount(pp, nx=10, ny=10))
# What do the numbers within the squares mean?
Answer: The numbers within the squares represent the number of data points that are within that square, thereby the probability of a data point existing in that square, since this is a probability plot
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 = 408.5, df = 399, p-value = 0.7211
## alternative hypothesis: two.sided
##
## Quadrats: 20 by 20 grid of tiles
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 = 407.98, df = 399, p-value = 0.7345
## alternative hypothesis: two.sided
##
## Quadrats: 20 by 20 grid of tiles
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 = 374.63, df = 399, p-value = 0.3914
## alternative hypothesis: two.sided
##
## Quadrats: 20 by 20 grid of tiles
#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. Items a), b), c), an d) should be columns in your table. There should be three rows. One for each iteration
Answer:
Number of Points | Number of Cells | P-value | Interpretation |
---|---|---|---|
500 | 400 | 0.6451 | This p-value is above 0.05, which means there is a slightly higher probability that the observed point pattern occurred in Complete Spatial Randomness |
500 | 400 | 0.3545 | This p-value is above 0.05, which means there is a slightly higher probability that the observed point pattern occurred in Complete Spatial Randomness |
500 | 400 | 0.2011 | This p-value is above 0.05, which means there is a slightly higher probability that the observed point pattern occurred in 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 = 92.48, df = 63, p-value = 0.01833
## alternative hypothesis: two.sided
##
## Quadrats: 8 by 8 grid of tiles
plot(density(pp))
plot(pp, pch=1, add=TRUE)
#Repeat this operation 3 times. Report and interpret your P-values.
Answer: 1st p-value = 0.109 This p-value is above 0.05, which means there is higher probability that the observed point pattern occurred randomly in the denisty Poisson plot
2nd p-value = 0.01079 This p-value is below 0.05, which means there is a lower probability that the observed point pattern occurred randomly in the denisty Poisson plot
3rd p-value = 0.003751 This p-value is well below 0.05, which means there is a much lower probability that the observed point pattern occurred randomly in the denisty Poisson plot
#Try different numbers of 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=10, ny=12)
## Warning: Some expected counts are small; chi^2 approximation may be inaccurate
##
## Chi-squared test of CSR using quadrat counts
##
## data: pp
## X2 = 148.82, df = 119, p-value = 0.06664
## alternative hypothesis: two.sided
##
## Quadrats: 10 by 12 grid of tiles
plot(density(pp))
plot(pp, pch=1, add=TRUE)
Answer: No, changing the number of grid cells does not affect my interpretation of the p-values obtained
plot(split(lansing))
plot(split(lansing))$hickory
## NULL
head(lansing)
## Marked planar point pattern: 6 points
## Multitype, with levels = blackoak, hickory, maple, misc, redoak, whiteoak
## window: rectangle = [0, 1] x [0, 1] units (one unit = 924 feet)
npoints(lansing)
## [1] 2251
#What is the area in sq. ft. of the study region for the lansing data?
#What is the total number of trees in the lansing dataset?
#What are the most and least abundant trees in the lansing dataset (ignoring “misc”).
Answer 7: 924 x 924 = 853,776 sq. ft. Answer 8: There are 2251 points in the lansing dataset Answer 9: The most abundant trees according to the split plots are hickory, while the least abundant trees are the blackoak
# 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, contour, quadrat_count, or hist(quadrat_count()).
plot(split(lansing))
Answer: The two most abundant species are hickory and whiteoak, hickory seems to be somewhat aggregated with random dsitribution as well, while whiteoak seems more randomly dispersed. The two least abundant species are blackoak and redoak, blackoak seems more dispersed whle redoak appears more random with some aggregation.
#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.
quadrat.test(split(lansing)$hickory)
##
## Chi-squared test of CSR using quadrat counts
##
## data: split(lansing)$hickory
## X2 = 233.45, df = 24, p-value < 2.2e-16
## alternative hypothesis: two.sided
##
## Quadrats: 5 by 5 grid of tiles
quadrat.test(split(lansing)$whiteoak)
##
## Chi-squared test of CSR using quadrat counts
##
## data: split(lansing)$whiteoak
## X2 = 51.554, df = 24, p-value = 0.001789
## alternative hypothesis: two.sided
##
## Quadrats: 5 by 5 grid of tiles
quadrat.test(split(lansing)$blackoak)
##
## Chi-squared test of CSR using quadrat counts
##
## data: split(lansing)$blackoak
## X2 = 145.56, df = 24, p-value < 2.2e-16
## alternative hypothesis: two.sided
##
## Quadrats: 5 by 5 grid of tiles
Answer: hickory p-value = 2.2e-16, which is very very below 0.05 which means that there is a very low probability that the observed point pattern for the trees occurred randomly in the unit of analysis whiteoak p-value = 0.001789 which is below 0.005 and means that there is a low probability that the observed point pattern for the whiteoak trees occurred randomly in the forest unit of analysis blackoak p-value = 2.2e-16 which is very very below 0.05 which means that there is a very low probability that the observed point pattern for the trees occurred randomly in the unit of analysis
# Run several quadrat tests for “hickory” using different quadrat numbers. Is the interpretation of your results robust to variation in quadrat size?
quadrat.test(split(lansing)$hickory)
##
## Chi-squared test of CSR using quadrat counts
##
## data: split(lansing)$hickory
## X2 = 233.45, df = 24, p-value < 2.2e-16
## alternative hypothesis: two.sided
##
## Quadrats: 5 by 5 grid of tiles
quadrat.test((split(lansing)$hickory), nx=10, ny=10)
##
## Chi-squared test of CSR using quadrat counts
##
## data: (split(lansing)$hickory)
## X2 = 360.58, df = 99, p-value < 2.2e-16
## alternative hypothesis: two.sided
##
## Quadrats: 10 by 10 grid of tiles
quadrat.test((split(lansing)$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: (split(lansing)$hickory)
## X2 = 766.7, df = 399, p-value < 2.2e-16
## alternative hypothesis: two.sided
##
## Quadrats: 20 by 20 grid of tiles
quadrat.test((split(lansing)$hickory), nx=12, ny=22)
## Warning: Some expected counts are small; chi^2 approximation may be inaccurate
##
## Chi-squared test of CSR using quadrat counts
##
## data: (split(lansing)$hickory)
## X2 = 536.64, df = 263, p-value < 2.2e-16
## alternative hypothesis: two.sided
##
## Quadrats: 12 by 22 grid of tiles
Answer: Yes, the interpretation of my results is different depending on the size variation of the quadrat grids
plot(apply(nndist(rpoispp(500), k=1:500), 2, FUN=mean))
# Illustrate two other ways you can do this.
plot(Gest(rpoispp(500)))
plot(nndist.default(rpoispp(500)))
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",
pch = 19)
nn_distances <- nndist(split(lansing)$maple, k = 1:100)
ann_values <- colMeans(nn_distances)
points(1:length(ann_values), ann_values, pch = 5)
# What does the plot suggest about the pattern of maple trees in this landscape?
Answer: The plot suggests that the maple tree pattern is not very randomly oriented, because the mean nearest neighbor distance line is separated from the randomly generated mean nearest neighbor distance curve, and further deviates as the neighbor order increases.
#rerun the plot from above, but for the cells dataset. Change the number of points you select in the random pattern to be the same as the number of points in the cells dataset. Change k to go from 1: no greater than the number of points in the cells dataset.
list(cells)
## [[1]]
## Planar point pattern: 42 points
## window: rectangle = [0, 1] x [0, 1] units
plot(apply(nndist(rpoispp(42), k=1:42), 2, FUN=mean),
xlab = "Neighbor Order (k)",
ylab = "Average Nearest Neighbor Distance",
main = "ANN Values for Different Neighbor Orders",
type = "b",
pch = 19)
nn_distances <- nndist(split(lansing)$cells, k = 1:42)
ann_values <- colMeans(nn_distances)
points(1:length(ann_values), ann_values, pch = 5)
# What does the plot suggest about the pattern of cells?
Answer: The plot suggests that the pattern of cells is randomly oriented, because the mean nearest neighbor distance line is not separated from the randomly generated mean nearest neighbor distance curve.
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)
#Repeat above analysis for hickory data
hickory <- envelope(split(lansing)$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(hickory)
#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?
Answer: The hickory data wanders above the confidence band, and the graph suggests aversion to the hickory data because a large portion of the hickory data lies beyond the confidence band.
#Repeat above analysis for blackoak data
blackoak <- envelope(split(lansing)$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(blackoak)
#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?
Answer: The blackoak data wanders above the confidence band, and the graph suggests a strong aversion to the blackoak data because a large portion of the data lies beyond the confidence band.
#Repeat analysis for cells data
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(cells)
#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?
Answer: The cells data wanders below the confidence band, and the graph suggests a strong aversion to the cells data because a a majority of the data lies beyond the confidence band.
#repeat analysis for longleaf dataset
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(longleaf)
#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?
Answer: The longleaf data wanders above the confidence band, and the graph suggests aversion to the longleaf data because a large portion of the data lies beyond the confidence band.