Install any packages you might be missing:
library(spatstat)
library(splancs)
# tree data
data(finpines)
#get info
print(finpines)
## Marked planar point pattern: 126 points
## Mark variables: diameter, height
## window: rectangle = [-5, 5] x [-8, 2] metres
intensity(finpines)
## [1] 1.26
summary(finpines)
## Marked planar point pattern: 126 points
## Average intensity 1.26 points per square metre
##
## Coordinates are given to 13 decimal places
##
## Mark variables: diameter, height
## Summary:
## diameter height
## Min. :0.000 Min. :0.800
## 1st Qu.:1.000 1st Qu.:1.825
## Median :2.000 Median :2.850
## Mean :2.532 Mean :2.828
## 3rd Qu.:3.000 3rd Qu.:3.600
## Max. :7.000 Max. :5.400
##
## Window: rectangle = [-5, 5] x [-8, 2] metres
## Window area = 100 square metres
## Unit of length: 1 metre
#creates point pattern data format from the x and y coordinates
finpines.pts<-as.points(finpines$x,finpines$y)
plot(finpines.pts, pch=19, xlab="X", ylab="Y",main="Finish Pines Locations")
#divide into quadrants and count number of points in the quadrant
Q <- quadratcount(finpines, nx = 4, ny = 3)
Q
## x
## y [-5,-2.5) [-2.5,0) [0,2.5) [2.5,5]
## [-1.33,2] 10 8 11 21
## [-4.67,-1.33) 8 7 9 3
## [-8,-4.67) 12 11 22 4
summary(Q)
## Number of cases in table: 126
## Number of factors: 2
## Test for independence of all factors:
## Chisq = 20.215, df = 6, p-value = 0.002535
Q_dat<-data.frame(Q)
var(Q_dat$Freq)
## [1] 33.72727
mean(Q_dat$Freq)
## [1] 10.5
plot(finpines.pts,pch=19, main="Finpines", xlab="X",ylab="Y")
plot(Q, add = TRUE, cex = 2)
# Finpines data
sp_point <- matrix(NA, nrow=length(finpines$x),ncol=2)
sp_point[,1] <- finpines$x
sp_point[,2] <- finpines$y
colnames(sp_point) <- c("x","y")
plot(x=sp_point[,1],y=sp_point[,2],main="Finpines Data", xlab="X",ylab="Y",cex=.5)