Package interspread September 7, 2012 Version 0.2-2 Date 2012-09-07 Title Functions for analysing InterSpread Plus simulation output Author Mark Stevenson <M.Stevenson@massey.ac.nz> A package for analysing InterSpread Plus simulation output. Maintainer Mark Stevenson <M.Stevenson@massey.ac.nz> Depends R (>= 2.7.0), sp, sm, spatstat, RColorBrewer, spatialkernel License GPL (>= 2) URL http://epicentre.massey.ac.nz R topics documented: is.about........................................... 1 is.act............................................. 2 is.boundary......................................... 2 is.describemovt....................................... 3 is.epicurve.......................................... 4 is.farms........................................... 5 is.move........................................... 7 is.sim............................................ 8 Index 11 is.about InterSpread Plus: summary information A collection of functions for analysing InterSpread Plus simulation output. is.about() 1
2 is.boundary Details The most recent version of the interspread package can be obtained from: http://epicentre. massey.ac.nz/ Author(s) Mark Stevenson, EpiCentre, IVABS, Massey University, Palmerston North New Zealand. is.act Details from an outbreak of foot-and-mouth disease This data set provides infection dates and location details of farms infected during an outbreak of foot-and-mouth disease. data(is.act) Format A data frame with the following variables: itno iteration number. time the estimated day of infection (relative to the date of infection of the index case). id farm identifier. type farm type. xcoord easting coordinate of the farm centroid. ycoord northing coordinate of the farm centroid. data(is.act) is.boundary Boundary of study area Polygon defining the boundary of a hypothetical study area. data(is.boundary)
is.describemovt 3 Format A two column data frame with the following variables: xcoord easting coordinates of the boundary vertices. ycoord northing coordinates of the boundary vertices. data(is.boundary) ## Not run: library(spatstat) ## Create an observation window. is.boundary is two column data frame with ## 173 rows. Reverse the row order and drop the last set of coordinates to ## coerce the data into a suitable format for spatstat: is.ow <- owin(poly = as.matrix(is.boundary[172:1,]), unitname = c("metre", "metres")) ## Method for SpatialPolygonsDataFrame object: ## is.ow <- as(as(is.boundary, "SpatialPolygonsDataFrame"), "owin") plot(is.ow, axes = TRUE) ## End(Not run) is.describemovt InterSpread Plus: describe parameterised movement patterns Returns descriptive statistics of the predicted number of events per iteration. is.describemovt(movements, ngrid = 100, min = 5, transform = 1000) Arguments movements ngrid min transform an eight column matrix listing the following data (in order): iteration number, time, outcome, easting of the location acting as the source of movement, northing of the location acting as the source of the movement, easting of the destination location, northing of the destination location, movement type. integer, specifying the number of grids to use for the smoothing function. integer, the minimum number of eligible distances required to compute a density estimate. scalar, distance values will be divided by this value (useful for converting metres into kilometres.)
4 is.epicurve ## Load data: data(is.move) move <- is.move$ex1 ## Select movements where type equals "MovementType10": id <- move[,8] == "MovementType10" move <- move[id, 1:8] rval <- is.describemovt(move, ngrid = 100, min = 5, transform = 1000) dim <- dim(rval$estimate) plot(rval$eval.points[,1], rval$estimate[,1], type = "l", xlim = c(0, 100), ylim = c(0, 0.1), xlab = "Distance (km)", ylab = "Density", col = "gray") for(i in 2:dim[2]){ lines(rval$eval.points[,i], rval$estimate[,i], col = "gray") } is.epicurve InterSpread Plus: epidemic curve Computes the cumulative number of locations predicted to experience an event as a function of time, suitable for plotting as an epidemic curve. is.epicurve(dat, daylim, xlim, ylim, n.iterations = 5, stats = FALSE, type = "cumulative", quant = c(0.25, 0.75)) Arguments dat daylim xlim ylim n.iterations stats a four column matrix listing the following data (in order): iteration number, time, easting of the location experiencing the event, northing of the location experiencing the event. vector of length two, defining the start and the end of the simulation period. vector of length two, defining map limits in the easting direction. vector of length two, defining map limits in the northing direction. integer defining the number of Interspread Plus iterations to be included. logical, if TRUE descriptive statistics of the cumulative number of infected premises at each epidemic time period are calculated. If FALSE the cumulative number of infected premises is reported for each iteration. type string indicating the type of analysis to performed. cumulative returns the cumulative number of events, frequency returns the count of events for each time period. quant vector of length two, defines the quantiles to be computed. Only used if stats = TRUE
is.farms 5 ## Load data: data(is.act) data(is.sim) ## Details of observed epidemic: act <- is.act[, c(1,2,5,6)] act[,3:4] <- act[,3:4]/1000 tmp <- as.data.frame(table(act$time)) tmp[,1] <- as.numeric(as.character(tmp[,1])) names(tmp) <- c("day", "n") ## Set boundaries of study area: xlim <- c(173,273) ylim <- c(340,440) ## Details of premises predicted to become infected by InterSpread Plus: inf <- is.sim$inf[, c(1,2,5,6)] inf[,3:4] <- inf[,3:4]/1000 ## Compare actual epidemic curve with that predicted by InterSpread Plus: fmd.pred <- is.epicurve(inf, daylim = c(0,60), xlim = xlim, ylim = ylim, n.iterations = 9, stats = FALSE, type = "cumulative", quant = c(0.25,0.75)) ## Plot results: plot(c(0,60), c(0,60), type = "n", xlab = "Simulation day", ylab = "Cumulative number of infected premises") for(i in 1:9){ lines(fmd.pred[,1], fmd.pred[,1+i], type = "s", lwd = 1) } lines(tmp$day, cumsum(tmp$n), type = "s", lwd = 2, col = "red") ## Compare actual epidemic curve with median, 25th percentile and 75th ## percentile, predicted by InterSpread Plus: fmd.pred <- is.epicurve(inf, daylim = c(0,60), xlim = xlim, ylim = ylim, n.iterations = 9, stats = TRUE, type = "cumulative") ## Plot results: plot(c(0, 60), c(0, 60), type = "n", xlab = "Simulation day", ylab = "Cumulative number of infected premises") lines(fmd.pred[,1], fmd.pred[,4], type = "s", lwd = 2) lines(fmd.pred[,1], fmd.pred[,5], type = "s", lwd = 1) lines(fmd.pred[,1], fmd.pred[,6], type = "s", lwd = 1) lines(tmp$day, cumsum(tmp$n), type = "s", lwd = 2, col = "red") legend(0, 50, legend = c("actual cumulative number IPs", "Predicted cumulative IPs (median of 9 iterations)", "25th and 75th prediction quartiles"), col = c("red", "black", "black"), lwd = c(3, 3, 1), bty = "n") is.farms Farm details
6 is.farms Format This data set provides, for a set of farms within a defined study area, details of location and the number of animals present. data(is.farms) A data frame with the following variables: id the primary farm identifier. farmid the secondary farm identifier. type farm type. cattle the number of cattle present. other the number of other (foot-and-mouth disease susceptible) species present. pigs the number of pigs present. xcoord easting coordinate of the farm centroid. ycoord northing coordinate of the farm centroid. data(is.farms) ## Not run: library(spatstat); library(rcolorbrewer); library(spatialkernel) data(is.boundary) data(is.farms) ## Create an observation window: is.ow <- owin(poly = as.matrix(is.boundary[172:1,]), unitname = c("metre", "metres")) ## Method for SpatialPolygonsDataFrame object: ## is.ow <- as(as(is.boundary, "SpatialPolygonsDataFrame"), "owin") # Create ppp object: farms.ppp <- ppp(x = is.farms$xcoord, y = is.farms$ycoord, window = is.ow) xylims <- rbind(range(is.farms$xcoord), range(is.farms$ycoord)) ## Method for SpatialPolygonsDataFrame object: ## xylims <- attr(is.boundary, "bbox") ratio <- (xylims[2,2] - xylims[2,1]) / (xylims[1,2] - xylims[1,1]) x.points <- seq(from = 180000, to = 250000, by = 10000); x.lab <- x.points/1000 y.points <- seq(from = 360000, to = 420000, by = 10000); y.lab <- y.points/1000 ## Plot farm locations: par(pin = c(1 * 5, ratio * 5), omi = c(0.5,0,0,0)) plot(x = xylims[1,], y = xylims[2,], xaxt = "n", yaxt = "n", type = "n", xlab = "", ylab = "", axes = TRUE)
is.move 7 points(x = is.farms$xcoord, y = is.farms$ycoord, col = "gray") plot(is.ow, add = TRUE) axis(side = 1, at = x.points, labels = x.lab, tick = TRUE, cex.axis = 0.80) axis(side = 2, at = y.points, labels = y.lab, tick = TRUE, cex.axis = 0.80) mtext("easting (km)", side = 1, line = 3, cex = 1.0) mtext("northing (km)", side = 2, line = 3, cex = 1.0) legend(x = "topleft", legend = "Farm locations", pch = 1, col = "gray", bty = "n") ## Set the bandwidth and grid dimensions: sigma <- 1200; dimyx = c(200, 200) ## Kernel smooth: farms.den <- density(farms.ppp, sigma = sigma, dimyx = dimyx) ## The density.ppp function returns an estimate of the intensity of the ## underlying point process, that is the expected number of points per unit ## area (in this case, the number of points per metre). Express results as ## the number of points per square kilometre (1 square metre = 0.000001 ## square kilometres): farms.den$v <- farms.den$v / 0.000001 summary(as.vector(farms.den$v)) ## Maximum farm density is 7 per farms per square kilometre. ## Image plot of farm density: breaks <- seq(from = 0, to = 7, length = 5) col <- brewer.pal(n = 4, name = "Blues") par(pin = c(1 * 5, ratio * 5), omi = c(0.5,0,0,0)) plot(x = xylims[1,], y = xylims[2,], type = "n", xlab = "Easting (m)", ylab = "Northing (m)", xaxt = "n", yaxt = "n") image(x = farms.den$xcol, y = farms.den$yrow, z = t(farms.den$v), zlim = c(0, 7), col = col, breaks = breaks, add = TRUE) plot(is.ow, add = TRUE) axis(side = 1, at = x.points, labels = x.lab, tick = TRUE, cex.axis = 0.80) axis(side = 2, at = y.points, labels = y.lab, tick = TRUE, cex.axis = 0.80) metre(xl = xylims[1,1], yb = xylims[2,1], xr = xylims[1,1] + 2000, yt = xylims[2,1] + 15000, lab = breaks, cols = col, shift = 0, cex = 0.75) ## End(Not run) is.move Movement details from an InterSpread Plus simulation This data set provides details of movement events generated during a typical InterSpread Plus simulation. data(is.move)
8 is.sim Format A list containing the following data frames: ex1 an eight column data frame listing the following (in order): itno iteration number, time time, outcome infection outcome (infected or not infected), src.xcoord easting of the location acting as the source of movement, src.ycoord northing of the location acting as the source of the movement, des.xcoord easting of the destination location, src.ycoord northing of the destination location, type movement type. ex2 an eight column data frame listing the following (in order): itno iteration number, time time, outcome infection outcome (infected or not infected), src.xcoord easting of the location acting as the source of movement, src.ycoord northing of the location acting as the source of the movement, des.xcoord easting of the destination location, src.ycoord northing of the destination location, type movement type. data(is.move) is.sim Details from an InterSpread Plus simulation This data set provides details from a typical InterSpread Plus simulation. data(is.sim) Format A list containing the following data frames: dep a nine column data frame listing the following (in order): itno iteration number, time time, id farm identifier, type depopulation resource, xcoord easting coordinate, xcoord northing coordinate, cattle cattle numbers, other other stock numbers, pigs pig numbers. det a six column data frame listing the following (in order): itno iteration number, time time, id farm identifier, type detection resource, xcoord easting coordinate, ycoord northing coordinate. inf a six column data frame listing the following (in order): itno iteration number, time time, id farm identifier, type infection mechanism, xcoordeasting coordinate, ycoord northing coordinate. vac a nine column data frame listing the following (in order): itno iteration number, time time, id farm identifier, type vaccination resource, xcoord easting coordinate, ycoord northing coordinate, cattle cattle numbers, other other stock numbers, pigs pig numbers.
is.sim 9 data(is.sim) ## Not run: library(spatstat); library(rcolorbrewer); library(spatialkernel) data(is.boundary) data(is.farms) ## Create an observation window: is.ow <- owin(poly = as.matrix(is.boundary[172:1,]), unitname = c("metre", "metres")) ## Method for SpatialPolygonsDataFrame object: ## is.ow <- as(as(is.boundary, "SpatialPolygonsDataFrame"), "owin") # Create ppp objects: farms.ppp <- ppp(x = is.farms$xcoord, y = is.farms$ycoord, window = is.ow) sim.ppp <- ppp(x = is.sim$inf$xcoord, y = is.sim$inf$ycoord, window = is.ow) xylims <- rbind(range(is.farms$xcoord), range(is.farms$ycoord)) ## Method for SpatialPolygonsDataFrame object: ## xylims <- attr(is.boundary, "bbox") ratio <- (xylims[2,2] - xylims[2,1]) / (xylims[1,2] - xylims[1,1]) x.points <- seq(from = 180000, to = 250000, by = 10000); x.lab <- x.points/1000 y.points <- seq(from = 360000, to = 420000, by = 10000); y.lab <- y.points/1000 ## Set the bandwidth and grid dimensions: sigma <- 1200; dimyx = c(200, 200) ## Kernel smooth: farms.den <- density(farms.ppp, sigma = sigma, dimyx = dimyx) sim.den <- density(sim.ppp, sigma = sigma, dimyx = dimyx) ## The density.ppp function returns an estimate of the intensity of the ## underlying point process, that is the expected number of points per unit ## area (in this case, the number of points per metre). Express results as ## the number of points per square kilometre (1 square metre = 0.000001 ## square kilometres): farms.den$v <- farms.den$v / 0.000001 summary(as.vector(farms.den$v)) ## Maximum farm density is 7 per farms per square kilometre. ## Do the same for the simulations. Note the division by 9, because simulation ## results are for 9 iterations: sim.den$v <- sim.den$v / 0.000001 summary(as.vector(sim.den$v) / 9) ## Image plot of farm density with superimposed contour plot to identify ## areas where the density of farms predicted to become infected was ## relatively high: breaks <- seq(from = 0, to = 7, length = 5) col <- brewer.pal(n = 4, name = "Blues")
10 is.sim par(pin = c(1 * 5, ratio * 5), omi = c(0.5,0,0,0)) plot(x = xylims[1,], y = xylims[2,], type = "n", xlab = "Easting (m)", ylab = "Northing (m)", xaxt = "n", yaxt = "n") image(x = farms.den$xcol, y = farms.den$yrow, z = t(farms.den$v), zlim = c(0, 7), col = col, breaks = breaks, add = TRUE) contour(x = sim.den$xcol, y = sim.den$yrow, z = t(sim.den$v / 9), levels = 0.02, col = "red", add = TRUE) plot(is.ow, add = TRUE) axis(side = 1, at = x.points, labels = x.lab, tick = TRUE, cex.axis = 0.80) axis(side = 2, at = y.points, labels = y.lab, tick = TRUE, cex.axis = 0.80) metre(xl = xylims[1,1], yb = xylims[2,1], xr = xylims[1,1] + 2000, yt = xylims[2,1] + 15000, lab = breaks, cols = col, shift = 0, cex = 0.75) ## End(Not run)
Index Topic datasets is.act, 2 is.boundary, 2 is.farms, 5 is.move, 7 is.sim, 8 Topic univar is.about, 1 is.describemovt, 3 is.epicurve, 4 is.about, 1 is.act, 2 is.boundary, 2 is.describemovt, 3 is.epicurve, 4 is.farms, 5 is.move, 7 is.sim, 8 11