R : Copyright 2005, The R Foundation for Statistical Computing Version 2.1.1 (2005-06-20), ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for a HTML browser interface to help. Type 'q()' to quit R. > ### *
> ### > attach(NULL, name = "CheckExEnv") > assign(".CheckExEnv", as.environment(2), pos = length(search())) # base > ## add some hooks to label plot pages for base and grid graphics > setHook("plot.new", ".newplot.hook") > setHook("persp", ".newplot.hook") > setHook("grid.newpage", ".gridplot.hook") > > assign("cleanEx", + function(env = .GlobalEnv) { + rm(list = ls(envir = env, all.names = TRUE), envir = env) + RNGkind("default", "default") + set.seed(1) + options(warn = 1) + delayedAssign("T", stop("T used instead of TRUE"), + assign.env = .CheckExEnv) + delayedAssign("F", stop("F used instead of FALSE"), + assign.env = .CheckExEnv) + sch <- search() + newitems <- sch[! sch %in% .oldSearch] + for(item in rev(newitems)) + eval(substitute(detach(item), list(item=item))) + missitems <- .oldSearch[! .oldSearch %in% sch] + if(length(missitems)) + warning("items ", paste(missitems, collapse=", "), + " have been removed from the search path") + }, + env = .CheckExEnv) > assign("..nameEx", "__{must remake R-ex/*.R}__", env = .CheckExEnv) # for now > assign("ptime", proc.time(), env = .CheckExEnv) > grDevices::postscript("spatstat-Examples.ps") > assign("par.postscript", graphics::par(no.readonly = TRUE), env = .CheckExEnv) > options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly")) > options(warn = 1) > library('spatstat') Loading required package: mgcv This is mgcv 1.3-1 Loading required package: sm Library `sm', version 2; Copyright (C) 1997, 2000 A.W.Bowman & A.Azzalini type help(sm) for summary information spatstat 1.6-9 Type "demo(spatstat)" for a demonstration See the Introduction and Quick Reference in /CRANPkg/check/spatstat.Rcheck/spatstat/doc > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "DiggleGratton" > > ### * DiggleGratton > > flush(stderr()); flush(stdout()) > > ### Name: DiggleGratton > ### Title: Diggle-Gratton model > ### Aliases: DiggleGratton > ### Keywords: spatial > > ### ** Examples > > data(cells) > ppm(cells, ~1, DiggleGratton(0.05, 0.1)) Stationary Diggle-Gratton process Trend: First order term: beta 264.2764 Interaction: Pairwise interaction family Interaction: Diggle-Gratton process lower limit delta: 0.05 upper limit rho: 0.1 Fitted exponent kappa: [1] 9.05 > > > > cleanEx(); ..nameEx <- "Fest" > > ### * Fest > > flush(stderr()); flush(stdout()) > > ### Name: Fest > ### Title: Estimate the empty space function F > ### Aliases: Fest empty.space > ### Keywords: spatial > > ### ** Examples > > data(cells) > Fc <- Fest(cells, 0.01) > > # Tip: don't use F for the left hand side! > # That's an abbreviation for FALSE > > plot(Fc) lty col km 1 1 rs 2 2 theo 3 3 > > # P-P style plot > plot(Fc, cbind(km, theo) ~ theo) lty col km 1 1 theo 2 2 > > # The empirical F is above the Poisson F > # indicating an inhibited pattern > > ## Not run: > ##D plot(Fc, . ~ theo) > ##D plot(Fc, asin(sqrt(.)) ~ asin(sqrt(theo))) > ##D > ## End(Not run) > > > > cleanEx(); ..nameEx <- "Gcross" > > ### * Gcross > > flush(stderr()); flush(stdout()) > > ### Name: Gcross > ### Title: Multitype Nearest Neighbour Distance Function (i-to-j) > ### Aliases: Gcross > ### Keywords: spatial > > ### ** Examples > > data(betacells) > # cat retina data > G01 <- Gcross(betacells, "off", "on") > plot(G01) lty col km 1 1 rs 2 2 theo 3 3 > > # empty space function of `on' points > ## Not run: > ##D F1 <- Fest(betacells[betacells == "on"], r = G01$r, eps=10.0) > ##D lines(F1$r, F1$km, lty=3) > ##D > ## End(Not run) > > # synthetic example > pp <- runifpoispp(50) > pp <- pp %mark% factor(sample(0:1, pp$n, replace=TRUE)) > G <- Gcross(pp, "0", "1") # note: "0" not 0 > > > > cleanEx(); ..nameEx <- "Gdot" > > ### * Gdot > > flush(stderr()); flush(stdout()) > > ### Name: Gdot > ### Title: Multitype Nearest Neighbour Distance Function (i-to-any) > ### Aliases: Gdot > ### Keywords: spatial > > ### ** Examples > > data(betacells) > # cat retina data > G0. <- Gdot(betacells, "off") > plot(G0.) lty col km 1 1 rs 2 2 theo 3 3 > > # synthetic example > pp <- runifpoispp(50) > pp <- pp %mark% factor(sample(0:1, pp$n, replace=TRUE)) > G <- Gdot(pp, "0") # note: "0" not 0 > > > > cleanEx(); ..nameEx <- "Gest" > > ### * Gest > > flush(stderr()); flush(stdout()) > > ### Name: Gest > ### Title: Nearest Neighbour Distance Function G > ### Aliases: Gest nearest.neighbour > ### Keywords: spatial > > ### ** Examples > > data(cells) > G <- Gest(cells) > plot(G) lty col km 1 1 rs 2 2 theo 3 3 > > # P-P style plot > plot(G, cbind(km,theo) ~ theo) lty col km 1 1 theo 2 2 > > # the empirical G is below the Poisson G, > # indicating an inhibited pattern > > ## Not run: > ##D plot(G, . ~ r) > ##D plot(G, . ~ theo) > ##D plot(G, asin(sqrt(.)) ~ asin(sqrt(theo))) > ##D > ## End(Not run) > > > > cleanEx(); ..nameEx <- "Geyer" > > ### * Geyer > > flush(stderr()); flush(stdout()) > > ### Name: Geyer > ### Title: Geyer's Saturation Point Process Model > ### Aliases: Geyer > ### Keywords: spatial > > ### ** Examples > > data(cells) > ppm(cells, ~1, Geyer(r=0.07, sat=2), rbord=0.07) Stationary Geyer saturation process Trend: First order term: beta 126.1468 Interaction: Saturated pairwise interaction family Interaction: Geyer saturation process interaction distance: 0.07 saturation parameter: 2 Fitted interaction parameter gamma: [1] 1e-04 > # fit the stationary saturation process to `cells' > > > > cleanEx(); ..nameEx <- "Gmulti" > > ### * Gmulti > > flush(stderr()); flush(stdout()) > > ### Name: Gmulti > ### Title: Marked Nearest Neighbour Distance Function > ### Aliases: Gmulti > ### Keywords: spatial > > ### ** Examples > > data(longleaf) > # Longleaf Pine data: marks represent diameter > ## Don't show: > longleaf <- longleaf[seq(1,longleaf$n, by=50), ] > > ## End Don't show > Gm <- Gmulti(longleaf, longleaf$marks <= 15, longleaf$marks >= 25) > plot(Gm) lty col km 1 1 rs 2 2 theo 3 3 > > > > cleanEx(); ..nameEx <- "Iest" > > ### * Iest > > flush(stderr()); flush(stdout()) > > ### Name: Iest > ### Title: Estimate the I-function > ### Aliases: Iest > ### Keywords: spatial > > ### ** Examples > > data(amacrine) > Ic <- Iest(amacrine) > plot(Ic, main="Amacrine Cells data") lty col km 1 1 rs 2 2 un 3 3 theo 4 4 > # values are below I= 0, suggesting negative association > # between 'on' and 'off' cells. > > > > cleanEx(); ..nameEx <- "Jcross" > > ### * Jcross > > flush(stderr()); flush(stdout()) > > ### Name: Jcross > ### Title: Multitype J Function (i-to-j) > ### Aliases: Jcross > ### Keywords: spatial > > ### ** Examples > > # Lansing woods data: 6 types of trees > data(lansing) > > ## Don't show: > lansing <- lansing[seq(1,lansing$n, by=30), ] > > ## End Don't show > Jhm <- Jcross(lansing, "hickory", "maple") > # diagnostic plot for independence between hickories and maples > plot(Jhm) lty col un 1 1 km 2 2 rs 3 3 theo 4 4 > > # synthetic example with two marks "a" and "b" > pp <- runifpoispp(50) > pp <- pp %mark% sample(c("a","b"), pp$n, replace=TRUE) > J <- Jcross(pp, "a", "b") > > > > cleanEx(); ..nameEx <- "Jdot" > > ### * Jdot > > flush(stderr()); flush(stdout()) > > ### Name: Jdot > ### Title: Multitype J Function (i-to-any) > ### Aliases: Jdot > ### Keywords: spatial > > ### ** Examples > > # Lansing woods data: 6 types of trees > data(lansing) > > ## Don't show: > lansing <- lansing[seq(1,lansing$n, by=30), ] > > ## End Don't show > Jh. <- Jdot(lansing, "hickory") > plot(Jh.) lty col un 1 1 km 2 2 rs 3 3 theo 4 4 > # diagnostic plot for independence between hickories and other trees > Jhh <- Jest(lansing[lansing$marks == "hickory", ]) > plot(Jhh, add=TRUE) lty col un 1 1 km 2 2 rs 3 3 theo 4 4 > > # synthetic example with two marks "a" and "b" > pp <- runifpoispp(50) > pp <- pp %mark% sample(c("a","b"), pp$n, replace=TRUE) > J <- Jdot(pp, "a") > > > > cleanEx(); ..nameEx <- "Jest" > > ### * Jest > > flush(stderr()); flush(stdout()) > > ### Name: Jest > ### Title: Estimate the J-function > ### Aliases: Jest > ### Keywords: spatial > > ### ** Examples > > data(cells) > J <- Jest(cells, 0.01) > plot(J, main="cells data") lty col un 1 1 km 2 2 rs 3 3 theo 4 4 > # values are far above J= 1, indicating regular pattern > > data(redwood) > J <- Jest(redwood, 0.01) > plot(J, main="redwood data") lty col un 1 1 km 2 2 rs 3 3 theo 4 4 > # values are below J= 1, indicating clustered pattern > > > > cleanEx(); ..nameEx <- "Jmulti" > > ### * Jmulti > > flush(stderr()); flush(stdout()) > > ### Name: Jmulti > ### Title: Marked J Function > ### Aliases: Jmulti > ### Keywords: spatial > > ### ** Examples > > data(longleaf) > # Longleaf Pine data: marks represent diameter > ## Don't show: > longleaf <- longleaf[seq(1,longleaf$n, by=50), ] > > ## End Don't show > Jm <- Jmulti(longleaf, longleaf$marks <= 15, longleaf$marks >= 25) > plot(Jm) lty col un 1 1 km 2 2 rs 3 3 theo 4 4 > > > > cleanEx(); ..nameEx <- "Kcross" > > ### * Kcross > > flush(stderr()); flush(stdout()) > > ### Name: Kcross > ### Title: Multitype K Function (Cross-type) > ### Aliases: Kcross > ### Keywords: spatial > > ### ** Examples > > data(betacells) > # cat retina data > K01 <- Kcross(betacells, "off", "on") > plot(K01) lty col iso 1 1 trans 2 2 border 3 3 theo 4 4 > > K10 <- Kcross(betacells, "on", "off") > > # synthetic example > pp <- runifpoispp(50) > pp <- pp %mark% factor(sample(0:1, pp$n, replace=TRUE)) > K <- Kcross(pp, "0", "1") # note: "0" not 0 > > > > cleanEx(); ..nameEx <- "Kdot" > > ### * Kdot > > flush(stderr()); flush(stdout()) > > ### Name: Kdot > ### Title: Multitype K Function (i-to-any) > ### Aliases: Kdot > ### Keywords: spatial > > ### ** Examples > > # Lansing woods data: 6 types of trees > data(lansing) > > ## Not run: > ##D Kh. <- Kdot(lansing, "hickory") > ##D > ## End(Not run) > ## Don't show: > sub <- lansing[seq(1,lansing$n, by=80), ] > Kh. <- Kdot(sub, "hickory") > > ## End Don't show > # diagnostic plot for independence between hickories and other trees > plot(Kh.) lty col iso 1 1 trans 2 2 border 3 3 theo 4 4 > > # synthetic example with two marks "a" and "b" > pp <- runifpoispp(50) > pp <- pp %mark% sample(c("a","b"), pp$n, replace=TRUE) > K <- Kdot(pp, "a") > > > > cleanEx(); ..nameEx <- "Kest" > > ### * Kest > > flush(stderr()); flush(stdout()) > > ### Name: Kest > ### Title: K-function > ### Aliases: Kest > ### Keywords: spatial > > ### ** Examples > > pp <- runifpoint(50) > K <- Kest(pp) > data(cells) > K <- Kest(cells, correction="isotropic") > plot(K) lty col iso 1 1 theo 2 2 > plot(K, main="K function for cells") lty col iso 1 1 theo 2 2 > # plot the L function > plot(K, sqrt(iso/pi) ~ r) > plot(K, sqrt(./pi) ~ r, ylab="L(r)", main="L function for cells") lty col iso 1 1 theo 2 2 > > > > cleanEx(); ..nameEx <- "Kest.fft" > > ### * Kest.fft > > flush(stderr()); flush(stdout()) > > ### Name: Kest.fft > ### Title: K-function using FFT > ### Aliases: Kest.fft > ### Keywords: spatial > > ### ** Examples > > pp <- runifpoint(10000) > ## Not run: > ##D spatstat.options(npixel=512) > ##D > ## End(Not run) > ## Don't show: > spatstat.options(npixel=256) > > ## End Don't show > Kpp <- Kest.fft(pp, 0.01) > plot(Kpp) lty col border 1 1 theo 2 2 > > > > cleanEx(); ..nameEx <- "Kinhom" > > ### * Kinhom > > flush(stderr()); flush(stdout()) > > ### Name: Kinhom > ### Title: Inhomogeneous K-function > ### Aliases: Kinhom > ### Keywords: spatial > > ### ** Examples > > data(lansing) > # inhomogeneous pattern of maples > X <- unmark(lansing[lansing$marks == "maple",]) > ## Don't show: > sub <- sample(c(TRUE,FALSE), X$n, replace=TRUE, prob=c(0.1,0.9)) > X <- X[sub , ] > > ## End Don't show > # fit spatial trend > fit <- ppm(X, ~ polynom(x,y,2), Poisson()) > # predict intensity values at points themselves > lambda <- predict(fit, locations=X, type="trend") > # inhomogeneous K function > Ki <- Kinhom(X, lambda) > plot(Ki) lty col iso 1 1 trans 2 2 bord.modif 3 3 border 4 4 theo 5 5 > > # SIMULATED DATA > # known intensity function > lamfun <- function(x,y) { 100 * x } > # inhomogeneous Poisson process > Y <- rpoispp(lamfun, 100, owin()) > # evaluate intensity at points of pattern > lambda <- lamfun(Y$x, Y$y) > # inhomogeneous K function > Ki <- Kinhom(Y, lambda) > plot(Ki) lty col iso 1 1 trans 2 2 bord.modif 3 3 border 4 4 theo 5 5 > > > > cleanEx(); ..nameEx <- "Kmeasure" > > ### * Kmeasure > > flush(stderr()); flush(stdout()) > > ### Name: Kmeasure > ### Title: Reduced Second Moment Measure > ### Aliases: Kmeasure > ### Keywords: spatial > > ### ** Examples > > data(cells) > image(Kmeasure(cells, 0.05)) > # shows pronounced dip around origin consistent with strong inhibition > data(redwood) > image(Kmeasure(redwood, 0.03), col=grey(seq(1,0,length=32))) > # shows peaks at several places, reflecting clustering and ?periodicity > > > > cleanEx(); ..nameEx <- "Kmulti" > > ### * Kmulti > > flush(stderr()); flush(stdout()) > > ### Name: Kmulti > ### Title: Marked K-Function > ### Aliases: Kmulti > ### Keywords: spatial > > ### ** Examples > > data(longleaf) > # Longleaf Pine data: marks represent diameter > ## Don't show: > longleaf <- longleaf[seq(1,longleaf$n, by=50), ] > > ## End Don't show > K <- Kmulti(longleaf, longleaf$marks <= 15, longleaf$marks >= 25) > plot(K) lty col iso 1 1 trans 2 2 border 3 3 theo 4 4 > > > > cleanEx(); ..nameEx <- "LennardJones" > > ### * LennardJones > > flush(stderr()); flush(stdout()) > > ### Name: LennardJones > ### Title: The Lennard-Jones Potential > ### Aliases: LennardJones > ### Keywords: spatial > > ### ** Examples > > X <- rpoispp(100) > ppm(X, ~1, LennardJones(), correction="translate") Stationary Lennard-Jones potential Trend: First order term: beta 91.55748 Interaction: Pairwise interaction family Interaction: Lennard-Jones potential : Fitted interaction parameters: sigma tau NA NA > # Typically yields very small values for theta_1, theta_2 > # so the values of sigma, tau may not be sensible > ########## > # How to plot the pair potential function (exponentiated) > plotLJ <- function(sigma, tau) { + dmax <- 2 * sigma * max(1, tau)^(1/6) + d <- seq(dmax * 0.0001, dmax, length=1000) + plot(d, exp(- (sigma/d)^12 + tau * (sigma/d)^6), type="l", + ylab="Lennard-Jones", + main=substitute(list(sigma==s, tau==t), + list(s=sigma,t=tau))) + abline(h=1, lty=2) + } > plotLJ(1,1) > > > > cleanEx(); ..nameEx <- "MultiStrauss" > > ### * MultiStrauss > > flush(stderr()); flush(stdout()) > > ### Name: MultiStrauss > ### Title: The Multitype Strauss Point Process Model > ### Aliases: MultiStrauss > ### Keywords: spatial > > ### ** Examples > > r <- matrix(c(1,2,2,1), nrow=2,ncol=2) > MultiStrauss(1:2, r) Multitype pairwise interaction family Interaction: Multitype Strauss process 2 types of points Possible types: [1] "1" "2" Interaction radii: 1 2 1 1 2 2 2 1 > # prints a sensible description of itself > data(betacells) > r <- 30.0 * matrix(c(1,2,2,1), nrow=2,ncol=2) > ppm(betacells, ~1, MultiStrauss(c("off","on"), r), rbord=60.0) Stationary Multitype Strauss process Possible marks: off on Trend: Fitted first order terms: beta_off beta_on 0.0001373652 0.0001373652 Interaction: Multitype pairwise interaction family Interaction: Multitype Strauss process 2 types of points Possible types: [1] "off" "on" Interaction radii: off on off 30 60 on 60 30 Fitted interaction parameters gamma_ij: off on off 0.0000 0.8303 on 0.8303 0.0000 > # fit the stationary multitype Strauss process to `betacells' > ppm(betacells, ~polynom(x,y,3), MultiStrauss(c("off","on"), r), rbord=60.0) Nonstationary Multitype Strauss process Possible marks: off on Trend: Trend formula: ~polynom(x, y, 3) Fitted coefficients for trend formula: (Intercept) polynom(x, y, 3)[x] polynom(x, y, 3)[y] -1.024463e+01 1.527585e-02 -1.822493e-03 polynom(x, y, 3)[x^2] polynom(x, y, 3)[x.y] polynom(x, y, 3)[y^2] -3.530505e-05 -7.962093e-06 7.862101e-06 polynom(x, y, 3)[x^3] polynom(x, y, 3)[x^2.y] polynom(x, y, 3)[x.y^2] 2.181347e-08 1.233072e-08 -2.606491e-09 polynom(x, y, 3)[y^3] -4.201735e-09 Interaction: Multitype pairwise interaction family Interaction: Multitype Strauss process 2 types of points Possible types: [1] "off" "on" Interaction radii: off on off 30 60 on 60 30 Fitted interaction parameters gamma_ij: off on off 0.0000 0.7324 on 0.7324 0.0000 > # fit a nonstationary Strauss process with log-cubic polynomial trend > > > > cleanEx(); ..nameEx <- "MultiStraussHard" > > ### * MultiStraussHard > > flush(stderr()); flush(stdout()) > > ### Name: MultiStraussHard > ### Title: The Multitype/Hard Core Strauss Point Process Model > ### Aliases: MultiStraussHard > ### Keywords: spatial > > ### ** Examples > > r <- matrix(3, nrow=2,ncol=2) > h <- matrix(c(1,2,2,1), nrow=2,ncol=2) > MultiStraussHard(1:2, r, h) Multitype pairwise interaction family Interaction: Multitype Strauss Hardcore process 2 types of points Possible types: [1] "1" "2" Interaction radii: 1 2 1 3 3 2 3 3 Hardcore radii: 1 2 1 1 2 2 2 1 > # prints a sensible description of itself > data(betacells) > r <- 30.0 * matrix(c(1,2,2,1), nrow=2,ncol=2) > h <- 30.0 * matrix(c(NA,1,1,NA), nrow=2,ncol=2) > ppm(betacells, ~1, MultiStraussHard(c("off","on"), r, h), rbord=60.0) Warning in mpl.prepare(Q, X, P, trend, interaction, covariates, want.trend, : 25 data point(s) are illegal (zero conditional intensity under the model) Stationary Multitype Strauss Hardcore process Possible marks: off on Trend: Fitted first order terms: beta_off beta_on 0.0001492623 0.0001492623 Interaction: Multitype pairwise interaction family Interaction: Multitype Strauss Hardcore process 2 types of points Possible types: [1] "off" "on" Interaction radii: off on off 30 60 on 60 30 Hardcore radii: off on off NA 30 on 30 NA Fitted interaction parameters gamma_ij: off on off 0.0000 0.8291 on 0.8291 0.0000 > # fit the stationary multitype hardcore Strauss process to `betacells' > > > > cleanEx(); ..nameEx <- "PairPiece" > > ### * PairPiece > > flush(stderr()); flush(stdout()) > > ### Name: PairPiece > ### Title: The Piecewise Constant Pairwise Interaction Point Process Model > ### Aliases: PairPiece > ### Keywords: spatial > > ### ** Examples > > PairPiece(c(0.1,0.2)) Pairwise interaction family Interaction: Piecewise constant pairwise interaction process interaction thresholds: c(0.1, 0.2) > # prints a sensible description of itself > data(cells) > ppm(cells, ~1, PairPiece(r = c(0.05, 0.1, 0.2)), rbord=0.2) Stationary Piecewise constant pairwise interaction process Trend: First order term: beta 1518.802 Interaction: Pairwise interaction family Interaction: Piecewise constant pairwise interaction process interaction thresholds: c(0.05, 0.1, 0.2) Fitted interaction parameters gamma_i: [0,0.05) [0.05,0.1) [0.1,0.2) 0.0000 0.0247 0.8748 > # fit a stationary piecewise constant pairwise interaction process > ppm(cells, ~polynom(x,y,3), PairPiece(c(0.05, 0.1)), rbord=0.1) Nonstationary Piecewise constant pairwise interaction process Trend: Trend formula: ~polynom(x, y, 3) Fitted coefficients for trend formula: (Intercept) polynom(x, y, 3)[x] polynom(x, y, 3)[y] 2.770327 16.329865 13.056614 polynom(x, y, 3)[x^2] polynom(x, y, 3)[x.y] polynom(x, y, 3)[y^2] -29.257015 -17.982790 -18.098769 polynom(x, y, 3)[x^3] polynom(x, y, 3)[x^2.y] polynom(x, y, 3)[x.y^2] 17.555897 9.824152 9.385077 polynom(x, y, 3)[y^3] 7.482870 Interaction: Pairwise interaction family Interaction: Piecewise constant pairwise interaction process interaction thresholds: c(0.05, 0.1) Fitted interaction parameters gamma_i: [0,0.05) [0.05,0.1) 0.0000 0.0155 > # nonstationary process with log-cubic polynomial trend > > > > cleanEx(); ..nameEx <- "Pairwise" > > ### * Pairwise > > flush(stderr()); flush(stdout()) > > ### Name: Pairwise > ### Title: Generic Pairwise Interaction model > ### Aliases: Pairwise > ### Keywords: spatial > > ### ** Examples > > #This is the same as StraussHard(r=0.7,h=0.2) > strpot <- function(t,par) { + r <- par$r + h <- par$h + value <- (t <= r) + value[t < h] <- -Inf + value + } > mySH <- Pairwise(strpot, "StraussHard", list(r=0.7,h=0.2), + c("interaction distance r", "hard core distance c")) > data(cells) > ppm(cells, ~ 1, mySH) Warning in mpl.prepare(Q, X, P, trend, interaction, covariates, want.trend, : 42 data point(s) are illegal (zero conditional intensity under the model) Stationary StraussHard Trend: First order term: beta 3.059023e-08 Interaction: StraussHard Potential function: function (t, par) { r <- par$r h <- par$h value <- (t <= r) value[t < h] <- -Inf value } Fitted interaction terms: Interaction 1 > > > > cleanEx(); ..nameEx <- "Poisson" > > ### * Poisson > > flush(stderr()); flush(stdout()) > > ### Name: Poisson > ### Title: Poisson Point Process Model > ### Aliases: Poisson > ### Keywords: spatial > > ### ** Examples > > data(nztrees) > ppm(nztrees, ~1, Poisson()) Stationary Poisson process Intensity: Uniform intensity: [1] 0.005916753 > # fit the stationary Poisson process to 'nztrees' > # no edge correction needed > > data(longleaf) > ## Don't show: > longleaf <- longleaf[seq(1, longleaf$n, by=50)] > > ## End Don't show > longadult <- longleaf[longleaf$marks >= 30, ] > longadult <- unmark(longadult) > ppm(longadult, ~ x, Poisson()) Nonstationary Poisson process Intensity: Trend formula: ~x Fitted coefficients for trend formula: (Intercept) x -8.052377176 -0.003696828 > # fit the nonstationary Poisson process > # with intensity lambda(x,y) = exp( a + bx) > > data(lansing) > # trees marked by species > ## Don't show: > lansing <- lansing[seq(1,lansing$n, by=30), ] > > ## End Don't show > ppm(lansing, ~ marks, Poisson()) Stationary multitype Poisson process Possible marks: blackoak hickory maple misc redoak whiteoak Intensity: Trend formula: ~marks Fitted intensities: beta_blackoak beta_hickory beta_maple beta_misc beta_redoak 5 23 18 3 12 beta_whiteoak 15 > # fit stationary marked Poisson process > # with different intensity for each species > > ## Not run: > ##D ppm(lansing, ~ marks * polynom(x,y,3), Poisson()) > ## End(Not run) > # fit nonstationary marked Poisson process > # with different log-cubic trend for each species > ## Don't show: > # equivalent functionality - smaller dataset > data(betacells) > ppm(betacells, ~ marks * polynom(x,y,2), Poisson()) Nonstationary multitype Poisson process Possible marks: off on Intensity: Trend formula: ~marks * polynom(x, y, 2) Fitted coefficients for trend formula: (Intercept) markson -9.414097e+00 7.140810e-01 polynom(x, y, 2)[x] polynom(x, y, 2)[y] -8.360216e-04 1.595380e-03 polynom(x, y, 2)[x^2] polynom(x, y, 2)[x.y] 5.373429e-07 -7.688609e-07 polynom(x, y, 2)[y^2] markson:polynom(x, y, 2)[x] -9.123127e-07 -2.244465e-03 markson:polynom(x, y, 2)[y] markson:polynom(x, y, 2)[x^2] -1.894023e-03 1.618490e-06 markson:polynom(x, y, 2)[x.y] markson:polynom(x, y, 2)[y^2] 1.823315e-06 1.075783e-06 > ## End Don't show > > > > cleanEx(); ..nameEx <- "Softcore" > > ### * Softcore > > flush(stderr()); flush(stdout()) > > ### Name: Softcore > ### Title: The Soft Core Point Process Model > ### Aliases: Softcore > ### Keywords: spatial > > ### ** Examples > > data(cells) > ppm(cells, ~1, Softcore(kappa=0.5), rbord=0) Stationary Soft core process Trend: First order term: beta 430.7452 Interaction: Pairwise interaction family Interaction: Soft core process Exponent kappa: 0.5 Fitted interaction parameter sigma: [1] 0.09291655 > # fit the stationary Soft Core process to `cells' > > > > cleanEx(); ..nameEx <- "Strauss" > > ### * Strauss > > flush(stderr()); flush(stdout()) > > ### Name: Strauss > ### Title: The Strauss Point Process Model > ### Aliases: Strauss > ### Keywords: spatial > > ### ** Examples > > Strauss(r=0.1) Pairwise interaction family Interaction: Strauss process interaction distance: 0.1 > # prints a sensible description of itself > data(cells) > ppm(cells, ~1, Strauss(r=0.07), rbord=0.07) Stationary Strauss process Trend: First order term: beta 126.1468 Interaction: Pairwise interaction family Interaction: Strauss process interaction distance: 0.07 Fitted interaction parameter gamma: [1] 0 > # fit the stationary Strauss process to `cells' > ppm(cells, ~polynom(x,y,3), Strauss(r=0.07), rbord=0.1) Nonstationary Strauss process Trend: Trend formula: ~polynom(x, y, 3) Fitted coefficients for trend formula: (Intercept) polynom(x, y, 3)[x] polynom(x, y, 3)[y] 0.05106119 32.80566353 0.12842709 polynom(x, y, 3)[x^2] polynom(x, y, 3)[x.y] polynom(x, y, 3)[y^2] -67.33464677 -5.36337896 6.19537368 polynom(x, y, 3)[x^3] polynom(x, y, 3)[x^2.y] polynom(x, y, 3)[x.y^2] 41.28159446 10.00958702 -4.28944313 polynom(x, y, 3)[y^3] -5.82298495 Interaction: Pairwise interaction family Interaction: Strauss process interaction distance: 0.07 Fitted interaction parameter gamma: [1] 0 > # fit a nonstationary Strauss process with log-cubic polynomial trend > > > > cleanEx(); ..nameEx <- "StraussHard" > > ### * StraussHard > > flush(stderr()); flush(stdout()) > > ### Name: StraussHard > ### Title: The Strauss / Hard Core Point Process Model > ### Aliases: StraussHard > ### Keywords: spatial > > ### ** Examples > > StraussHard(r=1,hc=0.02) Pairwise interaction family Interaction: Strauss - hard core process interaction distance: 1 hard core distance: 0.02 > # prints a sensible description of itself > > data(cells) > ppm(cells, ~1, StraussHard(r=0.1, hc=0.05), rbord=0.1) Stationary Strauss - hard core process Trend: First order term: beta 763.276 Interaction: Pairwise interaction family Interaction: Strauss - hard core process interaction distance: 0.1 hard core distance: 0.05 Fitted interaction parameter gamma: [1] 0.0145 > # fit the stationary Strauss/hard core process to `cells' > > ppm(cells, ~ polynom(x,y,3), StraussHard(r=0.1, hc=0.05), rbord=0.1) Nonstationary Strauss - hard core process Trend: Trend formula: ~polynom(x, y, 3) Fitted coefficients for trend formula: (Intercept) polynom(x, y, 3)[x] polynom(x, y, 3)[y] 2.770327 16.329865 13.056614 polynom(x, y, 3)[x^2] polynom(x, y, 3)[x.y] polynom(x, y, 3)[y^2] -29.257015 -17.982790 -18.098769 polynom(x, y, 3)[x^3] polynom(x, y, 3)[x^2.y] polynom(x, y, 3)[x.y^2] 17.555897 9.824152 9.385077 polynom(x, y, 3)[y^3] 7.482870 Interaction: Pairwise interaction family Interaction: Strauss - hard core process interaction distance: 0.1 hard core distance: 0.05 Fitted interaction parameter gamma: [1] 0.0155 > # fit a nonstationary Strauss/hard core process > # with log-cubic polynomial trend > > > > cleanEx(); ..nameEx <- "affine" > > ### * affine > > flush(stderr()); flush(stdout()) > > ### Name: affine > ### Title: Apply Affine Transformation > ### Aliases: affine > ### Keywords: spatial > > ### ** Examples > > data(cells) > # shear transformation > X <- affine(cells, matrix(c(1,0,0.6,1),ncol=2)) > ## Not run: > ##D plot(X) > ##D # rescale y coordinates by factor 1.3 > ##D plot(affine(cells, diag(c(1,1.3)))) > ##D > ## End(Not run) > > > > cleanEx(); ..nameEx <- "affine.owin" > > ### * affine.owin > > flush(stderr()); flush(stdout()) > > ### Name: affine.owin > ### Title: Apply Affine Transformation To Window > ### Aliases: affine.owin > ### Keywords: spatial > > ### ** Examples > > # shear transformation > X <- affine(owin(), matrix(c(1,0,0.6,1),ncol=2)) > ## Not run: > ##D plot(X) > ##D > ## End(Not run) > > > > cleanEx(); ..nameEx <- "affine.ppp" > > ### * affine.ppp > > flush(stderr()); flush(stdout()) > > ### Name: affine.ppp > ### Title: Apply Affine Transformation To Point Pattern > ### Aliases: affine.ppp > ### Keywords: spatial > > ### ** Examples > > data(cells) > # shear transformation > X <- affine(cells, matrix(c(1,0,0.6,1),ncol=2)) > ## Not run: > ##D plot(X) > ##D # rescale y coordinates by factor 1.3 > ##D plot(affine(cells, diag(c(1,1.3)))) > ##D > ## End(Not run) > > > > cleanEx(); ..nameEx <- "allstats" > > ### * allstats > > flush(stderr()); flush(stdout()) > > ### Name: allstats > ### Title: Calculate four standard summary functions of a point pattern. > ### Aliases: allstats > ### Keywords: spatial > > ### ** Examples > > data(swedishpines) > a <- allstats(swedishpines,dataname="Swedish Pines") > ## Not run: > ##D plot(a) > ##D plot(a, subset=list("r<=15","r<=15","r<=15","r<=50")) > ##D > ## End(Not run) > > > > cleanEx(); ..nameEx <- "alltypes" > > ### * alltypes > > flush(stderr()); flush(stdout()) > > ### Name: alltypes > ### Title: Calculate Statistic for All Types in a Multitype Point Pattern > ### Aliases: alltypes > ### Keywords: spatial > > ### ** Examples > > # bramblecanes (3 marks). > data(bramblecanes) > ## Not run: > ##D X.F <- alltypes(bramblecanes,fun="F",verb=TRUE) > ##D plot(X.F) > ##D X.G <- alltypes(bramblecanes,fun="G",verb=TRUE) > ##D X.J <- alltypes(bramblecanes,fun="J",verb=TRUE) > ##D X.K <- alltypes(bramblecanes,fun="K",verb=TRUE) > ##D X.Gd <- alltypes(bramblecanes,fun="Gdot",verb=TRUE) > ##D X.Jd <- alltypes(bramblecanes,fun="Jdot",verb=TRUE) > ##D X.Kd <- alltypes(bramblecanes,fun="Kdot",verb=TRUE) > ##D > ## End(Not run) > ## Don't show: > # smaller dataset > bram <- bramblecanes[seq(1, bramblecanes$n, by=20), ] > X.F <- alltypes(bram,fun="F",verb=TRUE) i = 1 j = 1 i = 2 j = 1 i = 3 j = 1 > X.G <- alltypes(bram,fun="G",verb=TRUE) i = 1 j = 1 i = 1 j = 2 i = 1 j = 3 i = 2 j = 1 i = 2 j = 2 i = 2 j = 3 i = 3 j = 1 i = 3 j = 2 i = 3 j = 3 > X.J <- alltypes(bram,fun="J",verb=TRUE) i = 1 j = 1 i = 1 j = 2 i = 1 j = 3 i = 2 j = 1 i = 2 j = 2 i = 2 j = 3 i = 3 j = 1 i = 3 j = 2 i = 3 j = 3 > X.K <- alltypes(bram,fun="K",verb=TRUE) i = 1 j = 1 i = 1 j = 2 i = 1 j = 3 i = 2 j = 1 i = 2 j = 2 i = 2 j = 3 i = 3 j = 1 i = 3 j = 2 i = 3 j = 3 > X.Gd <- alltypes(bram,fun="Gdot",verb=TRUE) i = 1 j = 1 i = 2 j = 1 i = 3 j = 1 > X.Jd <- alltypes(bram,fun="Jdot",verb=TRUE) i = 1 j = 1 i = 2 j = 1 i = 3 j = 1 > X.Kd <- alltypes(bram,fun="Kdot",verb=TRUE) i = 1 j = 1 i = 2 j = 1 i = 3 j = 1 > > ## End Don't show > > # Swedishpines (unmarked). > data(swedishpines) > ## Don't show: > swedishpines <- swedishpines[1:25] > > ## End Don't show > X.K <- alltypes(swedishpines,fun="K") > X.F <- alltypes(swedishpines,fun="F") > X.G <- alltypes(swedishpines,fun="G") > X.J <- alltypes(swedishpines,fun="J") > > # simulated data > ## Not run: > ##D pp <- runifpoint(350, owin(c(0,1),c(0,1))) > ##D pp$marks <- factor(c(rep(1,50),rep(2,100),rep(3,200))) > ##D X.F <- alltypes(pp,fun="F",verb=TRUE,dataname="Fake Data") > ##D X.G <- alltypes(pp,fun="G",verb=TRUE,dataname="Fake Data") > ##D X.J <- alltypes(pp,fun="J",verb=TRUE,dataname="Fake Data") > ##D X.K <- alltypes(pp,fun="K",verb=TRUE,dataname="Fake Data") > ##D > ## End(Not run) > > # A setting where you might REALLY want to use dataname: > ## Not run: > ##D xxx <- alltypes(ppp(Melvin$x,Melvin$y, > ##D window=as.owin(c(5,20,15,50)),marks=clyde), > ##D fun="F",verb=TRUE,dataname="Melvin") > ##D > ## End(Not run) > > > > cleanEx(); ..nameEx <- "anova.ppm" > > ### * anova.ppm > > flush(stderr()); flush(stdout()) > > ### Name: anova.ppm > ### Title: ANOVA for Fitted Point Process Models > ### Aliases: anova.ppm > ### Keywords: spatial > > ### ** Examples > > data(swedishpines) > mod0 <- ppm(swedishpines, ~1, Poisson()) > modx <- ppm(swedishpines, ~x, Poisson()) > anova.ppm(modx, mod0, test="Chi") Analysis of Deviance Table Model 1: .mpl.Y ~ x Model 2: .mpl.Y ~ 1 Resid. Df Resid. Dev Df Deviance P(>|Chi|) 1 698 406.94 2 699 408.10 -1 -1.15 0.28 > > > > cleanEx(); ..nameEx <- "ants" > > ### * ants > > flush(stderr()); flush(stdout()) > > ### Name: ants > ### Title: Harkness-Isham ants' nests data > ### Aliases: ants ants.extra > ### Keywords: datasets > > ### ** Examples > > > # Equivalent to Figure 1 of Harkness and Isham (1983) > > data(ants) > ants.extra$plot() > > # Data in subrectangle A, rotated > # Approximate data used by Sarkka (1993) > > angle <- atan(diff(ants.extra$fieldscrub$y)/diff(ants.extra$fieldscrub$x)) > plot(rotate(ants.extra$A, -angle)) Cataglyphis Messor 1 2 > > # Approximate window used by Takacs and Fiksel (1986) > > tfwindow <- bounding.box(ants$window) > antsTF <- ppp(ants$x, ants$y, window=tfwindow) > plot(antsTF) > > > > cleanEx(); ..nameEx <- "applynbd" > > ### * applynbd > > flush(stderr()); flush(stdout()) > > ### Name: applynbd > ### Title: Apply Function to Every Neighbourhood in a Point Pattern > ### Aliases: applynbd > ### Keywords: spatial > > ### ** Examples > > data(redwood) > > # count the number of points within radius 0.2 of each point of X > nneighbours <- applynbd(redwood, R=0.2, function(Y, ...){Y$n-1}) > # equivalent to: > nneighbours <- applynbd(redwood, R=0.2, function(Y, ...){Y$n}, exclude=TRUE) > > # compute the distance to the second nearest neighbour of each point > secondnndist <- applynbd(redwood, N = 2, + function(dists, ...){max(dists)}, + exclude=TRUE) > > # marked point pattern > data(longleaf) > ## Don't show: > # smaller dataset > longleaf <- longleaf[seq(1, longleaf$n, by=80)] > > ## End Don't show > # compute the median of the marks of all neighbours of a point > dbh.med <- applynbd(longleaf, R=40, exclude=TRUE, + function(Y, ...) { median(Y$marks)}) > > # ANIMATION explaining the definition of the K function > # (arguments `fullpicture' and 'rad' are passed to FUN) > > showoffK <- function(Y, current, dists, dranks, fullpicture,rad) { + plot(fullpicture, main="") + points(Y, cex=2) + u <- current + points(u[1],u[2],pch="+",cex=3) + theta <- seq(0,2*pi,length=100) + polygon(u[1]+ rad * cos(theta),u[2]+rad*sin(theta)) + text(u[1]+rad/3,u[2]+rad/2,Y$n,cex=3) + Sys.sleep(if(runif(1) < 0.1) 1.5 else 0.3) + return(Y$n - 1) + } > applynbd(redwood, R=0.2, showoffK, fullpicture=redwood, rad=0.2, exclude=TRUE) [1] 3 3 3 3 3 12 10 12 7 10 7 7 7 8 10 7 10 6 6 6 8 8 10 10 11 [26] 11 11 9 11 12 12 12 11 11 11 6 7 5 0 0 6 6 13 13 10 12 2 4 11 9 [51] 8 3 10 9 11 12 7 11 8 1 4 2 > > # animation explaining the definition of the G function > > showoffG <- function(Y, current, dists, dranks, fullpicture) { + plot(fullpicture, main="") + points(Y, cex=2) + u <- current + points(u[1],u[2],pch="+",cex=3) + v <- c(Y$x[1],Y$y[1]) + segments(u[1],u[2],v[1],v[2],lwd=2) + w <- (u + v)/2 + nnd <- dists[1] + text(w[1],w[2],round(nnd,3),cex=2) + Sys.sleep(if(runif(1) < 0.1) 1.5 else 0.3) + return(nnd) + } > > data(cells) > applynbd(cells, N=1, showoffG, exclude=TRUE, fullpicture=cells) [1] 0.14583895 0.11486514 0.14024621 0.11180340 0.11180340 0.15449595 [7] 0.15449595 0.11486514 0.14577380 0.14243595 0.15206906 0.12356780 [13] 0.12356780 0.12500000 0.12356780 0.14313630 0.13036104 0.13036104 [19] 0.10697663 0.13861097 0.12224974 0.15206906 0.13861097 0.08363014 [25] 0.13036104 0.11200000 0.12224974 0.15089400 0.15037619 0.10662551 [31] 0.11819052 0.08363014 0.13462912 0.11200000 0.10662551 0.13852076 [37] 0.14313630 0.14313630 0.13953136 0.12801562 0.12801562 0.13852076 > > > > cleanEx(); ..nameEx <- "area.owin" > > ### * area.owin > > flush(stderr()); flush(stdout()) > > ### Name: area.owin > ### Title: Area of a Window > ### Aliases: area.owin > ### Keywords: spatial > > ### ** Examples > > w <- unit.square() > area.owin(w) [1] 1 > # returns 1.00000 > > k <- 6 > theta <- 2 * pi * (0:(k-1))/k > co <- cos(theta) > si <- sin(theta) > mas <- owin(c(-1,1), c(-1,1), poly=list(x=co, y=si)) > area.owin(mas) [1] 2.598076 > # returns approx area of k-gon > > mas <- as.mask(w, eps=0.01) > X <- raster.x(mas) > Y <- raster.y(mas) > mas$m <- ((X - 0.5)^2 + (Y - 0.5)^2 <= 1) > area.owin(mas) [1] 1 > # returns 3.14 approx > > > > > cleanEx(); ..nameEx <- "as.im" > > ### * as.im > > flush(stderr()); flush(stdout()) > > ### Name: as.im > ### Title: Convert to Pixel Image > ### Aliases: as.im > ### Keywords: spatial > > ### ** Examples > > data(demopat) > # window object > W <- demopat$window > plot(W) > Z <- as.im(W) > image(Z) > # function > Z <- as.im(function(x,y) {x^2 + y^2}, unit.square()) > image(Z) > # function with extra arguments > f <- function(x, y, x0, y0) { + sqrt((x - x0)^2 + (y-y0)^2) + } > Z <- as.im(f, unit.square(), x0=0.5, y0=0.5) > image(Z) > # Revisit the Sixties > data(letterR) > Z <- as.im(f, letterR, x0=2.5, y0=2) > image(Z) > > > > cleanEx(); ..nameEx <- "as.mask" > > ### * as.mask > > flush(stderr()); flush(stdout()) > > ### Name: as.mask > ### Title: Pixel Image Approximation of a Window > ### Aliases: as.mask > ### Keywords: spatial > > ### ** Examples > > w <- owin(c(0,10),c(0,10), poly=list(x=c(1,2,3,2,1), y=c(2,3,4,6,7))) > ## Not run: plot(w) > m <- as.mask(w) > ## Not run: plot(m) > x <- 1:9 > y <- seq(0.25, 9.75, by=0.5) > m <- as.mask(w, xy=list(x=x, y=y)) > > > > cleanEx(); ..nameEx <- "as.owin" > > ### * as.owin > > flush(stderr()); flush(stdout()) > > ### Name: as.owin > ### Title: Convert Data To Class owin > ### Aliases: as.owin > ### Keywords: spatial > > ### ** Examples > > w <- as.owin(c(0,1,0,1)) > w <- as.owin(list(xrange=c(0,5),yrange=c(0,10))) > # point pattern > data(demopat) > w <- as.owin(demopat) > # image > Z <- as.im(function(x,y) { x + 3}, unit.square()) > w <- as.owin(Z) > > # Venables & Ripley 'spatial' package > require(spatial) Loading required package: spatial Attaching package: 'spatial' The following object(s) are masked from package:spatstat : Strauss [1] TRUE > towns <- ppinit("towns.dat") > w <- as.owin(towns) > detach(package:spatial) > > > > cleanEx(); ..nameEx <- "as.ppp" > > ### * as.ppp > > flush(stderr()); flush(stdout()) > > ### Name: as.ppp > ### Title: Convert Data To Class ppp > ### Aliases: as.ppp > ### Keywords: spatial > > ### ** Examples > > ## Not run: > ##D plot(c(0,1),c(0,1),type="n") > ##D xy <- locator(20) # click on 20 points in plot window > ##D pp <- as.ppp(xy, c(0,1,0,1)) > ##D > ##D w <- owin(c(0,1),c(0,1)) > ##D plot(w) # neater > ##D xy <- locator(20) # click on 20 points in plot window > ##D pp <- as.ppp(xy, w) > ##D > ## End(Not run) > > xy <- matrix(runif(40), ncol=2) > pp <- as.ppp(xy, c(0,1,0,1)) > > # Venables-Ripley format > require(spatial) Loading required package: spatial Attaching package: 'spatial' The following object(s) are masked from package:spatstat : Strauss [1] TRUE > towns <- ppinit("towns.dat") > pp <- as.ppp(towns) # converted to our format > detach(package:spatial) > > > > cleanEx(); ..nameEx <- "as.rectangle" > > ### * as.rectangle > > flush(stderr()); flush(stdout()) > > ### Name: as.rectangle > ### Title: Window Frame > ### Aliases: as.rectangle > ### Keywords: spatial > > ### ** Examples > > w <- owin(c(0,10),c(0,10), poly=list(x=c(1,2,3,2,1), y=c(2,3,4,6,7))) > r <- as.rectangle(w) > # returns a 10 x 10 rectangle > > > > cleanEx(); ..nameEx <- "bdist.pixels" > > ### * bdist.pixels > > flush(stderr()); flush(stdout()) > > ### Name: bdist.pixels > ### Title: Distance to Boundary of Window > ### Aliases: bdist.pixels > ### Keywords: spatial > > ### ** Examples > > u <- owin(c(0,1),c(0,1)) > d <- bdist.pixels(u, eps=0.01) > image(d) > d <- bdist.pixels(u, eps=0.01, coords=FALSE) > mean(d >= 0.1) [1] 0.64 > # value is approx (1 - 2 * 0.1)^2 = 0.64 > > > > cleanEx(); ..nameEx <- "bdist.points" > > ### * bdist.points > > flush(stderr()); flush(stdout()) > > ### Name: bdist.points > ### Title: Distance to Boundary of Window > ### Aliases: bdist.points > ### Keywords: spatial > > ### ** Examples > > data(cells) > d <- bdist.points(cells) > > > > cleanEx(); ..nameEx <- "betacells" > > ### * betacells > > flush(stderr()); flush(stdout()) > > ### Name: betacells > ### Title: Beta Ganglion Cells in Cat Retina > ### Aliases: betacells betacells.extra > ### Keywords: datasets > > ### ** Examples > > data(betacells) > plot(betacells) off on 1 2 > plot(betacells$window, main="beta cells") > symbols(betacells$x, betacells$y, + circles=sqrt(betacells.extra$area/pi), + inches=FALSE, add=TRUE) > > > > cleanEx(); ..nameEx <- "bounding.box" > > ### * bounding.box > > flush(stderr()); flush(stdout()) > > ### Name: bounding.box > ### Title: Bounding Box of a Window > ### Aliases: bounding.box > ### Keywords: spatial > > ### ** Examples > > w <- owin(c(0,10),c(0,10), poly=list(x=c(1,2,3,2,1), y=c(2,3,4,6,7))) > r <- bounding.box(w) > # returns rectangle [1,3] x [2,7] > > w2 <- unit.square() > r <- bounding.box(w, w2) > # returns rectangle [0,3] x [0,7] > > > > cleanEx(); ..nameEx <- "centroid.owin" > > ### * centroid.owin > > flush(stderr()); flush(stdout()) > > ### Name: centroid.owin > ### Title: Centroid of a window > ### Aliases: centroid.owin > ### Keywords: spatial > > ### ** Examples > > w <- owin(c(0,1),c(0,1)) > centroid.owin(w) $x [1] 0.5 $y [1] 0.5 > # returns 0.5, 0.5 > > data(demopat) > w <- demopat$window > # an irregular window > ## Not run: > ##D plot(w) > ##D # plot the window > ##D points(centroid.owin(w)) > ##D # mark its centroid > ##D > ## End(Not run) > > wapprox <- as.mask(w) > # pixel approximation of window > ## Not run: > ##D points(centroid.owin(wapprox)) > ##D # should be indistinguishable > ##D > ## End(Not run) > ## Don't show: > centroid.owin(w) $x [1] 5733.019 $y [1] 3634.136 > centroid.owin(wapprox) $x [1] 5732.25 $y [1] 3634.436 > > ## End Don't show > > > > cleanEx(); ..nameEx <- "coef.ppm" > > ### * coef.ppm > > flush(stderr()); flush(stdout()) > > ### Name: coef.ppm > ### Title: Coefficients of Fitted Point Process Model > ### Aliases: coef.ppm > ### Keywords: spatial > > ### ** Examples > > data(cells) > > poi <- ppm(cells, ~1, Poisson()) > coef(poi) $"log(lambda)" [1] 3.737670 > # This is the log of the fitted intensity of the Poisson process > > stra <- ppm(cells, ~1, Strauss(r=0.07), rbord=0.07) > coef(stra) (Intercept) Interaction 4.837446 -19.283583 > > # The two entries "(Intercept)" and "Interaction" > # are respectively log(beta) and log(gamma) > # in the usual notation for Strauss(beta, gamma, r) > > > > > cleanEx(); ..nameEx <- "complement.owin" > > ### * complement.owin > > flush(stderr()); flush(stdout()) > > ### Name: complement.owin > ### Title: Take Complement of a Window > ### Aliases: complement.owin > ### Keywords: spatial > > ### ** Examples > > # polygonal > data(demopat) > w <- demopat$window > outside <- complement.owin(w) > # mask > w <- as.mask(demopat$window) > outside <- complement.owin(w) > > > > cleanEx(); ..nameEx <- "concatxy" > > ### * concatxy > > flush(stderr()); flush(stdout()) > > ### Name: concatxy > ### Title: Concatenate x,y Coordinate Vectors > ### Aliases: concatxy > ### Keywords: spatial > > ### ** Examples > > dat <- runifrect(30) > xy <- list(x=runif(10),y=runif(10)) > new <- concatxy(dat, xy) > > > > cleanEx(); ..nameEx <- "copper" > > ### * copper > > flush(stderr()); flush(stdout()) > > ### Name: copper > ### Title: Berman-Huntington points and lines data > ### Aliases: copper > ### Keywords: datasets > > ### ** Examples > > > data(copper) > > # Plot full dataset > > plot(copper$points) > cl <- copper$lines > segments(cl[,1], cl[,2], cl[,3], cl[,4]) > > # Plot southern half of data > plot(copper$SouthPoints) > cl <- copper$SouthLines > segments(cl[,1], cl[,2], cl[,3], cl[,4]) > > ## Not run: > ##D Z <- copper$SouthDistance() > ##D plot(Z) > ##D X <- copper$SouthPoints > ##D ppm(X, ~D, covariates=list(D=Z)) > ##D > ## End(Not run) > > > > cleanEx(); ..nameEx <- "corners" > > ### * corners > > flush(stderr()); flush(stdout()) > > ### Name: corners > ### Title: Corners of a rectangle > ### Aliases: corners > ### Keywords: spatial > > ### ** Examples > > w <- unit.square() > corners(w) $x [1] 0 1 0 1 $y [1] 0 0 1 1 > # returns list(x=c(0,1,0,1),y=c(0,0,1,1)) > > > > cleanEx(); ..nameEx <- "crossdist" > > ### * crossdist > > flush(stderr()); flush(stdout()) > > ### Name: crossdist > ### Title: Pairwise distances between two different point patterns > ### Aliases: crossdist crossdist.ppp crossdist.default > ### Keywords: spatial > > ### ** Examples > > data(cells) > d <- crossdist(cells, runifpoint(6)) > > d <- crossdist(runif(7), runif(7), runif(12), runif(12)) > > > > cleanEx(); ..nameEx <- "cut.ppp" > > ### * cut.ppp > > flush(stderr()); flush(stdout()) > > ### Name: cut.ppp > ### Title: Convert Point Pattern Marks from Numeric to Factor > ### Aliases: cut.ppp cut > ### Keywords: spatial > > ### ** Examples > > data(longleaf) > # Longleaf Pines data > # the marks are positive real numbers indicating tree diameters. > > ## Don't show: > # smaller dataset > longleaf <- longleaf[seq(1, longleaf$n, by=80)] > > ## End Don't show > ## Not run: > ##D plot(longleaf) > ##D > ## End(Not run) > > # cut the range of tree diameters into three intervals > long3 <- cut(longleaf, 3) > ## Not run: > ##D plot(long3) > ##D > ## End(Not run) > > # adult trees defined to have diameter at least 30 cm > long2 <- cut(longleaf, breaks=c(0,30,100), labels=c("Sapling", "Adult")) > plot(long2) Sapling Adult 1 2 > plot(long2, cols=c("green","blue")) Sapling Adult 1 2 > > > > cleanEx(); ..nameEx <- "data.ppm" > > ### * data.ppm > > flush(stderr()); flush(stdout()) > > ### Name: data.ppm > ### Title: Extract Original Data from a Fitted Point Process Model > ### Aliases: data.ppm > ### Keywords: spatial > > ### ** Examples > > data(cells) > fit <- ppm(cells, ~1, Strauss(r=0.1), rbord=0.1) > X <- data.ppm(fit) > # 'X' is identical to 'cells' > > > > cleanEx(); ..nameEx <- "default.dummy" > > ### * default.dummy > > flush(stderr()); flush(stdout()) > > ### Name: default.dummy > ### Title: Generate a Default Pattern of Dummy Points > ### Aliases: default.dummy > ### Keywords: spatial > > ### ** Examples > > data(simdat) > P <- simdat > D <- default.dummy(P, 100) > ## Not run: plot(D) > Q <- quadscheme(P, D, "grid") > ## Not run: plot(union.quad(Q)) > > > > cleanEx(); ..nameEx <- "diagnose.ppm" > > ### * diagnose.ppm > > flush(stderr()); flush(stdout()) > > ### Name: diagnose.ppm > ### Title: Diagnostic Plots for Fitted Point Process Model > ### Aliases: diagnose.ppm > ### Keywords: spatial > > ### ** Examples > > data(cells) > fit <- ppm(cells, ~x, Strauss(r=0.15), rbord=0.15) > diagnose.ppm(fit, rbord=0.15) Model diagnostics (raw residuals) Diagnostics available: four-panel plot mark plot smoothed residual field x cumulative residuals y cumulative residuals sum of all residuals sum of raw residuals in clipped window = -9.558e-09 area of clipped window = 0.49 range of smoothed field = [ -51.05,37.61 ] > diagnose.ppm(fit, type="pearson", rbord=0.15) Model diagnostics (Pearson residuals) Diagnostics available: four-panel plot mark plot smoothed residual field x cumulative residuals y cumulative residuals sum of all residuals sum of Pearson residuals in clipped window = 0.1981 area of clipped window = 0.49 range of smoothed field = [ -5.18,16.05 ] > diagnose.ppm(fit, rbord=0.15, which="marks") Model diagnostics (raw residuals) Diagnostics available: mark plot > diagnose.ppm(fit, rbord=0.15, type="raw", plot.neg="discrete") Model diagnostics (raw residuals) Diagnostics available: four-panel plot mark plot (discrete representation only) smoothed residual field x cumulative residuals y cumulative residuals sum of all residuals sum of raw residuals in clipped window = -9.558e-09 area of clipped window = 0.49 range of smoothed field = [ -51.05,37.61 ] > > # save the diagnostics and plot them later > u <- diagnose.ppm(fit, rbord=0.15, plot.it=FALSE) > plot(u) > plot(u, which="marks") > > > > cleanEx(); ..nameEx <- "diameter" > > ### * diameter > > flush(stderr()); flush(stdout()) > > ### Name: diameter > ### Title: Diameter of a Window Frame > ### Aliases: diameter > ### Keywords: spatial > > ### ** Examples > > w <- owin(c(0,1),c(0,1)) > diameter(w) [1] 1.414214 > # returns sqrt(2) > > > > cleanEx(); ..nameEx <- "dirichlet.weights" > > ### * dirichlet.weights > > flush(stderr()); flush(stdout()) > > ### Name: dirichlet.weights > ### Title: Compute Quadrature Weights Based on Dirichlet Tessellation > ### Aliases: dirichlet.weights > ### Keywords: spatial > > ### ** Examples > > Q <- quadscheme(runifpoispp(10)) > X <- as.ppp(Q) # data and dummy points together > w <- dirichlet.weights(X, exact=FALSE) > > > > cleanEx(); ..nameEx <- "distmap" > > ### * distmap > > flush(stderr()); flush(stdout()) > > ### Name: distmap > ### Title: Distance Map > ### Aliases: distmap > ### Keywords: spatial > > ### ** Examples > > data(cells) > U <- distmap(cells) > data(letterR) > V <- distmap(letterR) > ## Not run: > ##D plot(U) > ##D plot(V) > ##D > ## End(Not run) > > > > cleanEx(); ..nameEx <- "distmap.owin" > > ### * distmap.owin > > flush(stderr()); flush(stdout()) > > ### Name: distmap.owin > ### Title: Distance Map of Window > ### Aliases: distmap.owin > ### Keywords: spatial > > ### ** Examples > > data(letterR) > U <- distmap(letterR) > ## Not run: > ##D plot(U) > ##D plot(attr(U, "bdry")) > ##D > ## End(Not run) > > > > cleanEx(); ..nameEx <- "distmap.ppp" > > ### * distmap.ppp > > flush(stderr()); flush(stdout()) > > ### Name: distmap.ppp > ### Title: Distance Map of Point Pattern > ### Aliases: distmap.ppp > ### Keywords: spatial > > ### ** Examples > > data(cells) > U <- distmap(cells) > ## Not run: > ##D plot(U) > ##D plot(attr(U, "bdry")) > ##D plot(attr(U, "index")) > ##D > ## End(Not run) > > > > cleanEx(); ..nameEx <- "dummy.ppm" > > ### * dummy.ppm > > flush(stderr()); flush(stdout()) > > ### Name: dummy.ppm > ### Title: Extract Dummy Points Used to Fit a Point Process Model > ### Aliases: dummy.ppm > ### Keywords: spatial > > ### ** Examples > > data(cells) > fit <- ppm(cells, ~1, Strauss(r=0.1), rbord=0.1) > X <- dummy.ppm(fit) > X$n [1] 629 > # this is the number of dummy points in the quadrature scheme > > > > cleanEx(); ..nameEx <- "eem" > > ### * eem > > flush(stderr()); flush(stdout()) > > ### Name: eem > ### Title: Exponential Energy Marks > ### Aliases: eem > ### Keywords: spatial > > ### ** Examples > > data(cells) > fit <- ppm(cells, ~x, Strauss(r=0.15), rbord=0.15) > ee <- eem(fit) > sum(ee)/area.owin(cells$window) # should be about 1 if model is correct [1] 0.8578947 > Y <- setmarks(cells, ee) > plot(Y, main="Cells data\n Exponential energy marks") 0 0.05 0.1 0.15 0.2 0.00000000 0.02999414 0.05998828 0.08998241 0.11997655 > > > > cleanEx(); ..nameEx <- "envelope" > > ### * envelope > > flush(stderr()); flush(stdout()) > > ### Name: envelope > ### Title: Simulation envelopes of summary function > ### Aliases: envelope > ### Keywords: spatial > > ### ** Examples > > X <- rpoispp(42) > > # Envelope of K function under CSR > ## Not run: > ##D plot(envelope(X)) > ##D > ## End(Not run) > ## Don't show: > plot(envelope(X, nsim=5)) Generating 5 simulations of CSR ... 1, 2, 3, 4, 5. Done. lty col obs 1 1 theo 2 2 lo 3 3 hi 4 4 > > ## End Don't show > > # Translation edge correction (this is also FASTER): > ## Not run: > ##D plot(envelope(X, correction="translate")) > ##D > ## End(Not run) > ## Don't show: > plot(envelope(X, nsim=5, correction="translate")) Generating 5 simulations of CSR ... 1, 2, 3, 4, 5. Done. lty col obs 1 1 theo 2 2 lo 3 3 hi 4 4 > > ## End Don't show > > # Envelope of K function for simulations from model > data(cells) > fit <- ppm(cells, ~1, Strauss(0.05)) > ## Not run: > ##D plot(envelope(fit)) > ##D > ## End(Not run) > ## Don't show: > plot(envelope(fit, nsim=4)) Generating 4 simulations of model ... 1, 2, 3, 4. Done. lty col obs 1 1 mmean 2 2 lo 3 3 hi 4 4 > > ## End Don't show > > # Envelope of G function under CSR > ## Not run: > ##D plot(envelope(X, Gest)) > ##D > ## End(Not run) > ## Don't show: > plot(envelope(X, Gest, nsim=5)) Generating 5 simulations of CSR ... 1, 2, 3, 4, 5. Done. lty col obs 1 1 theo 2 2 lo 3 3 hi 4 4 > > ## End Don't show > > # Use of `simulate' > ## Not run: > ##D plot(envelope(X, Gest, simulate=expression(runifpoint(42)))) > ##D plot(envelope(X, Gest, simulate=expression(rMaternI(100,0.02)))) > ##D > ## End(Not run) > ## Don't show: > plot(envelope(X, Gest, simulate=expression(runifpoint(42)), nsim=5)) Generating 5 simulations ... 1, 2, 3, 4, 5. Done. lty col obs 1 1 mmean 2 2 lo 3 3 hi 4 4 > plot(envelope(X, Gest, simulate=expression(rMaternI(100, 0.02)), nsim=5)) Generating 5 simulations ... 1, 2, 3, 4, 5. Done. lty col obs 1 1 mmean 2 2 lo 3 3 hi 4 4 > > ## End Don't show > > > > > cleanEx(); ..nameEx <- "erode.owin" > > ### * erode.owin > > flush(stderr()); flush(stdout()) > > ### Name: erode.owin > ### Title: Erode a Window > ### Aliases: erode.owin > ### Keywords: spatial > > ### ** Examples > > w <- owin(c(0,1),c(0,1)) > v <- erode.owin(w, 0.1) > # returns rectangle [0.1, 0.9] x [0.1,0.9] > ## Not run: > ##D v <- erode.owin(w, 0.6) > ##D #fails - erosion is empty > ##D > ## End(Not run) > > > > cleanEx(); ..nameEx <- "eroded.areas" > > ### * eroded.areas > > flush(stderr()); flush(stdout()) > > ### Name: eroded.areas > ### Title: Areas of Morphological Erosions > ### Aliases: eroded.areas > ### Keywords: spatial > > ### ** Examples > > w <- owin(c(0,1),c(0,1)) > a <- eroded.areas(w, seq(0.01,0.49,by=0.01)) > > > > cleanEx(); ..nameEx <- "expand.owin" > > ### * expand.owin > > flush(stderr()); flush(stdout()) > > ### Name: expand.owin > ### Title: Expand Window By Factor > ### Aliases: expand.owin > ### Keywords: spatial > > ### ** Examples > > w <- square(1) > expand.owin(w, 9) window: rectangle = [ -1 , 2 ] x [ -1 , 2 ] > # returns the square [-1,2] x [-1,2] > > > > cleanEx(); ..nameEx <- "fasp.object" > > ### * fasp.object > > flush(stderr()); flush(stdout()) > > ### Name: fasp.object > ### Title: Function Arrays for Spatial Patterns > ### Aliases: fasp.object > ### Keywords: spatial > > ### ** Examples > > # unmarked point pattern > data(swedishpines) > ## Don't show: > # smaller dataset > swedishpines <- swedishpines[1:30] > > ## End Don't show > a <- allstats(swedishpines,dataname="Swedish Pines") > a Function array (class "fasp") Dimensions: 2 x 2 Title: Four summary functions for Swedish Pines. > plot(a) > plot(a[1,]) > > # multitype point pattern > data(amacrine) > a <- alltypes(amacrine, "G") > plot(a) > > # select the row corresponding to cells of type "on" > b <- a["on", ] > plot(b) > > > > cleanEx(); ..nameEx <- "finpines" > > ### * finpines > > flush(stderr()); flush(stdout()) > > ### Name: finpines > ### Title: Pine saplings in Finland. > ### Aliases: finpines finpines.extra > ### Keywords: datasets > > ### ** Examples > > data(finpines) > plot(unmark(finpines), main="Finnish pines: locations") > plot(finpines, main="locations and heights") 0 1 2 3 4 5 6 0.0000000 0.1303089 0.2606178 0.3909267 0.5212356 0.6515445 0.7818534 > plot(finpines %mark% finpines.extra$diameter, main="diameters") 0 1 2 3 4 5 6 7 0.000000 0.100524 0.201048 0.301572 0.402096 0.502620 0.603144 0.703668 > > > > cleanEx(); ..nameEx <- "fitted.ppm" > > ### * fitted.ppm > > flush(stderr()); flush(stdout()) > > ### Name: fitted.ppm > ### Title: Fitted Conditional Intensity for Point Process Model > ### Aliases: fitted.ppm > ### Keywords: spatial > > ### ** Examples > > data(cells) > str <- ppm(cells, ~x, Strauss(r=0.15), rbord=0.15) > lambda <- fitted(str) > > # extract quadrature points in corresponding order > quadpoints <- union.quad(quad.ppm(str)) > > # plot conditional intensity values > # as circles centred on the quadrature points > quadmarked <- setmarks(quadpoints, lambda) > plot(quadmarked) 0 1000 2000 3000 4000 5000 0.000000000 0.006575748 0.013151497 0.019727245 0.026302994 0.032878742 > > > > cleanEx(); ..nameEx <- "fv.object" > > ### * fv.object > > flush(stderr()); flush(stdout()) > > ### Name: fv.object > ### Title: Data Frames of Function Values > ### Aliases: fv.object > ### Keywords: spatial > > ### ** Examples > > data(cells) > K <- Kest(cells) > > class(K) [1] "fv" "data.frame" > > K # prints a sensible summary Function value object (class "fv") for the function r -> K(r) Entries: id label description -- ----- ----------- r r distance argument r theo Kpois(r) theoretical Poisson K(r) border Kbord(r) border-corrected estimate of K(r) trans Ktrans(r) translation-corrected estimate of K(r) iso Kiso(r) Ripley isotropic correction estimate of K(r) -------------------------------------- Default plot formula: . ~ r Recommended range of argument r: [0, 0.25] > > plot(K) lty col iso 1 1 trans 2 2 border 3 3 theo 4 4 > > > > cleanEx(); ..nameEx <- "gridcentres" > > ### * gridcentres > > flush(stderr()); flush(stdout()) > > ### Name: gridcentres > ### Title: Rectangular grid of points > ### Aliases: gridcentres gridcenters > ### Keywords: spatial > > ### ** Examples > > w <- unit.square() > xy <- gridcentres(w, 10,15) > ## Not run: > ##D plot(w) > ##D points(xy) > ##D > ## End(Not run) > > bdry <- list(x=c(0.1,0.3,0.7,0.4,0.2), + y=c(0.1,0.1,0.5,0.7,0.3)) > w <- owin(c(0,1), c(0,1), poly=bdry) > xy <- gridcentres(w, 30, 30) > ok <- inside.owin(xy$x, xy$y, w) > ## Not run: > ##D plot(w) > ##D points(xy$x[ok], xy$y[ok]) > ##D > ## End(Not run) > > > > cleanEx(); ..nameEx <- "gridweights" > > ### * gridweights > > flush(stderr()); flush(stdout()) > > ### Name: gridweights > ### Title: Compute Quadrature Weights Based on Grid Counts > ### Aliases: gridweights > ### Keywords: spatial > > ### ** Examples > > Q <- quadscheme(runifpoispp(10)) > X <- as.ppp(Q) # data and dummy points together > w <- gridweights(X, 10) > w <- gridweights(X, c(10, 10)) > > > > cleanEx(); ..nameEx <- "harmonic" > > ### * harmonic > > flush(stderr()); flush(stdout()) > > ### Name: harmonic > ### Title: Basis for Harmonic Functions > ### Aliases: harmonic > ### Keywords: spatial > > ### ** Examples > > data(longleaf) > X <- unmark(longleaf) > # inhomogeneous point pattern > ## Don't show: > # smaller dataset > longleaf <- longleaf[seq(1,longleaf$n, by=50)] > > ## End Don't show > > # fit Poisson point process with log-cubic intensity > fit.3 <- ppm(X, ~ polynom(x,y,3), Poisson()) > > # fit Poisson process with log-cubic-harmonic intensity > fit.h <- ppm(X, ~ harmonic(x,y,3), Poisson()) > > # Likelihood ratio test > lrts <- 2 * (fit.3$maxlogpl - fit.h$maxlogpl) > x <- X$x > y <- X$y > df <- ncol(polynom(x,y,3)) - ncol(harmonic(x,y,3)) > pval <- 1 - pchisq(lrts, df=df) > > > > cleanEx(); ..nameEx <- "im" > > ### * im > > flush(stderr()); flush(stdout()) > > ### Name: im > ### Title: Create a Pixel Image Object > ### Aliases: im > ### Keywords: spatial > > ### ** Examples > > whitenoise <- im(matrix(rnorm(10000), 100, 100)) > image(whitenoise) > > > > cleanEx(); ..nameEx <- "inside.owin" > > ### * inside.owin > > flush(stderr()); flush(stdout()) > > ### Name: inside.owin > ### Title: Test Whether Points Are Inside A Window > ### Aliases: inside.owin > ### Keywords: spatial > > ### ** Examples > > # hexagonal window > k <- 6 > theta <- 2 * pi * (0:(k-1))/k > co <- cos(theta) > si <- sin(theta) > mas <- owin(c(-1,1), c(-1,1), poly=list(x=co, y=si)) > ## Not run: > ##D plot(mas) > ##D > ## End(Not run) > > # random points in rectangle > x <- runif(30,min=-1, max=1) > y <- runif(30,min=-1, max=1) > > ok <- inside.owin(x, y, mas) > > ## Not run: > ##D points(x[ok], y[ok]) > ##D points(x[!ok], y[!ok], pch="x") > ##D > ## End(Not run) > > > > cleanEx(); ..nameEx <- "intersect.owin" > > ### * intersect.owin > > flush(stderr()); flush(stdout()) > > ### Name: intersect.owin > ### Title: Intersection or Union of Two Windows > ### Aliases: intersect.owin union.owin > ### Keywords: spatial > > ### ** Examples > > # rectangles > u <- unit.square() > v <- owin(c(0.5,3.5), c(0.4,2.5)) > # polygon > data(letterR) > # mask > m <- as.mask(letterR) > > # two rectangles > intersect.owin(u, v) window: rectangle = [ 0.5 , 1 ] x [ 0.4 , 1 ] > union.owin(u,v) window: binary image mask enclosing rectangle: [ 0 , 3.5 ] x [ 0 , 2.5 ] > > # polygon and rectangle > intersect.owin(letterR, v) window: binary image mask enclosing rectangle: [ 2.017 , 3.5 ] x [ 0.645 , 2.5 ] > union.owin(letterR,v) window: binary image mask enclosing rectangle: [ 0.5 , 3.93 ] x [ 0.4 , 3.278 ] > > # mask and rectangle > intersect.owin(m, v) window: binary image mask enclosing rectangle: [ 2.017 , 3.5 ] x [ 0.645 , 2.5 ] > union.owin(m,v) window: binary image mask enclosing rectangle: [ 0.5 , 3.93 ] x [ 0.4 , 3.278 ] > # > A <- letterR > B <- rotate(letterR, 0.2) > plot(bounding.box(A,B), main="intersection") > w <- intersect.owin(A, B) > plot(w, add=TRUE) > plot(A, add=TRUE) > plot(B, add=TRUE) > > plot(bounding.box(A,B), main="union") > w <- union.owin(A,B) > plot(w, add=TRUE) > plot(A, add=TRUE) > plot(B, add=TRUE) > > > > cleanEx(); ..nameEx <- "is.marked.ppm" > > ### * is.marked.ppm > > flush(stderr()); flush(stdout()) > > ### Name: is.marked.ppm > ### Title: Test Whether A Point Process Model is Marked > ### Aliases: is.marked.ppm > ### Keywords: spatial > > ### ** Examples > > data(lansing) > # Multitype point pattern --- trees marked by species > > ## Don't show: > # Smaller dataset > data(betacells) > lansing <- betacells[seq(2, 135, by=3), ] > > ## End Don't show > > fit1 <- ppm(lansing, ~ marks, Poisson()) > is.marked(fit1) [1] TRUE > # TRUE > > fit2 <- ppm(lansing, ~ 1, Poisson()) > is.marked(fit2) [1] TRUE > # TRUE > > data(cells) > # Unmarked point pattern > > fit3 <- ppm(cells, ~ 1, Poisson()) > is.marked(fit3) [1] FALSE > # FALSE > > > > > cleanEx(); ..nameEx <- "is.marked.ppp" > > ### * is.marked.ppp > > flush(stderr()); flush(stdout()) > > ### Name: is.marked.ppp > ### Title: Test Whether A Point Pattern is Marked > ### Aliases: is.marked.ppp > ### Keywords: spatial > > ### ** Examples > > data(cells) > is.marked(cells) #FALSE [1] FALSE > data(longleaf) > is.marked(longleaf) #TRUE [1] TRUE > > > > cleanEx(); ..nameEx <- "is.subset.owin" > > ### * is.subset.owin > > flush(stderr()); flush(stdout()) > > ### Name: is.subset.owin > ### Title: Determine Whether One Window is Contained In Another > ### Aliases: is.subset.owin > ### Keywords: spatial > > ### ** Examples > > w1 <- as.owin(c(0,1,0,1)) > w2 <- as.owin(c(-1,2,-1,2)) > is.subset.owin(w1,w2) # Returns TRUE. [1] TRUE > is.subset.owin(w2,w1) # Returns FALSE. [1] FALSE > > > > cleanEx(); ..nameEx <- "ksmooth.ppp" > > ### * ksmooth.ppp > > flush(stderr()); flush(stdout()) > > ### Name: ksmooth.ppp > ### Title: Kernel Smoothed Intensity of Point Pattern > ### Aliases: ksmooth.ppp > ### Keywords: spatial > > ### ** Examples > > data(cells) > Z <- ksmooth.ppp(cells, 0.05) > plot(Z) > > > > cleanEx(); ..nameEx <- "lurking" > > ### * lurking > > flush(stderr()); flush(stdout()) > > ### Name: lurking > ### Title: Lurking variable plot > ### Aliases: lurking > ### Keywords: spatial > > ### ** Examples > > data(nztrees) > fit <- ppm(nztrees, ~x, Poisson()) > lurking(fit, expression(x)) > lurking(fit, expression(x), cumulative=FALSE) > > > > cleanEx(); ..nameEx <- "markcorr" > > ### * markcorr > > flush(stderr()); flush(stdout()) > > ### Name: markcorr > ### Title: Mark Correlation Function > ### Aliases: markcorr > ### Keywords: spatial > > ### ** Examples > > # CONTINUOUS-VALUED MARKS: > # (1) Longleaf Pine data > # marks represent tree diameter > data(longleaf) > # Subset of this large pattern > swcorner <- owin(c(0,100),c(0,100)) > sub <- longleaf[ , swcorner] > # mark correlation function > mc <- markcorr(sub) > plot(mc) lty col iso 1 1 trans 2 2 border 3 3 theo 4 4 > > # (2) simulated data with independent marks > X <- rpoispp(100) > X <- X %mark% runif(X$n) > Xc <- markcorr(X) > plot(Xc) lty col iso 1 1 trans 2 2 border 3 3 theo 4 4 > > # MULTITYPE DATA: > # Hughes' amacrine data > # Cells marked as 'on'/'off' > data(amacrine) > # (3) Kernel density estimate with Epanecnikov kernel > # (as proposed by Stoyan & Stoyan) > M <- markcorr(amacrine, function(m1,m2) {m1==m2}, + correction="translate", method="density", + kernel="epanechnikov") > plot(M) lty col trans 1 1 theo 2 2 > # Note: kernel="epanechnikov" comes from help(density) > > # (4) Same again with explicit control over bandwidth > M <- markcorr(amacrine, function(m1,m2) {m1==m2}, + correction="translate", method="density", + kernel="epanechnikov", bw=0.02) > # see help(density) for correct interpretation of 'bw' > > ## Don't show: > data(betacells) > betacells <- betacells[seq(1,betacells$n,by=3)] > niets <- markcorr(betacells, function(m1,m2){m1 == m2}, method="loess") > niets <- markcorr(X, correction="isotropic", method="smrep") > > ## End Don't show > > > > cleanEx(); ..nameEx <- "nearest.raster.point" > > ### * nearest.raster.point > > flush(stderr()); flush(stdout()) > > ### Name: nearest.raster.point > ### Title: Find Pixel Nearest to a Given Point > ### Aliases: nearest.raster.point > ### Keywords: spatial > > ### ** Examples > > w <- owin(c(0,1), c(0,1), mask=matrix(TRUE, 100,100)) # 100 x 100 grid > nearest.raster.point(0.5, 0.3, w) $row [1] 30 $col [1] 51 > nearest.raster.point(0.5, 0.3, w, indices=FALSE) $x [1] 0.505 $y [1] 0.295 > > > > cleanEx(); ..nameEx <- "nndist" > > ### * nndist > > flush(stderr()); flush(stdout()) > > ### Name: nndist > ### Title: Nearest neighbour distances > ### Aliases: nndist nndist.ppp nndist.default > ### Keywords: spatial > > ### ** Examples > > data(cells) > d <- nndist(cells) > > x <- runif(100) > y <- runif(100) > d <- nndist(x, y) > > # Stienen diagram > plot(cells %mark% (nndist(cells)/2), markscale=1) 0.04 0.05 0.06 0.07 0.08 0.04 0.05 0.06 0.07 0.08 > > > > cleanEx(); ..nameEx <- "owin" > > ### * owin > > flush(stderr()); flush(stdout()) > > ### Name: owin > ### Title: Create a Window > ### Aliases: owin > ### Keywords: spatial > > ### ** Examples > > w <- owin() > w <- owin(c(0,1), c(0,1)) > # the unit square > > w <- owin(c(10,20), c(10,30)) > # a rectangle of dimensions 10 x 20 units > # with lower left corner at (10,10) > > # polygon (diamond shape) > w <- owin(poly=list(x=c(0.5,1,0.5,0),y=c(0,1,2,1))) > w <- owin(c(0,1), c(0,2), poly=list(x=c(0.5,1,0.5,0),y=c(0,1,2,1))) > > # polygon with hole > ho <- owin(poly=list(list(x=c(0,1,1,0), y=c(0,0,1,1)), + list(x=c(0.6,0.4,0.4,0.6), y=c(0.2,0.2,0.4,0.4)))) > > w <- owin(c(-1,1), c(-1,1), mask=matrix(TRUE, 100,100)) > # 100 x 100 image, all TRUE > X <- raster.x(w) > Y <- raster.y(w) > wm <- owin(w$xrange, w$yrange, mask=(X^2 + Y^2 <= 1)) > # discrete approximation to the unit disc > > ## Not run: > ##D plot(c(0,1),c(0,1),type="n") > ##D bdry <- locator() > ##D # click the vertices of a polygon (anticlockwise) > ##D > ## End(Not run) > ## Don't show: > bdry <- list(x=c(0.1,0.3,0.7,0.4,0.2), + y=c(0.1,0.1,0.5,0.7,0.3)) > > ## End Don't show > w <- owin(poly=bdry) > ## Not run: plot(w) > > ## Not run: > ##D im <- as.logical(matrix(scan("myfile"), nrow=128, ncol=128)) > ##D # read in an arbitrary 128 x 128 digital image from text file > ##D rim <- im[, 128:1] > ##D # Assuming it was given in row-major order in the file > ##D # i.e. scanning left-to-right in rows from top-to-bottom, > ##D # the use of matrix() has effectively transposed rows & columns, > ##D # so to convert it to our format just reverse the column order. > ##D w <- owin(mask=rim) > ##D plot(w) > ##D # display it to check! > ##D > ## End(Not run) > > > > cleanEx(); ..nameEx <- "owin.object" > > ### * owin.object > > flush(stderr()); flush(stdout()) > > ### Name: owin.object > ### Title: Class owin > ### Aliases: owin.object > ### Keywords: spatial > > ### ** Examples > > w <- owin() > w <- owin(c(0,1), c(0,1)) > # the unit square > > w <- owin(c(0,1), c(0,2)) > ## Not run: > ##D plot(w) > ##D # plots edges of a box 1 unit x 2 units > ##D v <- locator() > ##D # click on points in the plot window > ##D # to be the vertices of a polygon > ##D # traversed in anticlockwise order > ##D u <- owin(c(0,1), c(0,2), poly=v) > ##D plot(u) > ##D # plots polygonal boundary using polygon() > ##D plot(as.mask(u, eps=0.02)) > ##D # plots discrete pixel approximation to polygon > ##D > ## End(Not run) > > > > cleanEx(); ..nameEx <- "pairdist" > > ### * pairdist > > flush(stderr()); flush(stdout()) > > ### Name: pairdist > ### Title: Pairwise distances > ### Aliases: pairdist pairdist.ppp pairdist.default > ### Keywords: spatial > > ### ** Examples > > data(cells) > d <- pairdist(cells) > > x <- runif(100) > y <- runif(100) > d <- pairdist(x, y) > > > > cleanEx(); ..nameEx <- "pcf" > > ### * pcf > > flush(stderr()); flush(stdout()) > > ### Name: pcf > ### Title: Pair Correlation Function > ### Aliases: pcf > ### Keywords: spatial > > ### ** Examples > > # ppp object > data(simdat) > ## Don't show: > simdat <- simdat[seq(1,simdat$n, by=4)] > > ## End Don't show > p <- pcf(simdat) > plot(p) lty col ripl 1 1 trans 2 2 theo 3 3 > > # fv object > K <- Kest(simdat) > p2 <- pcf(K) > plot(p2) lty col pcf 1 1 theo 2 2 > > # multitype pattern; fasp object > data(betacells) > ## Don't show: > betacells <- betacells[seq(1,betacells$n, by=10)] > > ## End Don't show > p <- pcf(alltypes(betacells, "K")) > plot(p) > > > > cleanEx(); ..nameEx <- "pcf.fasp" > > ### * pcf.fasp > > flush(stderr()); flush(stdout()) > > ### Name: pcf.fasp > ### Title: Pair Correlation Function obtained from array of K functions > ### Aliases: pcf.fasp > ### Keywords: spatial > > ### ** Examples > > # multitype point pattern > data(betacells) > ## Don't show: > betacells <- betacells[seq(1,betacells$n, by=10)] > > ## End Don't show > KK <- alltypes(betacells, "K") > p <- pcf.fasp(KK, spar=0.5, method="b") > plot(p) > # short range inhibition between all types > # strong inhibition between "on" and "off" > > > > cleanEx(); ..nameEx <- "pcf.fv" > > ### * pcf.fv > > flush(stderr()); flush(stdout()) > > ### Name: pcf.fv > ### Title: Pair Correlation Function obtained from K Function > ### Aliases: pcf.fv > ### Keywords: spatial > > ### ** Examples > > # univariate point pattern > data(simdat) > ## Don't show: > simdat <- simdat[seq(1,simdat$n, by=4)] > > ## End Don't show > K <- Kest(simdat) > p <- pcf.fv(K, spar=0.5, method="b") > plot(p, main="pair correlation function for simdat") lty col pcf 1 1 theo 2 2 > # indicates inhibition at distances r < 0.3 > > > > cleanEx(); ..nameEx <- "pcf.ppp" > > ### * pcf.ppp > > flush(stderr()); flush(stdout()) > > ### Name: pcf.ppp > ### Title: Pair Correlation Function of Point Pattern > ### Aliases: pcf.ppp > ### Keywords: spatial > > ### ** Examples > > data(simdat) > p <- pcf(simdat) > ## Don't show: > simdat <- simdat[seq(1,simdat$n, by=4)] > > ## End Don't show > plot(p, main="pair correlation function for simdat") lty col ripl 1 1 trans 2 2 theo 3 3 > # indicates inhibition at distances r < 0.3 > > > > cleanEx(); ..nameEx <- "plot.fasp" > > ### * plot.fasp > > flush(stderr()); flush(stdout()) > > ### Name: plot.fasp > ### Title: Plot a Function Array > ### Aliases: plot.fasp plot > ### Keywords: spatial > > ### ** Examples > > ## Not run: > ##D # Bramble Canes data. > ##D data(bramblecanes) > ##D > ##D X.G <- alltypes(bramblecanes,type="G",dataname="Bramblecanes",verb=TRUE) > ##D plot(X.G) > ##D plot(X.G,subset="r<=0.2") > ##D plot(X.G,formule=cbind(asin(sqrt(km)), > ##D asin(sqrt(theo))) ~ asin(sqrt(theo))) > ##D plot(X.G,fo=cbind(km-theo,0)~r,"r<=0.2") > ##D > ##D # Swedish pines. > ##D data(swedishpines) > ##D X <- allstats(swedishpines,dataname="Swedish Pines") > ##D plot(X,subset=list("r<=20","r<=20","r<=20","r<=50")) > ##D > ##D # Simulated data. > ##D pp <- runifpoint(350, owin(c(0,1),c(0,1))) > ##D pp$marks <- factor(c(rep(1,50),rep(2,100),rep(3,200))) > ##D X.K <- alltypes(pp,type="K",verb=TRUE,dataname="Fake Data") > ##D plot(X.K,fo=cbind(border,theo)~theo,"theo<=0.75") > ##D > ## End(Not run) > > > > cleanEx(); ..nameEx <- "plot.fv" > > ### * plot.fv > > flush(stderr()); flush(stdout()) > > ### Name: plot.fv > ### Title: Plot Function Valuesn > ### Aliases: plot.fv > ### Keywords: spatial > > ### ** Examples > > data(cells) > K <- Kest(cells) > # K is an object of class "fv" > > plot(K, iso ~ r) # plots iso against r > > plot(K, sqrt(iso/pi) ~ r) # plots sqrt(iso/r) against r > > plot(K, cbind(iso,theo) ~ r) # plots iso against r AND theo against r lty col iso 1 1 theo 2 2 > > plot(K, . ~ r) # plots all available estimates of K against r lty col iso 1 1 trans 2 2 border 3 3 theo 4 4 > > plot(K, sqrt(./pi) ~ r) # plots all estimates of L-function lty col iso 1 1 trans 2 2 border 3 3 theo 4 4 > # L(r) = sqrt(K(r)/pi) > > plot(K, cbind(iso,theo) ~ r, col=c(2,3)) lty col iso 1 2 theo 2 3 > # plots iso against r in colour 2 > # and theo against r in colour 3 > > plot(K, iso ~ r, subset=quote(r < 0.2)) > # plots iso against r for r < 10 > > > > cleanEx(); ..nameEx <- "plot.im" > > ### * plot.im > > flush(stderr()); flush(stdout()) > > ### Name: plot.im > ### Title: Plot a Pixel Image > ### Aliases: plot.im image.im > ### Keywords: spatial > > ### ** Examples > > # an image > Z <- setcov(owin()) > plot(Z) > plot(Z, col=terrain.colors(128), axes=FALSE) > > > > cleanEx(); ..nameEx <- "plot.owin" > > ### * plot.owin > > flush(stderr()); flush(stdout()) > > ### Name: plot.owin > ### Title: Plot a Spatial Window > ### Aliases: plot.owin > ### Keywords: spatial > > ### ** Examples > > ## Not run: > ##D # rectangular window > ##D data(nztrees) > ##D plot(nztrees$window) > ##D abline(v=148, lty=2) > ##D > ##D # polygonal window > ##D plot(c(0,1),c(0,1),type="n") > ##D bdry <- locator() > ##D # click the vertices of a polygon (anticlockwise) > ##D w <- owin(c(0,1), c(0,1), poly=bdry) > ##D plot(w) > ##D > ##D # binary mask > ##D we <- erode.owin(w, 0.05, FALSE) > ##D plot(we) > ##D spatstat.options(par.binary=list(col=grey(c(0.5,1)))) > ##D plot(we) > ## End(Not run) > > > > cleanEx(); ..nameEx <- "plot.plotppm" > > ### * plot.plotppm > > flush(stderr()); flush(stdout()) > > ### Name: plot.plotppm > ### Title: Plot a plotppm Object Created by plot.ppm > ### Aliases: plot.plotppm > ### Keywords: spatial > > ### ** Examples > > ## Not run: > ##D data(cells) > ##D Q <- quadscheme(cells) > ##D m <- ppm(Q, ~1, Strauss(0.05)) > ##D mpic <- plot(m) > ##D # Perspective plot only, with altered parameters: > ##D plot(mpic,how="persp", theta=-30,phi=40,d=4) > ##D # All plots, with altered parameters for perspective plot: > ##D spatstat.options(par.persp=list(theta=-30,phi=40,d=4)) > ##D plot(mpic) > ##D > ## End(Not run) > > > > cleanEx(); ..nameEx <- "plot.ppm" > > ### * plot.ppm > > flush(stderr()); flush(stdout()) > > ### Name: plot.ppm > ### Title: plot a Fitted Point Process Model > ### Aliases: plot.ppm > ### Keywords: spatial > > ### ** Examples > > ## Not run: > ##D data(cells) > ##D m <- ppm(cells, ~1, Strauss(0.05)) > ##D pm <- plot(m) # The object ``pm'' will be plotted as well as saved > ##D # for future plotting. > ##D > ## End(Not run) > > > > cleanEx(); ..nameEx <- "plot.ppp" > > ### * plot.ppp > > flush(stderr()); flush(stdout()) > > ### Name: plot.ppp > ### Title: plot a Spatial Point Pattern > ### Aliases: plot.ppp > ### Keywords: spatial > > ### ** Examples > > data(cells) > plot(cells) > > # make the plotting symbols larger (for publication at reduced scale) > plot(cells, cex=2) > > # multitype > data(lansing) > plot(lansing) blackoak hickory maple misc redoak whiteoak 1 2 3 4 5 6 > > # marked by a real number > data(longleaf) > plot(longleaf) 0 20 40 60 80 0.000000 1.722522 3.445045 5.167567 6.890090 > > # just plot the points > plot(longleaf, use.marks=FALSE) > plot(unmark(longleaf)) # equivalent > > # controlling COLOURS of points > plot(cells, cols="blue") > plot(lansing, cols=c("black", "yellow", "green", + "blue","red","pink")) blackoak hickory maple misc redoak whiteoak 1 2 3 4 5 6 > plot(longleaf, fg="blue") 0 20 40 60 80 0.000000 1.722522 3.445045 5.167567 6.890090 > > # make points and window purple > plot(lansing, col="purple") blackoak hickory maple misc redoak whiteoak 1 2 3 4 5 6 > # make everything purple > plot(lansing, col="purple", col.main="purple") blackoak hickory maple misc redoak whiteoak 1 2 3 4 5 6 > > # controlling PLOT CHARACTERS > plot(lansing, chars = 11:16) blackoak hickory maple misc redoak whiteoak 11 12 13 14 15 16 > plot(lansing, chars = c("o","h","m",".","o","o")) blackoak hickory maple misc redoak whiteoak "o" "h" "m" "." "o" "o" > > # controlling MARK SCALE > plot(longleaf, markscale=0.1) 0 20 40 60 80 0 2 4 6 8 > > # draw circles of diameter equal to nearest neighbour distance > plot(cells %mark% (nndist(cells)/2), markscale=1) 0.04 0.05 0.06 0.07 0.08 0.04 0.05 0.06 0.07 0.08 > > > > cleanEx(); ..nameEx <- "plot.quad" > > ### * plot.quad > > flush(stderr()); flush(stdout()) > > ### Name: plot.quad > ### Title: plot a Spatial Quadrature Scheme > ### Aliases: plot.quad > ### Keywords: spatial > > ### ** Examples > > data(nztrees) > Q <- quadscheme(nztrees) > > plot(Q, main="NZ trees: quadrature scheme") > > par(mfrow=c(2,1)) > plot(Q, main="NZ trees", dum=list(add=FALSE)) > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > cleanEx(); ..nameEx <- "plot.splitppp" > > ### * plot.splitppp > > flush(stderr()); flush(stdout()) > > ### Name: plot.splitppp > ### Title: Plot a List of Point Patterns > ### Aliases: plot.splitppp > ### Keywords: spatial > > ### ** Examples > > # Multitype point pattern > data(amacrine) > plot(split(amacrine)) > > > > cleanEx(); ..nameEx <- "ppm" > > ### * ppm > > flush(stderr()); flush(stdout()) > > ### Name: ppm > ### Title: Fit Point Process Model to Data > ### Aliases: ppm > ### Keywords: spatial > > ### ** Examples > > data(nztrees) > ppm(nztrees) Stationary Poisson process Intensity: Uniform intensity: [1] 0.005916753 > # fit the stationary Poisson process > # to point pattern 'nztrees' > > Q <- quadscheme(nztrees) > ppm(Q) Stationary Poisson process Intensity: Uniform intensity: [1] 0.005916753 > # equivalent. > > ppm(nztrees, ~ x) Nonstationary Poisson process Intensity: Trend formula: ~x Fitted coefficients for trend formula: (Intercept) x -5.335350623 0.002598965 > # fit the nonstationary Poisson process > # with intensity function lambda(x,y) = exp(a + bx) > # where x,y are the Cartesian coordinates > # and a,b are parameters to be estimated > > ppm(nztrees, ~ polynom(x,2)) Nonstationary Poisson process Intensity: Trend formula: ~polynom(x, 2) Fitted coefficients for trend formula: (Intercept) polynom(x, 2)[x] polynom(x, 2)[x^2] -4.8734315562 -0.0154824569 0.0001155524 > # fit the nonstationary Poisson process > # with intensity function lambda(x,y) = exp(a + bx + cx^2) > > library(splines) > ppm(nztrees, ~ bs(x,df=3)) Nonstationary Poisson process Intensity: Trend formula: ~bs(x, df = 3) Fitted coefficients for trend formula: (Intercept) bs(x, df = 3)1 bs(x, df = 3)2 bs(x, df = 3)3 -4.9411986 -0.5037808 -0.8175941 0.4621456 > # WARNING: do not use predict.ppm() on this result > # Fits the nonstationary Poisson process > # with intensity function lambda(x,y) = exp(B(x)) > # where B is a B-spline with df = 3 > > ppm(nztrees, ~1, Strauss(r=10), rbord=10) Stationary Strauss process Trend: First order term: beta 0.005770516 Interaction: Pairwise interaction family Interaction: Strauss process interaction distance: 10 Fitted interaction parameter gamma: [1] 0.999 > # Fit the stationary Strauss process with interaction range r=10 > # using the border method with margin rbord=10 > > ppm(nztrees, ~ x, Strauss(13), correction="periodic") Nonstationary Strauss process Trend: Trend formula: ~x Fitted coefficients for trend formula: (Intercept) x -5.533989737 0.002111864 Interaction: Pairwise interaction family Interaction: Strauss process interaction distance: 13 Fitted interaction parameter gamma: [1] 1.0768 > # Fit the nonstationary Strauss process with interaction range r=13 > # and exp(first order potential) = activity = beta(x,y) = exp(a+bx) > # using the periodic correction. > > # Huang-Ogata fit: > ## Not run: ppm(nztrees, ~1, Strauss(r=10), rbord=10, method="mpl") > > # COVARIATES > # > X <- rpoispp(42) > weirdfunction <- function(x,y){ 10 * x^2 + runif(length(x))} > Zimage <- as.im(weirdfunction, unit.square()) > # > # (a) covariate values in pixel image > ppm(X, ~ y + Z, covariates=list(Z=Zimage)) Nonstationary Poisson process Intensity: Trend formula: ~y + Z Fitted coefficients for trend formula: (Intercept) y Z 3.35131101 0.27434643 0.03007803 > # > # (b) covariate values in data frame > Q <- quadscheme(X) > xQ <- x.quad(Q) > yQ <- y.quad(Q) > Zvalues <- weirdfunction(xQ,yQ) > ppm(Q, ~ y + Z, covariates=data.frame(Z=Zvalues)) Nonstationary Poisson process Intensity: Trend formula: ~y + Z Fitted coefficients for trend formula: (Intercept) y Z 3.39489845 0.27462019 0.01932311 > # Note Q not X > > ## MULTITYPE POINT PROCESSES ### > data(lansing) > # Multitype point pattern --- trees marked by species > ## Don't show: > # equivalent functionality - smaller dataset > data(betacells) > > ## End Don't show > > # fit stationary marked Poisson process > # with different intensity for each species > ## Not run: ppm(lansing, ~ marks, Poisson()) > ## Don't show: > ppm(betacells, ~ marks, Poisson()) Stationary multitype Poisson process Possible marks: off on Intensity: Trend formula: ~marks Fitted intensities: beta_off beta_on 9.419807e-05 8.746964e-05 > ## End Don't show > > # fit nonstationary marked Poisson process > # with different log-cubic trend for each species > ## Not run: ppm(lansing, ~ marks * polynom(x,y,3), Poisson()) > ## Don't show: > ppm(betacells, ~ marks * polynom(x,y,2), Poisson()) Nonstationary multitype Poisson process Possible marks: off on Intensity: Trend formula: ~marks * polynom(x, y, 2) Fitted coefficients for trend formula: (Intercept) markson -9.414097e+00 7.140810e-01 polynom(x, y, 2)[x] polynom(x, y, 2)[y] -8.360216e-04 1.595380e-03 polynom(x, y, 2)[x^2] polynom(x, y, 2)[x.y] 5.373429e-07 -7.688609e-07 polynom(x, y, 2)[y^2] markson:polynom(x, y, 2)[x] -9.123127e-07 -2.244465e-03 markson:polynom(x, y, 2)[y] markson:polynom(x, y, 2)[x^2] -1.894023e-03 1.618490e-06 markson:polynom(x, y, 2)[x.y] markson:polynom(x, y, 2)[y^2] 1.823315e-06 1.075783e-06 > ## End Don't show > > > > > cleanEx(); ..nameEx <- "ppm.object" > > ### * ppm.object > > flush(stderr()); flush(stdout()) > > ### Name: ppm.object > ### Title: Class of Fitted Point Process Models > ### Aliases: ppm.object > ### Keywords: spatial > > ### ** Examples > > data(cells) > fit <- ppm(cells, ~ x, Strauss(0.1), correction="periodic") > fit Nonstationary Strauss process Trend: Trend formula: ~x Fitted coefficients for trend formula: (Intercept) x 5.74292851 0.08449064 Interaction: Pairwise interaction family Interaction: Strauss process interaction distance: 0.1 Fitted interaction parameter gamma: [1] 0.0237 > coef(fit) (Intercept) x Interaction 5.74292851 0.08449064 -3.74186444 > ## Not run: > ##D pred <- predict(fit) > ##D > ## End(Not run) > pred <- predict(fit, ngrid=20, type="trend") > ## Not run: > ##D plot(fit) > ##D > ## End(Not run) > > > > cleanEx(); ..nameEx <- "ppp" > > ### * ppp > > flush(stderr()); flush(stdout()) > > ### Name: ppp > ### Title: Create a Point Pattern > ### Aliases: ppp > ### Keywords: spatial > > ### ** Examples > > # some arbitrary coordinates in [0,1] > x <- runif(20) > y <- runif(20) > > # the following are equivalent > X <- ppp(x, y, c(0,1), c(0,1)) > X <- ppp(x, y) > X <- ppp(x, y, window=owin(c(0,1),c(0,1))) > > ## Not run: plot(X) > > # marks > m <- sample(1:2, 20, replace=TRUE) > m <- factor(m, levels=1:2) > X <- ppp(x, y, c(0,1), c(0,1), marks=m) > ## Not run: plot(X) > > # polygonal window > X <- ppp(x, y, poly=list(x=c(0,10,0), y=c(0,0,10))) > ## Not run: plot(X) > > # copy the window from another pattern > data(cells) > X <- ppp(x, y, window=cells$window) > > > > cleanEx(); ..nameEx <- "ppp.object" > > ### * ppp.object > > flush(stderr()); flush(stdout()) > > ### Name: ppp.object > ### Title: Class of Point Patterns > ### Aliases: ppp.object > ### Keywords: spatial > > ### ** Examples > > x <- runif(100) > y <- runif(100) > X <- ppp(x, y, c(0,1),c(0,1)) > X planar point pattern: 100 points window: rectangle = [ 0 , 1 ] x [ 0 , 1 ] > ## Not run: plot(X) > mar <- sample(1:3, 100, replace=TRUE) > mm <- ppp(x, y, c(0,1), c(0,1), marks=mar) > ## Not run: plot(mm) > # points with mark equal to 2 > ss <- mm[ mm$marks == 2 , ] > ## Not run: plot(ss) > # left half of pattern 'mm' > lu <- owin(c(0,0.5),c(0,1)) > mmleft <- mm[ , lu] > ## Not run: plot(mmleft) > ## Not run: > ##D # input data from file > ##D qq <- scanpp("my.table", unit.square()) > ##D > ##D # interactively build a point pattern > ##D plot(unit.square()) > ##D X <- as.ppp(locator(10), unit.square()) > ##D plot(X) > ##D > ## End(Not run) > > > > cleanEx(); ..nameEx <- "predict.ppm" > > ### * predict.ppm > > flush(stderr()); flush(stdout()) > > ### Name: predict.ppm > ### Title: Prediction from a Fitted Point Process Model > ### Aliases: predict.ppm > ### Keywords: spatial > > ### ** Examples > > data(cells) > m <- ppm(cells, ~ polynom(x,y,2), Strauss(0.05), rbord=0.05) > trend <- predict(m, type="trend") > ## Not run: > ##D image(trend) > ##D points(cells) > ##D > ## End(Not run) > cif <- predict(m, type="cif") > ## Not run: > ##D persp(cif) > ##D > ## End(Not run) > > > > cleanEx(); ..nameEx <- "print.im" > > ### * print.im > > flush(stderr()); flush(stdout()) > > ### Name: print.im > ### Title: Print Brief Details of an Image > ### Aliases: print.im > ### Keywords: spatial > > ### ** Examples > > data(letterR) > U <- as.im(letterR) > U Pixel image 256 x 256 pixel array enclosing rectangle: [ 2.017, 3.93 ] x [ 0.645, 3.278 ] > > > > cleanEx(); ..nameEx <- "print.owin" > > ### * print.owin > > flush(stderr()); flush(stdout()) > > ### Name: print.owin > ### Title: Print Brief Details of a Spatial Window > ### Aliases: print.owin > ### Keywords: spatial > > ### ** Examples > > owin() # the unit square window: rectangle = [ 0 , 1 ] x [ 0 , 1 ] > > data(demopat) > W <- demopat$window > W # just says it is polygonal window: polygonal boundary enclosing rectangle: [ 525 , 10575 ] x [ 450 , 7125 ] > as.mask(W) # just says it is a binary image window: binary image mask enclosing rectangle: [ 525 , 10575 ] x [ 450 , 7125 ] > > > > > cleanEx(); ..nameEx <- "print.ppm" > > ### * print.ppm > > flush(stderr()); flush(stdout()) > > ### Name: print.ppm > ### Title: Print a Fitted Point Process Model > ### Aliases: print.ppm > ### Keywords: spatial > > ### ** Examples > > ## Not run: > ##D data(cells) > ##D Q <- quadscheme(cells) > ##D m <- ppm(Q, ~1, Strauss(0.05)) > ##D m > ##D > ## End(Not run) > > > > cleanEx(); ..nameEx <- "print.ppp" > > ### * print.ppp > > flush(stderr()); flush(stdout()) > > ### Name: print.ppp > ### Title: Print Brief Details of a Point Pattern Dataset > ### Aliases: print.ppp > ### Keywords: spatial > > ### ** Examples > > data(cells) # plain vanilla point pattern > cells planar point pattern: 42 points window: rectangle = [ 0 , 1 ] x [ 0 , 1 ] > > data(lansing) # multitype point pattern > lansing marked planar point pattern: 2251 points multitype, with levels = blackoak hickory maple misc redoak whiteoak window: rectangle = [ 0 , 1 ] x [ 0 , 1 ] > > data(longleaf) # numeric marks > longleaf marked planar point pattern: 584 points marks are numeric, of type "double" window: rectangle = [ 0 , 200 ] x [ 0 , 200 ] > > data(demopat) # weird polygonal window > demopat marked planar point pattern: 112 points multitype, with levels = A B window: polygonal boundary enclosing rectangle: [ 525 , 10575 ] x [ 450 , 7125 ] > > > > cleanEx(); ..nameEx <- "print.quad" > > ### * print.quad > > flush(stderr()); flush(stdout()) > > ### Name: print.quad > ### Title: Print a Quadrature Scheme > ### Aliases: print.quad > ### Keywords: spatial > > ### ** Examples > > data(cells) > Q <- quadscheme(cells) > Q Quadrature scheme 42 data points, 629 dummy points Total weight 1.00000000000001 > > > > cleanEx(); ..nameEx <- "qqplot.ppm" > > ### * qqplot.ppm > > flush(stderr()); flush(stdout()) > > ### Name: qqplot.ppm > ### Title: Q-Q Plot of Residuals from Fitted Point Process Model > ### Aliases: qqplot.ppm > ### Keywords: spatial > > ### ** Examples > > data(cells) > > fit <- ppm(cells, ~1, Poisson()) > diagnose.ppm(fit) # no suggestion of departure from stationarity Model diagnostics (raw residuals) Diagnostics available: four-panel plot mark plot smoothed residual field x cumulative residuals y cumulative residuals sum of all residuals sum of raw residuals in entire window = 1.562e-13 area of entire window = 1 range of smoothed field = [ -26.69,15.74 ] > ## Not run: qqplot.ppm(fit, 80) # strong evidence of non-Poisson interaction > ## Don't show: > qqplot.ppm(fit, 5) Extracting model information...Evaluating trend...done. Simulating 5 realisations... 1, 2, 3, 4, 5, Calculating quantiles...averaging.....Done. > ## End Don't show > > ## Not run: > ##D diagnose.ppm(fit, type="pearson") > ##D qqplot.ppm(fit, type="pearson") > ## End(Not run) > ## Don't show: > qqplot.ppm(fit, 5, type="pearson") Extracting model information...Evaluating trend...done. Simulating 5 realisations... 1, 2, 3, 4, 5, Calculating quantiles...averaging.....Done. > ## End Don't show > > ########################################### > ## oops, I need the plot coordinates > mypreciousdata <- .Last.value > ## Not run: mypreciousdata <- qqplot.ppm(fit, type="pearson") > ## Don't show: > mypreciousdata <- qqplot.ppm(fit, 5, type="pearson") Extracting model information...Evaluating trend...done. Simulating 5 realisations... 1, 2, 3, 4, 5, Calculating quantiles...averaging.....Done. > ## End Don't show > plot(mypreciousdata) > > ###################################################### > # Q-Q plots based on fixed n > # The above QQ plots used simulations from the (fitted) Poisson process. > # But I want to simulate conditional on n, instead of Poisson > # Do this by setting rmhcontrol(p=1) > fixit <- list(p=1) > ## Not run: qqplot.ppm(fit, 100, control=fixit) > ## Don't show: > qqplot.ppm(fit, 5, control=fixit) Extracting model information...Evaluating trend...done. Simulating 5 realisations... 1, 2, 3, 4, 5, Calculating quantiles...averaging.....Done. > ## End Don't show > > ###################################################### > # Inhomogeneous Poisson data > X <- rpoispp(function(x,y){1000 * exp(-3*x)}, 1000) > plot(X) > # Inhomogeneous Poisson model > fit <- ppm(X, ~x, Poisson()) > ## Not run: qqplot.ppm(fit, 100) > ## Don't show: > qqplot.ppm(fit, 10) Extracting model information...Evaluating trend...done. Simulating 10 realisations... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 Calculating quantiles...averaging.....Done. > ## End Don't show > # conclusion: fitted inhomogeneous Poisson model looks OK > > ###################################################### > # Advanced use of 'expr' argument > # > # set the initial conditions in Metropolis-Hastings algorithm > # > expr <- expression(rmh(fit, start=list(n.start=42), verbose=FALSE)) > ## Not run: qqplot.ppm(fit, 100, expr) > ## Don't show: > qqplot.ppm(fit, 5, expr) Simulating 5 realisations... 1, 2, 3, 4, 5, Calculating quantiles...averaging.....Done. > ## End Don't show > > > > > cleanEx(); ..nameEx <- "quad.ppm" > > ### * quad.ppm > > flush(stderr()); flush(stdout()) > > ### Name: quad.ppm > ### Title: Extract Quadrature Scheme Used to Fit a Point Process Model > ### Aliases: quad.ppm > ### Keywords: spatial > > ### ** Examples > > data(cells) > fit <- ppm(cells, ~1, Strauss(r=0.1), rbord=0.1) > Q <- quad.ppm(fit) > ## Not run: plot(Q) > Q$data$n [1] 42 > Q$dummy$n [1] 629 > > > > cleanEx(); ..nameEx <- "quadratcount" > > ### * quadratcount > > flush(stderr()); flush(stdout()) > > ### Name: quadratcount > ### Title: Quadrat counting for a point pattern > ### Aliases: quadratcount > ### Keywords: spatial > > ### ** Examples > > X <- runifpoint(50) > quadratcount(X) y x [0,0.2] (0.2,0.4] (0.4,0.6] (0.6,0.8] (0.8,1] [0,0.2] 1 3 2 0 1 (0.2,0.4] 2 2 2 0 5 (0.4,0.6] 1 2 3 2 1 (0.6,0.8] 1 3 3 6 2 (0.8,1] 1 4 0 3 0 > quadratcount(X, 4, 5) y x [0,0.25] (0.25,0.5] (0.5,0.75] (0.75,1] [0,0.25] 2 5 0 3 (0.25,0.5] 2 8 0 3 (0.5,0.75] 3 4 4 3 (0.75,1] 3 2 3 5 > quadratcount(X, xbreaks=c(0, 0.3, 1), ybreaks=c(0, 0.4, 0.8, 1)) y x [0,0.4] (0.4,0.8] (0.8,1] [0,0.3] 5 4 3 (0.3,1] 15 17 6 > > > > cleanEx(); ..nameEx <- "quadscheme" > > ### * quadscheme > > flush(stderr()); flush(stdout()) > > ### Name: quadscheme > ### Title: Generate a Quadrature Scheme from a Point Pattern > ### Aliases: quadscheme > ### Keywords: spatial > > ### ** Examples > > data(simdat) > > # grid weights > Q <- quadscheme(simdat) > Q <- quadscheme(simdat, method="grid") > Q <- quadscheme(simdat, nd=50) # 1 dummy point per tile > Q <- quadscheme(simdat, ntile=25, nd=50) # 4 dummy points per tile > > # Dirichlet weights > Q <- quadscheme(simdat, method="dirichlet", exact=FALSE) > > # random dummy pattern > ## Not run: > ##D D <- runifpoint(250, simdat$window) > ##D Q <- quadscheme(simdat, D, method="dirichlet", exact=FALSE) > ##D > ## End(Not run) > > # polygonal window > data(demopat) > X <- unmark(demopat) > Q <- quadscheme(X) > > # mask window > X$window <- as.mask(X$window) > Q <- quadscheme(X) > > > > > cleanEx(); ..nameEx <- "rMatClust" > > ### * rMatClust > > flush(stderr()); flush(stdout()) > > ### Name: rMatClust > ### Title: Simulate Matern Cluster Process > ### Aliases: rMatClust > ### Keywords: spatial > > ### ** Examples > > pp <- rMatClust(10, 0.05, 4) > > > > cleanEx(); ..nameEx <- "rMaternI" > > ### * rMaternI > > flush(stderr()); flush(stdout()) > > ### Name: rMaternI > ### Title: Simulate Matern Model I > ### Aliases: rMaternI > ### Keywords: spatial > > ### ** Examples > > pp <- rMaternI(20, 0.05) > > > > cleanEx(); ..nameEx <- "rMaternII" > > ### * rMaternII > > flush(stderr()); flush(stdout()) > > ### Name: rMaternII > ### Title: Simulate Matern Model II > ### Aliases: rMaternII > ### Keywords: spatial > > ### ** Examples > > pp <- rMaternII(20, 0.05) > > > > cleanEx(); ..nameEx <- "rNeymanScott" > > ### * rNeymanScott > > flush(stderr()); flush(stdout()) > > ### Name: rNeymanScott > ### Title: Simulate Neyman-Scott Process > ### Aliases: rNeymanScott > ### Keywords: spatial > > ### ** Examples > > nclust <- function(x0, y0, radius, n) { + return(runifdisc(n, radius, x0, y0)) + } > X <- rNeymanScott(10, 0.2, nclust, radius=0.2, n=5) > > > > cleanEx(); ..nameEx <- "rSSI" > > ### * rSSI > > flush(stderr()); flush(stdout()) > > ### Name: rSSI > ### Title: Simple Sequential Inhibition > ### Aliases: rSSI > ### Keywords: spatial > > ### ** Examples > > pp <- rSSI(0.05, 200) > ## Not run: plot(pp) > > > > cleanEx(); ..nameEx <- "rThomas" > > ### * rThomas > > flush(stderr()); flush(stdout()) > > ### Name: rThomas > ### Title: Simulate Thomas Process > ### Aliases: rThomas > ### Keywords: spatial > > ### ** Examples > > X <- rThomas(10, 0.2, 5) > > > > cleanEx(); ..nameEx <- "raster.x" > > ### * raster.x > > flush(stderr()); flush(stdout()) > > ### Name: raster.x > ### Title: Cartesian Coordinates for a Pixel Raster > ### Aliases: raster.x raster.y > ### Keywords: spatial > > ### ** Examples > > u <- owin(c(-1,1),c(-1,1)) # square of side 2 > w <- as.mask(u, eps=0.01) # 200 x 200 grid > X <- raster.x(w) > Y <- raster.y(w) > disc <- owin(c(-1,1), c(-1,1), mask=(X^2 + Y^2 <= 1)) > ## Not run: plot(disc) > # approximation to the unit disc > > > > cleanEx(); ..nameEx <- "reach" > > ### * reach > > flush(stderr()); flush(stdout()) > > ### Name: reach > ### Title: Interaction Distance of a Point Process > ### Aliases: reach reach.ppm reach.interact > ### Keywords: spatial > > ### ** Examples > > reach(Poisson()) [1] 0 > # returns 0 > > reach(Strauss(r=7)) [1] 7 > # returns 7 > data(swedishpines) > fit <- ppm(swedishpines, ~1, Strauss(r=7)) > reach(fit) [1] 7 > # returns 7 > > reach(OrdThresh(42)) [1] Inf > # returns Inf > > reach(MultiStrauss(1:2, matrix(c(1,3,3,1),2,2))) [1] 3 > # returns 3 > > > > cleanEx(); ..nameEx <- "redwoodfull" > > ### * redwoodfull > > flush(stderr()); flush(stdout()) > > ### Name: redwoodfull > ### Title: California Redwoods Point Pattern (Entire Dataset) > ### Aliases: redwoodfull redwoodfull.extra > ### Keywords: datasets > > ### ** Examples > > data(redwoodfull) > plot(redwoodfull) > redwoodfull.extra$plot() > # extract the pattern in region II > redwoodII <- redwoodfull[, redwoodfull.extra$regionII] > > > > cleanEx(); ..nameEx <- "rescue.rectangle" > > ### * rescue.rectangle > > flush(stderr()); flush(stdout()) > > ### Name: rescue.rectangle > ### Title: Convert Window Back To Rectangle > ### Aliases: rescue.rectangle > ### Keywords: spatial > > ### ** Examples > > w <- owin(poly=list(x=c(0,1,1,0),y=c(0,0,1,1))) > rw <- rescue.rectangle(w) > > w <- as.mask(unit.square()) > rw <- rescue.rectangle(w) > > > > cleanEx(); ..nameEx <- "residuals.ppm" > > ### * residuals.ppm > > flush(stderr()); flush(stdout()) > > ### Name: residuals.ppm > ### Title: Residuals for Fitted Point Process Model > ### Aliases: residuals.ppm > ### Keywords: spatial > > ### ** Examples > > data(cells) > fit <- ppm(cells, ~x, Strauss(r=0.15), rbord=0.15) > > rp <- residuals.ppm(fit, type="pe") > sum(rp) # should be close to 0 [1] -5.693327 > > # extract quadrature points to which the residuals correspond > quadpoints <- union.quad(quad.ppm(fit)) > > # plot residuals as marks attached to the quadrature points > quadmarked <- setmarks(quadpoints, rp) > plot(quadmarked) -0.2 -0.1 0 0.1 0.2 0.3 -0.015085475 -0.007542737 0.000000000 0.007542737 0.015085475 0.022628212 0.4 0.5 0.030170950 0.037713687 > > > > cleanEx(); ..nameEx <- "residualspaper" > > ### * residualspaper > > flush(stderr()); flush(stdout()) > > ### Name: residualspaper > ### Title: Data and Code From JRSS Discussion Paper on Residuals > ### Aliases: residualspaper > ### Keywords: datasets > > ### ** Examples > > > ## Not run: > ##D data(residualspaper) > ##D > ##D X <- residualspaper$Fig4a > ##D summary(X) > ##D plot(X) > ##D > ##D # reproduce all Figures > ##D residualspaper$plotfig() > ##D > ##D # reproduce Figures 1 to 10 > ##D residualspaper$plotfig(1:10) > ##D > ##D # reproduce Figure 7 (a) > ##D residualspaper$plotfig("7a") > ## End(Not run) > > > > cleanEx(); ..nameEx <- "ripras" > > ### * ripras > > flush(stderr()); flush(stdout()) > > ### Name: ripras > ### Title: Estimate window from points alone > ### Aliases: ripras > ### Keywords: spatial > > ### ** Examples > > ## Not run: > ##D plot(owin()) > ##D > ## End(Not run) > x <- runif(30) > y <- runif(30) > ## Not run: points(x,y) > w <- ripras(x,y) > ## Not run: > ##D plot(w, box=FALSE) > ##D points(x,y) > ##D > ## End(Not run) > > > > cleanEx(); ..nameEx <- "rlabel" > > ### * rlabel > > flush(stderr()); flush(stdout()) > > ### Name: rlabel > ### Title: Random Re-Labelling of Point Pattern > ### Aliases: rlabel > ### Keywords: spatial > > ### ** Examples > > data(amacrine) > > # Randomly permute the marks "on" and "off" > # Result always has 142 "off" and 152 "on" > Y <- rlabel(amacrine) > > # randomly allocate marks "on" and "off" > # with probabilities p(off) = 0.48, p(on) = 0.52 > Y <- rlabel(amacrine, permute=FALSE) > > # randomly allocate marks "A" and "B" with equal probability > data(cells) > Y <- rlabel(cells, labels=factor(c("A", "B")), permute=FALSE) > > > > cleanEx(); ..nameEx <- "rmh" > > ### * rmh > > flush(stderr()); flush(stdout()) > > ### Name: rmh > ### Title: Simulate point patterns using the Metropolis-Hastings algorithm. > ### Aliases: rmh > ### Keywords: spatial > > ### ** Examples > > # See examples in rmh.default and rmh.ppm > > > > cleanEx(); ..nameEx <- "rmh.default" > > ### * rmh.default > > flush(stderr()); flush(stdout()) > > ### Name: rmh.default > ### Title: Simulate Point Process Models using the Metropolis-Hastings > ### Algorithm. > ### Aliases: rmh.default > ### Keywords: spatial > > ### ** Examples > > ## Not run: > ##D nr <- 1e5 > ##D nv <- 5000 > ##D > ## End(Not run) > ## Don't show: > nr <- 10 > nv <- 5 > > ## End Don't show > set.seed(961018) > > # Strauss process. > mod01 <- list(cif="strauss",par=c(beta=2,gamma=0.2,r=0.7), + w=c(0,10,0,10)) > X1.strauss <- rmh(model=mod01,start=list(n.start=80), + control=list(nrep=nr,nverb=nv)) Checking arguments..determining simulation windows...Starting simulation. Initial state...Proposal points...Start simulation. irep/nverb= [1] 1 irep/nverb= [1] 2 > > # Strauss process, conditioning on n = 80: > X2.strauss <- rmh(model=mod01,start=list(n.start=80), + control=list(p=1,nrep=nr,nverb=nv)) Checking arguments..determining simulation windows...Starting simulation. Initial state...Proposal points...Start simulation. irep/nverb= [1] 1 irep/nverb= [1] 2 > > # Strauss process equal to pure hardcore: > mod02 <- list(cif="strauss",par=c(beta=2,gamma=0,r=0.7),w=c(0,10,0,10)) > X3.strauss <- rmh(model=mod02,start=list(n.start=60,iseed=c(42,17,69)), + control=list(nrep=nr,nverb=nv)) Checking arguments..determining simulation windows...Starting simulation. Initial state...Proposal points...Start simulation. irep/nverb= [1] 1 irep/nverb= [1] 2 > > # Strauss process in a polygonal window. > x <- c(0.55,0.68,0.75,0.58,0.39,0.37,0.19,0.26,0.42) > y <- c(0.20,0.27,0.68,0.99,0.80,0.61,0.45,0.28,0.33) > mod03 <- list(cif="strauss",par=c(beta=2000,gamma=0.6,r=0.07), + w=owin(poly=list(x=x,y=y))) > X4.strauss <- rmh(model=mod03,start=list(n.start=90), + control=list(nrep=nr,nverb=nv)) Checking arguments..determining simulation windows...Starting simulation. Initial state...Proposal points...Start simulation. irep/nverb= [1] 1 irep/nverb= [1] 2 > > # Strauss process in a polygonal window, conditioning on n = 80. > X5.strauss <- rmh(model=mod03,start=list(n.start=90), + control=list(p=1,nrep=nr,nverb=nv)) Checking arguments..determining simulation windows...Starting simulation. Initial state...Proposal points...Start simulation. irep/nverb= [1] 1 irep/nverb= [1] 2 > > # Strauss process, starting off from X4.strauss, but with the > # polygonal window replace by a rectangular one. At the end, > # the generated pattern is clipped to the original polygonal window. > xxx <- X4.strauss > xxx$window <- as.owin(c(0,1,0,1)) > X6.strauss <- rmh(model=mod03,start=list(x.start=xxx), + control=list(nrep=nr,nverb=nv)) Checking arguments..determining simulation windows...Starting simulation. Initial state...Proposal points...Start simulation. irep/nverb= [1] 1 irep/nverb= [1] 2 > > # Strauss with hardcore: > mod04 <- list(cif="straush",par=c(beta=2,gamma=0.2,r=0.7,hc=0.3), + w=c(0,10,0,10)) > X1.straush <- rmh(model=mod04,start=list(n.start=70), + control=list(nrep=nr,nverb=nv)) Checking arguments..determining simulation windows...Starting simulation. Initial state...Proposal points...Start simulation. irep/nverb= [1] 1 irep/nverb= [1] 2 > > # Another Strauss with hardcore (with a perhaps surprising result): > mod05 <- list(cif="straush",par=c(beta=80,gamma=0.36,r=45,hc=2.5), + w=c(0,250,0,250)) > X2.straush <- rmh(model=mod05,start=list(n.start=250), + control=list(nrep=nr,nverb=nv)) Checking arguments..determining simulation windows...Starting simulation. Initial state...Proposal points...Start simulation. irep/nverb= [1] 1 irep/nverb= [1] 2 > > # Pure hardcore (identical to X3.strauss). > mod06 <- list(cif="straush",par=c(beta=2,gamma=1,r=1,hc=0.7), + w=c(0,10,0,10)) > X3.straush <- rmh(model=mod06,start=list(n.start=60, iseed=c(42,17,69)), + control=list(nrep=nr,nverb=nv)) Checking arguments..determining simulation windows...Starting simulation. Initial state...Proposal points...Start simulation. irep/nverb= [1] 1 irep/nverb= [1] 2 > > # Soft core: > par3 <- c(0.8,0.1,0.5) > w <- c(0,10,0,10) > mod07 <- list(cif="sftcr",par=c(beta=0.8,sigma=0.1,kappa=0.5), + w=c(0,10,0,10)) > X.sftcr <- rmh(model=mod07,start=list(n.start=70), + control=list(nrep=nr,nverb=nv)) Checking arguments..determining simulation windows...Starting simulation. Initial state...Proposal points...Start simulation. irep/nverb= [1] 1 irep/nverb= [1] 2 > > # Multitype Strauss: > beta <- c(0.027,0.008) > gmma <- matrix(c(0.43,0.98,0.98,0.36),2,2) > r <- matrix(c(45,45,45,45),2,2) > mod08 <- list(cif="straussm",par=list(beta=beta,gamma=gmma,radii=r), + w=c(0,250,0,250)) > X1.straussm <- rmh(model=mod08,start=list(n.start=80), + control=list(ptypes=c(0.75,0.25),nrep=nr,nverb=nv)) Checking arguments..determining simulation windows...Starting simulation. Initial state...Proposal points...Start simulation. irep/nverb= [1] 1 irep/nverb= [1] 2 > > # Multitype Strauss conditioning upon the total number > # of points being 80: > X2.straussm <- rmh(model=mod08,start=list(n.start=80), + control=list(p=1,ptypes=c(0.75,0.25),nrep=nr, + nverb=nv)) Checking arguments..determining simulation windows...Starting simulation. Initial state...Proposal points...Start simulation. irep/nverb= [1] 1 irep/nverb= [1] 2 > > # Conditioning upon the number of points of type 1 being 60 > # and the number of points of type 2 being 20: > X3.straussm <- rmh(model=mod08,start=list(n.start=c(60,20)), + control=list(fixall=TRUE,p=1,ptypes=c(0.75,0.25), + nrep=nr,nverb=nv)) Checking arguments..determining simulation windows...Starting simulation. Initial state...Proposal points...Start simulation. irep/nverb= [1] 1 irep/nverb= [1] 2 > > # Multitype Strauss hardcore: > rhc <- matrix(c(9.1,5.0,5.0,2.5),2,2) > mod09 <- list(cif="straushm",par=list(beta=beta,gamma=gmma, + iradii=r,hradii=rhc),w=c(0,250,0,250)) > X.straushm <- rmh(model=mod09,start=list(n.start=80), + control=list(ptypes=c(0.75,0.25),nrep=nr,nverb=nv)) Checking arguments..determining simulation windows...Starting simulation. Initial state...Proposal points...Start simulation. irep/nverb= [1] 1 irep/nverb= [1] 2 > > # Multitype Strauss hardcore with trends for each type: > beta <- c(0.27,0.08) > tr3 <- function(x,y){x <- x/250; y <- y/250; + exp((6*x + 5*y - 18*x^2 + 12*x*y - 9*y^2)/6) + } > # log quadratic trend > tr4 <- function(x,y){x <- x/250; y <- y/250; + exp(-0.6*x+0.5*y)} > # log linear trend > mod10 <- list(cif="straushm",par=list(beta=beta,gamma=gmma, + iradii=r,hradii=rhc),w=c(0,250,0,250), + trend=list(tr3,tr4)) > X1.straushm.trend <- rmh(model=mod10,start=list(n.start=350), + control=list(ptypes=c(0.75,0.25), + nrep=nr,nverb=nv)) Checking arguments..determining simulation windows...Evaluating trend integral...Starting simulation. Initial state...Proposal points...Start simulation. irep/nverb= [1] 1 irep/nverb= [1] 2 irep/nverb= [1] 2 > > # Multitype Strauss hardcore with trends for each type, given as images: > x <- seq(0,250,length=51) > xy <- expand.grid(x=x,y=x) > i1 <- im(matrix(tr3(xy$x,xy$y),nrow=51),x,x) > i2 <- im(matrix(tr4(xy$x,xy$y),nrow=51),x,x) > mod11 <- list(cif="straushm",par=list(beta=beta,gamma=gmma, + iradii=r,hradii=rhc),w=c(0,250,0,250), + trend=list(i1,i2)) > X2.straushm.trend <- rmh(model=mod11,start=list(n.start=350), + control=list(ptypes=c(0.75,0.25),expand=1, + nrep=nr,nverb=nv)) Checking arguments..determining simulation windows...Evaluating trend integral...Starting simulation. Initial state...Proposal points...Start simulation. irep/nverb= [1] 1 irep/nverb= [1] 1 irep/nverb= [1] 1 irep/nverb= [1] 1 irep/nverb= [1] 2 > > # Diggle, Gates, and Stibbard: > mod12 <- list(cif="dgs",par=c(beta=3600,rho=0.08),w=c(0,1,0,1)) > X.dgs <- rmh(model=mod12,start=list(n.start=300), + control=list(nrep=nr,nverb=nv)) Checking arguments..determining simulation windows...Starting simulation. Initial state...Proposal points...Start simulation. irep/nverb= [1] 1 irep/nverb= [1] 2 > > # Diggle-Gratton: > mod13 <- list(cif="diggra", + par=c(beta=1800,kappa=3,delta=0.02,rho=0.04), + w=square(1)) > X.diggra <- rmh(model=mod13,start=list(n.start=300), + control=list(nrep=nr,nverb=nv)) Checking arguments..determining simulation windows...Starting simulation. Initial state...Proposal points...Start simulation. irep/nverb= [1] 1 irep/nverb= [1] 2 > > # Geyer: > mod14 <- list(cif="geyer",par=c(beta=1.25,gamma=1.6,r=0.2,sat=4.5), + w=c(0,10,0,10)) > X1.geyer <- rmh(model=mod14,start=list(n.start=200), + control=list(nrep=nr,nverb=nv)) Checking arguments..determining simulation windows...Starting simulation. Initial state...Proposal points...Start simulation. irep/nverb= [1] 1 irep/nverb= [1] 2 > > # Geyer; same as a Strauss process with parameters > # (beta=2.25,gamma=0.16,r=0.7): > > mod15 <- list(cif="geyer",par=c(beta=2.25,gamma=0.4,r=0.7,sat=10000), + w=c(0,10,0,10)) > X2.geyer <- rmh(model=mod15,start=list(n.start=200), + control=list(nrep=nr,nverb=nv)) Checking arguments..determining simulation windows...Starting simulation. Initial state...Proposal points...Start simulation. irep/nverb= [1] 1 irep/nverb= [1] 2 > > mod16 <- list(cif="geyer",par=c(beta=8.1,gamma=2.2,r=0.08,sat=3)) > data(redwood) > X3.geyer <- rmh(model=mod16,start=list(x.start=redwood), + control=list(periodic=TRUE,nrep=nr,nverb=nv)) Checking arguments..determining simulation windows...Starting simulation. Initial state...Proposal points...Start simulation. irep/nverb= [1] 1 irep/nverb= [1] 2 > > # Geyer, starting from the redwood data set, simulating > # on a torus, and conditioning on n: > X4.geyer <- rmh(model=mod16,start=list(x.start=redwood), + control=list(p=1,periodic=TRUE,nrep=nr,nverb=nv)) Checking arguments..determining simulation windows...Starting simulation. Initial state...Proposal points...Start simulation. irep/nverb= [1] 1 irep/nverb= [1] 2 > > # Lookup (interaction function h_2 from page 76, Diggle (2003)): > r <- seq(from=0,to=0.2,length=101)[-1] # Drop 0. > h <- 20*(r-0.05) > h[r<0.05] <- 0 > h[r>0.10] <- 1 > mod17 <- list(cif="lookup",par=list(beta=4000,h=h,r=r),w=c(0,1,0,1)) > X.lookup <- rmh(model=mod17,start=list(n.start=100), + control=list(nrep=nr,nverb=nv)) Checking arguments..determining simulation windows...Starting simulation. Initial state...Proposal points...Start simulation. irep/nverb= [1] 1 irep/nverb= [1] 2 > > # Strauss with trend > tr <- function(x,y){x <- x/250; y <- y/250; + exp((6*x + 5*y - 18*x^2 + 12*x*y - 9*y^2)/6) + } > beta <- 0.3 > gmma <- 0.5 > r <- 45 > mod17 <- list(cif="strauss",par=c(beta=beta,gamma=gmma,r=r),w=c(0,250,0,250), + trend=tr3) > X1.strauss.trend <- rmh(model=mod17,start=list(n.start=90), + control=list(nrep=nr,nverb=nv)) Checking arguments..determining simulation windows...Evaluating trend integral...Starting simulation. Initial state...Proposal points...Start simulation. irep/nverb= [1] 1 irep/nverb= [1] 2 > > > > cleanEx(); ..nameEx <- "rmh.ppm" > > ### * rmh.ppm > > flush(stderr()); flush(stdout()) > > ### Name: rmh.ppm > ### Title: Simulate from a Fitted Point Process Model > ### Aliases: rmh.ppm > ### Keywords: spatial > > ### ** Examples > > data(swedishpines) > X <- swedishpines > plot(X, main="Swedish Pines data") > > # Poisson process > fit <- ppm(X, ~1, Poisson()) > Xsim <- rmh(fit) Extracting model information...Evaluating trend...done. Checking arguments..determining simulation windows...> plot(Xsim, main="simulation from fitted Poisson model") > > # Strauss process > fit <- ppm(X, ~1, Strauss(r=7), rbord=7) > Xsim <- rmh(fit, control=list(nrep=1e3)) Extracting model information...Evaluating trend...done. Checking arguments..determining simulation windows...Starting simulation. Initial state...Proposal points...Start simulation. > plot(Xsim, main="simulation from fitted Strauss model") > > # Strauss process simulated on a larger window > # then clipped to original window > Xsim <- rmh(fit, control=list(nrep=1e3, expand=2, periodic=TRUE)) Extracting model information...Evaluating trend...done. Checking arguments..determining simulation windows...Starting simulation. Initial state...Proposal points...Start simulation. > > # Strauss - hard core process > fit <- ppm(X, ~1, StraussHard(r=7,hc=2), rbord=7) > Xsim <- rmh(fit, start=list(n.start=X$n), control=list(nrep=1e3)) Extracting model information...Evaluating trend...done. Checking arguments..determining simulation windows...Starting simulation. Initial state...Proposal points...Start simulation. > plot(Xsim, main="simulation from fitted Strauss hard core model") > > # Geyer saturation process > fit <- ppm(X, ~1, Geyer(r=7,sat=2), rbord=7) > Xsim <- rmh(fit, start=list(n.start=X$n), control=list(nrep=1e3)) Extracting model information...Evaluating trend...done. Checking arguments..determining simulation windows...Starting simulation. Initial state...Proposal points...Start simulation. > plot(Xsim, main="simulation from fitted Geyer model") > > # soft core interaction process > Q <- quadscheme(X, nd=50) > fit <- ppm(Q, ~1, Softcore(kappa=0.1)) > Xsim <- rmh(fit, start=list(n.start=X$n), control=list(nrep=1e3)) Extracting model information...Evaluating trend...done. Checking arguments..determining simulation windows...Starting simulation. Initial state...Proposal points...Start simulation. > plot(Xsim, main="simulation from fitted Soft Core model") > > data(cells) > plot(cells) > # Diggle-Gratton pairwise interaction model > fit <- ppm(cells, ~1, DiggleGratton(0.05, 0.1)) > Xsim <- rmh(fit, start=list(n.start=cells$n), control=list(nrep=1e3)) Extracting model information...Evaluating trend...done. Checking arguments..determining simulation windows...Starting simulation. Initial state...Proposal points...Start simulation. > plot(Xsim, main="simulation from fitted Diggle-Gratton model") > > ## Not run: > ##D X <- rSSI(0.05, 100) > ##D plot(X, main="new data") > ##D > ##D # piecewise-constant pairwise interaction function > ##D fit <- ppm(X, ~1, PairPiece(seq(0.02, 0.1, by=0.01))) > ##D Xsim <- rmh(fit, control=list(nrep=1e3)) > ##D plot(Xsim, main="simulation from fitted pairwise model") > ##D > ## End(Not run) > > # marked point pattern > data(amacrine) > Y <- amacrine > plot(Y, main="Amacrine data") off on 1 2 > > # marked Poisson models > fit <- ppm(Y) > Ysim <- rmh(fit) Extracting model information...Evaluating trend...done. Checking arguments..determining simulation windows...> plot(Ysim, main="simulation from ppm(Y)") off on 1 2 > > fit <- ppm(Y,~marks) > Ysim <- rmh(fit) Extracting model information...Evaluating trend...done. Checking arguments..determining simulation windows...> plot(Ysim, main="simulation from ppm(Y, ~marks)") off on 1 2 > > fit <- ppm(Y,~polynom(x,y,2)) > Ysim <- rmh(fit) Extracting model information...Evaluating trend...done. Checking arguments..determining simulation windows...> plot(Ysim, main="simulation from ppm(Y, ~polynom(x,y,2))") off on 1 2 > > fit <- ppm(Y,~marks+polynom(x,y,2)) > Ysim <- rmh(fit) Extracting model information...Evaluating trend...done. Checking arguments..determining simulation windows...> plot(Ysim, main="simulation from ppm(Y, ~marks+polynom(x,y,2))") off on 1 2 > > fit <- ppm(Y,~marks*polynom(x,y,2)) > Ysim <- rmh(fit) Extracting model information...Evaluating trend...done. Checking arguments..determining simulation windows...> plot(Ysim, main="simulation from ppm(Y, ~marks*polynom(x,y,2))") off on 1 2 > > # multitype Strauss models > MS <- MultiStrauss(types = levels(Y$marks), + radii=matrix(0.07, ncol=2, nrow=2)) > fit <- ppm(Y, ~marks, MS) > Ysim <- rmh(fit, control=list(nrep=1e3)) Extracting model information...Model is invalid - projecting it Evaluating trend...done. Checking arguments..determining simulation windows...Starting simulation. Initial state...Proposal points...Start simulation. > plot(Ysim, main="simulation from fitted Multitype Strauss") off on 1 2 > > fit <- ppm(Y,~marks*polynom(x,y,2), MS) > Ysim <- rmh(fit, control=list(nrep=1e3)) Extracting model information...Evaluating trend...done. Checking arguments..determining simulation windows...Evaluating trend integral...Starting simulation. Initial state...Proposal points...Start simulation. > plot(Ysim, main="simulation from fitted inhomogeneous Multitype Strauss") off on 1 2 > > > > cleanEx(); ..nameEx <- "rmhcontrol" > > ### * rmhcontrol > > flush(stderr()); flush(stdout()) > > ### Name: rmhcontrol > ### Title: Set Control Parameters for Metropolis-Hastings Algorithm. > ### Aliases: rmhcontrol rmhcontrol.default > ### Keywords: spatial > > ### ** Examples > > # parameters given as named arguments > c1 <- rmhcontrol(p=0.3,periodic=TRUE,nrep=1e6,nverb=1e5) > > # parameters given as a list > liz <- list(p=0.9, nrep=1e4) > c2 <- rmhcontrol(liz) > > # parameters given in rmhcontrol object > c3 <- rmhcontrol(c1) > > > > cleanEx(); ..nameEx <- "rmhmodel" > > ### * rmhmodel > > flush(stderr()); flush(stdout()) > > ### Name: rmhmodel > ### Title: Define Point Process Model for Metropolis-Hastings Simulation. > ### Aliases: rmhmodel rmhmodel.default > ### Keywords: spatial > > ### ** Examples > > # Strauss process: > mod01 <- rmhmodel(cif="strauss",par=c(beta=2,gamma=0.2,r=0.7), + w=c(0,10,0,10)) > # Equivalent to: > a <- list(cif="strauss",par=c(beta=2,gamma=0.2,r=0.7), + w=c(0,10,0,10)) > mod01 <- rmhmodel(a) > > # Strauss with hardcore: > mod04 <- list(cif="straush",par=c(beta=2,gamma=0.2,r=0.7,hc=0.3), + w=owin(c(0,10),c(0,5))) > mod04 <- rmhmodel(mod04) > > # Soft core: > par3 <- c(0.8,0.1,0.5) > w <- square(10) > mod07 <- rmhmodel(cif="sftcr", + par=c(beta=0.8,sigma=0.1,kappa=0.5), + w=w) > > # Multitype Strauss: > beta <- c(0.027,0.008) > gmma <- matrix(c(0.43,0.98,0.98,0.36),2,2) > r <- matrix(c(45,45,45,45),2,2) > mod08 <- rmhmodel(cif="straussm", + par=list(beta=beta,gamma=gmma,radii=r), + w=square(250)) > # specify types > mod09 <- rmhmodel(cif="straussm", + par=list(beta=beta,gamma=gmma,radii=r), + w=square(250), + types=c("A", "B")) > > > # Multitype Strauss hardcore with trends for each type: > beta <- c(0.27,0.08) > ri <- matrix(c(45,45,45,45),2,2) > rhc <- matrix(c(9.1,5.0,5.0,2.5),2,2) > tr3 <- function(x,y){x <- x/250; y <- y/250; + exp((6*x + 5*y - 18*x^2 + 12*x*y - 9*y^2)/6) + } > # log quadratic trend > tr4 <- function(x,y){x <- x/250; y <- y/250; + exp(-0.6*x+0.5*y)} > # log linear trend > mod10 <- rmhmodel(cif="straushm",par=list(beta=beta,gamma=gmma, + iradii=ri,hradii=rhc),w=c(0,250,0,250), + trend=list(tr3,tr4)) > > # Lookup (interaction function h_2 from page 76, Diggle (2003)): > r <- seq(from=0,to=0.2,length=101)[-1] # Drop 0. > h <- 20*(r-0.05) > h[r<0.05] <- 0 > h[r>0.10] <- 1 > mod17 <- rmhmodel(cif="lookup",par=list(beta=4000,h=h,r=r),w=c(0,1,0,1)) > > > > cleanEx(); ..nameEx <- "rmhstart" > > ### * rmhstart > > flush(stderr()); flush(stdout()) > > ### Name: rmhstart > ### Title: Determine Initial State for Metropolis-Hastings Simulation. > ### Aliases: rmhstart rmhstart.default > ### Keywords: spatial > > ### ** Examples > > # 30 random points > a <- rmhstart(n.start=30) > > # a particular point pattern > data(cells) > b <- rmhstart(x.start=cells) > > # set the seed > d <- rmhstart(n.start=30, iseed=c(42, 4, 2)) > > > > cleanEx(); ..nameEx <- "rmpoint" > > ### * rmpoint > > flush(stderr()); flush(stdout()) > > ### Name: rmpoint > ### Title: Generate N Random Multitype Points > ### Aliases: rmpoint > ### Keywords: spatial > > ### ** Examples > > > abc <- c("a","b","c") > > ##### Model I > > rmpoint(25, types=abc) marked planar point pattern: 25 points multitype, with levels = a b c window: rectangle = [ 0 , 1 ] x [ 0 , 1 ] > rmpoint(25, 1, types=abc) marked planar point pattern: 25 points multitype, with levels = a b c window: rectangle = [ 0 , 1 ] x [ 0 , 1 ] > # 25 points, equal probability for each type, uniformly distributed locations > > rmpoint(25, function(x,y,m) {rep(1, length(x))}, types=abc) marked planar point pattern: 25 points multitype, with levels = a b c window: rectangle = [ 0 , 1 ] x [ 0 , 1 ] > # same as above > rmpoint(25, list(function(x,y){rep(1, length(x))}, + function(x,y){rep(1, length(x))}, + function(x,y){rep(1, length(x))}), + types=abc) marked planar point pattern: 25 points multitype, with levels = a b c window: rectangle = [ 0 , 1 ] x [ 0 , 1 ] > # same as above > > rmpoint(25, function(x,y,m) { x }, types=abc) marked planar point pattern: 25 points multitype, with levels = a b c window: rectangle = [ 0 , 1 ] x [ 0 , 1 ] > # 25 points, equal probability for each type, > # locations nonuniform with density proportional to x > > rmpoint(25, function(x,y,m) { ifelse(m == "a", 1, x) }, types=abc) marked planar point pattern: 25 points multitype, with levels = a b c window: rectangle = [ 0 , 1 ] x [ 0 , 1 ] > rmpoint(25, list(function(x,y) { rep(1, length(x)) }, + function(x,y) { x }, + function(x,y) { x }), + types=abc) marked planar point pattern: 25 points multitype, with levels = a b c window: rectangle = [ 0 , 1 ] x [ 0 , 1 ] > # 25 points, UNEQUAL probabilities for each type, > # type "a" points uniformly distributed, > # type "b" and "c" points nonuniformly distributed. > > ##### Model II > > rmpoint(25, 1, types=abc, ptypes=rep(1,3)/3) marked planar point pattern: 25 points multitype, with levels = a b c window: rectangle = [ 0 , 1 ] x [ 0 , 1 ] > rmpoint(25, 1, types=abc, ptypes=rep(1,3)) marked planar point pattern: 25 points multitype, with levels = a b c window: rectangle = [ 0 , 1 ] x [ 0 , 1 ] > # 25 points, equal probability for each type, > # uniformly distributed locations > > rmpoint(25, function(x,y,m) {rep(1, length(x))}, types=abc, ptypes=rep(1,3)) marked planar point pattern: 25 points multitype, with levels = a b c window: rectangle = [ 0 , 1 ] x [ 0 , 1 ] > # same as above > rmpoint(25, list(function(x,y){rep(1, length(x))}, + function(x,y){rep(1, length(x))}, + function(x,y){rep(1, length(x))}), + types=abc, ptypes=rep(1,3)) marked planar point pattern: 25 points multitype, with levels = a b c window: rectangle = [ 0 , 1 ] x [ 0 , 1 ] > # same as above > > rmpoint(25, function(x,y,m) { x }, types=abc, ptypes=rep(1,3)) marked planar point pattern: 25 points multitype, with levels = a b c window: rectangle = [ 0 , 1 ] x [ 0 , 1 ] > # 25 points, equal probability for each type, > # locations nonuniform with density proportional to x > > rmpoint(25, function(x,y,m) { ifelse(m == "a", 1, x) }, types=abc, ptypes=rep(1,3)) marked planar point pattern: 25 points multitype, with levels = a b c window: rectangle = [ 0 , 1 ] x [ 0 , 1 ] > # 25 points, EQUAL probabilities for each type, > # type "a" points uniformly distributed, > # type "b" and "c" points nonuniformly distributed. > > ###### Model III > > rmpoint(c(12, 8, 4), 1, types=abc) marked planar point pattern: 24 points multitype, with levels = a b c window: rectangle = [ 0 , 1 ] x [ 0 , 1 ] > # 12 points of type "a", > # 8 points of type "b", > # 4 points of type "c", > # each uniformly distributed > > rmpoint(c(12, 8, 4), function(x,y,m) { ifelse(m=="a", 1, x)}, types=abc) marked planar point pattern: 24 points multitype, with levels = a b c window: rectangle = [ 0 , 1 ] x [ 0 , 1 ] > rmpoint(c(12, 8, 4), list(function(x,y) { rep(1, length(x)) }, + function(x,y) { x }, + function(x,y) { x }), + types=abc) marked planar point pattern: 24 points multitype, with levels = a b c window: rectangle = [ 0 , 1 ] x [ 0 , 1 ] > > # 12 points of type "a", uniformly distributed > # 8 points of type "b", nonuniform > # 4 points of type "c", nonuniform > > ######### > > ## Randomising an existing point pattern: > data(demopat) > X <- demopat > > # same numbers of points of each type, uniform random locations (Model III) > rmpoint(table(X$marks), 1, types=levels(X$marks), win=X$window) marked planar point pattern: 112 points multitype, with levels = A B window: polygonal boundary enclosing rectangle: [ 525 , 10575 ] x [ 450 , 7125 ] > > # same total number of points, distribution of types estimated from X, > # uniform random locations (Model II) > rmpoint(X$n, 1, types=levels(X$marks), win=X$window, + ptypes=table(X$marks)) marked planar point pattern: 112 points multitype, with levels = A B window: polygonal boundary enclosing rectangle: [ 525 , 10575 ] x [ 450 , 7125 ] > > > > > cleanEx(); ..nameEx <- "rmpoispp" > > ### * rmpoispp > > flush(stderr()); flush(stdout()) > > ### Name: rmpoispp > ### Title: Generate Multitype Poisson Point Pattern > ### Aliases: rmpoispp > ### Keywords: spatial > > ### ** Examples > > # uniform bivariate Poisson process with total intensity 100 in unit square > pp <- rmpoispp(50, types=c("a","b")) > > # stationary bivariate Poisson process with intensity A = 30, B = 70 > pp <- rmpoispp(c(30,70), types=c("A","B")) > pp <- rmpoispp(c(30,70)) > > # works in any window > data(letterR) > pp <- rmpoispp(c(30,70), win=letterR, types=c("A","B")) > > # inhomogeneous lambda(x,y,m) > # note argument 'm' is a factor > lam <- function(x,y,m) { 50 * (x^2 + y^3) * ifelse(m=="A", 2, 1)} > pp <- rmpoispp(lam, win=letterR, types=c("A","B")) > # extra arguments > lam <- function(x,y,m,scal) { scal * (x^2 + y^3) * ifelse(m=="A", 2, 1)} > pp <- rmpoispp(lam, win=letterR, types=c("A","B"), scal=50) > > # list of functions lambda[[i]](x,y) > lams <- list(function(x,y){50 * x^2}, function(x,y){20 * abs(y)}) > pp <- rmpoispp(lams, win=letterR, types=c("A","B")) > pp <- rmpoispp(lams, win=letterR) > # functions with extra arguments > lams <- list(function(x,y,scal){5 * scal * x^2}, + function(x,y, scal){2 * scal * abs(y)}) > pp <- rmpoispp(lams, win=letterR, types=c("A","B"), scal=10) > pp <- rmpoispp(lams, win=letterR, scal=10) > > # florid example > lams <- list(function(x,y){ + 100*exp((6*x + 5*y - 18*x^2 + 12*x*y - 9*y^2)/6) + } + # log quadratic trend + , + function(x,y){ + 100*exp(-0.6*x+0.5*y) + } + # log linear trend + ) > X <- rmpoispp(lams, win=unit.square(), types=c("on", "off")) > > # pixel image > Z <- as.im(function(x,y){30 * (x^2 + y^3)}, letterR) > pp <- rmpoispp(Z, types=c("A","B")) > > # list of pixel images > ZZ <- list( + as.im(function(x,y){20 * (x^2 + y^3)}, letterR), + as.im(function(x,y){40 * (x^3 + y^2)}, letterR)) > pp <- rmpoispp(ZZ, types=c("A","B")) > pp <- rmpoispp(ZZ) > > > > > cleanEx(); ..nameEx <- "rotate" > > ### * rotate > > flush(stderr()); flush(stdout()) > > ### Name: rotate > ### Title: Rotate > ### Aliases: rotate > ### Keywords: spatial > > ### ** Examples > > data(cells) > X <- rotate(cells, pi/3) > ## Not run: > ##D plot(X) > ##D plot(rotate(cells$window, pi/4)) > ##D > ## End(Not run) > > > > cleanEx(); ..nameEx <- "rotate.owin" > > ### * rotate.owin > > flush(stderr()); flush(stdout()) > > ### Name: rotate.owin > ### Title: Rotate a Window > ### Aliases: rotate.owin > ### Keywords: spatial > > ### ** Examples > > w <- owin(c(0,1),c(0,1)) > v <- rotate(w, pi/3) > ## Not run: > ##D plot(v) > ##D > ## End(Not run) > > > > cleanEx(); ..nameEx <- "rotate.ppp" > > ### * rotate.ppp > > flush(stderr()); flush(stdout()) > > ### Name: rotate.ppp > ### Title: Rotate a Point Pattern > ### Aliases: rotate.ppp > ### Keywords: spatial > > ### ** Examples > > data(cells) > X <- rotate(cells, pi/3) > ## Not run: > ##D plot(X) > ##D > ## End(Not run) > > > > cleanEx(); ..nameEx <- "rpoint" > > ### * rpoint > > flush(stderr()); flush(stdout()) > > ### Name: rpoint > ### Title: Generate N Random Points > ### Aliases: rpoint > ### Keywords: spatial > > ### ** Examples > > # 100 uniform random points in the unit square > X <- rpoint(100) > > # 100 random points with probability density proportional to x^2 + y^2 > X <- rpoint(100, function(x,y) { x^2 + y^2}, 1) > > # `fmax' may be omitted > X <- rpoint(100, function(x,y) { x^2 + y^2}) > > # irregular window > data(letterR) > X <- rpoint(100, function(x,y) { x^2 + y^2}, win=letterR) > > # make a pixel image > Z <- setcov(letterR) > # 100 points with density proportional to pixel values > X <- rpoint(100, Z) > > > > cleanEx(); ..nameEx <- "rpoispp" > > ### * rpoispp > > flush(stderr()); flush(stdout()) > > ### Name: rpoispp > ### Title: Generate Poisson Point Pattern > ### Aliases: rpoispp > ### Keywords: spatial > > ### ** Examples > > # uniform Poisson process with intensity 100 in the unit square > pp <- rpoispp(100) > > # uniform Poisson process with intensity 1 in a 10 x 10 square > pp <- rpoispp(1, win=owin(c(0,10),c(0,10))) > # plots should look similar ! > > # inhomogeneous Poisson process in unit square > # with intensity lambda(x,y) = 100 * exp(-3*x) > # Intensity is bounded by 100 > pp <- rpoispp(function(x,y) {100 * exp(-3*x)}, 100) > > # How to tune the coefficient of x > lamb <- function(x,y,a) { 100 * exp( - a * x)} > pp <- rpoispp(lamb, 100, a=3) > > # pixel image > Z <- as.im(function(x,y){100 * sqrt(x+y)}, unit.square()) > pp <- rpoispp(Z) > > > > > cleanEx(); ..nameEx <- "rtoro" > > ### * rtoro > > flush(stderr()); flush(stdout()) > > ### Name: rtoro > ### Title: Random Toroidal Shift of Point Pattern > ### Aliases: rtoro > ### Keywords: spatial > > ### ** Examples > > data(amacrine) > > # point patterns: > # shift all points simultaneously > X <- rtoro(amacrine) > # shift "on" and "off" points separately > X <- rtoro(amacrine, which=amacrine$marks) > # shift "on" points and leave "off" points fixed > X <- rtoro(amacrine, which="on") > > # splitppp objects: > Y <- split(amacrine) > # shift "on" and "off" points separately > Z <- rtoro(Y) > # shift "on" points and leave "off" points fixed > Z <- rtoro(Y, "on") > # shift all points simultaneously > Z <- split(rtoro(superimpose(Y))) > > > > > cleanEx(); ..nameEx <- "runifpoint" > > ### * runifpoint > > flush(stderr()); flush(stdout()) > > ### Name: runifpoint > ### Title: Generate N Uniform Random Points > ### Aliases: runifpoint > ### Keywords: spatial > > ### ** Examples > > # 100 random points in the unit square > pp <- runifpoint(100) > # irregular window > data(letterR) > # polygonal > pp <- runifpoint(100, letterR) > # binary image mask > pp <- runifpoint(100, as.mask(letterR)) > > > > cleanEx(); ..nameEx <- "setcov" > > ### * setcov > > flush(stderr()); flush(stdout()) > > ### Name: setcov > ### Title: Set Covariance of a Window > ### Aliases: setcov > ### Keywords: spatial > > ### ** Examples > > w <- owin(c(0,1),c(0,1)) > v <- setcov(w) > plot(v) > > > > cleanEx(); ..nameEx <- "setmarks" > > ### * setmarks > > flush(stderr()); flush(stdout()) > > ### Name: setmarks > ### Title: Set or Reset the Marks in a Point Pattern > ### Aliases: setmarks \%mark\% > ### Keywords: spatial > > ### ** Examples > > data(cells) > > m <- runif(cells$n) > > Y <- setmarks(cells, m) > Y <- cells %mark% m > # equivalent > > ## Not run: plot(Y) > is.marked(Y) #TRUE [1] TRUE > > > > cleanEx(); ..nameEx <- "shift" > > ### * shift > > flush(stderr()); flush(stdout()) > > ### Name: shift > ### Title: Apply Vector Translation > ### Aliases: shift > ### Keywords: spatial > > ### ** Examples > > data(cells) > X <- shift(cells, c(2,3)) > ## Not run: > ##D plot(X) > ##D # no discernible difference except coordinates are different > ##D > ## End(Not run) > > > > cleanEx(); ..nameEx <- "shift.im" > > ### * shift.im > > flush(stderr()); flush(stdout()) > > ### Name: shift.im > ### Title: Apply Vector Translation To Pixel Image > ### Aliases: shift.im > ### Keywords: spatial > > ### ** Examples > > # make up an image > X <- setcov(unit.square()) > plot(X) > > Y <- shift(X, c(10,10)) > plot(Y) > # no discernible difference except coordinates are different > > > > cleanEx(); ..nameEx <- "shift.owin" > > ### * shift.owin > > flush(stderr()); flush(stdout()) > > ### Name: shift.owin > ### Title: Apply Vector Translation To Window > ### Aliases: shift.owin > ### Keywords: spatial > > ### ** Examples > > W <- owin(c(0,1),c(0,1)) > X <- shift(W, c(2,3)) > ## Not run: > ##D plot(W) > ##D # no discernible difference except coordinates are different > ##D > ## End(Not run) > > > > cleanEx(); ..nameEx <- "shift.ppp" > > ### * shift.ppp > > flush(stderr()); flush(stdout()) > > ### Name: shift.ppp > ### Title: Apply Vector Translation To Point Pattern > ### Aliases: shift.ppp > ### Keywords: spatial > > ### ** Examples > > data(cells) > X <- shift(cells, c(2,3)) > ## Not run: > ##D plot(X) > ##D # no discernible difference except coordinates are different > ##D > ## End(Not run) > Y <- superimpose(cells, shift(cells, c(0.1,0.1))) > ## Not run: plot(Y) > > > > cleanEx(); ..nameEx <- "spatstat.options" > > ### * spatstat.options > > flush(stderr()); flush(stdout()) > > ### Name: spatstat.options > ### Title: Internal Options in Spatstat Package > ### Aliases: spatstat.options > ### Keywords: spatial > > ### ** Examples > > spatstat.options(npixel=150) > spatstat.options(npixel=c(100,200)) > > spatstat.options(par.binary=list(col=grey(c(0.5,1)))) > > spatstat.options(par.persp=list(theta=-30,phi=40,d=4)) > # see help(persp.default) for other options > > > > > cleanEx(); ..nameEx <- "split.ppp" > > ### * split.ppp > > flush(stderr()); flush(stdout()) > > ### Name: split.ppp > ### Title: Divide Point Pattern into Sub-patterns > ### Aliases: split.ppp split<-.ppp split split<- > ### Keywords: spatial > > ### ** Examples > > > # Multitype point pattern: separate into types > data(amacrine) > u <- split(amacrine) > > # the following are equivalent: > amon <- amacrine[amacrine$marks == "on"] > amon <- split(amacrine)$on > > # plot them > plot(split(amacrine)) > > # Scramble the locations of the 'on' cells > u <- unmark(split(amacrine)) > u$on <- runifpoint(amon$n, amon$window) > split(amacrine) <- u > > # Point pattern with continuous marks > data(longleaf) > ## Don't show: > # smaller dataset > longleaf <- longleaf[seq(1, longleaf$n, by=80)] > > ## End Don't show > # cut the range of tree diameters into three intervals > long3 <- cut.ppp(longleaf, 3) > # now split them > long3split <- split(long3) > > # Unmarked point pattern > data(swedishpines) > # cut & split according to nearest neighbour distance > f <- cut(nndist(swedishpines), 3) > u <- split(swedishpines, f) > > > > cleanEx(); ..nameEx <- "spokes" > > ### * spokes > > flush(stderr()); flush(stdout()) > > ### Name: spokes > ### Title: Spokes pattern of dummy points > ### Aliases: spokes > ### Keywords: spatial > > ### ** Examples > > dat <- runifrect(10) > ## Not run: > ##D plot(dat) > ##D > ## End(Not run) > dum <- spokes(dat$x, dat$y) > ## Not run: > ##D points(dum$x, dum$y, pch=".") > ##D > ## End(Not run) > Q <- quadscheme(dat, dum) Warning in countingweights(id, areas) : some tiles with positive area do not contain any points > > > > cleanEx(); ..nameEx <- "spruces" > > ### * spruces > > flush(stderr()); flush(stdout()) > > ### Name: spruces > ### Title: Spruces Point Pattern > ### Aliases: spruces > ### Keywords: datasets > > ### ** Examples > > data(spruces) > plot(spruces) 0.15 0.2 0.25 0.3 0.35 0.4 1.276075 1.701433 2.126791 2.552149 2.977507 3.402865 > # To reproduce Goulard et al. Figure 3 > plot(spruces, maxsize=5*max(spruces$marks)) 0.15 0.2 0.25 0.3 0.35 0.4 0.75 1.00 1.25 1.50 1.75 2.00 > plot(unmark(spruces), add=TRUE) > > > > cleanEx(); ..nameEx <- "square" > > ### * square > > flush(stderr()); flush(stdout()) > > ### Name: square > ### Title: Square Window > ### Aliases: square unit.square > ### Keywords: spatial > > ### ** Examples > > W <- square(10) > > > > cleanEx(); ..nameEx <- "stratrand" > > ### * stratrand > > flush(stderr()); flush(stdout()) > > ### Name: stratrand > ### Title: Stratified random point pattern > ### Aliases: stratrand > ### Keywords: spatial > > ### ** Examples > > w <- unit.square() > xy <- stratrand(w, 10, 10) > ## Not run: > ##D plot(w) > ##D points(xy) > ##D > ## End(Not run) > > # polygonal boundary > bdry <- list(x=c(0.1,0.3,0.7,0.4,0.2), + y=c(0.1,0.1,0.5,0.7,0.3)) > w <- owin(c(0,1), c(0,1), poly=bdry) > xy <- stratrand(w, 10, 10, 3) > ## Not run: > ##D plot(w) > ##D points(xy) > ##D > ## End(Not run) > # determine which grid points are inside polygon > ok <- inside.owin(xy$x, xy$y, w) > ## Not run: > ##D plot(w) > ##D points(xy$x[ok], xy$y[ok]) > ##D > ## End(Not run) > > > > cleanEx(); ..nameEx <- "subset.fasp" > > ### * subset.fasp > > flush(stderr()); flush(stdout()) > > ### Name: subset.fasp > ### Title: Extract Subset of Function Array > ### Aliases: subset.fasp [.fasp > ### Keywords: spatial > > ### ** Examples > > # Lansing woods data - multitype points with 6 types > data(lansing) > ## Not run: > ##D # compute 6 x 6 array of all cross-type K functions > ##D a <- alltypes(lansing, "K") > ##D plot(a) > ##D > ## End(Not run) > ## Don't show: > # smaller dataset > sub <- lansing[ seq(1,lansing$n,by=40), ] > a <- alltypes(sub, "K") > > ## End Don't show > # first three marks only > b <- a[1:3,1:3] > ## Not run: plot(b) > # subset pertaining to hickories > h <- a[levels(lansing$marks) == "hickory", ] > ## Not run: plot(h) > > > > cleanEx(); ..nameEx <- "subset.fv" > > ### * subset.fv > > flush(stderr()); flush(stdout()) > > ### Name: subset.fv > ### Title: Extract Subset of Function Values > ### Aliases: subset.fv [.fv > ### Keywords: spatial > > ### ** Examples > > data(cells) > K <- Kest(cells) > > # discard the estimates of K(r) for r > 0.1 > Ksub <- K[K$r <= 0.1, ] > > # discard the border method estimator > Ksub <- K[ , names(K) != "border"] > > > > > cleanEx(); ..nameEx <- "subset.im" > > ### * subset.im > > flush(stderr()); flush(stdout()) > > ### Name: subset.im > ### Title: Extract Subset of Image > ### Aliases: subset.im [.im > ### Keywords: spatial > > ### ** Examples > > # make up an image > X <- setcov(unit.square()) > plot(X) > > # a rectangular subset > W <- owin(c(0,0.5),c(0.2,0.8)) > Y <- X[W] > plot(Y) > > # a polygonal subset > data(letterR) > R <- affine(letterR, diag(c(1,1)/2), c(-2,-0.7)) > Y <- X[R, drop=FALSE] > plot(Y) > > # a point pattern > P <- rpoispp(20) > Y <- X[P] > > > > cleanEx(); ..nameEx <- "subset.ppp" > > ### * subset.ppp > > flush(stderr()); flush(stdout()) > > ### Name: subset.ppp > ### Title: Extract or Replace Subset of Point Pattern > ### Aliases: subset.ppp [.ppp [<-.ppp > ### Keywords: spatial > > ### ** Examples > > data(longleaf) > # Longleaf pines data > ## Not run: > ##D plot(longleaf) > ##D > ## End(Not run) > ## Don't show: > longleaf <- longleaf[seq(1,longleaf$n,by=10)] > > ## End Don't show > # adult trees defined to have diameter at least 30 cm > adult <- (longleaf$marks >= 30) > longadult <- longleaf[adult] > # equivalent to: longadult <- subset.ppp(longleaf, subset=adult) > ## Not run: > ##D plot(longadult) > ##D > ## End(Not run) > # note that the marks are still retained. > # Use unmark(longadult) to remove the marks > > # New Zealand trees data > data(nztrees) > ## Not run: > ##D plot(nztrees) # plot shows a line of trees at the far right > ##D abline(v=148, lty=2) # cut along this line > ##D > ## End(Not run) > nzw <- owin(c(0,148),c(0,95)) # the subwindow > # trim dataset to this subwindow > nzsub <- nztrees[,nzw] > # equivalent to: nzsub <- subset.ppp(nztrees, window=nzw) > ## Not run: > ##D plot(nzsub) > ##D > ## End(Not run) > > # Redwood data > data(redwood) > ## Not run: > ##D plot(redwood) > ##D > ## End(Not run) > # Random thinning: delete 60% of data > retain <- (runif(redwood$n) < 0.4) > thinred <- redwood[retain] > ## Not run: > ##D plot(thinred) > ##D > ## End(Not run) > # Scramble 60% of data > modif <- (runif(redwood$n) < 0.6) > scramble <- function(x) { runifpoint(x$n, x$window) } > redwood[modif] <- scramble(redwood[modif]) > > # Lansing woods data - multitype points > data(lansing) > ## Don't show: > lansing <- lansing[seq(1, lansing$n, length=100)] > > ## End Don't show > # hickory trees only > hick <- lansing[lansing$marks == "hickory", ] > # still a marked pattern -- remove marks > hick <- unmark(hick) > > # scramble the hickories > lansing[lansing$marks == "hickory"] <- scramble(hick) > > > > > cleanEx(); ..nameEx <- "suffstat" > > ### * suffstat > > flush(stderr()); flush(stdout()) > > ### Name: suffstat > ### Title: Sufficient Statistic of Point Process Model > ### Aliases: suffstat > ### Keywords: spatial > > ### ** Examples > > data(swedishpines) > fitS <- ppm(swedishpines, ~1, Strauss(7)) > X <- rpoispp(summary(swedishpines)$intensity, win=swedishpines$window) > suffstat(fitS, X) (Intercept) Interaction 65 31 > > > > cleanEx(); ..nameEx <- "summary.im" > > ### * summary.im > > flush(stderr()); flush(stdout()) > > ### Name: summary.im > ### Title: Summarizing a Pixel Image > ### Aliases: summary.im print.summary.im > ### Keywords: spatial > > ### ** Examples > > # make an image > X <- as.im(function(x,y) {x^2}, unit.square()) > # summarize it > summary(X) Pixel image 200 x 100 pixel array enclosing rectangle: [ 8.67361737988404e-19, 1 ] x [ 4.33680868994202e-19, 1 ] dimensions of each pixel: 0.01 x 0.005 Image is defined on the full rectangular grid Frame area = 1 Pixel values : range = [2.5e-05,0.990025] integral = 0.333325000000017 mean = 0.333325000000017 > # save the summary > s <- summary(X) > # print it > print(X) Pixel image 200 x 100 pixel array enclosing rectangle: [ 8.67361737988404e-19, 1 ] x [ 4.33680868994202e-19, 1 ] > s Pixel image 200 x 100 pixel array enclosing rectangle: [ 8.67361737988404e-19, 1 ] x [ 4.33680868994202e-19, 1 ] dimensions of each pixel: 0.01 x 0.005 Image is defined on the full rectangular grid Frame area = 1 Pixel values : range = [2.5e-05,0.990025] integral = 0.333325000000017 mean = 0.333325000000017 > # extract stuff > X$dim [1] 200 100 > X$range NULL > X$integral NULL > > > > cleanEx(); ..nameEx <- "summary.owin" > > ### * summary.owin > > flush(stderr()); flush(stdout()) > > ### Name: summary.owin > ### Title: Summary of a Spatial Window > ### Aliases: summary.owin > ### Keywords: spatial > > ### ** Examples > > summary(owin()) # the unit square Window: rectangle = [ 0 , 1 ] x [ 0 , 1 ] Window area = 1 > > data(demopat) > W <- demopat$window # weird polygonal window > summary(W) # describes it Window: polygonal boundary 2 separate polygons (1 hole) vertices area relative.area polygon 1 32 52711875 1.110 polygon 2 (hole) 12 -5127188 -0.108 enclosing rectangle: [ 525 , 10575 ] x [ 450 , 7125 ] Window area = 47584687.5 > > summary(as.mask(W)) # demonstrates current pixel resolution Window: binary image mask 200 x 100 pixel array enclosing rectangle: [ 525 , 10575 ] x [ 450 , 7125 ] Window area = 47545607.8125 > > > > cleanEx(); ..nameEx <- "summary.ppm" > > ### * summary.ppm > > flush(stderr()); flush(stdout()) > > ### Name: summary.ppm > ### Title: Summarizing a Fitted Point Process Model > ### Aliases: summary.ppm print.summary.ppm > ### Keywords: spatial > > ### ** Examples > > # invent some data > X <- rpoispp(42) > # fit a model to it > fit <- ppm(X, ~x, Strauss(r=0.1)) > # summarize the fitted model > summary(fit) Point process model fitted by maximum pseudolikelihood Call: ppm(Q = X, trend = ~x, interaction = Strauss(r = 0.1)) Edge correction: 'border' ---------------------------------------------------- Quadrature scheme = data + dummy + weights Data pattern: Planar point pattern: 37 points Average intensity 37 points per unit area Window: rectangle = [ 0 , 1 ] x [ 0 , 1 ] Window area = 1 Dummy quadrature points: ( 25 x 25 grid, plus 4 corner points) Planar point pattern: 629 points Average intensity 629 points per unit area Window: rectangle = [ 0 , 1 ] x [ 0 , 1 ] Window area = 1 Quadrature weights: (counting weights based on 25 x 25 array of rectangular tiles) All weights: range: [0.000533, 0.0016] total: 1 Weights on data points: range: [0.000533, 8e-04] total: 0.0285 Weights on dummy points: range: [0.000533, 0.0016] total: 0.971 ---------------------------------------------------- FITTED MODEL: Nonstationary Strauss process ---- Trend: ---- Trend formula: ~x Fitted coefficients for trend formula: (Intercept) x 3.5880605 0.3130043 ---- Interaction: ----- Pairwise interaction family Interaction: Strauss process interaction distance: 0.1 Fitted interaction parameter gamma: [1] 0.8756 ----------- gory details ----- Fitted regular parameters (theta): (Intercept) x Interaction 3.5880605 0.3130043 -0.1328183 Fitted exp(theta): (Intercept) x Interaction 36.1638690 1.3675274 0.8756242 > # `quick' option > summary(fit, quick=TRUE) Nonstationary Strauss process > > # save the full summary > s <- summary(fit) > # print it > print(s) Point process model fitted by maximum pseudolikelihood Call: ppm(Q = X, trend = ~x, interaction = Strauss(r = 0.1)) Edge correction: 'border' ---------------------------------------------------- Quadrature scheme = data + dummy + weights Data pattern: Planar point pattern: 37 points Average intensity 37 points per unit area Window: rectangle = [ 0 , 1 ] x [ 0 , 1 ] Window area = 1 Dummy quadrature points: ( 25 x 25 grid, plus 4 corner points) Planar point pattern: 629 points Average intensity 629 points per unit area Window: rectangle = [ 0 , 1 ] x [ 0 , 1 ] Window area = 1 Quadrature weights: (counting weights based on 25 x 25 array of rectangular tiles) All weights: range: [0.000533, 0.0016] total: 1 Weights on data points: range: [0.000533, 8e-04] total: 0.0285 Weights on dummy points: range: [0.000533, 0.0016] total: 0.971 ---------------------------------------------------- FITTED MODEL: Nonstationary Strauss process ---- Trend: ---- Trend formula: ~x Fitted coefficients for trend formula: (Intercept) x 3.5880605 0.3130043 ---- Interaction: ----- Pairwise interaction family Interaction: Strauss process interaction distance: 0.1 Fitted interaction parameter gamma: [1] 0.8756 ----------- gory details ----- Fitted regular parameters (theta): (Intercept) x Interaction 3.5880605 0.3130043 -0.1328183 Fitted exp(theta): (Intercept) x Interaction 36.1638690 1.3675274 0.8756242 > s Point process model fitted by maximum pseudolikelihood Call: ppm(Q = X, trend = ~x, interaction = Strauss(r = 0.1)) Edge correction: 'border' ---------------------------------------------------- Quadrature scheme = data + dummy + weights Data pattern: Planar point pattern: 37 points Average intensity 37 points per unit area Window: rectangle = [ 0 , 1 ] x [ 0 , 1 ] Window area = 1 Dummy quadrature points: ( 25 x 25 grid, plus 4 corner points) Planar point pattern: 629 points Average intensity 629 points per unit area Window: rectangle = [ 0 , 1 ] x [ 0 , 1 ] Window area = 1 Quadrature weights: (counting weights based on 25 x 25 array of rectangular tiles) All weights: range: [0.000533, 0.0016] total: 1 Weights on data points: range: [0.000533, 8e-04] total: 0.0285 Weights on dummy points: range: [0.000533, 0.0016] total: 0.971 ---------------------------------------------------- FITTED MODEL: Nonstationary Strauss process ---- Trend: ---- Trend formula: ~x Fitted coefficients for trend formula: (Intercept) x 3.5880605 0.3130043 ---- Interaction: ----- Pairwise interaction family Interaction: Strauss process interaction distance: 0.1 Fitted interaction parameter gamma: [1] 0.8756 ----------- gory details ----- Fitted regular parameters (theta): (Intercept) x Interaction 3.5880605 0.3130043 -0.1328183 Fitted exp(theta): (Intercept) x Interaction 36.1638690 1.3675274 0.8756242 > # extract stuff > names(s) [1] "antiquated" "no.trend" "stationary" "poisson" "marked" [6] "multitype" "name" "has.covars" "args" "entries" [11] "data" "quad" "trend" "interaction" > s$args$correction [1] "border" > s$name [1] "Nonstationary Strauss process" > s$trend$value (Intercept) x 3.5880605 0.3130043 > > # multitype pattern > data(demopat) > fit <- ppm(demopat, ~marks, Poisson()) > summary(fit) Point process model fitted by maximum pseudolikelihood Call: ppm(Q = demopat, trend = ~marks, interaction = Poisson()) Edge correction: 'border' ---------------------------------------------------- Quadrature scheme = data + dummy + weights Data pattern: Marked planar point pattern: 112 points Average intensity 2.35e-06 points per unit area Marks: frequency proportion intensity A 45 0.402 9.46e-07 B 67 0.598 1.41e-06 Window: polygonal boundary 2 separate polygons (1 hole) vertices area relative.area polygon 1 32 52711875 1.110 polygon 2 (hole) 12 -5127188 -0.108 enclosing rectangle: [ 525 , 10575 ] x [ 450 , 7125 ] Window area = 47584687.5 Dummy quadrature points: ( 50 x 40 grid, plus 4 corner points) Marked planar point pattern: 3156 points Average intensity 6.63e-05 points per unit area Marks: frequency proportion intensity A 1590 0.503 3.34e-05 B 1570 0.497 3.29e-05 Window: polygonal boundary 2 separate polygons (1 hole) vertices area relative.area polygon 1 32 52711875 1.110 polygon 2 (hole) 12 -5127188 -0.108 enclosing rectangle: [ 525 , 10575 ] x [ 450 , 7125 ] Window area = 47584687.5 Quadrature weights: (counting weights based on 50 x 40 array of rectangular tiles) All weights: range: [3350, 33500] total: 95100000 Weights on data points: range: [5590, 16800] total: 1730000 Weights on dummy points: range: [3350, 33500] total: 93400000 ---------------------------------------------------- FITTED MODEL: Stationary multitype Poisson process Possible marks: A B ---- Intensity: ---- Trend formula: ~marks Fitted intensities: beta_A beta_B 9.464597e-07 1.409173e-06 ----------- gory details ----- Fitted regular parameters (theta): (Intercept) marksB -13.8705375 0.3980301 Fitted exp(theta): (Intercept) marksB 9.464597e-07 1.488889e+00 > > > > cleanEx(); ..nameEx <- "summary.ppp" > > ### * summary.ppp > > flush(stderr()); flush(stdout()) > > ### Name: summary.ppp > ### Title: Summary of a Point Pattern Dataset > ### Aliases: summary.ppp > ### Keywords: spatial > > ### ** Examples > > data(cells) # plain vanilla point pattern > summary(cells) Planar point pattern: 42 points Average intensity 42 points per unit area Window: rectangle = [ 0 , 1 ] x [ 0 , 1 ] Window area = 1 > > data(lansing) # multitype point pattern > summary(lansing) # tabulates frequences of each mark Marked planar point pattern: 2251 points Average intensity 2250 points per unit area Marks: frequency proportion intensity blackoak 135 0.0600 135 hickory 703 0.3120 703 maple 514 0.2280 514 misc 105 0.0466 105 redoak 346 0.1540 346 whiteoak 448 0.1990 448 Window: rectangle = [ 0 , 1 ] x [ 0 , 1 ] Window area = 1 > > data(longleaf) # numeric marks > summary(longleaf) # prints summary.default(x$marks) Marked planar point pattern: 584 points Average intensity 0.0146 points per unit area marks are numeric, of type "double" summary: Min. 1st Qu. Median Mean 3rd Qu. Max. 2.00 9.10 26.15 26.84 42.13 75.90 Window: rectangle = [ 0 , 200 ] x [ 0 , 200 ] Window area = 40000 > > data(demopat) # weird polygonal window > summary(demopat) # describes it Marked planar point pattern: 112 points Average intensity 2.35e-06 points per unit area Marks: frequency proportion intensity A 45 0.402 9.46e-07 B 67 0.598 1.41e-06 Window: polygonal boundary 2 separate polygons (1 hole) vertices area relative.area polygon 1 32 52711875 1.110 polygon 2 (hole) 12 -5127188 -0.108 enclosing rectangle: [ 525 , 10575 ] x [ 450 , 7125 ] Window area = 47584687.5 > > > > cleanEx(); ..nameEx <- "summary.quad" > > ### * summary.quad > > flush(stderr()); flush(stdout()) > > ### Name: summary.quad > ### Title: Summarizing a Quadrature Scheme > ### Aliases: summary.quad print.summary.quad > ### Keywords: spatial > > ### ** Examples > > # make a quadrature scheme > Q <- quadscheme(rpoispp(42)) > # summarize it > summary(Q) Quadrature scheme = data + dummy + weights Data pattern: Planar point pattern: 37 points Average intensity 37 points per unit area Window: rectangle = [ 0 , 1 ] x [ 0 , 1 ] Window area = 1 Dummy quadrature points: ( 25 x 25 grid, plus 4 corner points) Planar point pattern: 629 points Average intensity 629 points per unit area Window: rectangle = [ 0 , 1 ] x [ 0 , 1 ] Window area = 1 Quadrature weights: (counting weights based on 25 x 25 array of rectangular tiles) All weights: range: [0.000533, 0.0016] total: 1 Weights on data points: range: [0.000533, 8e-04] total: 0.0285 Weights on dummy points: range: [0.000533, 0.0016] total: 0.971 > # save the summary > s <- summary(Q) > # print it > print(s) Quadrature scheme = data + dummy + weights Data pattern: Planar point pattern: 37 points Average intensity 37 points per unit area Window: rectangle = [ 0 , 1 ] x [ 0 , 1 ] Window area = 1 Dummy quadrature points: ( 25 x 25 grid, plus 4 corner points) Planar point pattern: 629 points Average intensity 629 points per unit area Window: rectangle = [ 0 , 1 ] x [ 0 , 1 ] Window area = 1 Quadrature weights: (counting weights based on 25 x 25 array of rectangular tiles) All weights: range: [0.000533, 0.0016] total: 1 Weights on data points: range: [0.000533, 8e-04] total: 0.0285 Weights on dummy points: range: [0.000533, 0.0016] total: 0.971 > s Quadrature scheme = data + dummy + weights Data pattern: Planar point pattern: 37 points Average intensity 37 points per unit area Window: rectangle = [ 0 , 1 ] x [ 0 , 1 ] Window area = 1 Dummy quadrature points: ( 25 x 25 grid, plus 4 corner points) Planar point pattern: 629 points Average intensity 629 points per unit area Window: rectangle = [ 0 , 1 ] x [ 0 , 1 ] Window area = 1 Quadrature weights: (counting weights based on 25 x 25 array of rectangular tiles) All weights: range: [0.000533, 0.0016] total: 1 Weights on data points: range: [0.000533, 8e-04] total: 0.0285 Weights on dummy points: range: [0.000533, 0.0016] total: 0.971 > # extract total quadrature weight > s$w$all$sum [1] 1 > > > > cleanEx(); ..nameEx <- "superimpose" > > ### * superimpose > > flush(stderr()); flush(stdout()) > > ### Name: superimpose > ### Title: Superimpose Several Point Patterns > ### Aliases: superimpose > ### Keywords: spatial > > ### ** Examples > > dat <- runifrect(30) > xy <- list(x=runif(10),y=runif(10)) > new <- superimpose(dat, xy) > ## Not run: plot(new) > > # how to make a 2-type point pattern with types "a" and "b" > u <- superimpose(a = rpoispp(10), b = rpoispp(20)) > > # how to make a 2-type point pattern with types 1 and 2 > u <- superimpose("1" = rpoispp(10), "2" = rpoispp(20)) > > > > cleanEx(); ..nameEx <- "union.quad" > > ### * union.quad > > flush(stderr()); flush(stdout()) > > ### Name: union.quad > ### Title: Union of Data and Dummy Points > ### Aliases: union.quad > ### Keywords: spatial > > ### ** Examples > > data(simdat) > Q <- quadscheme(simdat, default.dummy(simdat)) > U <- union.quad(Q) > ## Not run: plot(U) > # equivalent: > U <- as.ppp(Q) > > > > cleanEx(); ..nameEx <- "unmark" > > ### * unmark > > flush(stderr()); flush(stdout()) > > ### Name: unmark > ### Title: Remove Marks from a Marked Point Pattern > ### Aliases: unmark > ### Keywords: spatial > > ### ** Examples > > data(lansing) > hicks <- lansing[lansing$marks == "hickory", ] > ## Not run: > ##D plot(hicks) # still a marked point pattern, but only 1 value of marks > ##D plot(unmark(hicks)) # unmarked > ##D > ## End(Not run) > > > > cleanEx(); ..nameEx <- "update.ppm" > > ### * update.ppm > > flush(stderr()); flush(stdout()) > > ### Name: update.ppm > ### Title: Update a Fitted Point Process Model > ### Aliases: update.ppm > ### Keywords: spatial > > ### ** Examples > > data(nztrees) > data(cells) > > # fit the stationary Poisson process > fit <- ppm(nztrees, ~ 1) > > # fit a nonstationary Poisson process > fitP <- update(fit, trend=~x) > fitP <- update(fit, ~x) > > # fit a stationary Strauss process > fitS <- update(fit, interaction=Strauss(13)) > fitS <- update(fit, Strauss(13)) > > # oops, forgot the edge correction > fitS <- update(fitS, rbord=13) > > # re-fit the model to a subset > # of the original point pattern > nzw <- owin(c(0,148),c(0,95)) > nzsub <- nztrees[,nzw] > fut <- update(fitS, Q=nzsub) > fut <- update(fitS, nzsub) > > # WARNING: the point pattern argument is called 'Q' > > > > ### *