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("splancs-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('splancs') Spatial Point Pattern Analysis Code in S-Plus Version 2 - Spatial and Space-Time analysis > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "Fhat" > > ### * Fhat > > flush(stderr()); flush(stdout()) > > ### Name: Fhat > ### Title: F nearest neighbour distribution function > ### Aliases: Fhat > ### Keywords: spatial > > ### ** Examples > > data(uganda) > plot(seq(20, 500, 20), Fhat(as.points(uganda), + as.points(csr(uganda$poly, length(uganda$x))), seq(20, 500, 20)), + type="l", xlab="distance", ylab="Estimated F") > plot(Ghat(as.points(uganda), seq(20, 500, 20)), Fhat(as.points(uganda), + as.points(csr(uganda$poly, length(uganda$x))), seq(20, 500, 20)), + type="l", xlab="Estimated G", ylab="Estimated F") > lines(c(0,1),c(0,1),lty=2) > > > > cleanEx(); ..nameEx <- "Fzero" > > ### * Fzero > > flush(stderr()); flush(stdout()) > > ### Name: Fzero > ### Title: Theoretical nearest neighbour distribution function > ### Aliases: Fzero > ### Keywords: spatial > > ### ** Examples > > data(uganda) > plot(Ghat(as.points(uganda), seq(20, 500, 20)), Fzero(pdense(as.points(uganda), + uganda$poly), seq(20, 500, 20)), type="l", ylab="Theoretical G", + xlab="Estimated G") > lines(c(0,1),c(0,1),lty=2) > > > > cleanEx(); ..nameEx <- "Ghat" > > ### * Ghat > > flush(stderr()); flush(stdout()) > > ### Name: Ghat > ### Title: G nearest neighbour distribution function > ### Aliases: Ghat > ### Keywords: spatial > > ### ** Examples > > data(uganda) > plot(seq(20, 500, 20), Ghat(as.points(uganda), seq(20, 500, 20)), + type="l", xlab="distance", ylab="Estimated G") > > > > cleanEx(); ..nameEx <- "Kenv.csr" > > ### * Kenv.csr > > flush(stderr()); flush(stdout()) > > ### Name: Kenv.csr > ### Title: Envelope of Khat from simulations of complete spatial randomness > ### Aliases: Kenv.csr > ### Keywords: spatial > > ### ** Examples > > data(cardiff) > UL.khat <- Kenv.csr(length(cardiff$x), cardiff$poly, nsim=29, seq(2,30,2)) Doing simulation 1 Doing simulation 2 Doing simulation 3 Doing simulation 4 Doing simulation 5 Doing simulation 6 Doing simulation 7 Doing simulation 8 Doing simulation 9 Doing simulation 10 Doing simulation 11 Doing simulation 12 Doing simulation 13 Doing simulation 14 Doing simulation 15 Doing simulation 16 Doing simulation 17 Doing simulation 18 Doing simulation 19 Doing simulation 20 Doing simulation 21 Doing simulation 22 Doing simulation 23 Doing simulation 24 Doing simulation 25 Doing simulation 26 Doing simulation 27 Doing simulation 28 Doing simulation 29 > plot(seq(2,30,2), sqrt(khat(as.points(cardiff), cardiff$poly, + seq(2,30,2))/pi)-seq(2,30,2), type="l", xlab="Splancs - polygon boundary", + ylab="Estimated L", ylim=c(-1,1.5)) > lines(seq(2,30,2), sqrt(UL.khat$upper/pi)-seq(2,30,2), lty=2) > lines(seq(2,30,2), sqrt(UL.khat$lower/pi)-seq(2,30,2), lty=2) > > > > cleanEx(); ..nameEx <- "Kenv.label" > > ### * Kenv.label > > flush(stderr()); flush(stdout()) > > ### Name: Kenv.label > ### Title: Envelope of K1hat-K2hat from random labelling of two point > ### patterns > ### Aliases: Kenv.label > ### Keywords: spatial > > ### ** Examples > > data(okwhite) > data(okblack) > okpoly <- list(x=c(okwhite$x, okblack$x), y=c(okwhite$y, okblack$y)) > K1.hat <- khat(as.points(okwhite), bbox(as.points(okpoly)), seq(5,80,5)) > K2.hat <- khat(as.points(okblack), bbox(as.points(okpoly)), seq(5,80,5)) > K.diff <- K1.hat-K2.hat > plot(seq(5,80,5), K.diff, xlab="distance", ylab=expression(hat(K)[1]-hat(K)[2]), + ylim=c(-11000,7000), type="l", main="Simulation envelopes, random labelling") > env.lab <- Kenv.label(as.points(okwhite), as.points(okblack), + bbox(as.points(okpoly)), nsim=29, s=seq(5,80,5)) Doing labelling 1 / 29 Doing labelling 2 / 29 Doing labelling 3 / 29 Doing labelling 4 / 29 Doing labelling 5 / 29 Doing labelling 6 / 29 Doing labelling 7 / 29 Doing labelling 8 / 29 Doing labelling 9 / 29 Doing labelling 10 / 29 Doing labelling 11 / 29 Doing labelling 12 / 29 Doing labelling 13 / 29 Doing labelling 14 / 29 Doing labelling 15 / 29 Doing labelling 16 / 29 Doing labelling 17 / 29 Doing labelling 18 / 29 Doing labelling 19 / 29 Doing labelling 20 / 29 Doing labelling 21 / 29 Doing labelling 22 / 29 Doing labelling 23 / 29 Doing labelling 24 / 29 Doing labelling 25 / 29 Doing labelling 26 / 29 Doing labelling 27 / 29 Doing labelling 28 / 29 Doing labelling 29 / 29 > lines(seq(5,80,5), env.lab$upper, lty=2) > lines(seq(5,80,5), env.lab$lower, lty=2) > > > > cleanEx(); ..nameEx <- "Kenv.pcp" > > ### * Kenv.pcp > > flush(stderr()); flush(stdout()) > > ### Name: Kenv.pcp > ### Title: Calculate simulation envelope for a Poisson Cluster Process > ### Aliases: Kenv.pcp > ### Keywords: spatial > > ### ** Examples > > data(cardiff) > polymap(cardiff$poly) > pointmap(as.points(cardiff), add=TRUE) > title("Locations of homes of 168 juvenile offenders") > pcp.fit <- pcp(as.points(cardiff), cardiff$poly, h0=30, n.int=30) > pcp.fit $par s2 rho 6.16109743 0.01136752 $value [1] 0.02734823 $counts function gradient 77 NA $convergence [1] 0 $message NULL > m <- npts(as.points(cardiff))/(areapl(cardiff$poly)*pcp.fit$par[2]) > r <- seq(2,30,by=2) > K.env <- Kenv.pcp(pcp.fit$par[2], m, pcp.fit$par[1], cardiff$poly, + nsim=20, r=r) > L.env <- lapply(K.env, FUN=function(x) sqrt(x/pi)-r) > limits <- range(unlist(L.env)) > plot(r, sqrt(khat(as.points(cardiff),cardiff$poly,r)/pi)-r, ylim=limits, + main="L function with simulation envelopes and average", type="l", + xlab="distance", ylab="") > lines(r, L.env$lower, lty=5) > lines(r, L.env$upper, lty=5) > lines(r, L.env$ave, lty=6) > abline(h=0) > > > > cleanEx(); ..nameEx <- "Kenv.tor" > > ### * Kenv.tor > > flush(stderr()); flush(stdout()) > > ### Name: Kenv.tor > ### Title: Envelope of K12hat from random toroidal shifts of two point > ### patterns > ### Aliases: Kenv.tor > ### Keywords: spatial > > ### ** Examples > > data(okwhite) > data(okblack) > okpoly <- list(x=c(okwhite$x, okblack$x), y=c(okwhite$y, okblack$y)) > plot(seq(5,80,5), sqrt(k12hat(as.points(okwhite), as.points(okblack), + bbox(as.points(okpoly)), seq(5,80,5))/pi) - seq(5,80,5), xlab="distance", + ylab=expression(hat(L)[12]), ylim=c(-35,35), type="l", + main="Simulation envelopes, random toroidal shifts") > env.ok <- Kenv.tor(as.points(okwhite), as.points(okblack), + bbox(as.points(okpoly)), nsim=29, s=seq(5,80,5)) Doing shift 1 / 29 Doing shift 2 / 29 Doing shift 3 / 29 Doing shift 4 / 29 Doing shift 5 / 29 Doing shift 6 / 29 Doing shift 7 / 29 Doing shift 8 / 29 Doing shift 9 / 29 Doing shift 10 / 29 Doing shift 11 / 29 Doing shift 12 / 29 Doing shift 13 / 29 Doing shift 14 / 29 Doing shift 15 / 29 Doing shift 16 / 29 Doing shift 17 / 29 Doing shift 18 / 29 Doing shift 19 / 29 Doing shift 20 / 29 Doing shift 21 / 29 Doing shift 22 / 29 Doing shift 23 / 29 Doing shift 24 / 29 Doing shift 25 / 29 Doing shift 26 / 29 Doing shift 27 / 29 Doing shift 28 / 29 Doing shift 29 / 29 > lines(seq(5,80,5), sqrt(env.ok$upper/pi)-seq(5,80,5), lty=2) > lines(seq(5,80,5), sqrt(env.ok$lower/pi)-seq(5,80,5), lty=2) > > > > cleanEx(); ..nameEx <- "Kenv.tor1" > > ### * Kenv.tor1 > > flush(stderr()); flush(stdout()) > > ### Name: Kenv.tor1 > ### Title: Modified envelope of K12hat from random toroidal shifts of two > ### point patterns > ### Aliases: Kenv.tor1 > ### Keywords: spatial > > ### ** Examples > > data(amacrines) > ama.a <- rbind(amacrines.on, amacrines.off) > ama.bb <- bbox(as.points(ama.a)) > ama.t <- seq(from = 0.002, to=.250, by=0.002) > nsim=999 > plot(amacrines.on, asp=1, pch=19, + main="Data set, match figure 1.4 of Diggle(2002)?") > points(amacrines.off, pch=1) > # > k12 <- k12hat(amacrines.on, amacrines.off, ama.bb, ama.t) > # > k11 <- khat(amacrines.on, ama.bb, ama.t) > k22 <- khat(amacrines.off, ama.bb, ama.t) > k00 <- khat(ama.a, ama.bb, ama.t) > theor <- pi * (ama.t^2) > # > plot(ama.t, k12-theor, ylim=c(min( c(k12, k11, k22, k00) - theor), + max( c(k12, k11, k22, k00) - theor)), + main="2nd order properties, match figure 4.8 of Diggle (2002)", type="l") > lines(ama.t, -theor) > lines(ama.t, k11-theor, lty=2) > lines(ama.t, k22-theor, lty=3) > lines(ama.t, k00-theor, lty=5) > # > k12.tor <- Kenv.tor(amacrines.on, amacrines.off, ama.bb, + nsim, ama.t, quiet=TRUE) > plot(ama.t, k12-theor, type="l", main="Output from Kenv.tor") > lines(ama.t, k12.tor$upper-theor, type="l", col="red") > lines(ama.t, k12.tor$lower-theor, type="l", col="red") > # > k12.sims <- Kenv.tor1(amacrines.on, amacrines.off, ama.bb, + nsim, ama.t, quiet=TRUE) > plot(ama.t, sqrt(k12.sims$real/pi), type="l", asp=1, bty="n", + main=paste("K12 versus toroidal sims; rank ", k12.sims$rank, "of", + length(k12.sims$u))) > lines(ama.t, sqrt(k12.sims$upper/pi), col="red") > lines(ama.t, sqrt(k12.sims$lower/pi), col="red") > > > > cleanEx(); ..nameEx <- "burkitt" > > ### * burkitt > > flush(stderr()); flush(stdout()) > > ### Name: burkitt > ### Title: Burkitt's lymphoma in Uganda > ### Aliases: burkitt burbdy burpts > ### Keywords: datasets > > ### ** Examples > > data(burkitt) > burDates <- as.Date(as.character(burkitt$dates), "%y-%m-%d") > res <- aggregate(rep(1, length(burDates)), list(quarters(burDates), format(burDates, "%y")), sum) > plot(as.numeric(as.character(res$Group.2))+0.25*(as.numeric(substr(as.character(res$Group.1), 2, 2))-1), res$x, type="h", lwd=3, col=ifelse(as.character(res$Group.1)=="Q3","grey","red"), xlab="year", ylab="count", xaxt="n") > axis(1, at=seq(61,75,4), labels=format(seq.Date(as.Date("1961/1/1"), as.Date("1975/1/1"), "4 years"))) > title("Plot of Burkitt's lymphoma in West Nile district,\nQ3 grey shaded") > op <- par(mfrow=c(3,5)) > for (i in unique(format(burDates, "%y"))) { + polymap(burbdy) + pointmap(burpts[which(format(burDates, "%y") == i),], add=TRUE, pch=19) + title(main=paste("19", i, sep="")) + } > par(op) > op <- par(mfrow=c(2,2)) > for (i in c("Q1", "Q2", "Q3", "Q4")) { + polymap(burbdy) + pointmap(burpts[which(unclass(quarters(burDates)) == i),], add=TRUE, + pch=19) + title(main=i) + } > par(op) > op <- par(mfrow=c(3,4)) > for (i in months(seq(as.Date("70-01-01", "%y-%m-%d"), len=12, by="1 month"))) { + polymap(burbdy) + pointmap(burpts[which(unclass(months(burDates)) == i),], add=TRUE, pch=19) + title(main=i) + } > par(op) > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > cleanEx(); ..nameEx <- "csr" > > ### * csr > > flush(stderr()); flush(stdout()) > > ### Name: csr > ### Title: Generate completely spatially random points on a polygon > ### Aliases: csr > ### Keywords: spatial > > ### ** Examples > > data(cardiff) > nsim <- 29 > emp.Ghat <- Ghat(as.points(cardiff), seq(0,30,1)) > av.Ghat <- numeric(length(emp.Ghat)) > U.Ghat <- numeric(length(emp.Ghat)) > L.Ghat <- numeric(length(emp.Ghat)) > U.Ghat <- -99999 > L.Ghat <- 99999 > for(i in 1:nsim) { + S.Ghat <- Ghat(csr(cardiff$poly, length(cardiff$x)), seq(0,30,1)) + av.Ghat <- av.Ghat + S.Ghat + L.Ghat <- pmin(S.Ghat, L.Ghat) + U.Ghat <- pmax(S.Ghat, U.Ghat) + } > av.Ghat <- av.Ghat/nsim > plot(av.Ghat, emp.Ghat, type="l", xlim=c(0,1), ylim=c(0,1), + xlab="Simulated average G", ylab="Empirical G") > lines(c(0,1),c(0,1),lty=2) > lines(U.Ghat,emp.Ghat,lty=3) > lines(L.Ghat,emp.Ghat,lty=3) > > > > cleanEx(); ..nameEx <- "inout" > > ### * inout > > flush(stderr()); flush(stdout()) > > ### Name: inout > ### Title: Test points for inclusion in a polygon > ### Aliases: inout > ### Keywords: spatial > > ### ** Examples > > data(uganda) > suganda <- sbox(uganda$poly) > ruganda <- csr(suganda, 1000) > polymap(suganda) > polymap(uganda$poly, add=TRUE) > def <- inout(ruganda, uganda$poly, bound=NULL) > pointmap(as.points(ruganda[def,1], ruganda[def,2]), add=TRUE, col="black") > pointmap(as.points(ruganda[!def,1], ruganda[!def,2]), add=TRUE, col="red") > tru <- inout(ruganda, uganda$poly, bound=TRUE, quiet=FALSE) No points on boundary > which(tru & !def) numeric(0) > ds1 <- as.points(expand.grid(x=seq(-1.5,1.5,0.5), y=seq(-1.5,1.5,0.5))) > ds1.poly <- ds1[chull(ds1),] > ds2 <- as.points(rnorm(300),rnorm(300)) > plot(ds2, type="n", asp=1) > polymap(ds1.poly, add=TRUE, border="lightblue", col="lightblue", lwd=1) > points(ds2[inout(ds2,ds1.poly),], col="green", pch=20) > points(ds2[!inout(ds2,ds1.poly),], col="orange", pch=20) > points(ds1[inout(ds1,ds1.poly),], col="black", pch=20) > points(ds1[!inout(ds1,ds1.poly),], col="red", pch=20) > plot(ds2, type="n", asp=1) > polymap(ds1.poly, add=TRUE, border="lightblue", col="lightblue", lwd=1) > points(ds2[inout(ds2,ds1.poly,bound=TRUE),], col="green", pch=20) > points(ds2[!inout(ds2,ds1.poly,bound=TRUE),], col="orange", pch=20) > points(ds1[inout(ds1,ds1.poly,bound=TRUE),], col="black", pch=20) > points(ds1[!inout(ds1,ds1.poly,bound=TRUE),], col="red", pch=20) > plot(ds2, type="n", asp=1) > polymap(ds1.poly, add=TRUE, border="lightblue", col="lightblue", lwd=1) > points(ds2[inout(ds2,ds1.poly,bound=FALSE),], col="green", pch=20) > points(ds2[!inout(ds2,ds1.poly,bound=FALSE),], col="orange", pch=20) > points(ds1[inout(ds1,ds1.poly,bound=FALSE),], col="black", pch=20) > points(ds1[!inout(ds1,ds1.poly,bound=FALSE),], col="red", pch=20) > > > > cleanEx(); ..nameEx <- "k12hat" > > ### * k12hat > > flush(stderr()); flush(stdout()) > > ### Name: k12hat > ### Title: Bivariate K-function > ### Aliases: k12hat > ### Keywords: spatial > > ### ** Examples > > data(okwhite) > data(okblack) > okpoly <- list(x=c(okwhite$x, okblack$x), y=c(okwhite$y, okblack$y)) > plot(seq(5,80,5), sqrt(k12hat(as.points(okwhite), as.points(okblack), + bbox(as.points(okpoly)), seq(5,80,5))/pi) - seq(5,80,5), xlab="distance", + ylab=expression(hat(L)[12]), ylim=c(-20,20), type="l") > > > > cleanEx(); ..nameEx <- "kernel2d" > > ### * kernel2d > > flush(stderr()); flush(stdout()) > > ### Name: kernel2d > ### Title: Kernel smoothing of a point pattern > ### Aliases: kernel2d > ### Keywords: spatial > > ### ** Examples > > data(bodmin) > plot(bodmin$poly, asp=1, type="n") > image(kernel2d(as.points(bodmin), bodmin$poly, h0=2, nx=100, ny=100), + add=TRUE, col=terrain.colors(20)) Xrange is -5.2 9.5 Yrange is -11.5 8.3 Doing quartic kernel > pointmap(as.points(bodmin), add=TRUE) > polymap(bodmin$poly, add=TRUE) > > > > cleanEx(); ..nameEx <- "kernel3d" > > ### * kernel3d > > flush(stderr()); flush(stdout()) > > ### Name: kernel3d > ### Title: Space-time kernel > ### Aliases: kernel3d > ### Keywords: spatial > > ### ** Examples > > data(burkitt) > b3d <- kernel3d(burpts, burkitt$t, seq(250,350,10), seq(250, 400, 10), + seq(365,5800,365), 30, 200) > brks <- quantile(b3d$v, seq(0,1,0.05)) > cols <- heat.colors(length(brks)-1) > oldpar <- par(mfrow=c(3,5)) > for (i in 1:15) image(seq(250,350,10), seq(250, 400, 10), b3d$v[,,i], + asp=1, xlab="", ylab="", main=1960+i, breaks=brks, col=cols) > par(oldpar) > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > cleanEx(); ..nameEx <- "khat" > > ### * khat > > flush(stderr()); flush(stdout()) > > ### Name: khat > ### Title: K-function > ### Aliases: khat print.khat plot.khat > ### Keywords: spatial > > ### ** Examples > > data(cardiff) > s <- seq(2,30,2) > plot(s, sqrt(khat(as.points(cardiff), cardiff$poly, s)/pi) - s, + type="l", xlab="Splancs - polygon boundary", ylab="Estimated L", + ylim=c(-1,1.5)) > newstyle <- khat(as.points(cardiff), cardiff$poly, s, newstyle=TRUE) > str(newstyle) List of 4 $ khat : num [1:15] 30.3 88.6 168.0 274.4 401.5 ... $ counts: int [1:168, 1:15] 0 0 1 2 1 0 0 1 2 0 ... $ khats : num [1:168, 1:15] 0.000 0.000 0.220 0.441 0.220 ... $ s : num [1:15] 2 4 6 8 10 12 14 16 18 20 ... - attr(*, "class")= chr "khat" > newstyle [1] 30.31848 88.62523 167.95850 274.37766 401.46106 543.63622 [7] 715.22877 909.69473 1123.65207 1375.54225 1661.75200 1929.58087 [13] 2250.68876 2565.17067 2871.96159 > apply(newstyle$khats, 2, sum) [1] 30.31848 88.62523 167.95850 274.37766 401.46106 543.63622 [7] 715.22877 909.69473 1123.65207 1375.54225 1661.75200 1929.58087 [13] 2250.68876 2565.17067 2871.96159 > plot(newstyle) > > > > cleanEx(); ..nameEx <- "mse2d" > > ### * mse2d > > flush(stderr()); flush(stdout()) > > ### Name: mse2d > ### Title: Mean Square Error for a Kernel Smoothing > ### Aliases: mse2d > ### Keywords: spatial > > ### ** Examples > > data(bodmin) > Mse2d <- mse2d(as.points(bodmin), bodmin$poly, nsmse=50, range=8) > plot(Mse2d$h[5:50],Mse2d$mse[5:50], type="l") > > > > cleanEx(); ..nameEx <- "nndistF" > > ### * nndistF > > flush(stderr()); flush(stdout()) > > ### Name: nndistF > ### Title: Nearest neighbour distances as used by Fhat() > ### Aliases: nndistF > ### Keywords: spatial > > ### ** Examples > > data(uganda) > boxplot(nndistF(as.points(uganda), as.points(csr(uganda$poly, length(uganda$x))))) > plot(ecdf(nndistF(as.points(uganda), + as.points(csr(uganda$poly, length(uganda$x))))), + main="Fhat ecdf Uganda volcano data") > > > > cleanEx(); ..nameEx <- "nndistG" > > ### * nndistG > > flush(stderr()); flush(stdout()) > > ### Name: nndistG > ### Title: Nearest neighbour distances as used by Ghat() > ### Aliases: nndistG > ### Keywords: spatial > > ### ** Examples > > data(uganda) > boxplot(nndistG(as.points(uganda))$dists) > plot(ecdf(nndistG(as.points(uganda))$dists)) > > > > cleanEx(); ..nameEx <- "pcp" > > ### * pcp > > flush(stderr()); flush(stdout()) > > ### Name: pcp > ### Title: Fit a Poisson cluster process > ### Aliases: pcp > ### Keywords: spatial > > ### ** Examples > > data(cardiff) > polymap(cardiff$poly) > pointmap(as.points(cardiff), add=TRUE) > title("Locations of homes of 168 juvenile offenders") > pcp.fit <- pcp(as.points(cardiff), cardiff$poly, h0=30, n.int=30) > pcp.fit $par s2 rho 6.16109743 0.01136752 $value [1] 0.02734823 $counts function gradient 77 NA $convergence [1] 0 $message NULL > > > > cleanEx(); ..nameEx <- "pcp.sim" > > ### * pcp.sim > > flush(stderr()); flush(stdout()) > > ### Name: pcp.sim > ### Title: Generate a Poisson Cluster Process > ### Aliases: pcp.sim > ### Keywords: spatial > > ### ** Examples > > data(cardiff) > polymap(cardiff$poly) > pointmap(as.points(cardiff), add=TRUE) > title("Locations of homes of 168 juvenile offenders") > pcp.fit <- pcp(as.points(cardiff), cardiff$poly, h0=30, n.int=30) > pcp.fit $par s2 rho 6.16109743 0.01136752 $value [1] 0.02734823 $counts function gradient 77 NA $convergence [1] 0 $message NULL > m <- npts(as.points(cardiff))/(areapl(cardiff$poly)*pcp.fit$par[2]) > sims <- pcp.sim(pcp.fit$par[2], m, pcp.fit$par[1], cardiff$poly) > pointmap(as.points(sims), add=TRUE, col="red") > > > > cleanEx(); ..nameEx <- "pointmap" > > ### * pointmap > > flush(stderr()); flush(stdout()) > > ### Name: pointmap > ### Title: Graphics > ### Aliases: pointmap > ### Keywords: spatial > > ### ** Examples > > data(bodmin) > plot(bodmin$poly, asp=1, type="n") > pointmap(as.points(bodmin), add=TRUE) > polymap(bodmin$poly, add=TRUE) > > > > cleanEx(); ..nameEx <- "polymap" > > ### * polymap > > flush(stderr()); flush(stdout()) > > ### Name: polymap > ### Title: Graphics > ### Aliases: polymap > ### Keywords: spatial > > ### ** Examples > > data(bodmin) > plot(bodmin$poly, asp=1, type="n") > pointmap(as.points(bodmin), add=TRUE) > polymap(bodmin$poly, add=TRUE) > > > > cleanEx(); ..nameEx <- "southlancs" > > ### * southlancs > > flush(stderr()); flush(stdout()) > > ### Name: southlancs > ### Title: Cancer cases in Chorley-Ribble > ### Aliases: southlancs southlancs.pts southlancs.cc old.incinerator > ### southlancs.bdy > ### Keywords: datasets > > ### ** Examples > > data(southlancs) > op <- par(mfrow=c(2,1)) > pointmap(southlancs.pts[southlancs.cc == 0,]) > pointmap(old.incinerator, add=TRUE, col="red", pch=19) > title("Lung cancer controls") > pointmap(southlancs.pts[southlancs.cc == 1,]) > pointmap(old.incinerator, add=TRUE, col="red", pch=19) > title("Larynx cancer cases") > par(op) > polymap(southlancs.bdy,border="grey") > contour(kernel2d(southlancs.pts[southlancs.cc == 0,], + southlancs.bdy, h=500, nx=100, ny=100), nlevels=20, + add=TRUE,drawlabels=FALSE) Xrange is 343709.1 366255.6 Yrange is 410927.2 429344.1 Doing quartic kernel > pointmap(southlancs.pts[southlancs.cc == 1,], add=TRUE, pch=19, + col="green") > pointmap(old.incinerator, add=TRUE, pch=19, col="red") > title(xlab="h=500, quartic kernel") > title("Density map of control, green case points, red old incinerator") > > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > cleanEx(); ..nameEx <- "stdiagn" > > ### * stdiagn > > flush(stderr()); flush(stdout()) > > ### Name: stdiagn > ### Title: Summary plots for clustering analysis > ### Aliases: stdiagn > ### Keywords: spatial > > ### ** Examples > > example(stkhat) stkhat> data(burkitt) stkhat> bur1 <- stkhat(burpts, burkitt$t, burbdy, c(400, 5800), seq(1, 40, 2), seq(100, 1500, 100)) stkhat> oldpar <- par(mfrow = c(2, 1)) stkhat> plot(bur1$s, bur1$ks, type = "l", xlab = "distance", ylab = "Estimated K", main = "spatial K function") stkhat> plot(bur1$t, bur1$kt, type = "l", xlab = "time", ylab = "Estimated K", main = "temporal K function") stkhat> par(oldpar) > example(stsecal) stsecl> example(stkhat) stkhat> data(burkitt) stkhat> bur1 <- stkhat(burpts, burkitt$t, burbdy, c(400, 5800), seq(1, 40, 2), seq(100, 1500, 100)) stkhat> oldpar <- par(mfrow = c(2, 1)) stkhat> plot(bur1$s, bur1$ks, type = "l", xlab = "distance", ylab = "Estimated K", main = "spatial K function") stkhat> plot(bur1$t, bur1$kt, type = "l", xlab = "time", ylab = "Estimated K", main = "temporal K function") stkhat> par(oldpar) stsecl> bur1se <- stsecal(burpts, burkitt$t, burbdy, c(400, 5800), seq(1, 40, 2), seq(100, 1500, 100)) > example(stmctest) stmcts> example(stkhat) stkhat> data(burkitt) stkhat> bur1 <- stkhat(burpts, burkitt$t, burbdy, c(400, 5800), seq(1, 40, 2), seq(100, 1500, 100)) stkhat> oldpar <- par(mfrow = c(2, 1)) stkhat> plot(bur1$s, bur1$ks, type = "l", xlab = "distance", ylab = "Estimated K", main = "spatial K function") stkhat> plot(bur1$t, bur1$kt, type = "l", xlab = "time", ylab = "Estimated K", main = "temporal K function") stkhat> par(oldpar) stmcts> bur1mc <- stmctest(burpts, burkitt$t, burbdy, c(400, 5800), seq(1, 40, 2), seq(100, 1500, 100), nsim = 49, quiet = TRUE) > stdiagn(burpts, bur1, bur1se, bur1mc) > > > > cleanEx(); ..nameEx <- "stkhat" > > ### * stkhat > > flush(stderr()); flush(stdout()) > > ### Name: stkhat > ### Title: Space-time K-functions > ### Aliases: stkhat > ### Keywords: spatial > > ### ** Examples > > data(burkitt) > bur1 <- stkhat(burpts, burkitt$t, burbdy, c(400, 5800), + seq(1,40,2), seq(100, 1500, 100)) > oldpar <- par(mfrow=c(2,1)) > plot(bur1$s, bur1$ks, type="l", xlab="distance", ylab="Estimated K", + main="spatial K function") > plot(bur1$t, bur1$kt, type="l", xlab="time", ylab="Estimated K", + main="temporal K function") > par(oldpar) > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > cleanEx(); ..nameEx <- "stmctest" > > ### * stmctest > > flush(stderr()); flush(stdout()) > > ### Name: stmctest > ### Title: Monte-Carlo test of space-time clustering > ### Aliases: stmctest > ### Keywords: spatial > > ### ** Examples > > example(stkhat) stkhat> data(burkitt) stkhat> bur1 <- stkhat(burpts, burkitt$t, burbdy, c(400, 5800), seq(1, 40, 2), seq(100, 1500, 100)) stkhat> oldpar <- par(mfrow = c(2, 1)) stkhat> plot(bur1$s, bur1$ks, type = "l", xlab = "distance", ylab = "Estimated K", main = "spatial K function") stkhat> plot(bur1$t, bur1$kt, type = "l", xlab = "time", ylab = "Estimated K", main = "temporal K function") stkhat> par(oldpar) > bur1mc <- stmctest(burpts, burkitt$t, burbdy, c(400, 5800), + seq(1,40,2), seq(100, 1500, 100), nsim=49, quiet=TRUE) > > > > cleanEx(); ..nameEx <- "stsecal" > > ### * stsecal > > flush(stderr()); flush(stdout()) > > ### Name: stsecal > ### Title: Standard error for space-time clustering > ### Aliases: stsecal > ### Keywords: spatial > > ### ** Examples > > example(stkhat) stkhat> data(burkitt) stkhat> bur1 <- stkhat(burpts, burkitt$t, burbdy, c(400, 5800), seq(1, 40, 2), seq(100, 1500, 100)) stkhat> oldpar <- par(mfrow = c(2, 1)) stkhat> plot(bur1$s, bur1$ks, type = "l", xlab = "distance", ylab = "Estimated K", main = "spatial K function") stkhat> plot(bur1$t, bur1$kt, type = "l", xlab = "time", ylab = "Estimated K", main = "temporal K function") stkhat> par(oldpar) > bur1se <- stsecal(burpts, burkitt$t, burbdy, c(400, 5800), + seq(1,40,2), seq(100, 1500, 100)) > > > > ### *