• No results found

The nspp package

The general estimation method described in the previous section has been implemented in the R package nspp (Stevenson, 2016). This section introduces, describes, and provides examples for various functions found within the package. All exported data objects and functions have full documentation, and so further information can be found in the package’s manual.

6.3.1 The sim.ns() function

The nspp package comes with two example sets of simulated data—found in the exported objects example.1D and example.2D—providing realisations of NSPPs in one- and two- dimensional space, respectively. These were generated with sim.ns(), a function used to simulate data from NSPPs.

The function has three main arguments:

• pars: a vector of model parameters,θ. This must contain named elements D,sigma, andchild.par—corresponding toD,σ, andψ, respectively. Recall thatψ must only contain a single parameter.

• lims: a matrix with d rows, each giving the limits of a dimension of W. Only (hyper)rectangular observation windows are permitted.

• rchild: a function that simulates random variates from the distribution of C. The first argument of this function must provide the number of random variables to gen-

erate (as per standard R functions for random number generation), and the second must provide the parameter ψ.

Additional optional parameters allow for the generation of plots of either the simulated point process or the empirical PI function (see Fewster et al., in press). The simulated locations are subject to periodic boundary conditions (PBCs).

For example, simulating data subject toC ∼Poisson(ν), D= 5, σ = 0.05,ν = 10, and

W = [0,2]2 can be achieved using

points <- sim.ns(pars = c(D = 5, sigma = 0.05, child.par = 10), lims = rbind(c(0, 2), c(0, 2)), rchild = rpois)

The resulting object8 is a matrix withnrows and 2 columns, providing the locations of the simulated children.

6.3.2 The fit.ns() function

Given a set of observed locations, estimation ofθcan be achieved via thefit.ns()function. The log of the Palm likelihood (Equation (6.15), or, more generally, (6.21)) is maximised (Equation (6.17)) numerically using a limited-memory, quasi-Newton approach with box constraints (Byrd, Lu, Nocedal, & Zhu, 1995), implemented in the "L-BFGS-B"method of the optim()function.

A selection of the function’s arguments are

• points: a matrix containing locations of the observed points. The object returned by sim.ns()is suitable.

• lims: equivalent to the argument of sim.ns()with the same name.

• R: the truncation distancet.

• child.dist: a list containing information about the distribution fitted to C. Recall that this only enters the likelihood via its expectation, Ec(ψ), and variance, Vc(ψ).

Thus expressions of these in terms of the single parameter ψ must therefore be pro- vided. The required named components of this list are

– mean: a function that takes ψ as its only argument and returnsEc(ψ).

– var: a function that takes ψ as its only argument and returns Vc(ψ).

8Runningset.seed(1234) prior to executing this code will result in the samepointsobject, which is

– sv: the start value ofψ for the optimisation algorithm.

– bounds: a vector containing bounds for the parameter ψ.

• siblings: a list containing information about known sibling and known nonsibling relationships. The required named components of this list are

– matrix: a matrix, where thejth element of the ith row is TRUEifxi and xj are

known siblings,FALSEif they are known nonsiblings, andNA if their relationship is unknown.

– pT: the (fixed) value ofα.

– pF: the (fixed) value ofβ.

Assuming no sibling information is available,θcan be estimated from thepointsobject generated above by sim.ns()by running

child.dist <- list(mean = function(nu) nu, var = function(nu) nu, sv = 5, bounds = c(0, 100))

fit <- fit.ns(points = points, lims = rbind(c(0, 2), c(0, 2)), R = 1, child.dist = child.dist)

The resulting object is a list containing various components that provide information about the fitted model. The best way of accessing this information is by extracting it using a variety of utility functions.

6.3.3 Utility functions

A range of S3 methods have been written for generic functions—includingcoef()for param- eter estimates,confint()for CIs,plot()to visualise the fitted PI function, andsummary() for a model summary. For example:

coef(fit)

# D sigma child.par

# 2.14915069 0.06030259 13.68802014

# Coefficients:

# Estimate Std. Error

# D 2.149151

# sigma 0.060303

# child.par 13.688020

Notice that summary() did not return standard errors—recall that variance estimates are only available following a parametric bootstrap.

6.3.4 The boot.ns() function

The relationship between the functionsadmbsecr()andboot.admbsecr()in theadmbsecr package is the same to that between fit.ns() and boot.ns() here: the object returned by fit.ns()can be used as the first argument to boot.ns(), and results in the execution of a parametric bootstrap procedure. Again, the argument Nsets the number of bootstrap resamples to carry out. An additional argument is rchild, which provides the function from which the number of children spawned by each parent is simulated. This is equivalent to the argument of sim.ns()with the same name.

A parametric bootstrap can therefore be carried out using the function call boot.fit <- boot.ns(fit, rchild = rpois, N = 1000, prog = TRUE)

This allows for the display of standard errors whensummary() is called, and for the calcu- lation of CIs with confint():

summary(boot.fit) # Coefficients: # Estimate Std. Error # D 2.149151 1.0027 # sigma 0.060303 0.0239 # child.par 13.688020 7.8125 confint(boot.fit) # 2.5 % 97.5 % # D 0.2830518 4.1419100 # sigma 0.0479578 0.1439433 # child.par 8.7472087 36.2930559