This session covers modelling of marked point patterns using marked point processes.
The lecturer’s R script is available here (right click and save).

### Exercise 1

The dataset spruces contains the Norwegian Spruces dataset giving the locations of trees and their diameters at breast height.

1. Read the help file for the data;

2. access the dataset and plot it;

3. re-plot the data so that the tree diameters are displayed at a physical scale that is 10 times the physical scale of the location coordinates.

4. use Smooth (notice the upper case S) to compute and plot a pixel image of the local average tree diameter;

5. trees are normally classified as ‘adult’ when their diameter exceeds 30 centimetres. Use the cut command to classify each tree as adult or juvenile, and produce a multitype point pattern in which the trees are marked as adult or juvenile. Plot this pattern, and plot the adults and juveniles separately.

### Exercise 2

The file anthills.txt is available in the Data directory on github and downloadable by this direct link (right click and save).

It records the locations of anthills recorded in a 1200x1500 metre study region in northern Australia. Coordinates are given in metres, along with a letter code recording the ecological ‘status’ of each anthill.

1. read the data into R as a data frame, using the R function read.table. (Since the input file has a header line, you will need to use the argument header=TRUE when you call read.table.)

2. check the data for any peculiarities.

3. create a point pattern hills containing these data. Ensure that the marks are a factor, and that the unit of length is given its correct name.

4. plot the data.

### Exercise 3

The dataset hamster is a multitype pattern representing the locations of cells of two types, dividing and pyknotic.

1. plot the data;

2. plot the patterns of pyknotic and dividing cells separately;

3. plot kernel estimates of the intensity functions of pyknotic and dividing cells separately;

4. use relrisk to perform cross-validated bandwidth selection and computation of the relative intensity of pyknotic cells.

### Exercise 4

The command rmpoispp generates simulated realisations of a multitype Poisson process. The first argument lambda specifies the intensity function $$\lambda(x,y,m)$$ which gives the intensity of points at location (x,y). It may be given in several forms.

1. If lambda is a single number, it specifies the intensity of points of each type. Try computing, inspecting and plotting the result of

rmpoispp(21, win=square(1), types=c("yes", "no"))

What is the expected total number of points generated by this command?

2. If lambda is a vector of numbers, the vector entries specify the intensities for each type of point. Try

rmpoispp(c(20,40,20), types=letters[1:3])

What is the expected total number of points generated by this command?

3. If lambda is a function with arguments x,y,m then this is interpreted as the intensity function $$\lambda(x,y,m)$$. Try

fun <- function(x,y,m) { 40 * (x+y) }
X <- rmpoispp(fun, types=letters[24:26])
fun2 <- function(x,y,m) { ifelse(m == "yes", 100 * x, 50 * (1-x)) }
X2 <- rmpoispp(fun2, types=c("yes", "no"))

What is the expected total number of points in X?

### Exercise 5

Take the Harkness-Isham ants’ nests data ants

1. use summary to estimate the average intensities of the points of each type.

2. Generate and plot a realisation of a marked Poisson process in the same window as the data, with the same possible types of points, with uniform intensities for each type, given by the intensities estimated from the data.

3. Repeat the simulation several times. Do the simulations look like the data?

### Exercise 6

Here we will fit multitype Poisson point process models to the Harkness-Isham ants’ nests data ants.

1. Fit the model ppm(ants ~ marks) and interpret the result. Compare the result with summary(ants) and explain the similarities.

2. Fit the model ppm(ants ~ marks + x) and write down an expression for the fitted intensity function.

3. Fit the model ppm(ants ~ marks * x) and write down an expression for the fitted intensity function.

4. Compute the fitted intensities of the three models fitted above using predict and plot the results.

5. Explain the difference between the models fitted by ppm(ants ~ marks + x) and ppm(ants ~ marks * x) .

### Exercise 7

The study region for the ants’ nests data ants is divided into areas of ‘scrub’ and ‘field’. We want to fit a Poisson model with different intensities in the field and scrub areas.

The coordinates of two points on the boundary line between field and scrub are given in ants.extra$fieldscrub. First construct a function that determines which side of the line we are on: fs <- function(x,y) { ends <- ants.extra$fieldscrub
angle <- atan(diff(ends$y)/diff(ends$x))
normal <- angle + pi/2
project <- (x - ends$x) * cos(normal) + (y - ends$y) * sin(normal)
factor(ifelse(project > 0, "scrub", "field"))
}

Now fit the models:

ppm(ants ~ marks + side, covariates=list(side=fs))
ppm(ants ~ marks * side, covariates=list(side=fs))

and interpret the results.