R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

# Setting the working directory
setwd("C:/Users/John/Desktop/Statistics Masters/Spatial Data Analysis/R Directory")

# Installing the necessary libraries
library(spatstat)
## Warning: package 'spatstat' was built under R version 3.3.3
## Loading required package: spatstat.data
## Warning: package 'spatstat.data' was built under R version 3.3.3
## Loading required package: nlme
## Loading required package: rpart
## 
## spatstat 1.55-0       (nickname: 'Stunned Mullet') 
## For an introduction to spatstat, type 'beginner'
## 
## Note: R version 3.3.2 (2016-10-31) is more than 9 months old; we strongly recommend upgrading to the latest version
# Specifying a fixed intensity of 100 across the whole study area
pp_homogeneous <- rpoispp(150)
pp_homogeneous
## Planar point pattern: 158 points
## window: rectangle = [0, 1] x [0, 1] units
plot(pp_homogeneous)

plot(density(pp_homogeneous))
plot(pp_homogeneous, add=T)
contour(density(pp_homogeneous), add=T)

# Specifying a function to define an intensity lambda = 100xy
pp_nonhomogenous1 <- rpoispp(function(x,y) {100*x*y})
pp_nonhomogenous1
## Planar point pattern: 18 points
## window: rectangle = [0, 1] x [0, 1] units
plot(pp_nonhomogenous1)

plot(density(pp_nonhomogenous1))
plot(pp_nonhomogenous1, add=T)
contour(density(pp_nonhomogenous1), add=T)

# Specifying a function to define an intensity lambda = 100x^2 + 100y^2
pp_nonhomogenous2 <- rpoispp(function(x,y) {100*x*x + 100*y*y})
pp_nonhomogenous2
## Planar point pattern: 69 points
## window: rectangle = [0, 1] x [0, 1] units
plot(pp_nonhomogenous2)

plot(density(pp_nonhomogenous2))
plot(pp_nonhomogenous2, add=T)
contour(density(pp_nonhomogenous2), add=T)

# Specifying a function to define an intensity lambda = 200*sqrt((x-0.5)^2 + (y-0.5)^2
pp_nonhomogenous3 <- rpoispp(function(x,y) {200*sqrt((x-0.5)^2 + (y-0.5)^2)})
pp_nonhomogenous3
## Planar point pattern: 86 points
## window: rectangle = [0, 1] x [0, 1] units
plot(pp_nonhomogenous3)

plot(density(pp_nonhomogenous3))
plot(pp_nonhomogenous3, add=T)
contour(density(pp_nonhomogenous3), add=T)

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.