├── CHANGES ├── DESCRIPTION ├── NAMESPACE ├── R ├── ASTIKhat.R ├── KLISTAhat.R ├── LISTAhat.R ├── PCFhat.R ├── STIKhat.R ├── animation.R ├── as.3dpoints.R ├── gsp.R ├── gte.R ├── is.3dpoints.R ├── kmmr.R ├── kmmt.R ├── kmr.R ├── kmt.R ├── plot.stpp.R ├── plotK.R ├── plotPCF.R ├── rinfec.R ├── rinter.R ├── rlgcp.R ├── rpcp.R ├── rpp.R ├── sim.stpp.R ├── stan.R ├── stdcpp.R └── sthpcpp.R ├── README.md ├── data ├── fmd.R └── northcumbria.R ├── man ├── ASTIKhat.Rd ├── KLISTAhat.Rd ├── LISTAhat.Rd ├── PCFhat.Rd ├── STIKhat.Rd ├── animation.Rd ├── as.3dpoint.Rd ├── fmd.Rd ├── gsp.Rd ├── gte.Rd ├── is.3dpoints.Rd ├── kmmr.Rd ├── kmmt.Rd ├── kmr.Rd ├── kmt.Rd ├── northcumbria.Rd ├── plot.stpp.Rd ├── plotK.Rd ├── plotPCF.Rd ├── rinfec.Rd ├── rinter.Rd ├── rlgcp.Rd ├── rpcp.Rd ├── rpp.Rd ├── sim.stpp.Rd ├── stan.Rd ├── stdcpp.Rd ├── sthpcpp.Rd └── stpp-package.Rd ├── src ├── astk.f ├── circ.f ├── covst.f ├── gspcore.f ├── gspcoreinh.f ├── gtecore.f ├── gtecoreinh.f ├── init.c ├── klistafunction.f ├── kmmrcore.f ├── kmmrcoreinh.f ├── kmmtcore.f ├── kmmtcoreinh.f ├── kmrcore.f ├── kmrcoreinh.f ├── kmtcore.f ├── kmtcoreinh.f ├── listafunction.f ├── pcffunction.f └── stikfunction.f └── vignettes └── docs.Rmd /CHANGES: -------------------------------------------------------------------------------- 1 | CHANGES IN stpp VERSION 2.0.8 2 | 3 | * Updated dependency on spatstat 4 | 5 | -------------------------------------------------------------------------------- 6 | 7 | CHANGES IN stpp VERSION 2.0.7 8 | 9 | * Updated dependency on spatstat.explore 10 | 11 | -------------------------------------------------------------------------------- 12 | 13 | CHANGES IN stpp VERSION 2.0.6 14 | 15 | Some compatibility issues with the package spatstat have been fixed 16 | 17 | -------------------------------------------------------------------------------- 18 | 19 | CHANGES IN stpp VERSION 2.0.5 20 | 21 | * The function 'kmmr' have been included 22 | * The function 'kmmt' have been included 23 | * The function 'kmr' have been included 24 | * The function 'kmt' have been included 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: stpp 2 | Version: 2.0-8 3 | Date: 2024-06-27 4 | Title: Space-Time Point Pattern Simulation, Visualisation and Analysis 5 | Authors@R: c(person("Edith", "Gabriel", role=c("aut","cre"), email="edith.gabriel@inrae.fr"), 6 | person("Peter J", "Diggle", role="aut", email="p.diggle@lancaster.ac.uk"), 7 | person("Barry", "Rowlingson",role="aut", email="b.rowlingson@lancaster.ac.uk"), 8 | person("Francisco J", "Rodriguez-Cortes", role="aut", email="frrodriguezc@unal.edu.co")) 9 | Maintainer: Edith Gabriel 10 | Depends: R (>= 3.3.0), grDevices, graphics, rpanel, splancs 11 | Imports: KernSmooth, ggplot2, gridExtra, plot3D, rgl, spatstat.univar, spatstat.explore, spatstat.geom, spatstat.random, stats 12 | Suggests: knitr(>= 1.11), rmarkdown(>= 0.8.1) 13 | Description: Many of the models encountered in applications of point process methods to the study of spatio-temporal phenomena are covered in 'stpp'. This package provides statistical tools for analyzing the global and local second-order properties of spatio-temporal point processes, including estimators of the space-time inhomogeneous K-function and pair correlation function. It also includes tools to get static and dynamic display of spatio-temporal point patterns. See Gabriel et al (2013) . 14 | License: GPL-3 15 | LazyLoad: yes 16 | NeedsCompilation: yes 17 | RoxygenNote: 6.0.1 18 | BuildVignettes: True 19 | VignetteBuilder: knitr 20 | BugReports: https://github.com/stpp-GitHub-community 21 | Author: Edith Gabriel [aut, cre], 22 | Peter J Diggle [aut], 23 | Barry Rowlingson [aut], 24 | Francisco J Rodriguez-Cortes [aut] 25 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | useDynLib(stpp,.registration=TRUE) 2 | 3 | export("animation") 4 | export("as.3dpoints") 5 | export("ASTIKhat") 6 | export("is.3dpoints") 7 | export("LISTAhat") 8 | export("KLISTAhat") 9 | export("PCFhat") 10 | export("plotK") 11 | export("plotPCF") 12 | export("rinfec") 13 | export("rinter") 14 | export("rlgcp") 15 | export("rpcp") 16 | export("rpp") 17 | export("sim.stpp") 18 | export("stan") 19 | export("stdcpp") 20 | export("sthpcpp") 21 | export("STIKhat") 22 | export("gsp") 23 | export("gte") 24 | export("kmr") 25 | export("kmt") 26 | export("kmmr") 27 | export("kmmt") 28 | 29 | import(rpanel) 30 | import(splancs) 31 | 32 | importFrom("grDevices","chull","colorRampPalette","dev.list","dev.new","dev.off","gray","grey","heat.colors","rgb") 33 | importFrom("graphics","axTicks","axis","box","contour","image","par","persp","plot","points","title") 34 | importFrom("stats","dnorm","fft","median","rexp","rnorm","rpois","runif","time","dist") 35 | importFrom("rgl","par3d","rotationMatrix","surface3d","plot3d","axis3d","aspect3d","rgl.pop","lines3d","segments3d","points3d","spheres3d") 36 | importFrom("spatstat.explore","edge.Trans","bw.stoyan","edge.Ripley") 37 | importFrom("spatstat.geom","as.im","verifyclass","owin","as.rectangle","inside.owin","ppp","bdist.points","eroded.areas","area","pairdist","perimeter") 38 | importFrom("spatstat.univar","make.even.breaks") 39 | importFrom("spatstat.random","rMatClust") 40 | importFrom("KernSmooth","dpik") 41 | importFrom("plot3D","scatter3D") 42 | importFrom("ggplot2","ggplot","aes_string","geom_point","ggtitle","geom_path","geom_line","labs","aes","scale_shape","geom_bar","theme","element_text") 43 | importFrom("gridExtra","grid.arrange") 44 | 45 | S3method(plot,stpp) 46 | -------------------------------------------------------------------------------- /R/ASTIKhat.R: -------------------------------------------------------------------------------- 1 | ASTIKhat <- function(xyt,s.region,t.region,lambda,dist,times,ang=2*pi,correction="border"){ 2 | 3 | verifyclass(xyt,"stpp") 4 | 5 | correc=c("none","border","modified.border","translate") 6 | id <- match(correction, correc, nomatch = NA) 7 | if (any(nbg <- is.na(id))) { 8 | mess <- paste("unrecognised correction method:", paste(dQuote(correction[nbg]), collapse = ",")) 9 | stop(mess, call. = FALSE) 10 | } 11 | id = unique(id) 12 | correc2 = rep(0,4) 13 | correc2[id] = 1 14 | 15 | dup <- any(duplicated(data.frame(xyt[,1], xyt[,2], xyt[,3]))) 16 | if (dup == TRUE){ 17 | messnbd <- paste("Space-time data contains duplicated points") 18 | warning(messnbd,call. = FALSE) 19 | } 20 | 21 | if (missing(s.region)) s.region <- sbox(xyt[,1:2], xfrac=0.01, yfrac=0.01) 22 | if (missing(t.region)){ 23 | xr = range(xyt[,3], na.rm = TRUE) 24 | xw = diff(xr) 25 | t.region <- c(xr[1]- 0.01 * xw, xr[2] + 0.01 * xw) 26 | } 27 | bsupt <- max(t.region) 28 | binft <- min(t.region) 29 | 30 | xp <- s.region[,1] 31 | yp <- s.region[,2] 32 | nedges <- length(xp) 33 | yp <- yp - min(yp) 34 | nxt <- c(2:nedges, 1) 35 | dx <- xp[nxt] - xp 36 | ym <- (yp + yp[nxt])/2 37 | Areaxy <- -sum(dx * ym) 38 | 39 | if (Areaxy > 0){ 40 | bdry <- owin(poly = list(x = s.region[,1], y = s.region[,2])) 41 | }else{ 42 | bdry <- owin(poly = list(x = s.region[,1][length(s.region[,1]):1], y = s.region[,2][length(s.region[,1]):1])) 43 | } 44 | 45 | if (missing(dist)){ 46 | rect = as.rectangle(bdry) 47 | maxd = min(diff(rect$xrange), diff(rect$yrange))/4 48 | dist = make.even.breaks(maxd, npos=15)$r 49 | } 50 | 51 | if (missing(times)) { 52 | maxt = (bsupt-binft)/4 53 | times = make.even.breaks(maxt, npos=15)$r 54 | } 55 | 56 | dist <- sort(dist) 57 | if(dist[1] == 0) dist = dist[-1] 58 | times <- sort(times) 59 | if(times[1] == 0) times = times[-1] 60 | 61 | ok <- inside.owin(xyt[,1],xyt[,2],w=bdry) 62 | xyt.ins <- data.frame(x=xyt[,1][ok],y=xyt[,2][ok],t=xyt[,3][ok]) 63 | xyt.in <- .intim(xyt.ins,t.region) 64 | 65 | pts <- xyt.in[,1:2] 66 | xytimes <- xyt.in[,3] 67 | ptsx <- pts[, 1] 68 | ptsy <- pts[, 2] 69 | ptst <- xytimes 70 | npt <- length(ptsx) 71 | ndist <- length(dist) 72 | ntimes <- length(times) 73 | area <- area(bdry) * (bsupt - binft) 74 | astkf <- array(0,dim=c(ndist, ntimes, 4)) 75 | 76 | if(missing(lambda)){ 77 | misl <- 1 78 | lambda <- rep(npt/area, npt) 79 | } 80 | else misl <- 0 81 | if (length(lambda) == 1) lambda <- rep(lambda, npt) 82 | 83 | storage.mode(astkf) <- "double" 84 | 85 | wbi = array(0, dim = c(npt, ndist, ntimes)) 86 | wbimod = array(0, dim = c(npt, ndist, ntimes)) 87 | wt = array(0, dim = c(npt, npt)) 88 | 89 | options(warn = -1) 90 | 91 | pppxy = ppp(x = ptsx, y = ptsy, window = bdry) 92 | 93 | # correction=="border" and "modified border" 94 | if(any(correction=="border")|any(correction=="modified.border")){ 95 | 96 | bi=bdist.points(pppxy) 97 | bj=.bdist.times(xytimes,t.region) 98 | 99 | for(i in 1:ndist){ 100 | for(j in 1:ntimes){ 101 | wbi[,i,j] = (bi>dist[i])*(bj>times[j])/sum((bi>dist[i])*(bj>times[j])/lambda) 102 | wbimod[,i,j] = (bi>dist[i])*(bj>times[j])/(eroded.areas(bdry,dist[i])*.eroded.areat(t.region,times[j])) 103 | } } 104 | wbi[is.na(wbi)] <- 0 105 | wbimod[is.na(wbimod)] <- 0 106 | } 107 | 108 | # correction=="translate" 109 | if(any(correction=="translate")) 110 | { 111 | wtt = .overlap.tint(xytimes,t.region) 112 | wts = edge.Trans(pppxy) 113 | wt = wtt*wts 114 | wt=1/wt 115 | } 116 | 117 | options(warn = 0) 118 | 119 | astk <- .Fortran("astk", as.double(ptsx), 120 | as.double(ptsy), as.double(ptst), 121 | as.integer(npt), as.double(lambda), 122 | as.double(ang), as.double(dist), 123 | as.integer(ndist), as.double(times), 124 | as.integer(ntimes), as.double(wbi), 125 | as.double(wbimod), as.double(wt), 126 | as.integer(correc2), (astkf)) 127 | 128 | astkf <- astk[[15]] 129 | 130 | astkf[,,c(1,2,4)]=astkf[,,c(1,2,4)]/area 131 | 132 | if(length(id)==1) AKhat=as.array(astkf[,,id]) 133 | else{ 134 | AKhat=list() 135 | for(i in 1:length(id)) AKhat[[i]]=astkf[,,id[i]] 136 | names(AKhat)=correc[id] 137 | } 138 | correction=correc[id] 139 | 140 | 141 | invisible(return(list(AKhat=AKhat,dist=dist,times=times,correction=correction))) 142 | } -------------------------------------------------------------------------------- /R/KLISTAhat.R: -------------------------------------------------------------------------------- 1 | KLISTAhat <-function(xyt, s.region, t.region, dist, times, lambda, correction = "isotropic"){ 2 | 3 | verifyclass(xyt,"stpp") 4 | 5 | correc = c("none", "isotropic", "border", "modified.border", "translate") 6 | id <- match(correction, correc, nomatch = NA) 7 | if (any(nbg <- is.na(id))){ 8 | mess <- paste("unrecognised correction method:", paste(dQuote(correction[nbg]), collapse = ",")) 9 | stop(mess, call. = FALSE) 10 | } 11 | 12 | id = unique(id) 13 | correc2 = rep(0, 5) 14 | correc2[id] = 1 15 | 16 | dup <- any(duplicated(data.frame(xyt[,1], xyt[,2], xyt[,3]))) 17 | if (dup == TRUE){ 18 | messnbd <- paste("Space-time data contains duplicated points") 19 | warning(messnbd,call. = FALSE) 20 | } 21 | 22 | if (missing(s.region)) 23 | s.region <- sbox(xyt[, 1:2], xfrac = 0.01, yfrac = 0.01) 24 | if (missing(t.region)){ 25 | xr = range(xyt[, 3], na.rm = TRUE) 26 | xw = diff(xr) 27 | t.region <- c(xr[1] - 0.01 * xw, xr[2] + 0.01 * xw) 28 | } 29 | bsupt <- max(t.region) 30 | binft <- min(t.region) 31 | 32 | xp <- s.region[,1] 33 | yp <- s.region[,2] 34 | nedges <- length(xp) 35 | yp <- yp - min(yp) 36 | nxt <- c(2:nedges, 1) 37 | dx <- xp[nxt] - xp 38 | ym <- (yp + yp[nxt])/2 39 | Areaxy <- -sum(dx * ym) 40 | 41 | if (Areaxy > 0){ 42 | bdry <- owin(poly = list(x = s.region[,1], y = s.region[,2])) 43 | }else{ 44 | bdry <- owin(poly = list(x = s.region[,1][length(s.region[,1]):1], y = s.region[,2][length(s.region[,1]):1])) 45 | } 46 | 47 | if (missing(dist)){ 48 | rect = as.rectangle(bdry) 49 | maxd = min(diff(rect$xrange), diff(rect$yrange))/4 50 | dist = make.even.breaks(maxd, bstep = maxd/512)$r 51 | } 52 | if (missing(times)) { 53 | maxt = (bsupt - binft)/4 54 | times = make.even.breaks(maxt, npos = 15)$r 55 | } 56 | dist <- sort(dist) 57 | if (dist[1] == 0) 58 | dist = dist[-1] 59 | times <- sort(times) 60 | if (times[1] == 0) 61 | times = times[-1] 62 | 63 | ok <- inside.owin(xyt[,1],xyt[,2],w=bdry) 64 | xyt.ins <- data.frame(x=xyt[,1][ok],y=xyt[,2][ok],t=xyt[,3][ok]) 65 | xyt.in <- .intim(xyt.ins,t.region) 66 | 67 | pts <- xyt.in[,1:2] 68 | xytimes <- xyt.in[,3] 69 | ptsx <- pts[, 1] 70 | ptsy <- pts[, 2] 71 | ptst <- xytimes 72 | npt <- length(ptsx) 73 | ndist <- length(dist) 74 | ntimes <- length(times) 75 | area <- area(bdry) * (bsupt - binft) 76 | np <- length(s.region[, 1]) 77 | polyx <- c(s.region[, 1], s.region[1, 1]) 78 | polyy <- c(s.region[, 2], s.region[1, 2]) 79 | 80 | if (missing(lambda)){ 81 | misl <- 1 82 | lambda <- rep(npt/area, npt) 83 | } 84 | else misl <- 0 85 | if (length(lambda) == 1) 86 | lambda <- rep(lambda, npt) 87 | 88 | wbi = array(0, dim = c(npt, ndist, ntimes)) 89 | wbimod = array(0, dim = c(npt, ndist, ntimes)) 90 | wt = array(0, dim = c(npt, npt)) 91 | 92 | options(warn = -1) 93 | 94 | pppxy = ppp(x = ptsx, y = ptsy, window = bdry) 95 | 96 | # correction=="border" and "modified border" 97 | if (any(correction == "border") | any(correction == "modified.border")) { 98 | 99 | bi = bdist.points(pppxy) 100 | bj = .bdist.times(xytimes, t.region) 101 | 102 | for (i in 1 : ndist) { 103 | for (j in 1 : ntimes) { 104 | wbi[, i, j] = (bi > dist[i]) * (bj > times[j])/sum((bi > dist[i]) * (bj > times[j])/lambda) 105 | wbimod[, i, j] = (bi > dist[i]) * (bj > times[j])/(eroded.areas(bdry, dist[i]) * .eroded.areat(t.region, times[j])) 106 | } 107 | } 108 | wbi[is.na(wbi)] <- 0 109 | wbimod[is.na(wbimod)] <- 0 110 | } 111 | 112 | # correction=="translate" 113 | if (any(correction == "translate")) { 114 | wtt = .overlap.tint(xytimes, t.region) 115 | wts = edge.Trans(pppxy) 116 | wt = wtt * wts 117 | wt = 1/wt 118 | } 119 | 120 | options(warn = 0) 121 | 122 | all.klista <- sapply(seq(1,npt), function(i) .i.KLISTAhat(i,id,ptsx,ptsy,ptst,npt,polyx,polyy,np,dist,ndist,times,ntimes,bsupt,binft,lambda,wbi,wbimod,wt,correc2,correc,area),simplify="array") 123 | 124 | correction = correc[id] 125 | klistatheo <- matrix(0,ncol=length(times),nrow=length(dist)) 126 | for(i in 1:length(dist)) klistatheo[i,] <- pi*(dist[i]^2)*times 127 | 128 | invisible(return(list(list.KLISTA = all.klista, klistatheo = klistatheo, dist = dist, times = times, correction = correction))) 129 | } 130 | 131 | .i.KLISTAhat <- function(i,id,ptsx,ptsy,ptst,npt,polyx,polyy,np,dist,ndist,times,ntimes,bsupt,binft,lambda,wbi,wbimod,wt,correc2,correc,area){ 132 | 133 | xi <- ptsx[i] 134 | yi <- ptsy[i] 135 | ti <- ptst[i] 136 | klistahat <- array(0, dim = c(ndist, ntimes, 5)) 137 | 138 | storage.mode(klistahat) <- "double" 139 | 140 | kflista <- .Fortran("klistafunction", as.integer(i), 141 | as.double(xi), as.double(yi), 142 | as.double(ti), as.double(ptsx), 143 | as.double(ptsy), as.double(ptst), 144 | as.integer(npt), as.double(polyx), 145 | as.double(polyy), as.integer(np), 146 | as.double(dist), as.integer(ndist), 147 | as.double(times), as.integer(ntimes), 148 | as.double(bsupt), as.double(binft), 149 | as.double(lambda), (klistahat), 150 | as.double(wbi), as.double(wbimod), 151 | as.double(wt), as.integer(correc2)) 152 | 153 | klistahat <- kflista[[19]] 154 | 155 | klistahat[, , c(1, 2, 5)] = klistahat[, , c(1, 2, 5)]/area 156 | klistahat <- (npt-1)*klistahat 157 | 158 | if (length(id) == 1) 159 | iKLISTA = as.array(klistahat[, , id]) 160 | else { 161 | iKLISTA = list() 162 | for (i in 1:length(id)) iKLISTA[[i]] = klistahat[, , id[i]] 163 | names(iKLISTA) = correc[id] 164 | } 165 | 166 | return(iKLISTA) 167 | } 168 | -------------------------------------------------------------------------------- /R/PCFhat.R: -------------------------------------------------------------------------------- 1 | PCFhat <-function(xyt, s.region, t.region, dist, times, lambda, ks = "box", hs, kt = "box", ht, correction = "isotropic"){ 2 | 3 | verifyclass(xyt,"stpp") 4 | 5 | correc = c("none", "isotropic", "border", "modified.border", "translate") 6 | id <- match(correction, correc, nomatch = NA) 7 | if (any(nbg <- is.na(id))) {mess <- paste("unrecognised correction method:", paste(dQuote(correction[nbg]), collapse = ", ")) 8 | stop(mess, call. = FALSE) 9 | } 10 | id = unique(id) 11 | correc2 = rep(0, 5) 12 | correc2[id] = 1 13 | 14 | dup <- any(duplicated(data.frame(xyt[,1], xyt[,2], xyt[,3]))) 15 | if (dup == TRUE){ 16 | messnbd <- paste("Space-time data contains duplicated points") 17 | warning(messnbd,call. = FALSE) 18 | } 19 | 20 | if (missing(s.region)) 21 | s.region <- sbox(xyt[, 1:2], xfrac = 0.01, yfrac = 0.01) 22 | if (missing(t.region)){ 23 | xr = range(xyt[, 3], na.rm = TRUE) 24 | xw = diff(xr) 25 | t.region <- c(xr[1] - 0.01 * xw, xr[2] + 0.01 * xw) 26 | } 27 | bsupt <- max(t.region) 28 | binft <- min(t.region) 29 | 30 | xp <- s.region[,1] 31 | yp <- s.region[,2] 32 | nedges <- length(xp) 33 | yp <- yp - min(yp) 34 | nxt <- c(2:nedges, 1) 35 | dx <- xp[nxt] - xp 36 | ym <- (yp + yp[nxt])/2 37 | Areaxy <- -sum(dx * ym) 38 | 39 | if (Areaxy > 0){ 40 | bdry <- owin(poly = list(x = s.region[,1], y = s.region[,2])) 41 | }else{ 42 | bdry <- owin(poly = list(x = s.region[,1][length(s.region[,1]):1], y = s.region[,2][length(s.region[,1]):1])) 43 | } 44 | 45 | if (missing(dist)){ 46 | rect = as.rectangle(bdry) 47 | maxd = min(diff(rect$xrange), diff(rect$yrange))/4 48 | dist = make.even.breaks(maxd, bstep = maxd/512)$r 49 | } 50 | if (missing(times)) { 51 | maxt = (bsupt - binft)/4 52 | times = make.even.breaks(maxt, npos = 15)$r 53 | } 54 | dist <- sort(dist) 55 | if (dist[1] == 0) 56 | dist = dist[-1] 57 | times <- sort(times) 58 | if (times[1] == 0) 59 | times = times[-1] 60 | 61 | ok <- inside.owin(xyt[,1],xyt[,2],w=bdry) 62 | xyt.ins <- data.frame(x=xyt[,1][ok],y=xyt[,2][ok],t=xyt[,3][ok]) 63 | xyt.in <- .intim(xyt.ins,t.region) 64 | 65 | pts <- xyt.in[,1:2] 66 | xytimes <- xyt.in[,3] 67 | ptsx <- pts[, 1] 68 | ptsy <- pts[, 2] 69 | ptst <- xytimes 70 | npt <- length(ptsx) 71 | ndist <- length(dist) 72 | ntimes <- length(times) 73 | area <- area(bdry) * (bsupt - binft) 74 | np <- length(s.region[, 1]) 75 | polyx <- c(s.region[, 1], s.region[1, 1]) 76 | polyy <- c(s.region[, 2], s.region[1, 2]) 77 | pcfhat <- array(0, dim = c(ndist, ntimes, 5)) 78 | 79 | frac = 1 80 | if (missing(hs)) { 81 | d = dist(pts) 82 | if (ks == "gaussian") 83 | hs = dpik(d, kernel = "normal", range.x = c(min(d), max(d)/frac)) 84 | else hs = dpik(d, kernel = ks, range.x = c(min(d), max(d)/frac)) 85 | } 86 | if (missing(ht)) { 87 | d = dist(ptst) 88 | if (kt == "gaussian") 89 | ht = dpik(d, kernel = "normal", range.x = c(min(d), max(d)/frac)) 90 | else ht = dpik(d, kernel = kt, range.x = c(min(d), max(d)/frac)) 91 | } 92 | kernel = c(ks = ks, hs = hs, kt = kt, ht = ht) 93 | if (ks == "box") 94 | ks = 1 95 | else if (ks == "epanech") 96 | ks = 2 97 | else if (ks == "gaussian") 98 | ks = 3 99 | else if (ks == "biweight") 100 | ks = 4 101 | if (kt == "box") 102 | kt = 1 103 | else if (kt == "epanech") 104 | kt = 2 105 | else if (kt == "gaussian") 106 | kt = 3 107 | else if (kt == "biweight") 108 | kt = 4 109 | 110 | if (missing(lambda)){ 111 | misl <- 1 112 | lambda <- rep(npt/area, npt) 113 | } 114 | else misl <- 0 115 | if (length(lambda) == 1) 116 | lambda <- rep(lambda, npt) 117 | 118 | storage.mode(pcfhat) <- "double" 119 | 120 | wbi = array(0, dim = c(npt, ndist, ntimes)) 121 | wbimod = array(0, dim = c(npt, ndist, ntimes)) 122 | wt = array(0, dim = c(npt, npt)) 123 | 124 | options(warn = -1) 125 | 126 | pppxy = ppp(x = ptsx, y = ptsy, window = bdry) 127 | 128 | # correction=="border" and "modified border" 129 | if (any(correction == "border") | any(correction == "modified.border")) { 130 | 131 | bi = bdist.points(pppxy) 132 | bj = .bdist.times(xytimes, t.region) 133 | 134 | for (i in 1 : ndist) { 135 | for (j in 1 : ntimes) { 136 | wbi[, i, j] = (bi > dist[i]) * (bj > times[j])/sum((bi > dist[i]) * (bj > times[j])/lambda) 137 | wbimod[, i, j] = (bi > dist[i]) * (bj > times[j])/(eroded.areas(bdry, dist[i]) * .eroded.areat(t.region, times[j])) 138 | } 139 | } 140 | wbi[is.na(wbi)] <- 0 141 | wbimod[is.na(wbimod)] <- 0 142 | } 143 | 144 | # correction=="translate" 145 | if (any(correction == "translate")) { 146 | wtt = .overlap.tint(xytimes, t.region) 147 | wts = edge.Trans(pppxy) 148 | wt = wtt * wts 149 | wt = 1/wt 150 | } 151 | 152 | options(warn = 0) 153 | 154 | klist <- .Fortran("pcffunction", as.double(ptsx), 155 | as.double(ptsy), as.double(ptst), 156 | as.integer(npt), as.double(polyx), 157 | as.double(polyy), as.integer(np), 158 | as.double(dist), as.integer(ndist), 159 | as.double(times), as.integer(ntimes), 160 | as.double(bsupt), as.double(binft), 161 | as.double(lambda), as.integer(ks), 162 | as.integer(kt), as.double(hs), 163 | as.double(ht), (pcfhat), 164 | as.double(wbi), as.double(wbimod), 165 | as.double(wt), as.integer(correc2)) 166 | 167 | pcfhat <- klist[[19]] 168 | 169 | pcfhat[, , c(1, 2, 5)] = pcfhat[, , c(1, 2, 5)]/area 170 | pcfhat <- pcfhat/(4 * pi * dist) 171 | 172 | if (length(id) == 1) 173 | PCFhat = as.array(pcfhat[, , id]) 174 | else { 175 | PCFhat = list() 176 | for (i in 1:length(id)) PCFhat[[i]] = pcfhat[, , id[i]] 177 | names(PCFhat) = correc[id] 178 | } 179 | correction = correc[id] 180 | 181 | pcftheo = array(1, dim = c(ndist, ntimes)) 182 | 183 | invisible(return(list(pcf = PCFhat, pcftheo = pcftheo, dist = dist, times = times, kernel = kernel, correction = correction))) 184 | } -------------------------------------------------------------------------------- /R/animation.R: -------------------------------------------------------------------------------- 1 | animation <- function(xyt, s.region, t.region, runtime=1, incident="red", prevalent="pink3", pch=19, cex=0.5, plot.s.region=TRUE, scales=TRUE, border.frac=0.05, add=FALSE){ 2 | 3 | verifyclass(xyt,"stpp") 4 | 5 | if (missing(s.region)) s.region <- sbox(xyt[,1:2],xfrac=0.01,yfrac=0.01) 6 | if (missing(t.region)) t.region <- range(xyt[,3],na.rm=T) 7 | 8 | ott<-order(xyt[,3]) 9 | sxyt<-xyt[ott,] 10 | rangex<-range(s.region[,1]) 11 | rangey<-range(s.region[,2]) 12 | xlim<-c(rangex[1]-border.frac*(rangex[2]-rangex[1]),rangex[2]+border.frac*(rangex[2]-rangex[1])) 13 | ylim<-c(rangey[1]-border.frac*(rangey[2]-rangey[1]),rangey[2]+border.frac*(rangey[2]-rangey[1])) 14 | xy<-as.matrix(sxyt[,1:2]) 15 | tt<-sxyt[,3] 16 | npts<-length(tt) 17 | T0 <- max(t.region) 18 | 19 | if (add==FALSE) 20 | { 21 | par(pty="s",mfrow=c(1,1)) 22 | if (scales==FALSE) 23 | plot(xy[,1],xy[,2],type="n",xlim=xlim,ylim=ylim,xaxt="n",yaxt="n",bty="n",xlab=" ",ylab=" ") 24 | if (scales==TRUE) 25 | plot(sxyt[,1],sxyt[,2],type="n",xlim=xlim,ylim=ylim,bty="n",xlab="X",ylab="Y") 26 | if (plot.s.region==TRUE) 27 | polymap(as.points(s.region),add=TRUE,lwd=2) 28 | } 29 | nplotted<-0 30 | tt.now<-0 31 | tt.fade<-0 32 | while (nplotted0) 40 | points(xy[1:n.fade,1],xy[1:n.fade,2],col=prevalent,pch=19,cex=cex) 41 | 42 | M=which(tt==tt[i]) 43 | points(xy[M,1],xy[M,2],col=incident,pch=19,cex=cex) 44 | nplotted<-nplotted+length(M) 45 | tt.now<-tt[i] 46 | tt.fade<-tt.now 47 | } 48 | } 49 | 50 | 51 | -------------------------------------------------------------------------------- /R/as.3dpoints.R: -------------------------------------------------------------------------------- 1 | as.3dpoints <- function (...) 2 | { 3 | nv <- nargs() 4 | fargs <- list(...) 5 | if (nv == 3) { 6 | l1 <- length(fargs[[1]]) 7 | l2 <- length(fargs[[2]]) 8 | l3 <- length(fargs[[3]]) 9 | if ((l1 == l2) & (l1 == l3)) { 10 | pts <- cbind(x=fargs[[1]], y=fargs[[2]], t=fargs[[3]]) 11 | } 12 | else { 13 | stop("Cannot make points from different length vectors") 14 | } 15 | } 16 | else { 17 | if (nv == 1) { 18 | if (is.list(fargs[[1]])) { 19 | fargs <- fargs[[1]] 20 | if (any(names(fargs) == "x") & any(names(fargs) == 21 | "y") & any(names(fargs) == "t")) { 22 | arx <- fargs$x 23 | ary <- fargs$y 24 | art <- fargs$t 25 | if ((length(arx) != length(ary)) | (length(arx) != length(art))) { 26 | stop("Cannot make points from different length x, y and t list components!") 27 | } 28 | else { 29 | pts <- cbind(x=arx, y=ary, t=art) 30 | } 31 | } 32 | else { 33 | stop("Cannot make points from list without x and y components.") 34 | } 35 | } 36 | else { 37 | if (is.3dpoints(fargs[[1]])) 38 | { 39 | pts <- fargs[[1]] 40 | colnames(pts)=c("x","y","t") 41 | } 42 | 43 | else stop("Cannot make points from this object") 44 | } 45 | } 46 | else { 47 | stop("Cannot make object into points!") 48 | } 49 | } 50 | x=sort(pts[,3],index.return=TRUE) 51 | pts=pts[x$ix,] 52 | oldClass(pts)="stpp" 53 | pts 54 | } 55 | -------------------------------------------------------------------------------- /R/gsp.R: -------------------------------------------------------------------------------- 1 | gsp <- function(xyt,s.region,s.lambda,ds,ks="epanech",hs,correction="none",approach="simplified"){ 2 | 3 | verifyclass(xyt,"stpp") 4 | 5 | correc <- c("none","isotropic","border","modified.border","translate","setcovf") 6 | id <- match(correction,correc,nomatch=NA) 7 | if (any(nbg <- is.na(id))){ 8 | messnbg <- paste("unrecognised correction method:",paste(dQuote(correction[nbg]),collapse=",")) 9 | stop(messnbg,call.=FALSE) 10 | } 11 | id <- unique(id) 12 | correc2 <- rep(0,6) 13 | correc2[id] <- 1 14 | 15 | appro <- c("simplified","standardised") 16 | im <- match(approach,appro,nomatch=NA) 17 | if (any(nbm <- is.na(im))){ 18 | messnbm <- paste("unrecognised type of estimator:",paste(dQuote(approach[nbm]),collapse=",")) 19 | stop(messnbm,call.=FALSE) 20 | } 21 | im <- unique(im) 22 | appro2 <- rep(0,2) 23 | appro2[im] <- 1 24 | 25 | ker <- c("box","epanech","biweight") 26 | ik <- match(ks,ker,nomatch=NA) 27 | if (any(nbk <- is.na(ik))){ 28 | messnbk <- paste("unrecognised kernel function:",paste(dQuote(ks[nbk]),collapse=",")) 29 | stop(messnbk,call.=FALSE) 30 | } 31 | ik <- unique(ik) 32 | ker2 <- rep(0,3) 33 | ker2[ik] <- 1 34 | 35 | dup <- duplicated(data.frame(xyt[,1],xyt[,2],xyt[,3]),fromLast = TRUE)[1] 36 | if (dup == TRUE){ 37 | messnbd <- paste("spatio-temporal data contain duplicated points") 38 | warning(messnbd,call.=FALSE) 39 | } 40 | 41 | options(warn = -1) 42 | 43 | if (missing(s.region)) s.region <- sbox(xyt[,1:2], xfrac=0.01, yfrac=0.01) 44 | 45 | xp <- s.region[,1] 46 | yp <- s.region[,2] 47 | nedges <- length(xp) 48 | yp <- yp - min(yp) 49 | nxt <- c(2:nedges, 1) 50 | dx <- xp[nxt] - xp 51 | ym <- (yp + yp[nxt])/2 52 | Areaxy <- -sum(dx * ym) 53 | 54 | if (Areaxy > 0){ 55 | bsw <- owin(poly = list(x = s.region[,1], y = s.region[,2])) 56 | }else{ 57 | bsw <- owin(poly = list(x = s.region[,1][length(s.region[,1]):1], y = s.region[,2][length(s.region[,1]):1])) 58 | } 59 | 60 | area <- area(bsw) 61 | pert <- perimeter(bsw) 62 | 63 | ok <- inside.owin(xyt[,1],xyt[,2],w=bsw) 64 | xyt.inside <- data.frame(x=xyt[,1][ok],y=xyt[,2][ok],t=xyt[,3][ok]) 65 | 66 | ptsx <- xyt.inside[,1] 67 | ptsy <- xyt.inside[,2] 68 | ptst <- xyt.inside[,3] 69 | 70 | pxy <- ppp(x=ptsx,y=ptsy,window=bsw) 71 | 72 | if (missing(hs)){ 73 | hs <- bw.stoyan(pxy) 74 | } 75 | 76 | if (missing(ds)){ 77 | rect <- as.rectangle(bsw) 78 | maxd <- min(diff(rect$xrange),diff(rect$yrange))/4 79 | ds <- seq(hs, maxd,len=100)[-1] 80 | ds <- sort(ds) 81 | } 82 | if(ds[1]==0){ds <- ds[-1] 83 | } 84 | bsupt <- max(ptst) 85 | binft <- min(ptst) 86 | 87 | kernel <- c(ks=ks,hs=hs) 88 | gsptheo <- ((bsupt-binft)^2)/12 89 | npt <- pxy$n[1] 90 | nds <- length(ds) 91 | gsps <- rep(0,nds) 92 | 93 | storage.mode(gsps) <- "double" 94 | 95 | if (appro2[1]==1){ 96 | gspout <- .Fortran("gspcore",as.double(ptsx),as.double(ptsy),as.double(ptst), 97 | as.integer(npt),as.double(ds),as.integer(nds),as.integer(ker2), 98 | as.double(hs),(gsps)) 99 | 100 | gsps <- gspout[[9]] 101 | 102 | dsf <- rep(0,nds+2) 103 | dsf[3:(nds+2)] <- ds 104 | ds <- dsf 105 | 106 | egsp <- rep(0,nds+2) 107 | egsp[2] <- gsps[1] 108 | egsp[3:(nds+2)] <- gsps 109 | 110 | invisible(return(list(egsp=egsp,ds=ds,kernel=kernel,gsptheo=gsptheo))) 111 | } else { 112 | 113 | if(missing(s.lambda)){ 114 | misl <- 1 115 | s.lambda <- rep(npt/area,npt) 116 | } else { 117 | misl <- 0 118 | if (length(s.lambda)==1){ 119 | s.lambda <- rep(s.lambda,npt) 120 | } 121 | } 122 | 123 | wrs <- array(0,dim=c(npt,npt)) 124 | wts <- array(0,dim=c(npt,npt)) 125 | wbi <- array(0,dim=c(npt,nds)) 126 | wbimod <- array(0,dim=c(npt,nds)) 127 | wss <- rep(0,nds) 128 | 129 | # correction="isotropic" 130 | if(correction=="isotropic"){ 131 | wisot <- edge.Ripley(pxy,pairdist(pxy)) 132 | wrs <- 1/wisot 133 | } 134 | 135 | # correction="translate" 136 | if(correction=="translate"){ 137 | wtras <- edge.Trans(pxy) 138 | wts <- 1/wtras 139 | } 140 | 141 | # correction=="border" or "modified border" 142 | if(any(correction=="border")|any(correction=="modified.border")){ 143 | bi <- bdist.points(pxy) 144 | for(i in 1:nds){ 145 | wbi[,i] <- (bi>ds[i])/sum((bi>ds[i])/s.lambda) 146 | wbimod[,i] <- (bi>ds[i])/eroded.areas(bsw,ds[i]) 147 | } 148 | wbi[is.na(wbi)] <- 0 149 | wbimod[is.na(wbimod)] <- 0 150 | } 151 | 152 | # correction="setcovf" 153 | if(correction=="setcovf"){ 154 | for (i in 1:nds){ 155 | wss[i] <- area-((pert*ds[i])/pi) 156 | } 157 | wss <- 1/wss 158 | } 159 | 160 | options(warn = 0) 161 | 162 | gspout <- .Fortran("gspcoreinh",as.double(ptsx),as.double(ptsy),as.double(ptst), 163 | as.integer(npt),as.double(ds),as.integer(nds),as.double(s.lambda), 164 | as.integer(ker2),as.double(hs),as.double(wrs),as.double(wts), 165 | as.double(wbi),as.double(wbimod),as.double(wss),as.integer(correc2), 166 | (gsps)) 167 | 168 | gsps <- gspout[[16]] 169 | 170 | dsf <- rep(0,nds+2) 171 | dsf[3:(nds+2)] <- ds 172 | ds <- dsf 173 | 174 | egsp <- rep(0,nds+2) 175 | egsp[2] <- gsps[1] 176 | egsp[3:(nds+2)] <- gsps 177 | 178 | invisible(return(list(egsp=egsp,ds=ds,kernel=kernel,gsptheo=gsptheo))) 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /R/gte.R: -------------------------------------------------------------------------------- 1 | gte <- function(xyt,t.region,t.lambda,dt,kt="epanech",ht,correction="none",approach="simplified"){ 2 | 3 | verifyclass(xyt,"stpp") 4 | 5 | correc <- c("none","isotropic","border","modified.border","translate","setcovf") 6 | id <- match(correction,correc,nomatch=NA) 7 | if (any(nbg <- is.na(id))){ 8 | messnbg <- paste("unrecognised correction method:",paste(dQuote(correction[nbg]),collapse=",")) 9 | stop(messnbg,call.=FALSE) 10 | } 11 | id <- unique(id) 12 | correc2 <- rep(0,6) 13 | correc2[id] <- 1 14 | 15 | appro <- c("simplified","standardised") 16 | im <- match(approach,appro,nomatch=NA) 17 | if (any(nbm <- is.na(im))){ 18 | messnbm <- paste("unrecognised type of estimator:",paste(dQuote(approach[nbm]),collapse=",")) 19 | stop(messnbm,call.=FALSE) 20 | } 21 | im <- unique(im) 22 | appro2 <- rep(0,2) 23 | appro2[im] <- 1 24 | 25 | ker <- c("box","epanech","biweight") 26 | ik <- match(kt,ker,nomatch=NA) 27 | if (any(nbk <- is.na(ik))){ 28 | messnbk <- paste("unrecognised kernel function:",paste(dQuote(kt[nbk]),collapse=",")) 29 | stop(messnbk,call.=FALSE) 30 | } 31 | ik <- unique(ik) 32 | ker2 <- rep(0,3) 33 | ker2[ik] <- 1 34 | 35 | dup <- duplicated(data.frame(xyt[,1],xyt[,2],xyt[,3]),fromLast = TRUE)[1] 36 | if (dup == TRUE){ 37 | messnbd <- paste("spatio-temporal data contain duplicated points") 38 | warning(messnbd,call.=FALSE) 39 | } 40 | 41 | if (missing(t.region)){ 42 | tr <- range(xyt[,3],na.rm=TRUE) 43 | tw <- diff(tr) 44 | t.region <- c(tr[1]-0.01*tw,tr[2]+0.01*tw) 45 | } 46 | 47 | xyt.inside <- .intim(xyt,t.region) 48 | 49 | if (missing(ht)){ 50 | d <- dist(xyt.inside[,3]) 51 | ht <- dpik(d,kernel=kt,range.x=c(min(d),max(d))) 52 | } 53 | 54 | bsupt <- max(t.region) 55 | binft <- min(t.region) 56 | W <- sbox(xyt.inside[,1:2], xfrac=0.01, yfrac=0.01) 57 | a <- diff(range(W[,1])) 58 | b <- diff(range(W[,2])) 59 | 60 | if (missing(dt)) { 61 | maxt <- (bsupt-binft)/4 62 | dt <- seq(ht,maxt,len=100)[-1] 63 | } 64 | if(dt[1]==0){ 65 | dt <- dt[-1] 66 | } 67 | 68 | kernel <- c(kt=kt,ht=ht) 69 | gtetheo <- ((a^2)+(b^2))/12 70 | 71 | pts <- xyt.inside[,1:2] 72 | xytimes <- xyt.inside[,3] 73 | ptsx <- pts[,1] 74 | ptsy <- pts[,2] 75 | ptst <- xytimes 76 | npt <- length(ptsx) 77 | ndt <- length(dt) 78 | gtet <- rep(0,ndt) 79 | 80 | storage.mode(gtet) <- "double" 81 | 82 | if (appro2[1]==1){ 83 | gteout <- .Fortran("gtecore",as.double(ptsx),as.double(ptsy),as.double(ptst),as.integer(npt),as.double(dt), 84 | as.integer(ndt),as.integer(ker2),as.double(ht),(gtet)) 85 | gtet <- gteout[[9]] 86 | 87 | dtf <- rep(0,ndt+2) 88 | dtf[3:(ndt+2)] <- dt 89 | dt <- dtf 90 | 91 | egte <- rep(0,ndt+2) 92 | egte[2] <- gtet[1] 93 | egte[3:(ndt+2)] <- gtet 94 | 95 | invisible(return(list(egte=egte,dt=dt,kernel=kernel,gtetheo=gtetheo))) 96 | } else { 97 | 98 | if(missing(t.lambda)){ 99 | misl <- 1 100 | t.lambda <- rep(npt/(bsupt-binft),npt) 101 | } else { 102 | misl <- 0 103 | if (length(t.lambda)==1){ 104 | t.lambda <- rep(t.lambda,npt) 105 | } 106 | } 107 | 108 | wrt <- array(0,dim=c(npt,npt)) 109 | wtt <- array(0,dim=c(npt,npt)) 110 | wbit <- array(0,dim=c(npt,ndt)) 111 | wbimodt <- array(0,dim=c(npt,ndt)) 112 | wst <- rep(0,ndt) 113 | 114 | # correction="isotropic" 115 | if(correction=="isotropic"){ 116 | wist <- tedgeRipley(ptst,binft,bsupt) 117 | wrt <- 1/wist 118 | } 119 | 120 | # correction="translate" 121 | if(correction=="translate"){ 122 | wtrat <- tedgeTrans(ptst,t.region) 123 | wtt <- 1/wtrat 124 | } 125 | 126 | # correction=="border" or "modified border" 127 | if(any(correction=="border")|any(correction=="modified.border")){ 128 | bj = .bdist.times(xytimes, t.region) 129 | for(j in 1:ndt) { 130 | wbit[,j] <- (bj>dt[j])/sum((bj>dt[j])/t.lambda) 131 | wbimodt[,j] <- (bj>dt[j])/.eroded.areat(t.region,dt[j]) 132 | } 133 | wbit[is.na(wbit)] <- 0 134 | wbimodt[is.na(wbimodt)] <- 0 135 | } 136 | 137 | # correction="setcovf" 138 | if(correction=="setcovf"){ 139 | wsett <- tsetcovf(dt,ndt,bsupt-binft) 140 | wst <- 1/wsett 141 | } 142 | 143 | gteout <- .Fortran("gtecoreinh",as.double(ptsx),as.double(ptsy),as.double(ptst),as.integer(npt), 144 | as.double(dt),as.integer(ndt),as.double(t.lambda),as.integer(ker2), 145 | as.double(ht),as.double(wrt),as.double(wtt),as.double(wbit), 146 | as.double(wbimodt),as.double(wst),as.integer(correc2),(gtet)) 147 | 148 | gtet <- gteout[[16]] 149 | 150 | dtf <- rep(0,ndt+2) 151 | dtf[3:(ndt+2)] <- dt 152 | dt <- dtf 153 | 154 | egte <- rep(0,ndt+2) 155 | egte[2] <- gtet[1] 156 | egte[3:(ndt+2)] <- gtet 157 | 158 | invisible(return(list(egte=egte,dt=dt,kernel=kernel,gtetheo=gtetheo))) 159 | } 160 | } 161 | 162 | tedgeRipley <- function(times,binft,bsupt){ 163 | ntimes <- length(times) 164 | wrt <- matrix(1,ncol=ntimes,nrow=ntimes) 165 | 166 | for(i in 1:ntimes){ 167 | ti <- times[i] 168 | for(j in 1:ntimes){ 169 | tij <- abs(ti-times[j]) 170 | if (i!=j){ 171 | bsup <- ti+tij 172 | binf <- ti-tij 173 | if ((bsup<=bsupt)&(binf>=binft)){ 174 | wrt[i,j] <- 1} 175 | else { 176 | wrt[i,j] <- 2 177 | } 178 | } 179 | } 180 | } 181 | invisible(return(wrt)) 182 | } 183 | 184 | tedgeTrans <- function(times,t.region){ 185 | if (missing(t.region)){ 186 | t.region <- range(times) 187 | } 188 | 189 | ntimes <- length(times) 190 | a <- diff(range(t.region)) 191 | wtt <- matrix(a,ncol=ntimes,nrow=ntimes) 192 | 193 | for(i in 1:ntimes){ 194 | for(j in 1:ntimes){ 195 | if (i!=j){ 196 | b <- a-abs(times[i]-times[j]) 197 | wtt[i,j] <- a/b 198 | } 199 | } 200 | } 201 | invisible(return(wtt)) 202 | } 203 | 204 | tsetcovf <- function(times,ntimes,longit){ 205 | wst <- rep(0,ntimes) 206 | for (i in 1:ntimes){ 207 | wst[i] <- longit-times[i]} 208 | invisible(return(wst=wst)) 209 | } 210 | 211 | .bdist.times=function(times,t.region){ 212 | if (missing(t.region)){ 213 | t.region <- range(times) 214 | } 215 | ntimes <- length(times) 216 | a <- min(t.region) 217 | b <- max(t.region) 218 | 219 | bj <- NULL 220 | for(j in 1:ntimes) 221 | bj <- c(bj,min(c(abs(times[j]-a),abs(times[j]-b)))) 222 | 223 | invisible(return(bj)) 224 | } -------------------------------------------------------------------------------- /R/is.3dpoints.R: -------------------------------------------------------------------------------- 1 | is.3dpoints <- function (x) 2 | { 3 | is <- FALSE 4 | if (is.array(x)) 5 | if (length(dim(x)) == 2) 6 | if (dim(x)[2] >= 3) 7 | is <- TRUE 8 | is 9 | } 10 | -------------------------------------------------------------------------------- /R/kmmr.R: -------------------------------------------------------------------------------- 1 | kmmr <- function(xyt,s.region,s.lambda,ds,ks="epanech",hs,correction="none",approach="simplified"){ 2 | 3 | verifyclass(xyt,"stpp") 4 | 5 | correc <- c("none","isotropic","border","modified.border","translate","setcovf") 6 | id <- match(correction,correc,nomatch=NA) 7 | if (any(nbg <- is.na(id))){ 8 | messnbg <- paste("unrecognised correction method:",paste(dQuote(correction[nbg]),collapse=",")) 9 | stop(messnbg,call.=FALSE) 10 | } 11 | id <- unique(id) 12 | correc2 <- rep(0,6) 13 | correc2[id] <- 1 14 | 15 | appro <- c("simplified","standardised") 16 | im <- match(approach,appro,nomatch=NA) 17 | if (any(nbm <- is.na(im))){ 18 | messnbm <- paste("unrecognised type of estimator:",paste(dQuote(approach[nbm]),collapse=",")) 19 | stop(messnbm,call.=FALSE) 20 | } 21 | im <- unique(im) 22 | appro2 <- rep(0,2) 23 | appro2[im] <- 1 24 | 25 | ker <- c("box","epanech","biweight") 26 | ik <- match(ks,ker,nomatch=NA) 27 | if (any(nbk <- is.na(ik))){ 28 | messnbk <- paste("unrecognised kernel function:",paste(dQuote(ks[nbk]),collapse=",")) 29 | stop(messnbk,call.=FALSE) 30 | } 31 | ik <- unique(ik) 32 | ker2 <- rep(0,3) 33 | ker2[ik] <- 1 34 | 35 | dup <- duplicated(data.frame(xyt[,1],xyt[,2],xyt[,3]),fromLast = TRUE)[1] 36 | if (dup == TRUE){ 37 | messnbd <- paste("spatio-temporal data contain duplicated points") 38 | warning(messnbd,call.=FALSE) 39 | } 40 | 41 | options(warn = -1) 42 | 43 | if (missing(s.region)) s.region <- sbox(xyt[,1:2], xfrac=0.01, yfrac=0.01) 44 | 45 | xp <- s.region[,1] 46 | yp <- s.region[,2] 47 | nedges <- length(xp) 48 | yp <- yp - min(yp) 49 | nxt <- c(2:nedges, 1) 50 | dx <- xp[nxt] - xp 51 | ym <- (yp + yp[nxt])/2 52 | Areaxy <- -sum(dx * ym) 53 | 54 | if (Areaxy > 0){ 55 | bsw <- owin(poly = list(x = s.region[,1], y = s.region[,2])) 56 | }else{ 57 | bsw <- owin(poly = list(x = s.region[,1][length(s.region[,1]):1], y = s.region[,2][length(s.region[,1]):1])) 58 | } 59 | 60 | area <- area(bsw) 61 | pert <- perimeter(bsw) 62 | 63 | ok <- inside.owin(xyt[,1],xyt[,2],w=bsw) 64 | xyt.inside <- data.frame(x=xyt[,1][ok],y=xyt[,2][ok],t=xyt[,3][ok]) 65 | 66 | ptsx <- xyt.inside[,1] 67 | ptsy <- xyt.inside[,2] 68 | ptst <- xyt.inside[,3] 69 | 70 | pxy <- ppp(x=ptsx,y=ptsy,window=bsw) 71 | 72 | if (missing(hs)){ 73 | hs <- bw.stoyan(pxy) 74 | } 75 | 76 | if (missing(ds)){ 77 | rect <- as.rectangle(bsw) 78 | maxd <- min(diff(rect$xrange),diff(rect$yrange))/4 79 | ds <- seq(0, maxd,len=100) 80 | ds <- sort(ds) 81 | } 82 | if(ds[1]==0){ds <- ds[-1] 83 | } 84 | 85 | kernel <- c(ks=ks,hs=hs) 86 | kmmrtheo <- 1 87 | npt <- pxy$n[1] 88 | nds <- length(ds) 89 | mummr <- mean(ptst) 90 | ekmmr <- rep(0,nds) 91 | 92 | storage.mode(ekmmr) <- "double" 93 | 94 | if (appro2[1]==1){ 95 | kmmrout <- .Fortran("kmmrcore",as.double(ptsx),as.double(ptsy),as.double(ptst), 96 | as.integer(npt),as.double(ds),as.integer(nds),as.integer(ker2) 97 | ,as.double(hs),(ekmmr),PACKAGE="stpp") 98 | 99 | ekmmr <- kmmrout[[9]]/(mummr^2) 100 | 101 | invisible(return(list(ekmmr=ekmmr,ds=ds,kernel=kernel,kmmrtheo=kmmrtheo))) 102 | } else { 103 | 104 | if(missing(s.lambda)){ 105 | misl <- 1 106 | s.lambda <- rep(npt/area,npt) 107 | } else { 108 | misl <- 0 109 | if (length(s.lambda)==1){ 110 | s.lambda <- rep(s.lambda,npt) 111 | } 112 | } 113 | 114 | wrs <- array(0,dim=c(npt,npt)) 115 | wts <- array(0,dim=c(npt,npt)) 116 | wbi <- array(0,dim=c(npt,nds)) 117 | wbimod <- array(0,dim=c(npt,nds)) 118 | wss <- rep(0,nds) 119 | 120 | # correction="isotropic" 121 | if(correction=="isotropic"){ 122 | wisot <- edge.Ripley(pxy,pairdist(pxy)) 123 | wrs <- 1/wisot 124 | } 125 | 126 | # correction="translate" 127 | if(correction=="translate"){ 128 | wtras <- edge.Trans(pxy) 129 | wts <- 1/wtras 130 | } 131 | 132 | # correction=="border" or "modified border 133 | if(any(correction=="border")|any(correction=="modified.border")){ 134 | bi <- bdist.points(pxy) 135 | for(i in 1:nds) { 136 | wbi[,i] <- (bi>ds[i])/sum((bi>ds[i])/s.lambda) 137 | wbimod[,i] <- (bi>ds[i])/eroded.areas(bsw,ds[i]) 138 | } 139 | wbi[is.na(wbi)] <- 0 140 | wbimod[is.na(wbimod)] <- 0 141 | } 142 | 143 | # correction="setcovf" 144 | if(correction=="setcovf"){ 145 | for (i in 1:nds){ 146 | wss[i] <- area-((pert*ds[i])/pi) 147 | } 148 | wss <- 1/wss 149 | } 150 | 151 | options(warn = 0) 152 | 153 | kmmrout <- .Fortran("kmmrcoreinh",as.double(ptsx),as.double(ptsy),as.double(ptst), 154 | as.integer(npt),as.double(ds),as.integer(nds),as.double(s.lambda), 155 | as.integer(ker2),as.double(hs),as.double(wrs),as.double(wts), 156 | as.double(wbi),as.double(wbimod),as.double(wss),as.integer(correc2), 157 | (ekmmr),PACKAGE="stpp") 158 | 159 | ekmmr <- kmmrout[[16]]/(mummr^2) 160 | 161 | invisible(return(list(ekmmr=ekmmr,ds=ds,kernel=kernel,kmmrtheo=kmmrtheo,s.lambda=s.lambda))) 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /R/kmmt.R: -------------------------------------------------------------------------------- 1 | kmmt <- function(xyt,t.region,t.lambda,dt,kt="epanech",ht,correction="none",approach="simplified"){ 2 | 3 | verifyclass(xyt,"stpp") 4 | 5 | correc <- c("none","isotropic","border","modified.border","translate","setcovf") 6 | id <- match(correction,correc,nomatch=NA) 7 | if (any(nbg <- is.na(id))){ 8 | messnbg <- paste("unrecognised correction method:",paste(dQuote(correction[nbg]),collapse=",")) 9 | stop(messnbg,call.=FALSE) 10 | } 11 | id <- unique(id) 12 | correc2 <- rep(0,6) 13 | correc2[id] <- 1 14 | 15 | appro <- c("simplified","standardised") 16 | im <- match(approach,appro,nomatch=NA) 17 | if (any(nbm <- is.na(im))){ 18 | messnbm <- paste("unrecognised type of estimator:",paste(dQuote(approach[nbm]),collapse=",")) 19 | stop(messnbm,call.=FALSE) 20 | } 21 | im <- unique(im) 22 | appro2 <- rep(0,2) 23 | appro2[im] <- 1 24 | 25 | ker <- c("box","epanech","biweight") 26 | ik <- match(kt,ker,nomatch=NA) 27 | if (any(nbk <- is.na(ik))){ 28 | messnbk <- paste("unrecognised kernel function:",paste(dQuote(kt[nbk]),collapse=",")) 29 | stop(messnbk,call.=FALSE) 30 | } 31 | ik <- unique(ik) 32 | ker2 <- rep(0,3) 33 | ker2[ik] <- 1 34 | 35 | dup <- duplicated(data.frame(xyt[,1],xyt[,2],xyt[,3]),fromLast = TRUE)[1] 36 | if (dup == TRUE){ 37 | messnbd <- paste("spatio-temporal data contain duplicated points") 38 | warning(messnbd,call.=FALSE) 39 | } 40 | 41 | if (missing(t.region)){ 42 | tr <- range(xyt[,3],na.rm=TRUE) 43 | tw <- diff(tr) 44 | t.region <- c(tr[1]-0.01*tw,tr[2]+0.01*tw) 45 | } 46 | 47 | xyt.inside <- .intim(xyt,t.region) 48 | 49 | if (missing(ht)){ 50 | d <- dist(xyt.inside[,3]) 51 | ht <- dpik(d,kernel=kt,range.x=c(min(d),max(d))) 52 | } 53 | 54 | bsupt <- max(t.region) 55 | binft <- min(t.region) 56 | 57 | if (missing(dt)) { 58 | maxt <- (bsupt-binft)/4 59 | dt <- seq(ht,maxt,len=100)[-1] 60 | } 61 | if(dt[1]==0){ 62 | dt <- dt[-1] 63 | } 64 | 65 | kernel <- c(kt=kt,ht=ht) 66 | kmmttheo <- 1 67 | 68 | pts <- xyt.inside[,1:2] 69 | xytimes <- xyt.inside[,3] 70 | ptsx <- pts[,1] 71 | ptsy <- pts[,2] 72 | ptst <- xytimes 73 | npt <- length(ptsx) 74 | ndt <- length(dt) 75 | snorm <- apply(pts,MARGIN=1,FUN=norm,type="2") 76 | mummt <- mean(snorm) 77 | ekmmt <- rep(0,ndt) 78 | 79 | storage.mode(ekmmt) <- "double" 80 | 81 | if (appro2[1]==1){ 82 | kmmtout <- .Fortran("kmmtcore",as.double(snorm),as.double(ptst),as.integer(npt),as.double(dt), 83 | as.integer(ndt),as.integer(ker2),as.double(ht),(ekmmt)) 84 | 85 | ekmmt <- kmmtout[[8]]/(mummt^2) 86 | 87 | invisible(return(list(ekmmt=ekmmt,dt=dt,kernel=kernel,kmmttheo=kmmttheo))) 88 | } else { 89 | 90 | if(missing(t.lambda)){ 91 | misl <- 1 92 | t.lambda <- rep(npt/(bsupt-binft),npt) 93 | } else { 94 | misl <- 0 95 | if (length(t.lambda)==1){ 96 | t.lambda <- rep(t.lambda,npt) 97 | } 98 | } 99 | 100 | wrt <- array(0,dim=c(npt,npt)) 101 | wtt <- array(0,dim=c(npt,npt)) 102 | wbit <- array(0,dim=c(npt,ndt)) 103 | wbimodt <- array(0,dim=c(npt,ndt)) 104 | wst <- rep(0,ndt) 105 | 106 | # correction="isotropic" 107 | if(correction=="isotropic"){ 108 | wist <- tedgeRipley(ptst,binft,bsupt) 109 | wrt <- 1/wist 110 | } 111 | 112 | # correction="translate" 113 | if(correction=="translate"){ 114 | wtrat <- tedgeTrans(ptst,t.region) 115 | wtt <- 1/wtrat 116 | } 117 | 118 | # correction=="border" or "modified border" 119 | if(any(correction=="border")|any(correction=="modified.border")){ 120 | bj = .bdist.times(xytimes, t.region) 121 | for(j in 1:ndt) { 122 | wbit[,j] <- (bj>dt[j])/sum((bj>dt[j])/t.lambda) 123 | wbimodt[,j] <- (bj>dt[j])/.eroded.areat(t.region,dt[j]) 124 | } 125 | wbit[is.na(wbit)] <- 0 126 | wbimodt[is.na(wbimodt)] <- 0 127 | } 128 | 129 | # correction="setcovf" 130 | if(correction=="setcovf"){ 131 | wsett <- tsetcovf(dt,ndt,bsupt-binft) 132 | wst <- 1/wsett 133 | } 134 | 135 | kmmtout <- .Fortran("kmmtcoreinh",as.double(snorm),as.double(ptst),as.integer(npt), 136 | as.double(dt),as.integer(ndt),as.double(t.lambda),as.integer(ker2), 137 | as.double(ht),as.double(wrt),as.double(wtt),as.double(wbit), 138 | as.double(wbimodt),as.double(wst),as.integer(correc2),(ekmmt)) 139 | 140 | ekmmt <- kmmtout[[15]]/(mummt^2) 141 | 142 | invisible(return(list(ekmmt=ekmmt,dt=dt,kernel=kernel,kmmttheo=kmmttheo,t.lambda=t.lambda))) 143 | } 144 | } 145 | 146 | tedgeRipley <- function(times,binft,bsupt){ 147 | ntimes <- length(times) 148 | wrt <- matrix(1,ncol=ntimes,nrow=ntimes) 149 | 150 | for(i in 1:ntimes){ 151 | ti <- times[i] 152 | for(j in 1:ntimes){ 153 | tij <- abs(ti-times[j]) 154 | if (i!=j){ 155 | bsup <- ti+tij 156 | binf <- ti-tij 157 | if ((bsup<=bsupt)&(binf>=binft)){ 158 | wrt[i,j] <- 1} 159 | else { 160 | wrt[i,j] <- 2 161 | } 162 | } 163 | } 164 | } 165 | invisible(return(wrt)) 166 | } 167 | 168 | tedgeTrans <- function(times,t.region){ 169 | if (missing(t.region)){ 170 | t.region <- range(times) 171 | } 172 | 173 | ntimes <- length(times) 174 | a <- diff(range(t.region)) 175 | wtt <- matrix(a,ncol=ntimes,nrow=ntimes) 176 | 177 | for(i in 1:ntimes){ 178 | for(j in 1:ntimes){ 179 | if (i!=j){ 180 | b <- a-abs(times[i]-times[j]) 181 | wtt[i,j] <- a/b 182 | } 183 | } 184 | } 185 | invisible(return(wtt)) 186 | } 187 | 188 | tsetcovf <- function(times,ntimes,longit){ 189 | wst <- rep(0,ntimes) 190 | for (i in 1:ntimes){ 191 | wst[i] <- longit-times[i]} 192 | invisible(return(wst=wst)) 193 | } 194 | 195 | .bdist.times=function(times,t.region){ 196 | if (missing(t.region)){ 197 | t.region <- range(times) 198 | } 199 | ntimes <- length(times) 200 | a <- min(t.region) 201 | b <- max(t.region) 202 | 203 | bj <- NULL 204 | for(j in 1:ntimes) 205 | bj <- c(bj,min(c(abs(times[j]-a),abs(times[j]-b)))) 206 | 207 | invisible(return(bj)) 208 | } 209 | 210 | .eroded.areat=function(t.region,dist){ 211 | a <- diff(range(t.region)) 212 | b <- a-dist 213 | invisible(return(b)) 214 | } -------------------------------------------------------------------------------- /R/kmr.R: -------------------------------------------------------------------------------- 1 | kmr <- function(xyt,s.region,s.lambda,ds,ks="epanech",hs,correction="none",approach="simplified"){ 2 | 3 | verifyclass(xyt,"stpp") 4 | 5 | correc <- c("none","isotropic","border","modified.border","translate","setcovf") 6 | id <- match(correction,correc,nomatch=NA) 7 | if (any(nbg <- is.na(id))){ 8 | messnbg <- paste("unrecognised correction method:",paste(dQuote(correction[nbg]),collapse=",")) 9 | stop(messnbg,call.=FALSE) 10 | } 11 | id <- unique(id) 12 | correc2 <- rep(0,6) 13 | correc2[id] <- 1 14 | 15 | appro <- c("simplified","standardised") 16 | im <- match(approach,appro,nomatch=NA) 17 | if (any(nbm <- is.na(im))){ 18 | messnbm <- paste("unrecognised type of estimator:",paste(dQuote(approach[nbm]),collapse=",")) 19 | stop(messnbm,call.=FALSE) 20 | } 21 | im <- unique(im) 22 | appro2 <- rep(0,2) 23 | appro2[im] <- 1 24 | 25 | ker <- c("box","epanech","biweight") 26 | ik <- match(ks,ker,nomatch=NA) 27 | if (any(nbk <- is.na(ik))){ 28 | messnbk <- paste("unrecognised kernel function:",paste(dQuote(ks[nbk]),collapse=",")) 29 | stop(messnbk,call.=FALSE) 30 | } 31 | ik <- unique(ik) 32 | ker2 <- rep(0,3) 33 | ker2[ik] <- 1 34 | 35 | dup <- duplicated(data.frame(xyt[,1],xyt[,2],xyt[,3]),fromLast = TRUE)[1] 36 | if (dup == TRUE){ 37 | messnbd <- paste("spatio-temporal data contain duplicated points") 38 | warning(messnbd,call.=FALSE) 39 | } 40 | 41 | options(warn = -1) 42 | 43 | if (missing(s.region)) s.region <- sbox(xyt[,1:2], xfrac=0.01, yfrac=0.01) 44 | 45 | xp <- s.region[,1] 46 | yp <- s.region[,2] 47 | nedges <- length(xp) 48 | yp <- yp - min(yp) 49 | nxt <- c(2:nedges, 1) 50 | dx <- xp[nxt] - xp 51 | ym <- (yp + yp[nxt])/2 52 | Areaxy <- -sum(dx * ym) 53 | 54 | if (Areaxy > 0){ 55 | bsw <- owin(poly = list(x = s.region[,1], y = s.region[,2])) 56 | }else{ 57 | bsw <- owin(poly = list(x = s.region[,1][length(s.region[,1]):1], y = s.region[,2][length(s.region[,1]):1])) 58 | } 59 | 60 | area <- area(bsw) 61 | pert <- perimeter(bsw) 62 | 63 | ok <- inside.owin(xyt[,1],xyt[,2],w=bsw) 64 | xyt.inside <- data.frame(x=xyt[,1][ok],y=xyt[,2][ok],t=xyt[,3][ok]) 65 | 66 | ptsx <- xyt.inside[,1] 67 | ptsy <- xyt.inside[,2] 68 | ptst <- xyt.inside[,3] 69 | 70 | pxy <- ppp(x=ptsx,y=ptsy,window=bsw) 71 | 72 | if (missing(hs)){ 73 | hs <- bw.stoyan(pxy) 74 | } 75 | 76 | if (missing(ds)){ 77 | rect <- as.rectangle(bsw) 78 | maxd <- min(diff(rect$xrange),diff(rect$yrange))/4 79 | ds <- seq(hs, maxd,len=100)[-1] 80 | ds <- sort(ds) 81 | } 82 | if(ds[1]==0){ds <- ds[-1] 83 | } 84 | 85 | kernel <- c(ks=ks,hs=hs) 86 | kmrtheo <- 1 87 | npt <- pxy$n[1] 88 | nds <- length(ds) 89 | mumr <- mean(ptst) 90 | ekmr <- rep(0,nds) 91 | 92 | storage.mode(ekmr) <- "double" 93 | 94 | if (appro2[1]==1){ 95 | kmrout <- .Fortran("kmrcore",as.double(ptsx),as.double(ptsy),as.double(ptst), 96 | as.integer(npt),as.double(ds),as.integer(nds),as.integer(ker2) 97 | ,as.double(hs),(ekmr)) 98 | 99 | ekmr <- kmrout[[9]]/mumr 100 | 101 | invisible(return(list(ekmr=ekmr,ds=ds,kernel=kernel,kmrtheo=kmrtheo))) 102 | } else { 103 | 104 | if(missing(s.lambda)){ 105 | misl <- 1 106 | s.lambda <- rep(npt/area,npt) 107 | } else { 108 | misl <- 0 109 | if (length(s.lambda)==1){ 110 | s.lambda <- rep(s.lambda,npt) 111 | } 112 | } 113 | 114 | wrs <- array(0,dim=c(npt,npt)) 115 | wts <- array(0,dim=c(npt,npt)) 116 | wbi <- array(0,dim=c(npt,nds)) 117 | wbimod <- array(0,dim=c(npt,nds)) 118 | wss <- rep(0,nds) 119 | 120 | # correction="isotropic" 121 | if(correction=="isotropic"){ 122 | wisot <- edge.Ripley(pxy,pairdist(pxy)) 123 | wrs <- 1/wisot 124 | } 125 | 126 | # correction="translate" 127 | if(correction=="translate"){ 128 | wtras <- edge.Trans(pxy) 129 | wts <- 1/wtras 130 | } 131 | 132 | # correction=="border" or "modified border" 133 | if(any(correction=="border")|any(correction=="modified.border")){ 134 | bi <- bdist.points(pxy) 135 | for(i in 1:nds) { 136 | wbi[,i] <- (bi>ds[i])/sum((bi>ds[i])/s.lambda) 137 | wbimod[,i] <- (bi>ds[i])/eroded.areas(bsw,ds[i]) 138 | } 139 | wbi[is.na(wbi)] <- 0 140 | wbimod[is.na(wbimod)] <- 0 141 | } 142 | 143 | # correction="setcovf" 144 | if(correction=="setcovf"){ 145 | for (i in 1:nds){ 146 | wss[i] <- area-((pert*ds[i])/pi) 147 | } 148 | wss <- 1/wss 149 | } 150 | 151 | options(warn = 0) 152 | 153 | kmrout <- .Fortran("kmrcoreinh",as.double(ptsx),as.double(ptsy),as.double(ptst), 154 | as.integer(npt),as.double(ds),as.integer(nds),as.double(s.lambda), 155 | as.integer(ker2),as.double(hs),as.double(wrs),as.double(wts), 156 | as.double(wbi),as.double(wbimod),as.double(wss),as.integer(correc2), 157 | (ekmr)) 158 | 159 | ekmr <- kmrout[[16]]/mumr 160 | 161 | invisible(return(list(ekmr=ekmr,ds=ds,kernel=kernel,kmrtheo=kmrtheo,s.lambda=s.lambda))) 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /R/kmt.R: -------------------------------------------------------------------------------- 1 | kmt <- function(xyt,t.region,t.lambda,dt,kt="epanech",ht,correction="none",approach="simplified"){ 2 | 3 | verifyclass(xyt,"stpp") 4 | 5 | correc <- c("none","isotropic","border","modified.border","translate","setcovf") 6 | id <- match(correction,correc,nomatch=NA) 7 | if (any(nbg <- is.na(id))){ 8 | messnbg <- paste("unrecognised correction method:",paste(dQuote(correction[nbg]),collapse=",")) 9 | stop(messnbg,call.=FALSE) 10 | } 11 | id <- unique(id) 12 | correc2 <- rep(0,6) 13 | correc2[id] <- 1 14 | 15 | appro <- c("simplified","standardised") 16 | im <- match(approach,appro,nomatch=NA) 17 | if (any(nbm <- is.na(im))){ 18 | messnbm <- paste("unrecognised type of estimator:",paste(dQuote(approach[nbm]),collapse=",")) 19 | stop(messnbm,call.=FALSE) 20 | } 21 | im <- unique(im) 22 | appro2 <- rep(0,2) 23 | appro2[im] <- 1 24 | 25 | ker <- c("box","epanech","biweight") 26 | ik <- match(kt,ker,nomatch=NA) 27 | if (any(nbk <- is.na(ik))){ 28 | messnbk <- paste("unrecognised kernel function:",paste(dQuote(kt[nbk]),collapse=",")) 29 | stop(messnbk,call.=FALSE) 30 | } 31 | ik <- unique(ik) 32 | ker2 <- rep(0,3) 33 | ker2[ik] <- 1 34 | 35 | dup <- duplicated(data.frame(xyt[,1],xyt[,2],xyt[,3]),fromLast = TRUE)[1] 36 | if (dup == TRUE){ 37 | messnbd <- paste("spatio-temporal data contain duplicated points") 38 | warning(messnbd,call.=FALSE) 39 | } 40 | 41 | if (missing(t.region)){ 42 | tr <- range(xyt[,3],na.rm=TRUE) 43 | tw <- diff(tr) 44 | t.region <- c(tr[1]-0.01*tw,tr[2]+0.01*tw) 45 | } 46 | 47 | xyt.inside <- .intim(xyt,t.region) 48 | 49 | if (missing(ht)){ 50 | d <- dist(xyt.inside[,3]) 51 | ht <- dpik(d,kernel=kt,range.x=c(min(d),max(d))) 52 | } 53 | 54 | bsupt <- max(t.region) 55 | binft <- min(t.region) 56 | 57 | if (missing(dt)) { 58 | maxt <- (bsupt-binft)/4 59 | dt <- seq(ht,maxt,len=100)[-1] 60 | } 61 | if(dt[1]==0){ 62 | dt <- dt[-1] 63 | } 64 | 65 | kernel <- c(kt=kt,ht=ht) 66 | kmttheo <- 1 67 | 68 | pts <- xyt.inside[,1:2] 69 | xytimes <- xyt.inside[,3] 70 | ptsx <- pts[,1] 71 | ptsy <- pts[,2] 72 | ptst <- xytimes 73 | npt <- length(ptsx) 74 | ndt <- length(dt) 75 | snorm <- apply(pts,MARGIN=1,FUN=norm,type="2") 76 | mumt <- mean(snorm) 77 | ekmt <- rep(0,ndt) 78 | 79 | storage.mode(ekmt) <- "double" 80 | 81 | if (appro2[1]==1){ 82 | kmtout <- .Fortran("kmtcore",as.double(snorm),as.double(ptst),as.integer(npt),as.double(dt), 83 | as.integer(ndt),as.integer(ker2),as.double(ht),(ekmt)) 84 | 85 | ekmt <- kmtout[[8]]/mumt 86 | 87 | invisible(return(list(ekmt=ekmt,dt=dt,kernel=kernel,kmttheo=kmttheo))) 88 | } else { 89 | 90 | if(missing(t.lambda)){ 91 | misl <- 1 92 | t.lambda <- rep(npt/(bsupt-binft),npt) 93 | } else { 94 | misl <- 0 95 | if (length(t.lambda)==1){ 96 | t.lambda <- rep(t.lambda,npt) 97 | } 98 | } 99 | 100 | wrt <- array(0,dim=c(npt,npt)) 101 | wtt <- array(0,dim=c(npt,npt)) 102 | wbit <- array(0,dim=c(npt,ndt)) 103 | wbimodt <- array(0,dim=c(npt,ndt)) 104 | wst <- rep(0,ndt) 105 | 106 | # correction="isotropic" 107 | if(correction=="isotropic"){ 108 | wist <- tedgeRipley(ptst,binft,bsupt) 109 | wrt <- 1/wist 110 | } 111 | 112 | # correction="translate" 113 | if(correction=="translate"){ 114 | wtrat <- tedgeTrans(ptst,t.region) 115 | wtt <- 1/wtrat 116 | } 117 | 118 | # correction=="border" or "modified border" 119 | if(any(correction=="border")|any(correction=="modified.border")){ 120 | bj = .bdist.times(xytimes, t.region) 121 | for(j in 1:ndt) { 122 | wbit[,j] <- (bj>dt[j])/sum((bj>dt[j])/t.lambda) 123 | wbimodt[,j] <- (bj>dt[j])/.eroded.areat(t.region,dt[j]) 124 | } 125 | wbit[is.na(wbit)] <- 0 126 | wbimodt[is.na(wbimodt)] <- 0 127 | } 128 | 129 | # correction="setcovf" 130 | if(correction=="setcovf"){ 131 | wsett <- tsetcovf(dt,ndt,bsupt-binft) 132 | wst <- 1/wsett 133 | } 134 | 135 | kmtout <- .Fortran("kmtcoreinh",as.double(snorm),as.double(ptst),as.integer(npt), 136 | as.double(dt),as.integer(ndt),as.double(t.lambda),as.integer(ker2), 137 | as.double(ht),as.double(wrt),as.double(wtt),as.double(wbit), 138 | as.double(wbimodt),as.double(wst),as.integer(correc2),(ekmt)) 139 | 140 | ekmt <- kmtout[[15]]/mumt 141 | 142 | invisible(return(list(ekmt=ekmt,dt=dt,kernel=kernel,kmttheo=kmttheo,t.lambda=t.lambda))) 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /R/plot.stpp.R: -------------------------------------------------------------------------------- 1 | plot.stpp <- function(x, s.region=NULL, t.region=NULL, style="generic", type="projection", mark=NULL, mark.cexmin=0.4, mark.cexmax=1.2, mark.col=1, ...){ 2 | 3 | verifyclass(x,"stpp") 4 | 5 | if(!is.null(mark)){ 6 | if (mark==TRUE){ 7 | type <- "mark" 8 | style <- "generic" 9 | } 10 | if (mark==FALSE){ 11 | type <- "projection" 12 | style <- "generic" 13 | } 14 | } 15 | 16 | if (type=="scatter"){ 17 | if(style=="generic"){ 18 | par(mfrow=c(1,1),pty="s") 19 | scatter3D(x[,1],x[,2],x[,3],zlab="\n t",main="xyt-locations",...) 20 | } 21 | 22 | if(style=="elegant"){ 23 | par(mfrow=c(1,1),pty="s") 24 | scatter3D(x[,1],x[,2],x[,3],zlab="\n t",main="xyt-locations",facets=FALSE,curtain=FALSE,col.panel="#EBEBEB",col.grid="F8F8F8",bty="g",border=NA,...) 25 | } 26 | } 27 | 28 | if (type=="projection"){ 29 | if(style=="generic"){ 30 | par(mfrow=c(1,2),pty="s") 31 | if (is.null(s.region)){ 32 | plot(x[,1:2],main="xy-locations",...) 33 | }else{ 34 | polymap(s.region,xlab="x",ylab="y") 35 | points(x[,1:2],...) 36 | title("xy-locations")} 37 | plot(sort(x[,3]),seq(1,length(x[,3])),type="l",xlab="t",ylab="",main="cumulative number",las=1,xlim=t.region) 38 | } 39 | 40 | if(style=="elegant"){ 41 | sd <- data.frame(x=x[,1],y=x[,2]) 42 | td <- data.frame(t=sort(x[,3]),y=seq(1,length(x[,3]))) 43 | if (is.null(s.region)){ 44 | sp <- ggplot(sd,aes_string("x","y"))+geom_point()+theme(text=element_text(...))+ggtitle("xy-locations") 45 | }else{ 46 | SW <- data.frame(x=c(s.region[,1],s.region[1,1]),y=c(s.region[,2],s.region[1,2])) 47 | sp <- ggplot(sd,aes_string("x","y"))+geom_path(data=SW,aes_string("x","y"))+geom_point()+theme(text=element_text(...))+ggtitle("xy-locations") 48 | } 49 | tp <- ggplot(td,aes_string("t","y"))+geom_line()+labs(y="")+theme(text=element_text(...))+ggtitle("cumulative number") 50 | grid.arrange(sp,tp,ncol=2,nrow=1) 51 | } 52 | } 53 | 54 | if (type=="mark"){ 55 | if(is.null(mark)){ 56 | sn=apply(x[,1:2],MARGIN=1,FUN=norm,type="2") 57 | t=x[,3]} 58 | if(style=="generic"){ 59 | l=dim(x)[1] 60 | CEX=seq(mark.cexmin,mark.cexmax,length=l) 61 | if (mark.col==0){ 62 | if (!is.null(mark)){ 63 | par(mfrow=c(1,1),pty="s") 64 | }else{ 65 | par(mfrow=c(1,2),pty="s") 66 | } 67 | if (is.null(s.region)){ 68 | plot(x[,1:2],cex=CEX,...) 69 | if(is.null(mark)){ 70 | title("Time mark") 71 | } 72 | }else{ 73 | polymap(s.region,xlab="x",ylab="y") 74 | points(x[,1:2],cex=CEX,...) 75 | if(is.null(mark)){ 76 | title("Time mark") 77 | } 78 | } 79 | }else{ 80 | if (mark.col=="black" | mark.col==1){COL=grey((l:1)/l)} 81 | if (mark.col=="red" | mark.col==2){COL=rgb(l:0, 0, 0, maxColorValue = l)} 82 | if (mark.col=="green" | mark.col==3){COL=rgb(0, l:0, 0, maxColorValue = l)} 83 | if (mark.col=="blue" | mark.col==4){COL=rgb(0, 0, l:0, maxColorValue = l)} 84 | if (!is.null(mark)){ 85 | par(mfrow=c(1,1),pty="s") 86 | }else{ 87 | par(mfrow=c(1,2),pty="s") 88 | } 89 | if (is.null(s.region)){ 90 | plot(x[,1:2],col=COL,cex=CEX,...) 91 | if(is.null(mark)){ 92 | title("Time mark") 93 | } 94 | }else{ 95 | polymap(s.region,xlab="x",ylab="y") 96 | points(x[,1:2],col=COL,cex=CEX,...) 97 | if(is.null(mark)){ 98 | title("Time mark") 99 | } 100 | } 101 | } 102 | if(is.null(mark)){ 103 | plot(t,sn,type="h",ylab="||(x,y)||",main="Space mark",...) 104 | }} 105 | if (style=="elegant"){ 106 | sdm <- data.frame(x=x[,1],y=x[,2],t=x[,3]) 107 | if (is.null(s.region)){ 108 | spm <- ggplot(sdm,aes_string("x","y"))+geom_point(aes(size=t),shape=1,show.legend=FALSE)+scale_shape(solid=FALSE)+theme(text=element_text(...))+ggtitle("Time marks") 109 | }else{ 110 | SW <- data.frame(x=c(s.region[,1],s.region[1,1]),y=c(s.region[,2],s.region[1,2])) 111 | spm <- ggplot(sdm,aes_string("x","y"))+geom_path(data=SW,aes_string("x","y"))+geom_point(aes(size=t),shape=1,show.legend=FALSE)+theme(text=element_text(...))+ggtitle("Time marks") 112 | } 113 | tdm <- data.frame(t=t,sn=sn) 114 | tpm <- ggplot(tdm,aes_string("t","sn"))+geom_bar(stat="identity",colour="black")+labs(y="||(x,y)||")+theme(text=element_text(...))+ggtitle("Space marks") 115 | grid.arrange(spm,tpm,ncol=2,nrow=1) 116 | } 117 | } 118 | } 119 | 120 | getS3method("plot", "stpp", optional = FALSE) -------------------------------------------------------------------------------- /R/plotPCF.R: -------------------------------------------------------------------------------- 1 | plotPCF <- function(PCF,n=15,type="contour",legend=TRUE,which=NULL,main=NULL,...) 2 | { 3 | devl=dev.list() 4 | if(is.null(devl)) 5 | { 6 | old.par <- par(no.readonly = TRUE) 7 | on.exit(par(old.par)) 8 | } 9 | else 10 | { 11 | dev.off(devl[length(devl)]) 12 | dev.new() 13 | old.par <- par(no.readonly = TRUE) 14 | on.exit(par(old.par)) 15 | } 16 | 17 | 18 | correc=c("none","isotropic","border","modified.border","translate") 19 | correc2=PCF$correction 20 | id <- match(correc2, correc, nomatch = NA) 21 | 22 | if ((is.null(which) && length(id)>1) || any(is.na(match(which, correc, nomatch = NA)))) 23 | { 24 | mess <- paste("Please specify the argument \'which\', among:", paste(dQuote(correc2), 25 | collapse = ", ")) 26 | stop(mess, call. = FALSE) 27 | } 28 | 29 | if (is.matrix(PCF$pcf)) 30 | { 31 | if (is.null(which)) which=correc2 32 | else { 33 | if (!(is.null(which)) && which!=correc2) 34 | { 35 | mess <- paste("Argument \'which\' should be", paste(dQuote(correc2), 36 | collapse = ", ")) 37 | stop(mess, call. = FALSE) 38 | } } 39 | } 40 | 41 | if (!is.matrix(PCF$pcf)) 42 | { 43 | id <- match(which, correc2, nomatch = NA) 44 | if(is.na(id)) 45 | { 46 | mess <- paste("Please specify the argument \'which\', among:", paste(dQuote(correc2), 47 | collapse = ", ")) 48 | stop(mess, call. = FALSE) 49 | } 50 | else PCF$pcf=PCF$pcf[[id]] 51 | } 52 | 53 | 54 | k=PCF$pcf 55 | K=PCF 56 | 57 | if(!is.null(main)) {titl=main; subtitl=""} 58 | else { 59 | titl <- expression(hat(g)* group("(",list(u,v),")") ) 60 | subtitl <- paste("edge correction method: ",which,sep="") 61 | } 62 | 63 | 64 | typeplot=c("contour","image","persp") 65 | id <- match(type, typeplot, nomatch = NA) 66 | if (any(nbg <- is.na(id))) { 67 | mess <- paste("unrecognised plot type:", paste(dQuote(type[nbg]), 68 | collapse = ", ")) 69 | stop(mess, call. = FALSE) 70 | } 71 | if((length(id)!=1)||is.na(id)) stop("Please specify one type among \"contour\", \"image\" and \"persp\" ") 72 | typeplot=rep(0,3) 73 | typeplot[id]=1 74 | 75 | colo <- colorRampPalette(c("red", "white", "blue")) 76 | M <- max(abs(range(k))) 77 | M <- pretty(c(-M,M),n=n) 78 | 79 | if (max(M)>15) M <- c(-max(M),-10, pretty(c(-5,5),n=n), 10, max(M)) 80 | else if (max(M)>10 & max(M)<15) M <- c(-15,-10, pretty(c(-5,5),n=n), 10, 15) 81 | 82 | n <- length(M) 83 | COL <- colo(n) 84 | if (typeplot[3]==1) 85 | { 86 | mask <- matrix(0,ncol=length(K$times),nrow=length(K$dist)) 87 | for(i in 1:length(K$dist)){ for(j in 1:length(K$times)){mask[i,j] <- COL[findInterval(x=k[i,j],vec=M)]}} 88 | COL <- mask[1:(length(K$dist)-1),1:(length(K$times)-1)] 89 | 90 | if(isTRUE(legend)) 91 | { 92 | par(cex.lab=2,cex.axis=1.5,font=2,lwd=1,mar=c(0,0,3,0)) 93 | par(fig=c(0,0.825,0,1)) 94 | persp(x=K$dist, y=K$times, z=k, xlab="u",ylab="v", zlab="",expand=1, col=COL, ...) 95 | title(titl,cex.main=1.5,sub=subtitl,outer=TRUE,line=-1) 96 | par(fig=c(0.825,1,0,1)) 97 | mini <- findInterval(x=min(k,na.rm=TRUE),vec=M) 98 | maxi <- findInterval(x=max(k,na.rm=TRUE),vec=M) 99 | legend("right",fill=colo(n)[maxi:mini],legend=M[maxi:mini],horiz=F,bty="n") 100 | } 101 | else 102 | { 103 | par(cex.lab=2,cex.axis=1.5,font=2,lwd=1) 104 | persp(x=K$dist, y=K$times, z=k, xlab="u",ylab="v", zlab="", expand=1, col=COL, ...) 105 | title(titl,cex.main=1.5,sub=subtitl) 106 | } 107 | } 108 | if(typeplot[1]==1) 109 | { 110 | if(isTRUE(legend)) 111 | { 112 | par(cex.lab=1.5,cex.axis=1.5,font=2,plt=c(0,1,0,1),lwd=1,mar=c(0.5,0.5,2.5,0.5),las=1) 113 | par(fig=c(0.1,0.825,0.1,1)) 114 | contour(K$dist, K$times, k, labcex=1.5,levels=M,drawlabels=F,col=colo(n),zlim=range(M),axes=F) 115 | box(lwd=2) 116 | at <- axTicks(1) 117 | axis(1,at=at[1:length(at)],labels=at[1:length(at)]) 118 | at <- axTicks(2) 119 | axis(2,at=at[1:length(at)],labels=at[1:length(at)]) 120 | title(titl,cex.main=1.5,sub=subtitl,outer=TRUE,line=-1) 121 | par(fig=c(0,1,0.1,1)) 122 | mini <- findInterval(x=min(k,na.rm=TRUE),vec=M) 123 | maxi <- findInterval(x=max(k,na.rm=TRUE),vec=M) 124 | legend("right",fill=colo(n)[maxi:mini],legend=M[maxi:mini],horiz=F,bty="n") 125 | } 126 | else 127 | { 128 | par(cex.lab=2,cex.axis=1.5,font=2,lwd=2,las=1) 129 | contour(K$dist, K$times, k, labcex=1.5,levels=M,drawlabels=T,col=colo(n),zlim=range(M),axes=F) 130 | box(lwd=2) 131 | at <- axTicks(1) 132 | axis(1,at=at[1:length(at)],labels=at[1:length(at)]) 133 | at <- axTicks(2) 134 | axis(2,at=at[1:length(at)],labels=at[1:length(at)]) 135 | title(titl,cex.main=1.5,sub=subtitl) 136 | } 137 | } 138 | if(typeplot[2]==1) 139 | { 140 | if(isTRUE(legend)) 141 | { 142 | par(cex.lab=1.5,cex.axis=1.5,font=2,lwd=1,plt=c(0,1,0,1),mar=c(0.5,0.5,2.5,0.5),las=1) 143 | par(fig=c(0.1,0.825,0.1,1)) 144 | image(K$dist, K$times, k, col=colo(n),zlim=range(M),axes=F,xlab="",ylab="") 145 | box(lwd=2) 146 | at <- axTicks(1) 147 | axis(1,at=at[1:length(at)],labels=at[1:length(at)]) 148 | at <- axTicks(2) 149 | axis(2,at=at[1:length(at)],labels=at[1:length(at)]) 150 | title(titl,cex.main=1.5,sub=subtitl,outer=TRUE,line=-1) 151 | par(fig=c(0,1,0.1,1)) 152 | mini <- findInterval(x=min(k,na.rm=TRUE),vec=M) 153 | maxi <- findInterval(x=max(k,na.rm=TRUE),vec=M) 154 | legend("right",fill=colo(n)[maxi:mini],legend=M[maxi:mini],horiz=F,bty="n") 155 | } 156 | else 157 | { 158 | par(cex.lab=2,cex.axis=1.5,font=2,lwd=2,las=1) 159 | image(K$dist, K$times, k, col=colo(n),zlim=range(M),axes=F,xlab="",ylab="") 160 | box(lwd=2) 161 | at <- axTicks(1) 162 | axis(1,at=at[1:length(at)],labels=at[1:length(at)]) 163 | at <- axTicks(2) 164 | axis(2,at=at[1:length(at)],labels=at[1:length(at)]) 165 | title(titl,cex.main=1.5,sub=subtitl) 166 | } 167 | } 168 | 169 | par(old.par) 170 | } 171 | 172 | -------------------------------------------------------------------------------- /R/sim.stpp.R: -------------------------------------------------------------------------------- 1 | sim.stpp <- function(class="poisson", s.region, t.region, npoints=NULL, nsim=1, ...) 2 | { 3 | 4 | if (sum(class==c("poisson","cluster","cox","infectious","inhibition"))==0) 5 | stop("class must be chosen among \"poisson\", \"cluster\", \"cox\", \"inhibition\", \"infectious\" ") 6 | 7 | if (class=="poisson") res=rpp(s.region=s.region, t.region=t.region, npoints=npoints, nsim=nsim, ...) 8 | if (class=="cluster") res=rpcp(s.region=s.region, t.region=t.region, npoints=npoints, nsim=nsim, ...) 9 | if (class=="cox") res=rlgcp(s.region=s.region, t.region=t.region, npoints=npoints, nsim=nsim, ...) 10 | if (class=="infectious") res=rinfec(s.region=s.region, t.region=t.region, npoints=npoints, nsim=nsim, ...) 11 | if (class=="inhibition") res=rinter(s.region=s.region, t.region=t.region, npoints=npoints, nsim=nsim, ...) 12 | 13 | invisible(return(res)) 14 | } 15 | 16 | -------------------------------------------------------------------------------- /R/stdcpp.R: -------------------------------------------------------------------------------- 1 | stdcpp <- function(lambp, a, b, c, mu, s.region, t.region){ 2 | 3 | if (missing(s.region)) s.region <- matrix(c(1,1,0,0,0,1,1,0),ncol=2) 4 | 5 | xp <- s.region[,1] 6 | yp <- s.region[,2] 7 | nedges <- length(xp) 8 | yp <- yp - min(yp) 9 | nxt <- c(2:nedges, 1) 10 | dx <- xp[nxt] - xp 11 | ym <- (yp + yp[nxt])/2 12 | Areaxy <- -sum(dx * ym) 13 | 14 | if (Areaxy > 0){ 15 | bsw <- owin(poly = list(x = s.region[,1], y = s.region[,2])) 16 | }else{ 17 | bsw <- owin(poly=list(x=s.region[,1][length(s.region[,1]):1],y=s.region[,2][length(s.region[,1]):1])) 18 | } 19 | 20 | if (missing(t.region)) t.region <- c(0,1) 21 | 22 | stPoip <- rpp(lambda=lambp,s.region,t.region)$xyt 23 | stmc <- do.call(rbind, sapply(seq(1,length(stPoip[,1])), function(i) .PoiSph(a,b,c,mu=mu,centre=stPoip[i,]))) 24 | 25 | ok <- inside.owin(stmc[,1],stmc[,2],w=bsw) 26 | insw <- data.frame(x=stmc[,1][ok],y=stmc[,2][ok],t=stmc[,3][ok]) 27 | stc3 <- .intim(insw,t.region) 28 | stc3 <- as.3dpoints(stc3) 29 | 30 | invisible(return(list(xyt=stc3,s.region=s.region,t.region=t.region))) 31 | } 32 | 33 | .PoiSph <- function(a,b,c,mu,centre){ 34 | n <- rpois(1,mu) 35 | 36 | if (a==b & b==c){ 37 | r <- a*((runif(n))^(1/3)) 38 | 39 | theta <- 2 * pi * runif(n) 40 | phi <- acos(2 * runif(n)-1) 41 | 42 | xr <- r * cos(theta)* sin(phi) + centre[1] 43 | yr <- r * sin(theta)* sin(phi) + centre[2] 44 | zr <- r * cos(phi) + centre[3] 45 | } 46 | else{ 47 | a0 <- a*(runif(n)^(1/3)) 48 | b0 <- b*(runif(n)^(1/3)) 49 | c0 <- c*(runif(n)^(1/3)) 50 | 51 | theta <- 2 * pi * runif(n) 52 | phi <- acos(2 * runif(n)-1) 53 | 54 | x0 <- a0 * cos(theta) * sin(phi) 55 | y0 <- b0 * sin(theta) * sin(phi) 56 | z0 <- c0 * cos(phi) 57 | 58 | aa <- 2*pi*runif(1) 59 | ab <- 2*pi*runif(1) 60 | ac <- 2*pi*runif(1) 61 | 62 | xr <- (z0*(sin(aa)*sin(ac)+cos(aa)*cos(ac)*sin(ab))-y0*(cos(aa)*sin(ac)-cos(ac)*sin(aa)*sin(ab))+x0*(cos(ac)*cos(ab))) + centre[1] 63 | yr <- (y0*(cos(aa)*cos(ac)+sin(aa)*sin(ac)*sin(ab))-z0*(cos(ac)*sin(aa)-cos(aa)*sin(ac)*sin(ab))+x0*(cos(ab)*sin(ac))) + centre[2] 64 | zr <- (z0*(cos(aa)*cos(ab))-x0*(sin(ab))+y0*(cos(ab)*sin(aa))) + centre[3]} 65 | 66 | invisible(return(cbind(xr,yr,zr))) 67 | } 68 | -------------------------------------------------------------------------------- /R/sthpcpp.R: -------------------------------------------------------------------------------- 1 | sthpcpp <- function(lambp, r, mu, s.region, t.region){ 2 | 3 | if (missing(s.region)) s.region <- matrix(c(1,1,0,0,0,1,1,0),ncol=2) 4 | 5 | xp <- s.region[,1] 6 | yp <- s.region[,2] 7 | nedges <- length(xp) 8 | yp <- yp - min(yp) 9 | nxt <- c(2:nedges, 1) 10 | dx <- xp[nxt] - xp 11 | ym <- (yp + yp[nxt])/2 12 | Areaxy <- -sum(dx * ym) 13 | 14 | if (Areaxy > 0){ 15 | bsw <- owin(poly = list(x = s.region[,1], y = s.region[,2])) 16 | }else{ 17 | bsw <- owin(poly = list(x = s.region[,1][length(s.region[,1]):1], y = s.region[,2][length(s.region[,1]):1])) 18 | } 19 | 20 | if (missing(t.region)) {t.region <- c(0,1)} 21 | 22 | spp <- rMatClust(lambp, r, mu, win=bsw) 23 | tpp <- runif(spp$n,t.region[1],t.region[2]) 24 | 25 | stc1 <- cbind(spp$x,spp$y,tpp) 26 | stc1 <- as.3dpoints(stc1) 27 | 28 | invisible(return(list(xyt=stc1,s.region=s.region,t.region=t.region))) 29 | } 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # stpp: Space-Time Point Pattern Simulation, Visualisation and Analysis 2 | 3 | Many of the models encountered in applications of point process methods to the study of spatio-temporal phenomena are covered in 'stpp'. This package provides statistical tools for analyzing the global and local second-order properties of spatio-temporal point processes, including estimators of the space-time inhomogeneous K-function and pair correlation function. It also includes tools to get static and dynamic display of spatio-temporal point patterns. 4 | 5 | ## This is the development version 6 | 7 | **Installation guide** 8 | 9 | The easiest way to install the development version of `stpp` from GitHub is using the `devtools` package which can be installed run the next command: 10 | ``` 11 | install.packages('devtools') 12 | ``` 13 | and thereafter run the commands: 14 | ``` 15 | require(devtools) 16 | install_github('stpp-GitHub-community/stpp') 17 | ``` 18 | Ubuntu users can follow the instructions in this discussion on stackoverflow to avoid complexity in installing some of the packages, particularly [rgdal](https://stackoverflow.com/questions/44382368/rgdal-installation-difficulty-on-ubuntu-16-04-lts) and [rgl](https://stackoverflow.com/questions/31820865/error-in-installing-rgl-package). 19 | 20 | ## References 21 | 22 | - [Gabriel E., Rowlingson B., Diggle P. (2013). stpp: an R package for plotting, simulating and analyzing Spatio-Temporal Point Patterns. *Journal of Statistical Software*, **53**(2), 1-29.](https://www.jstatsoft.org/htaccess.php?volume=053&type=i&issue=02&filename=paper) 23 | - [González, J. A., Rodríguez-Cortés, F. J., Cronie, O. and Mateu, J. (2016). Spatio-temporal point process statistics: a review. *Spatial Statiscts*, **18**:505-544.](https://www.sciencedirect.com/science/article/pii/S2211675316301130) 24 | 25 | ## CiteBibtex 26 | 27 | A BibTeX entry for LaTeX users is 28 | 29 | ``` 30 | @misc{gdrrc02, 31 | author = {Edith Gabriel and Peter J. Diggle and Barry Rowlingson and Francisco J. Rodr\'iguez-Cort\'es}, 32 | title = {stpp: Space-Time Point Pattern Simulation, Visualisation and Analysis}, 33 | year = {2022}, 34 | note = {R package version 2.0-7}, 35 | url = {https://cran.r-project.org/web/packages/stpp}} 36 | ``` 37 | ### Autors: 38 | 39 | [Edith Gabriel, Avignon University, Avignon, France](https://biosp.mathnum.inrae.fr/homepage-edith-gabriel/) 40 | 41 | [Peter J. Diggle, Lancaster University, Lancaster, UK](https://www.lancaster.ac.uk/staff/diggle/) 42 | 43 | [Barry Rowlingson, Lancaster University, Lancaster, UK](http://barry.rowlingson.com/) 44 | 45 | [Francisco J. Rodríguez-Cortés, National University of Colombia, Medellín, Colombia](https://fjrodriguezcortes.wordpress.com/) 46 | -------------------------------------------------------------------------------- /data/northcumbria.R: -------------------------------------------------------------------------------- 1 | northcumbria <- 2 | structure(c(346618.656524861, 340011.691269045, 338487.006979241, 3 | 332896.497916628, 332896.497916628, 333658.84006153, 330609.471481922, 4 | 328576.559095517, 326543.646709113, 325273.076467609, 315362.628583885, 5 | 305452.180700161, 306722.750941665, 301894.584023953, 297574.645202842, 6 | 295541.732816438, 294017.048526634, 293762.934478333, 306976.864989965, 7 | 306722.750941665, 312567.374052579, 320190.795501597, 319682.567404996, 8 | 321207.2516948, 320190.795501597, 321461.3657431, 324510.734322708, 9 | 327814.216950616, 328068.330998916, 325273.076467609, 325527.19051591, 10 | 328068.330998916, 334421.182206432, 339249.349124143, 340774.033413947, 11 | 342298.717703751, 347380.998669763, 365423.096099106, 373808.859693027, 12 | 375587.658031131, 381178.167093745, 380669.938997143, 383973.421625051, 13 | 388547.474494462, 389818.044735965, 389563.930687665, 386514.562108057, 14 | 386514.562108057, 379907.596852241, 381432.281142045, 381432.281142045, 15 | 377874.684465837, 380669.938997143, 379653.482803941, 373046.517548125, 16 | 369743.034920217, 366185.438244008, 363390.183712702, 362881.9556161, 17 | 364914.868002505, 364152.525857603, 362119.613471198, 363898.411809303, 18 | 363898.411809303, 369234.806823616, 368472.464678714, 365423.096099106, 19 | 361611.385374597, 357291.446553487, 357291.446553487, 356274.990360284, 20 | 583056.7468651, 575941.553512683, 573908.641126278, 574162.755174579, 21 | 573400.413029677, 571621.614691573, 566031.105628959, 565776.991580659, 22 | 563744.079194254, 564760.535387456, 563998.193242554, 549005.464392818, 23 | 541636.1569921, 537062.104122689, 529692.796721971, 516732.98025864, 24 | 515208.295968836, 512921.269534131, 492846.259718382, 488780.434945572, 25 | 475312.39038564, 477599.416820345, 481157.013496554, 482173.469689756, 26 | 493100.373766683, 495133.286153088, 501740.251408904, 502248.479505505, 27 | 502756.707602106, 505043.734036812, 507838.988568119, 508347.21666472, 28 | 511650.699292628, 508093.102616419, 507838.988568119, 510380.129051125, 29 | 509109.558809622, 497674.426636094, 497420.312587793, 495895.62829799, 30 | 498436.768780996, 504281.39189191, 506060.190230014, 506314.304278315, 31 | 507584.874519818, 515716.524065438, 515462.410017137, 518257.664548444, 32 | 526389.314094063, 529184.56862537, 530709.252915174, 533250.39339818, 33 | 542144.385088701, 545193.753668309, 550784.262730922, 549005.464392818, 34 | 546210.209861511, 551292.490827524, 554341.859407131, 559170.026324843, 35 | 563489.965145953, 563744.079194254, 566285.21967726, 569334.588256867, 36 | 572129.842788174, 577466.237802487, 576958.009705886, 581786.176623597, 37 | 586106.115444708, 587376.685686211, 588901.369976014), .Dim = c(71L, 38 | 2L), .Dimnames = list(NULL, c("x", "y"))) 39 | -------------------------------------------------------------------------------- /man/ASTIKhat.Rd: -------------------------------------------------------------------------------- 1 | \name{ASTIKhat} 2 | \alias{ASTIKhat} 3 | \title{Anisotropic Space-Time Inhomogeneous \eqn{K}{K}-function} 4 | \usage{ 5 | ASTIKhat(xyt, s.region, t.region, lambda, dist, times, ang, 6 | correction = "border") 7 | } 8 | \arguments{ 9 | \item{xyt}{Coordinates and times \eqn{(x,y,t)}{(x,y,t)} of the point pattern.} 10 | 11 | \item{s.region}{Two-column matrix specifying polygonal region containing all data locations. If \code{s.region} is missing, the bounding box of \code{xyt[,1:2]} is considered.} 12 | 13 | \item{t.region}{Vector containing the minimum and maximum values of the time interval. If \code{t.region} is missing, the range of \code{xyt[,3]} is considered.} 14 | 15 | \item{dist}{Vector of distances \eqn{u}{u} at which \eqn{\widehat{K}_{\phi}(r,t)}{K_\phi(r,t)} is computed. If missing, the maximum of \code{dist} is given by \eqn{\min(S_x,S_y)/4}{min(S_x, S_y)/4}, where \eqn{S_x}{S_x} and \eqn{S_y}{S_y} represent the maximum width and height of the bounding box of \code{s.region}.} 16 | 17 | \item{times}{Vector of times \eqn{v}{v} at which \eqn{\widehat{K}_{\phi}(r,t)}{K_\phi(r,t)} is computed. If missing, the maximum of \code{times} is given by \eqn{(T_{\max} - T_{\min})/4}{(T_max - T_min)/4}, where \eqn{T_{\min}}{T_min} and \eqn{T_{\max}}{T_max} are the minimum and maximum of the time interval \eqn{T}{T}.} 18 | 19 | \item{lambda}{Vector of values of the space-time intensity function evaluated at the points \eqn{(x,y,t)}{(x,y,t)} in \eqn{S\times T}{S x T}. If \code{lambda} is missing, the estimate of the anisotropic space-time \eqn{K}{K}-function is computed as for the homogeneous case, i.e. considering \eqn{n/|S\times T|}{n/|S x T|} as an estimate of the space-time intensity.} 20 | 21 | \item{ang}{Angle in radians at which \eqn{\widehat{K}_{\phi}(r,t)}{K_\phi(r,t)} is computed. The argument \code{ang=2*pi} by default.} 22 | 23 | \item{correction}{A character vector specifying the edge correction(s) to be applied among "border", "modified.border", "translate" and "none" (see \code{\link{STIKhat}}). The default is "border".} 24 | } 25 | \value{ 26 | A list containing: 27 | 28 | \item{AKhat}{\code{ndist} x \code{ntimes} matrix containing values of \eqn{\widehat{K}_{\phi}(u,t)}{K_\phi(u,v)}.} 29 | \item{dist, times}{Parameters passed in argument.} 30 | \item{correction}{The name(s) of the edge correction method(s) passed in argument.} 31 | } 32 | 33 | \description{ 34 | Compute an estimation of the Anisotropic Space-Time inhomogeneous \eqn{K}{K}-function. 35 | } 36 | 37 | \author{ 38 | Francisco J. Rodriguez-Cortes 39 | } 40 | \references{ 41 | Illian, J. B., Penttinen, A., Stoyan, H. and Stoyan, D. (2008). Statistical Analysis and Modelling of Spatial Point Patterns. John Wiley and Sons, London. 42 | 43 | Gonzalez, J. A., Rodriguez-Cortes, F. J., Cronie, O., Mateu, J. (2016). Spatio-temporal point process statistics: a review. Spatial Statistics. Accepted. 44 | 45 | Ohser, J. and D. Stoyan (1981). On the second-order and orientation analysis of planar stationary point processes. Biometrical Journal 23, 523-533. 46 | } -------------------------------------------------------------------------------- /man/KLISTAhat.Rd: -------------------------------------------------------------------------------- 1 | \name{KLISTAhat} 2 | \alias{KLISTAhat} 3 | 4 | \title{Estimation of the Space-Time Inhomogeneous K LISTA functions} 5 | 6 | \description{Compute an estimate of the space-time K LISTA functions.} 7 | 8 | \usage{ 9 | KLISTAhat(xyt, s.region, t.region, dist, times, lambda, correction = "isotropic") 10 | } 11 | 12 | \arguments{ 13 | \item{xyt}{Coordinates and times \eqn{(x,y,t)}{(x,y,t)} of the point pattern.} 14 | \item{s.region}{Two-column matrix specifying polygonal region containing all data locations. If \code{s.region} is missing, the bounding box of \code{xyt[,1:2]} is considered.} 15 | 16 | \item{t.region}{Vector containing the minimum and maximum values of the time interval. If \code{t.region} is missing, the range of \code{xyt[,3]} is considered.} 17 | 18 | \item{dist}{Vector of distances \eqn{u}{u} at which \eqn{K^{(i)}(u,v)}{K^{(i)}(u,v)} is computed. If missing, the maximum of \code{dist} is given by \eqn{\min(S_x,S_y)/4}{min(S_x, S_y)/4}, where \eqn{S_x}{S_x} and \eqn{S_y}{S_y} represent the maximum width and height of the bounding box of \code{s.region}.} 19 | 20 | \item{times}{Vector of times \eqn{v}{v} at which \eqn{K^{(i)}(u,v)}{K^{(i)}(u,v)} is computed. If missing, the maximum of \code{times} is given by \eqn{(T_{\max} - T_{\min})/4}{(T_max - T_min)/4}, where \eqn{T_{\min}}{T_min} and \eqn{T_{\max}}{T_max} are the minimum and maximum of the time interval \eqn{T}{T}.} 21 | 22 | \item{lambda}{Vector of values of the space-time intensity function evaluated at the points \eqn{(x,y,t)}{(x,y,t)} in \eqn{S\times T}{S x T}. If \code{lambda} is missing, the estimate of the space-time pair correlation function is computed as for the homogeneous case, i.e. considering \eqn{(n-1)/|S \times T|}{(n-1)/|S x T|} as an estimate of the space-time intensity.} 23 | 24 | 25 | \item{correction}{A character vector specifying the edge correction(s) to be applied among \code{"isotropic"}, \code{"border"}, \code{"modified.border"}, \code{"translate"} and \code{"none"} (see \code{\link{PCFhat}}). The default is \code{"isotropic"}. 26 | } 27 | } 28 | 29 | \details{An individual product density LISTA functions \eqn{K^{(i)}(.,.)}{K^{(i)}(.,.)} should reveal the extent of the contribution of the event \eqn{(u_i,t_i)}{(u_i,t_i)} to the global estimator of the K-function \eqn{K(.,.)}{K(.,.)}, and may provide a further description of structure in the data (e.g., determining events with similar local structure through dissimilarity measures of the individual LISTA functions), for more details see Siino et al. (2019).} 30 | 31 | \value{ 32 | A list containing: 33 | 34 | \item{list.KLISTA}{ A list containing the values of the estimation of \eqn{K^{(i)}(r,t)}{K^{(i)}(r,t)} for each one of \eqn{n} points of the point pattern by matrixs.} 35 | 36 | \item{klistatheo}{\code{ndist} x \code{ntimes} matrix containing theoretical values for a Poisson process.} 37 | 38 | \item{dist, times}{Parameters passed in argument.} 39 | 40 | \item{correction}{The name(s) of the edge correction method(s) passed in argument.} 41 | 42 | } 43 | 44 | \references{ 45 | Baddeley, A. and Turner, J. (2005). \code{spatstat}: An R Package for Analyzing Spatial Point Pattens. Journal of Statistical Software 12, 1-42. 46 | 47 | Cressie, N. and Collins, L. B. (2001). Analysis of spatial point patterns using bundles of product density LISA functions. Journal of Agricultural, Biological, and Environmental Statistics 6, 118-135. 48 | 49 | Cressie, N. and Collins, L. B. (2001). Patterns in spatial point locations: Local indicators of spatial association in a minefield with clutter Naval Research Logistics (NRL), John Wiley & Sons, Inc. 48, 333-347. 50 | 51 | Siino, M., Adelfio, G., Mateu, J. and Rodriguez-Cortes, F. J. (2019). Some properties of weighted local second-order statistcs for spatio-temporal point process. Submitted. 52 | 53 | Stoyan, D. and Stoyan, H. (1994). Fractals, random shapes, and point fields: methods of geometrical statistics. Chichester: Wiley. 54 | } 55 | \author{Francisco J. Rodriguez-Cortes } 56 | -------------------------------------------------------------------------------- /man/LISTAhat.Rd: -------------------------------------------------------------------------------- 1 | \name{LISTAhat} 2 | \alias{LISTAhat} 3 | 4 | \title{Estimation of the Space-Time Inhomogeneous Pair Correlation LISTA functions} 5 | 6 | \description{Compute an estimate of the space-time pair correlarion LISTA functions.} 7 | 8 | \usage{ 9 | LISTAhat(xyt, s.region, t.region, dist, times, lambda, 10 | ks = "box", hs, kt = "box", ht, correction = "isotropic") 11 | } 12 | 13 | \arguments{ 14 | \item{xyt}{Coordinates and times \eqn{(x,y,t)}{(x,y,t)} of the point pattern.} 15 | \item{s.region}{Two-column matrix specifying polygonal region containing all data locations. If \code{s.region} is missing, the bounding box of \code{xyt[,1:2]} is considered.} 16 | 17 | \item{t.region}{Vector containing the minimum and maximum values of the time interval. If \code{t.region} is missing, the range of \code{xyt[,3]} is considered.} 18 | 19 | \item{dist}{Vector of distances \eqn{u}{u} at which \eqn{g^{(i)}(u,v)}{g^{(i)}(u,v)} is computed. If missing, the maximum of \code{dist} is given by \eqn{\min(S_x,S_y)/4}{min(S_x, S_y)/4}, where \eqn{S_x}{S_x} and \eqn{S_y}{S_y} represent the maximum width and height of the bounding box of \code{s.region}.} 20 | 21 | \item{times}{Vector of times \eqn{v}{v} at which \eqn{g^{(i)}(u,v)}{g^{(i)}(u,v)} is computed. If missing, the maximum of \code{times} is given by \eqn{(T_{\max} - T_{\min})/4}{(T_max - T_min)/4}, where \eqn{T_{\min}}{T_min} and \eqn{T_{\max}}{T_max} are the minimum and maximum of the time interval \eqn{T}{T}.} 22 | 23 | \item{lambda}{Vector of values of the space-time intensity function evaluated at the points \eqn{(x,y,t)}{(x,y,t)} in \eqn{S\times T}{S x T}. If \code{lambda} is missing, the estimate of the space-time pair correlation function is computed as for the homogeneous case, i.e. considering \eqn{(n-1)/|S \times T|}{(n-1)/|S x T|} as an estimate of the space-time intensity.} 24 | 25 | \item{ks}{Kernel function for the spatial distances. Default is the \code{"box"} kernel. Can also be \code{"epanech"} for the Epanechnikov kernel or \code{"gaussian"} or \code{"biweight"}.} 26 | 27 | \item{hs}{Bandwidth of the kernel function \code{ks}.} 28 | 29 | \item{kt}{Kernel function for the temporal distances. Default is the \code{"box"} kernel. Can also be \code{"epanech"} for the Epanechnikov kernel or \code{"gaussian"} or \code{"biweight"}.} 30 | 31 | \item{ht}{Bandwidth of the kernel function \code{kt}.} 32 | 33 | \item{correction}{A character vector specifying the edge correction(s) to be applied among \code{"isotropic"}, \code{"border"}, \code{"modified.border"}, \code{"translate"} and \code{"none"} (see \code{\link{PCFhat}}). The default is \code{"isotropic"}. 34 | } 35 | } 36 | 37 | \details{An individual product density LISTA functions \eqn{g^{(i)}(.,.)}{g^{(i)}(.,.)} should reveal the extent of the contribution of the event \eqn{(u_i,t_i)}{(u_i,t_i)} to the global estimator of the pair correlation function \eqn{g(.,.)}{g(.,.)}, and may provide a further description of structure in the data (e.g., determining events with similar local structure through dissimilarity measures of the individual LISTA functions), for more details see Siino et al. (2017).} 38 | 39 | \value{ 40 | A list containing: 41 | 42 | \item{list.LISTA}{ A list containing the values of the estimation of \eqn{g^{(i)}(r,t)}{g^{(i)}(r,t)} for each one of \eqn{n} points of the point pattern by matrixs.} 43 | 44 | \item{listatheo}{\code{ndist} x \code{ntimes} matrix containing theoretical values for a Poisson process.} 45 | 46 | \item{dist, times}{Parameters passed in argument.} 47 | 48 | \item{kernel}{Vector of names and bandwidths of the spatial and temporal kernels.} 49 | 50 | \item{correction}{The name(s) of the edge correction method(s) passed in argument.} 51 | 52 | } 53 | 54 | \references{ 55 | Baddeley, A. and Turner, J. (2005). \code{spatstat}: An R Package for Analyzing Spatial Point Pattens. Journal of Statistical Software 12, 1-42. 56 | 57 | Cressie, N. and Collins, L. B. (2001). Analysis of spatial point patterns using bundles of product density LISA functions. Journal of Agricultural, Biological, and Environmental Statistics 6, 118-135. 58 | 59 | Cressie, N. and Collins, L. B. (2001). Patterns in spatial point locations: Local indicators of spatial association in a minefield with clutter Naval Research Logistics (NRL), John Wiley & Sons, Inc. 48, 333-347. 60 | 61 | Siino, M., Rodriguez-Cortes, F. J., Mateu, J. and Adelfio, G. (2017). Testing for local structure in spatio-temporal point pattern data. Environmetrics. DOI: 10.1002/env.2463. 62 | 63 | Stoyan, D. and Stoyan, H. (1994). Fractals, random shapes, and point fields: methods of geometrical statistics. Chichester: Wiley. 64 | } 65 | \author{Francisco J. Rodriguez-Cortes } 66 | -------------------------------------------------------------------------------- /man/animation.Rd: -------------------------------------------------------------------------------- 1 | \name{animation} 2 | \alias{animation} 3 | \title{Space-time data animation} 4 | 5 | \description{ 6 | Provide an animation of spatio-temporal point patterns.} 7 | 8 | \usage{ 9 | animation(xyt, s.region, t.region, runtime=1, incident="red", 10 | prevalent="pink3", pch=19, cex=0.5, plot.s.region=TRUE, 11 | scales=TRUE, border.frac=0.05, add=FALSE) 12 | } 13 | 14 | \arguments{ 15 | \item{xyt}{Data-matrix containing the \eqn{(x,y,t)}{(x,y,t)}-coordinates. } 16 | \item{s.region}{Two-column matrix specifying polygonal region containing 17 | all data-locations \code{xyt[,1:2]}. 18 | If missing, \code{s.region} is the bounding box of \code{xyt[,1:2]}.} 19 | \item{t.region}{Interval containing all data-times \code{xyt[,3]}. 20 | If missing, \code{t.region} is defined by the range of \code{xyt[,3]}.} 21 | \item{runtime}{Approximate running time of animation, in seconds, 22 | but it is longer than expected. Can also be \code{NULL}.} 23 | \item{incident}{Colour in which incident point \code{xyt[i,1:2]} is 24 | plotted at time \code{xyt[i,3]}.} 25 | \item{prevalent}{Colour to which prevalent point \code{xyt[i,1:2]} fades 26 | at time \code{xyt[i+1,3]}.} 27 | \item{pch}{Plotting symbol used for each point.} 28 | \item{cex}{Magnification of plotting symbol relative to standard size.} 29 | \item{plot.s.region}{If \code{TRUE}, plot \code{s.region} as polygon.} 30 | \item{scales}{If \code{TRUE}, plot X and Y axes with scales.} 31 | \item{border.frac}{Extent of border of plotting region surounding 32 | \code{s.region}, as fraction of ranges of X and Y.} 33 | \item{add}{If \code{TRUE}, add the animation to an existing plot.} 34 | } 35 | 36 | \value{ 37 | None 38 | } 39 | 40 | \author{Peter J Diggle, Edith Gabriel .} 41 | -------------------------------------------------------------------------------- /man/as.3dpoint.Rd: -------------------------------------------------------------------------------- 1 | \name{as.3dpoints} 2 | \alias{as.3dpoints} 3 | \title{Create data in spatio-temporal point format} 4 | 5 | \description{ 6 | Create data in spatio-temporal point format.} 7 | 8 | \usage{ 9 | as.3dpoints(...) 10 | } 11 | 12 | \arguments{ 13 | \item{...}{Any object(s), such as \eqn{x}{x}, \eqn{y}{y} and \eqn{t}{t} vectors of the same length, or a list or data frame containing \eqn{x}{x}, \eqn{y}{y} and \eqn{t}{t} vectors. Valid options for \code{...} are: a points object: returns it unaltered; a list with \eqn{x}{x}, \eqn{y}{y} and \eqn{t}{t} elements of the same length: returns a points object with the \eqn{x}{x}, \eqn{y}{y} and \eqn{t}{t} elements as the coordinates of the points; three vectors of equal length: returns a points object with the first vector as the \eqn{x}{x} coordinates, the second vector as the \eqn{y}{y}-coordinates and the third vector as the \eqn{t}{t}-coordinates.} 14 | } 15 | 16 | \value{ 17 | The output is an object of the class \code{stpp}. 18 | as.3dpoints tries to return the argument(s) as a spatio-temporal points object. 19 | } 20 | 21 | \author{Edith Gabriel , Peter Diggle, Barry Rowlingson.} 22 | -------------------------------------------------------------------------------- /man/fmd.Rd: -------------------------------------------------------------------------------- 1 | \name{fmd} 2 | \docType{data} 3 | \alias{fmd} 4 | \title{2001 food-and-mouth epidemic, north Cumbria (UK)} 5 | \description{ 6 | This data set gives the spatial locations and reported times of food-and-mouth 7 | disease in north Cumbria (UK), 2001. It is of no scientific value, as it 8 | deliberately excludes confidential information on farms at risk in the 9 | study-region. It is included in the package purely as an illustrative example. 10 | } 11 | \usage{data(fmd)} 12 | \format{A matrix containing \eqn{(x,y,t)}{(x,y,t)} coordinates of the 648 observations.} 13 | 14 | \references{ 15 | Diggle, P., Rowlingson, B. and Su, T. (2005). Point process methodology 16 | for on-line spatio-temporal disease surveillance. Environmetrics, 16, 423--34. 17 | } 18 | 19 | \seealso{ 20 | \code{\link{northcumbria}} for boundaries of the county of north Cumbria. 21 | } 22 | 23 | \keyword{datasets} 24 | -------------------------------------------------------------------------------- /man/gsp.Rd: -------------------------------------------------------------------------------- 1 | \name{gsp} 2 | \alias{gsp} 3 | %- Also NEED an '\alias' for EACH other topic documented here. 4 | \title{Spatial mark variogram function 5 | %% ~~function to do ... ~~ 6 | } 7 | \description{Computes an estimator of the spatial mark variogram function. 8 | %% ~~ A concise (1-5 lines) description of what the function does. ~~ 9 | } 10 | \usage{ 11 | gsp(xyt,s.region,s.lambda,ds,ks="epanech",hs,correction="none",approach="simplified") 12 | } 13 | %- maybe also 'usage' for other objects documented here. 14 | \arguments{ 15 | \item{xyt}{Spatial coordinates and times \eqn{(x,y,t)} of the point pattern.} 16 | \item{s.region}{Two-column matrix specifying polygonal region containing all data locations. } 17 | \item{s.lambda}{Vector of values of the spatial intensity function evaluated at the points \eqn{(x,y)} in \eqn{W}. If \code{s.lambda} is missing, the estimate of the spatial mark correlation function is computed as for the homogeneous case, i.e. considering \eqn{n/|W|} as an estimate of the spatial intensity under the parameter \code{approach="standardised"}.} 18 | \item{ds}{A vector of distances \code{u} at which \code{gsp(u)} is computed.} 19 | \item{ks}{A kernel function for the spatial distances. The default is the \code{"epanech"} kernel. It can also be \code{"box"} for the uniform kernel, or \code{"biweight"}.} 20 | \item{hs}{A bandwidth of the kernel function \code{ks}.} 21 | \item{correction}{A character vector specifying the edge-correction(s) to be applied among \code{"isotropic"}, \code{"border"}, \code{"modified.border"}, \code{"translate"}, \code{"setcovf"} and \code{"none"}. The default is \code{"none"}.} 22 | \item{approach}{A character vector specifying the approach to use for the estimation to be applied among "simplified" or \code{"standardised"}. If approach is missing, \code{"simplified"} is considered by default.} 23 | %% ~~Describe \code{x} here~~ 24 | } 25 | \details{By default, this command calculates an estimate of the spatial mark variogram function \eqn{\gamma_[sp](r)} for a spatio-temporal point pattern.} 26 | \value{ 27 | %% ~Describe the value returned 28 | %% If it is a LIST, use 29 | \item{egsp}{ A vector containing the values of \eqn{\gamma_{sp}(r)} estimated} 30 | \item{ds}{If \code{ds} is missing, a vector of distances \code{u} at which \code{gsp(u)} is computed from 0 to until quarter of the maximum distance between the points in the pattern.} 31 | \item{kernel}{A vector of names and bandwidth of the spatial kernel.} 32 | \item{gsptheo}{Value under the Poisson case is calculated considering \eqn{\tau}=\code{max(xyt[,3])-min(xyt[,3])}.}} 33 | %% ... 34 | \references{ 35 | %% ~put references to the literature/web site here ~ 36 | Baddeley, A., Rubak, E., Turner, R. (2015). Spatial Point Patterns: Methodology and Applications with R. CRC Press, Boca Raton. 37 | 38 | Chiu, S. N., Stoyan, D., Kendall, W. S., and Mecke, J. (2013). Stochastic Geometry and its Applications. John Wiley & Sons. 39 | 40 | Gabriel, E., Rowlingson, B., Diggle P J. (2013) \code{stpp}: an R package for plotting, simulating and analyzing Spatio-Temporal Point Patterns. Journal of Statistical Software. 53, 1-29. 41 | 42 | Illian, J B., Penttinen, A., Stoyan, H. and Stoyan, D. (2008). Statistical Analysis and Modelling of Spatial Point Patterns. John Wiley and Sons, London. 43 | 44 | Stoyan, D., Rodriguez-Cortes, F. J., Mateu, J., and Gille, W. (2017). Mark variograms for spatio-temporal point processes. Spatial Statistics. 20, 125-147. 45 | } 46 | \author{Francisco J. Rodriguez Cortes \url{https://fjrodriguezcortes.wordpress.com} 47 | %% ~~who you are~~ 48 | } 49 | %\note{ 50 | %% ~~further notes~~ 51 | %} 52 | 53 | %% ~Make other sections like Warning with \section{Warning }{....} ~ 54 | 55 | \examples{ 56 | ## Not run: 57 | ################# 58 | 59 | # A realisation of spatio-temporal homogeneous Poisson point processes 60 | hpp <- rpp(lambda = 100, replace = FALSE)$xyt 61 | 62 | # R plot 63 | plot(hpp) 64 | 65 | # This function provides an kernel estimator of the spatial mark variogram function 66 | out <- gsp(hpp) 67 | 68 | # R plot - Spatial mark variogram function 69 | par(mfrow=c(1,1)) 70 | xl <- c(0,0.25) 71 | yl <- c(0,max(out$gsptheo,out$egsp)) 72 | plot(out$ds,out$egsp,type="l",xlab="r = distance",ylab=expression(gamma[sp](r)), 73 | xlim=xl,ylim=yl,col=1,cex.lab=1.5,cex.axis=1.5) 74 | lines(out$ds,rep(out$gsptheo,length(out$ds)),col=11) 75 | 76 | ## End(Not run) 77 | 78 | } 79 | % Add one or more standard keywords, see file 'KEYWORDS' in the 80 | % R documentation directory. 81 | %\keyword{ ~kwd1 }% use one of RShowDoc("KEYWORDS")% 82 | %\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line 83 | -------------------------------------------------------------------------------- /man/gte.Rd: -------------------------------------------------------------------------------- 1 | \name{gte} 2 | \alias{gte} 3 | %- Also NEED an '\alias' for EACH other topic documented here. 4 | \title{Temporal mark variogram function 5 | %% ~~function to do ... ~~ 6 | } 7 | \description{Computes an estimator of the temporal mark variogram function. 8 | %% ~~ A concise (1-5 lines) description of what the function does. ~~ 9 | } 10 | \usage{ 11 | gte(xyt,t.region,t.lambda,dt,kt="epanech",ht,correction="none",approach="simplified") 12 | } 13 | %- maybe also 'usage' for other objects documented here. 14 | \arguments{ 15 | \item{xyt}{Spatial coordinates and times \eqn{(x,y,t)} of the point pattern.} 16 | \item{t.region}{Vector containing the minimum and maximum values of the time interval.} 17 | \item{t.lambda}{Vector of values of the temporal intensity function evaluated at the points \eqn{t} in \eqn{T}. If \code{t.lambda} is missing, the estimate of the temporal mark correlation function is computed as for the homogeneous case, i.e. considering \eqn{n/|T|} as an estimate of the temporal intensity under the parameter \code{approach="standardised"}.} 18 | \item{dt}{A vector of times \code{v} at which \code{gte(v)} is computed.} 19 | \item{kt}{A kernel function for the temporal distances. The default is the \code{"epanech"} kernel. It can also be \code{"box"} for the uniform kernel, or \code{"biweight"}.} 20 | \item{ht}{A bandwidth of the kernel function \code{kt}.} 21 | \item{correction}{A character vector specifying the edge-correction(s) to be applied among \code{"isotropic"}, \code{"border"}, \code{"modified.border"}, \code{"translate"}, \code{"setcovf"} and \code{"none"}. The default is \code{"none"}.} 22 | \item{approach}{A character vector specifying the approach to use for the estimation to be applied among "simplified" or \code{"standardised"}. If approach is missing, \code{"simplified"} is considered by default.} 23 | %% ~~Describe \code{x} here~~ 24 | } 25 | \details{By default, this command calculates an estimate of the temporal mark variogram function \eqn{\gamma_[te](t)} for a spatio-temporal point pattern. 26 | %% ~~ If necessary, more details than the description above ~~ 27 | } 28 | \value{ 29 | %% ~Describe the value returned 30 | %% If it is a LIST, use 31 | \item{egte}{A vector containing the values of \eqn{\gamma_[te](v)} estimated.} 32 | \item{dt}{Parameter passed in argument. If \code{dt} is missing, a vector of temporal distances \code{v} at which \code{gte(v)} is computed from 0 to until quarter of the maximum distance between the times in the temporal pattern.} 33 | \item{kernel}{Parameters passed in argument. A vector of names and bandwidth of the spatial kernel.} 34 | \item{gtetheo}{Value under the Poisson case is calculated considering the side lengths of the bounding box of \code{xyt[,1:2]}.}} 35 | %% ... 36 | \references{ 37 | %% ~put references to the literature/web site here ~ 38 | Baddeley, A., Rubak, E., Turner, R. (2015). Spatial Point Patterns: Methodology and Applications with R. CRC Press, Boca Raton. 39 | 40 | Chiu, S. N., Stoyan, D., Kendall, W. S., and Mecke, J. (2013). Stochastic Geometry and its Applications. John Wiley & Sons. 41 | 42 | Gabriel, E., Rowlingson, B., Diggle P J. (2013) \code{stpp}: an R package for plotting, simulating and analyzing Spatio-Temporal Point Patterns. Journal of Statistical Software 53, 1-29. 43 | 44 | Illian, J B., Penttinen, A., Stoyan, H. and Stoyan, D. (2008). Statistical Analysis and Modelling of Spatial Point Patterns. John Wiley and Sons, London. 45 | 46 | Stoyan, D., Rodriguez-Cortes, F. J., Mateu, J., and Gille, W. (2017). Mark variograms for spatio-temporal point processes. Spatial Statistics. 20, 125-147. 47 | } 48 | \author{Francisco J. Rodriguez Cortes \url{https://fjrodriguezcortes.wordpress.com} 49 | %% ~~who you are~~ 50 | } 51 | %\note{ 52 | %% ~~further notes~~ 53 | %} 54 | 55 | %% ~Make other sections like Warning with \section{Warning }{....} ~ 56 | 57 | \examples{ 58 | ## Not run: 59 | ################# 60 | 61 | # A realisation of spatio-temporal homogeneous Poisson point processes 62 | hpp <- rpp(lambda = 100, replace = FALSE)$xyt 63 | 64 | # R plot 65 | plot(hpp) 66 | 67 | # This function provides an kernel estimator of the temporal mark variograma function 68 | out <- gte(hpp) 69 | 70 | # R plot - Temporal mark variogram function 71 | par(mfrow=c(1,1)) 72 | xl <- c(0,0.25) 73 | yl <- c(0,max(out$egte,out$gtetheo)) 74 | plot(out$dt,out$egte,type="l",xlab="t = time",ylab=expression(gamma[te](t)), 75 | xlim=xl,ylim=yl,col=1,cex.lab=1.5,cex.axis=1.5) 76 | lines(out$dt,rep(out$gtetheo,length(out$dt)),col=11) 77 | 78 | ## End(Not run) 79 | 80 | } 81 | % Add one or more standard keywords, see file 'KEYWORDS' in the 82 | % R documentation directory. 83 | %\keyword{ ~kwd1 }% use one of RShowDoc("KEYWORDS")% 84 | %\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line 85 | -------------------------------------------------------------------------------- /man/is.3dpoints.Rd: -------------------------------------------------------------------------------- 1 | \name{is.3dpoints} 2 | \alias{is.3dpoints} 3 | \title{Spatio-temporal point objects} 4 | 5 | \description{ 6 | Tests for data in spatio-temporal point format.} 7 | 8 | \usage{ 9 | is.3dpoints(x) 10 | } 11 | 12 | \arguments{ 13 | \item{x}{any object.} 14 | } 15 | 16 | \value{ 17 | is.3dpoints returns TRUE if \code{x} is a spatio-temporal points object, FALSE 18 | otherwise.} 19 | 20 | \author{Edith Gabriel , Peter Diggle, Barry 21 | Rowlingson.} 22 | -------------------------------------------------------------------------------- /man/kmmr.Rd: -------------------------------------------------------------------------------- 1 | \name{kmmr} 2 | \alias{kmmr} 3 | %- Also NEED an '\alias' for EACH other topic documented here. 4 | \title{Spatial mark correlation function 5 | %% ~~function to do ... ~~ 6 | } 7 | \description{Computes an estimator of the spatial mark correlation function. 8 | %% ~~ A concise (1-5 lines) description of what the function does. ~~ 9 | } 10 | \usage{ 11 | kmmr(xyt,s.region,s.lambda,ds,ks="epanech",hs,correction="none",approach="simplified") 12 | } 13 | %- maybe also 'usage' for other objects documented here. 14 | \arguments{ 15 | \item{xyt}{Spatial coordinates and times \eqn{(x,y,t)} of the point pattern.} 16 | \item{s.region}{Two-column matrix specifying polygonal region containing all data locations. } 17 | \item{s.lambda}{Vector of values of the spatial intensity function evaluated at the points \eqn{(x,y)} in \eqn{W}. If \code{s.lambda} is missing, the estimate of the spatial mark correlation function is computed as for the homogeneous case, i.e. considering \eqn{n/|W|} as an estimate of the spatial intensity under the parameter \code{approach="standardised"}.} 18 | \item{ds}{A vector of distances \code{u} at which \code{kmmr(u)} is computed.} 19 | \item{ks}{A kernel function for the spatial distances. The default is the \code{"epanech"} kernel. It can also be \code{"box"} for the uniform kernel, or \code{"biweight"}.} 20 | \item{hs}{A bandwidth of the kernel function \code{ks}.} 21 | \item{correction}{A character vector specifying the edge-correction(s) to be applied among \code{"isotropic"}, \code{"border"}, \code{"modified.border"}, \code{"translate"}, \code{"setcovf"} and \code{"none"}. The default is \code{"none"}.} 22 | \item{approach}{A character vector specifying the approach to use for the estimation to be applied among "simplified" or \code{"standardised"}. If approach is missing, \code{"simplified"} is considered by default.} 23 | %% ~~Describe \code{x} here~~ 24 | } 25 | \details{By default, this command calculates an estimate of the spatial mark correlation function \eqn{k_[mm](r)} for a spatio-temporal point pattern. 26 | %% ~~ If necessary, more details than the description above ~~ 27 | } 28 | \value{ 29 | %% ~Describe the value returned 30 | %% If it is a LIST, use 31 | \item{ekmmr}{A vector containing the values of \eqn{k_[mm](u)} estimated.} 32 | \item{ds}{If \code{ds} is missing, a vector of distances \code{u} at which \code{kmmr(u)} is computed from 0 to until quarter of the maximum distance between the points in the pattern.} 33 | \item{kernel}{A vector of names and bandwidth of the spatial kernel.} 34 | \item{kmmrtheo}{Value under the Poisson case is calculated considering \eqn{\tau}=\code{max(xyt[,3])-min(xyt[,3])}.} 35 | } 36 | %% ... 37 | \references{ 38 | %% ~put references to the literature/web site here ~ 39 | Baddeley, A., Rubak, E., Turner, R. (2015). Spatial Point Patterns: Methodology and Applications with R. CRC Press, Boca Raton. 40 | 41 | Chiu, S. N., Stoyan, D., Kendall, W. S., and Mecke, J. (2013). Stochastic Geometry and its Applications. John Wiley & Sons. 42 | 43 | Gabriel, E., Rowlingson, B., Diggle P J. (2013) \code{stpp}: an R package for plotting, simulating and analyzing Spatio-Temporal Point Patterns. Journal of Statistical Software 53, 1-29. 44 | 45 | Illian, J B., Penttinen, A., Stoyan, H. and Stoyan, D. (2008). Statistical Analysis and Modelling of Spatial Point Patterns. John Wiley and Sons, London. 46 | 47 | Stoyan, D., Rodriguez-Cortes, F. J., Mateu, J. and Wilfried, G. (2016). Mark variograms for spatio-temporal 48 | point processes, Submitted . 49 | } 50 | \author{Francisco J. Rodriguez Cortes \url{https://fjrodriguezcortes.wordpress.com} 51 | %% ~~who you are~~ 52 | } 53 | %\note{ 54 | %% ~~further notes~~ 55 | %} 56 | 57 | %% ~Make other sections like Warning with \section{Warning }{....} ~ 58 | 59 | \examples{ 60 | ## Not run: 61 | ################# 62 | 63 | # A realisation of spatio-temporal homogeneous Poisson point processes 64 | hpp <- rpp(lambda = 100, replace = FALSE)$xyt 65 | 66 | # R plot 67 | plot(hpp) 68 | 69 | # This function provides an kernel estimator of the spatial mark correlation function 70 | out <- kmmr(hpp) 71 | 72 | # R plot - Spatial mark correlation function 73 | par(mfrow=c(1,1)) 74 | xl <- c(0,0.25) 75 | plot(out$ds,out$ekmmr,type="l",xlab="r = distance",ylab=expression(k[mm](r)), 76 | xlim=xl,col=1,cex.lab=1.5,cex.axis=1.5) 77 | lines(out$ds,rep(out$kmmrtheo,length(out$ds)),col=11) 78 | 79 | ## End(Not run) 80 | 81 | } 82 | % Add one or more standard keywords, see file 'KEYWORDS' in the 83 | % R documentation directory. 84 | %\keyword{ ~kwd1 }% use one of RShowDoc("KEYWORDS")% 85 | %\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line 86 | -------------------------------------------------------------------------------- /man/kmmt.Rd: -------------------------------------------------------------------------------- 1 | \name{kmmt} 2 | \alias{kmmt} 3 | %- Also NEED an '\alias' for EACH other topic documented here. 4 | \title{Temporal mark correlation function 5 | %% ~~function to do ... ~~ 6 | } 7 | \description{Computes an estimator of the temporal mark correlation function. 8 | %% ~~ A concise (1-5 lines) description of what the function does. ~~ 9 | } 10 | \usage{ 11 | kmmt(xyt,t.region,t.lambda,dt,kt="epanech",ht,correction="none",approach="simplified") 12 | } 13 | %- maybe also 'usage' for other objects documented here. 14 | \arguments{ 15 | \item{xyt}{Spatial coordinates and times \eqn{(x,y,t)} of the point pattern.} 16 | \item{t.region}{Vector containing the minimum and maximum values of the time interval.} 17 | \item{t.lambda}{Vector of values of the temporal intensity function evaluated at the points \eqn{t} in \eqn{T}. If \code{t.lambda} is missing, the estimate of the temporal mark correlation function is computed as for the homogeneous case, i.e. considering \eqn{n/|T|} as an estimate of the temporal intensity under the parameter \code{approach="standardised"}.} 18 | \item{dt}{A vector of times \code{v} at which \code{kmmt(v)} is computed.} 19 | \item{kt}{A kernel function for the temporal distances. The default is the \code{"epanech"} kernel. It can also be \code{"box"} for the uniform kernel, or \code{"biweight"}.} 20 | \item{ht}{A bandwidth of the kernel function \code{kt}.} 21 | \item{correction}{A character vector specifying the edge-correction(s) to be applied among \code{"isotropic"}, \code{"border"}, \code{"modified.border"}, \code{"translate"}, \code{"setcovf"} and \code{"none"}. The default is \code{"none"}.} 22 | \item{approach}{A character vector specifying the approach to use for the estimation to be applied among "simplified" or \code{"standardised"}. If approach is missing, \code{"simplified"} is considered by default.} 23 | %% ~~Describe \code{x} here~~ 24 | } 25 | \details{By default, this command calculates an estimate of the temporal mark correlation function \eqn{k_[mm](t)} for a spatio-temporal point pattern. 26 | %% ~~ If necessary, more details than the description above ~~ 27 | } 28 | \value{ 29 | %% ~Describe the value returned 30 | %% If it is a LIST, use 31 | \item{ekmmt}{A vector containing the values of \eqn{k_[mm](v)} estimated.} 32 | \item{dt}{Parameter passed in argument. If \code{dt} is missing, a vector of temporal distances \code{v} at which \code{kmmt(v)} is computed from 0 to until quarter of the maximum distance between the times in the temporal pattern.} 33 | \item{kernel}{Parameters passed in argument. A vector of names and bandwidth of the spatial kernel.} 34 | \item{kmmttheo}{Value under the Poisson case is calculated considering the side lengths of the bounding box of \code{xyt[,1:2]}.}} 35 | 36 | %% ... 37 | \references{ 38 | %% ~put references to the literature/web site here ~ 39 | Baddeley, A., Rubak, E., Turner, R. (2015). Spatial Point Patterns: Methodology and Applications with R. CRC Press, Boca Raton. 40 | 41 | Chiu, S. N., Stoyan, D., Kendall, W. S., and Mecke, J. (2013). Stochastic Geometry and its Applications. John Wiley & Sons. 42 | 43 | Gabriel, E., Rowlingson, B., Diggle P J. (2013) \code{stpp}: an R package for plotting, simulating and analyzing Spatio-Temporal Point Patterns. Journal of Statistical Software 53, 1-29. 44 | 45 | Illian, J B., Penttinen, A., Stoyan, H. and Stoyan, D. (2008). Statistical Analysis and Modelling of Spatial Point Patterns. John Wiley and Sons, London. 46 | 47 | Stoyan, D., Rodriguez-Cortes, F. J., Mateu, J. and Wilfried, G. (2016). Mark variograms for spatio-temporal 48 | point processes, Submitted . 49 | } 50 | \author{Francisco J. Rodriguez Cortes \url{https://fjrodriguezcortes.wordpress.com} 51 | %% ~~who you are~~ 52 | } 53 | %\note{ 54 | %% ~~further notes~~ 55 | %} 56 | 57 | %% ~Make other sections like Warning with \section{Warning }{....} ~ 58 | 59 | \examples{ 60 | ## Not run: 61 | ################# 62 | 63 | # A realisation of spatio-temporal homogeneous Poisson point processes 64 | hpp <- rpp(lambda = 100, replace = FALSE)$xyt 65 | 66 | # R plot 67 | plot(hpp) 68 | 69 | # This function provides an kernel estimator of the temporal mark correlation function 70 | out <- kmmt(hpp) 71 | 72 | # R plot - Temporal mark correlation function 73 | par(mfrow=c(1,1)) 74 | xl <- c(0,0.25) 75 | plot(out$dt,out$ekmmt,type="l",xlab="t = time",ylab=expression(k[mm](t)), 76 | xlim=xl,col=1,cex.lab=1.5,cex.axis=1.5) 77 | lines(out$dt,rep(out$kmmttheo,length(out$dt)),col=11) 78 | 79 | ## End(Not run) 80 | 81 | } 82 | % Add one or more standard keywords, see file 'KEYWORDS' in the 83 | % R documentation directory. 84 | %\keyword{ ~kwd1 }% use one of RShowDoc("KEYWORDS")% 85 | %\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line 86 | -------------------------------------------------------------------------------- /man/kmr.Rd: -------------------------------------------------------------------------------- 1 | \name{kmr} 2 | \alias{kmr} 3 | %- Also NEED an '\alias' for EACH other topic documented here. 4 | \title{Spatial \eqn{r}-mark function 5 | %% ~~function to do ... ~~ 6 | } 7 | \description{Computes an estimator of the spatial \eqn{r}-mark function. 8 | %% ~~ A concise (1-5 lines) description of what the function does. ~~ 9 | } 10 | \usage{ 11 | kmr(xyt,s.region,s.lambda,ds,ks="epanech",hs,correction="none",approach="simplified") 12 | } 13 | %- maybe also 'usage' for other objects documented here. 14 | \arguments{ 15 | \item{xyt}{Spatial coordinates and times \eqn{(x,y,t)} of the point pattern.} 16 | \item{s.region}{Two-column matrix specifying polygonal region containing all data locations. } 17 | \item{s.lambda}{Vector of values of the spatial intensity function evaluated at the points \eqn{(x,y)} in \eqn{W}. If \code{s.lambda} is missing, the estimate of the spatial mark correlation function is computed as for the homogeneous case, i.e. considering \eqn{n/|W|} as an estimate of the spatial intensity under the parameter \code{approach="standardised"}.} 18 | \item{ds}{A vector of distances \code{u} at which \code{kmr(u)} is computed.} 19 | \item{ks}{A kernel function for the spatial distances. The default is the \code{"epanech"} kernel. It can also be \code{"box"} for the uniform kernel, or \code{"biweight"}.} 20 | \item{hs}{A bandwidth of the kernel function \code{ks}.} 21 | \item{correction}{A character vector specifying the edge-correction(s) to be applied among \code{"isotropic"}, \code{"border"}, \code{"modified.border"}, \code{"translate"}, \code{"setcovf"} and \code{"none"}. The default is \code{"none"}.} 22 | \item{approach}{A character vector specifying the approach to use for the estimation to be applied among "simplified" or \code{"standardised"}. If approach is missing, \code{"simplified"} is considered by default.} 23 | %% ~~Describe \code{x} here~~ 24 | } 25 | \details{By default, this command calculates an estimate of the spatial \eqn{r}-mark function \eqn{k_[m.](r)} for a spatio-temporal point pattern. 26 | %% ~~ If necessary, more details than the description above ~~ 27 | } 28 | \value{ 29 | %% ~Describe the value returned 30 | %% If it is a LIST, use 31 | \item{ekmr}{A vector containing the values of \eqn{k_[m.](u)} estimated.} 32 | \item{ds}{If \code{ds} is missing, a vector of distances \code{u} at which \code{kmr(u)} is computed from 0 to until quarter of the maximum distance between the points in the pattern.} 33 | \item{kernel}{A vector of names and bandwidth of the spatial kernel.} 34 | \item{kmrtheo}{Value under the Poisson case is calculated considering \eqn{\tau}=\code{max(xyt[,3])-min(xyt[,3])}.}} 35 | 36 | %% ... 37 | \references{ 38 | %% ~put references to the literature/web site here ~ 39 | Baddeley, A., Rubak, E., Turner, R. (2015). Spatial Point Patterns: Methodology and Applications with R. CRC Press, Boca Raton. 40 | 41 | Chiu, S. N., Stoyan, D., Kendall, W. S., and Mecke, J. (2013). Stochastic Geometry and its Applications. John Wiley & Sons. 42 | 43 | Gabriel, E., Rowlingson, B., Diggle P J. (2013) \code{stpp}: an R package for plotting, simulating and analyzing Spatio-Temporal Point Patterns. Journal of Statistical Software 53, 1-29. 44 | 45 | Illian, J B., Penttinen, A., Stoyan, H. and Stoyan, D. (2008). Statistical Analysis and Modelling of Spatial Point Patterns. John Wiley and Sons, London. 46 | 47 | Stoyan, D., Rodriguez-Cortes, F. J., Mateu, J. and Wilfried, G. (2016). Mark variograms for spatio-temporal 48 | point processes, Submitted . 49 | } 50 | \author{Francisco J. Rodriguez Cortes \url{https://fjrodriguezcortes.wordpress.com} 51 | %% ~~who you are~~ 52 | } 53 | %\note{ 54 | %% ~~further notes~~ 55 | %} 56 | 57 | %% ~Make other sections like Warning with \section{Warning }{....} ~ 58 | 59 | \examples{ 60 | ## Not run: 61 | ################# 62 | 63 | # A realisation of spatio-temporal homogeneous Poisson point processes 64 | hpp <- rpp(lambda = 100, replace = FALSE)$xyt 65 | 66 | # R plot 67 | plot(hpp) 68 | 69 | # This function provides an kernel estimator of the spatial r-mark function 70 | out <- kmr(hpp) 71 | 72 | # R plot - Spatial r-mark function 73 | par(mfrow=c(1,1)) 74 | xl <- c(0,0.25) 75 | plot(out$ds,out$ekmr,type="l",xlab="r = distance",ylab=expression(k[m.](r)), 76 | xlim=xl,col=1,cex.lab=1.5,cex.axis=1.5) 77 | lines(out$ds,rep(out$kmrtheo,length(out$ds)),col=11) 78 | 79 | ## End(Not run) 80 | } 81 | % Add one or more standard keywords, see file 'KEYWORDS' in the 82 | % R documentation directory. 83 | %\keyword{ ~kwd1 }% use one of RShowDoc("KEYWORDS")% 84 | %\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line 85 | -------------------------------------------------------------------------------- /man/kmt.Rd: -------------------------------------------------------------------------------- 1 | \name{kmt} 2 | \alias{kmt} 3 | %- Also NEED an '\alias' for EACH other topic documented here. 4 | \title{Temporal \eqn{t}-mark function 5 | %% ~~function to do ... ~~ 6 | } 7 | \description{Computes an estimator of the temporal \eqn{t}-mark function. 8 | %% ~~ A concise (1-5 lines) description of what the function does. ~~ 9 | } 10 | \usage{kmt(xyt,t.region,t.lambda,dt,kt="epanech",ht,correction="none",approach="simplified")} 11 | %- maybe also 'usage' for other objects documented here. 12 | \arguments{ 13 | \item{xyt}{Spatial coordinates and times \eqn{(x,y,t)} of the point pattern.} 14 | \item{t.region}{Vector containing the minimum and maximum values of the time interval.} 15 | \item{t.lambda}{Vector of values of the temporal intensity function evaluated at the points \eqn{t} in \eqn{T}. If \code{t.lambda} is missing, the estimate of the temporal mark correlation function is computed as for the homogeneous case, i.e. considering \eqn{n/|T|} as an estimate of the temporal intensity under the parameter \code{approach="standardised"}.} 16 | \item{dt}{A vector of times \code{v} at which \code{kmt(v)} is computed.} 17 | \item{kt}{A kernel function for the temporal distances. The default is the \code{"epanech"} kernel. It can also be \code{"box"} for the uniform kernel, or \code{"biweight"}.} 18 | \item{ht}{A bandwidth of the kernel function \code{kt}.} 19 | \item{correction}{A character vector specifying the edge-correction(s) to be applied among \code{"isotropic"}, \code{"border"}, \code{"modified.border"}, \code{"translate"}, \code{"setcovf"} and \code{"none"}. The default is \code{"none"}.} 20 | \item{approach}{A character vector specifying the approach to use for the estimation to be applied among "simplified" or \code{"standardised"}. If approach is missing, \code{"simplified"} is considered by default.} 21 | %% ~~Describe \code{x} here~~ 22 | } 23 | \details{By default, this command calculates an estimate of the temporal \eqn{t}-mark function \eqn{k_[m.](t)} for a spatio-temporal point pattern. 24 | %% ~~ If necessary, more details than the description above ~~ 25 | } 26 | \value{ 27 | %% ~Describe the value returned 28 | %% If it is a LIST, use 29 | \item{ekmt}{A vector containing the values of \eqn{k_[m.](v)} estimated.} 30 | \item{dt}{Parameter passed in argument. If \code{dt} is missing, a vector of temporal distances \code{v} at which \code{kmt(v)} is computed from 0 to until quarter of the maximum distance between the times in the temporal pattern.} 31 | \item{kernel}{Parameters passed in argument. A vector of names and bandwidth of the spatial kernel.} 32 | \item{kmttheo}{Value under the Poisson case is calculated considering the side lengths of the bounding box of \code{xyt[,1:2]}.} 33 | } 34 | %% ... 35 | \references{ 36 | %% ~put references to the literature/web site here ~ 37 | Baddeley, A., Rubak, E., Turner, R. (2015). Spatial Point Patterns: Methodology and Applications with R. CRC Press, Boca Raton. 38 | 39 | Chiu, S. N., Stoyan, D., Kendall, W. S., and Mecke, J. (2013). Stochastic Geometry and its Applications. John Wiley & Sons. 40 | 41 | Gabriel, E., Rowlingson, B., Diggle P J. (2013) \code{stpp}: an R package for plotting, simulating and analyzing Spatio-Temporal Point Patterns. Journal of Statistical Software 53, 1-29. 42 | 43 | Illian, J B., Penttinen, A., Stoyan, H. and Stoyan, D. (2008). Statistical Analysis and Modelling of Spatial Point Patterns. John Wiley and Sons, London. 44 | 45 | Stoyan, D., Rodriguez-Cortes, F. J., Mateu, J. and Wilfried, G. (2016). Mark variograms for spatio-temporal 46 | point processes, Submitted . 47 | } 48 | \author{Francisco J. Rodriguez Cortes \url{https://fjrodriguezcortes.wordpress.com} 49 | %% ~~who you are~~ 50 | } 51 | %\note{ 52 | %% ~~further notes~~ 53 | %} 54 | 55 | %% ~Make other sections like Warning with \section{Warning }{....} ~ 56 | 57 | \examples{ 58 | ## Not run: 59 | ################# 60 | 61 | # A realisation of spatio-temporal homogeneous Poisson point processes 62 | hpp <- rpp(lambda = 100, replace = FALSE)$xyt 63 | 64 | # R plot 65 | plot(hpp) 66 | 67 | # This function provides an kernel estimator of the temporal t-mark function 68 | out <- kmt(hpp) 69 | 70 | # R plot - Temporal t-mark function 71 | par(mfrow=c(1,1)) 72 | xl <- c(0,0.25) 73 | plot(out$dt,out$ekmt,type="l",xlab="t = time",ylab=expression(k[m.](t)), 74 | xlim=xl,col=1,cex.lab=1.5,cex.axis=1.5) 75 | lines(out$dt,rep(out$kmttheo,length(out$dt)),col=11) 76 | 77 | ## End(Not run) 78 | 79 | } 80 | % Add one or more standard keywords, see file 'KEYWORDS' in the 81 | % R documentation directory. 82 | %\keyword{ ~kwd1 }% use one of RShowDoc("KEYWORDS")% 83 | %\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line 84 | -------------------------------------------------------------------------------- /man/northcumbria.Rd: -------------------------------------------------------------------------------- 1 | \name{northcumbria} 2 | \docType{data} 3 | \alias{northcumbria} 4 | \title{Polygon boundary of north Cumbria} 5 | \description{ 6 | This data set gives the boundary of the county of north Cumbria (UK). 7 | } 8 | \usage{data(northcumbria)} 9 | \format{A matrix containing \eqn{(x,y)}{(x,y)} coordinates of the boundary.} 10 | \seealso{ 11 | \code{\link{fmd}} for the space-time pattern of food-and-mouth disease in this county in 2001. 12 | } 13 | 14 | \keyword{datasets} -------------------------------------------------------------------------------- /man/plot.stpp.Rd: -------------------------------------------------------------------------------- 1 | \name{plot.stpp} 2 | \alias{plot.stpp} 3 | \alias{plot} 4 | 5 | \title{Plot for spatio-temporal point objects} 6 | 7 | \description{ 8 | This function plot either \eqn{xy}{xy}-locations and cumulative distribution of the times, or a space-time 3D scatter, or the time-mark and space-mark of the spatio-temporal point pattern, through arguments \code{style} and \code{type}. 9 | 10 | It can also plot \eqn{xy}{xy}-locations with time treated as a quantitative mark attached to each location, as in the previous version of the function, through argument \code{mark} (see stpp version < 2.0.0). 11 | } 12 | 13 | \usage{\method{plot}{stpp}(x, s.region=NULL, t.region=NULL, style="generic", type="projection", 14 | mark=NULL , mark.cexmin=0.4, mark.cexmax=1.2, mark.col=1, ...)} 15 | \arguments{ 16 | \item{x}{Any object of class \code{stpp} in spatio-temporal point format.} 17 | \item{s.region}{Two-column matrix specifying polygonal region containing all data locations. If \code{s.region} is missing, the default limits are considered.} 18 | \item{t.region}{Vector containing the minimum and maximum values of the time interval. If \code{t.region} is missing, the default limits are considered.} 19 | \item{type}{Specify the kind of graphical representation. If \code{type="projection"} (default) the function plot the xy-locations and cumulative distribution of the times. If \code{type="mark"} the function plot the time-mark and space-mark. If \code{type="scatter"} the function plot space-time 3D scatter.} 20 | \item{style}{Two different classes of graphic styles can be chosen. If \code{style="generic"} (default) the graphics are plot by default function plot in \code{R} and if \code{style="elegant"} the graphics are plot based on the \code{R} packages ggplot2 and plot3D. } 21 | \item{mark}{Logical. If \code{NULL} (default), xy-locations and cumulative distribution of the times are plotted. If \code{TRUE}, the time is treated as a quantitative mark attached to each location, and the locations are plotted with the size and/or colour of the plotting symbol determined by the value of the mark.} 22 | \item{mark.cexmin, mark.cexmax}{Range of the size of the plotting symbol when \code{mark=TRUE}.} 23 | \item{mark.col}{Colour of the plotting symbol when \code{mark=TRUE}. If \code{mark.col=0}, all locations have the same colour specified by the usual \code{col} argument. 24 | Otherwise, can be 1 or "black" (default), 2 or "red", 3 or "green", 4 or "blue", in which cases symbols colour is faded, and the darker corresponds to the most recent time.} 25 | \item{...}{Further arguments to be passed to the functions plot and scatter3D. Typical arguments are \code{pch}, \code{theta} and \code{phi}.} 26 | } 27 | 28 | \value{None} 29 | 30 | \seealso{\code{\link{as.3dpoints}} for creating data in spatio-temporal point format.} 31 | 32 | \author{Edith Gabriel and Francisco J. Rodriguez-Cortes.} 33 | 34 | \references{ 35 | Gabriel E., Rowlingson B., Diggle P. (2013). stpp: an R package for plotting, simulating and analyzing Spatio-Temporal Point Patterns. Journal of Statistical Software, 53(2), 1--29. 36 | 37 | Stoyan, D., Rodriguez-Cortes, F. J., Mateu, J., and Gille, W. (2017). Mark variograms for spatio-temporal point processes. Spatial Statistics. 20, 125-147.} 38 | -------------------------------------------------------------------------------- /man/plotK.Rd: -------------------------------------------------------------------------------- 1 | \name{plotK} \alias{plotK} 2 | \title{Plot the estimation of the Space-Time Inhomogeneous K-function} 3 | 4 | \description{Contour plot or perspective plot or image of the Space-Time 5 | Inhomogeneous K-function estimate.} 6 | 7 | \usage{plotK(K,n=15,L=FALSE,type="contour",legend=TRUE,which=NULL, 8 | main=NULL,...) } 9 | 10 | \arguments{ 11 | \item{K}{Result of the \code{STIKhat} function.} 12 | \item{n}{Number of contour levels desired.} 13 | \item{L}{Logical indicating whether \eqn{K_{ST}(u,v)}{K(u,v)} or \eqn{L(u,v)=K_{ST}(u,v)-\pi u^2 v}{K(u,v)-pi u^2 v} must be plotted.} 14 | \item{type}{Specifies the kind of plot: \code{contour} by default, but can also be \code{persp} or \code{image}} 15 | \item{legend}{Logical indicating whether a legend must be added to the plot.} 16 | \item{which}{A character specifying the edge correction among the ones used in \code{STIKhat}. If a single edge correction method was used in \code{STIKhat}, it is not necessary to specify \code{which}.} 17 | \item{main}{Plot title.} 18 | \item{...}{Additional arguments to \code{persp} if \code{persp=TRUE}, such as \code{theta} and \code{phi}.} 19 | } 20 | 21 | \seealso{ 22 | \code{\link{contour}}, \code{\link{persp}}, \code{\link{image}} and \code{\link{STIKhat}} for an example. 23 | } 24 | 25 | \author{ 26 | Edith Gabriel } 27 | 28 | 29 | -------------------------------------------------------------------------------- /man/plotPCF.Rd: -------------------------------------------------------------------------------- 1 | \name{plotPCF} \alias{plotPCF} 2 | \title{Plot the estimation of the Space-Time Inhomogeneous Pair Correlation function} 3 | 4 | \description{Contour, image or perspective plot of the Space-Time Inhomogeneous Pair correlation function estimate.} 5 | 6 | \usage{plotPCF(PCF,n=15,type="contour",legend=TRUE,which=NULL, 7 | main=NULL,...) } 8 | 9 | \arguments{ 10 | \item{PCF}{Result of the \code{PCFhat} function.} 11 | \item{n}{Number of contour levels desired.} 12 | \item{type}{Specifies the kind of plot: \code{contour} by default, but can also be \code{persp} or \code{image}} 13 | \item{legend}{Logical indicating whether a legend must be added to the plot.} 14 | \item{which}{A character specifying the edge correction among the ones used in \code{PCFhat}. If a single edge correction method was used in \code{PCFhat}, it is not necessary to specify \code{which}.} 15 | \item{main}{Plot title.} 16 | \item{...}{Additional arguments to \code{persp} if \code{persp=TRUE}, such as \code{theta} and \code{phi}.} 17 | } 18 | 19 | \seealso{ 20 | \code{\link{contour}}, \code{\link{persp}}, \code{\link{image}} and \code{\link{PCFhat}} for an example. 21 | } 22 | 23 | \author{ 24 | Edith Gabriel } 25 | 26 | 27 | -------------------------------------------------------------------------------- /man/rinfec.Rd: -------------------------------------------------------------------------------- 1 | \name{rinfec} 2 | \alias{rinfec} 3 | \title{Generate infection point patterns} 4 | 5 | \description{ 6 | Generate one (or several) realisation(s) of the infection process 7 | in a region \eqn{S\times T}{S x T}. 8 | } 9 | 10 | \usage{ 11 | rinfec(npoints, s.region, t.region, nsim=1, alpha, beta, gamma, 12 | s.distr="exponential", t.distr="uniform", maxrad, delta, h="step", 13 | g="min", recent=1, lambda=NULL, lmax=NULL, nx=100, ny=100, nt=1000, 14 | t0, inhibition=FALSE, ...) 15 | } 16 | 17 | \arguments{ 18 | \item{npoints}{Number of points to simulate. } 19 | \item{s.region}{Two-column matrix specifying polygonal region containing 20 | all data locations. If \code{s.region} is missing, the unit square is considered.} 21 | \item{t.region}{Vector containing the minimum and maximum values of 22 | the time interval. If \code{t.region} is missing, the interval \eqn{[0,1]}{[0,1]} is considered.} 23 | \item{nsim}{Number of simulations to generate. Default is 1. } 24 | \item{alpha}{Numerical value for the latent period.} 25 | \item{beta}{Numerical value for the maximum infection rate.} 26 | \item{gamma}{Numerical value for the infection period.} 27 | \item{h}{Infection rate function which depends on alpha, beta and delta. 28 | Must be choosen among "step" and "gaussian".} 29 | \item{s.distr}{Spatial distribution. Must be choosen among "uniform", 30 | "gaussian", "exponential" and "poisson". } 31 | \item{t.distr}{Temporal distribution. Must be choosen among "uniform" and 32 | "exponential".} 33 | \item{maxrad}{Single value or 2-vector of spatial and temporal maximum 34 | radiation respectively. If single value, the same value is used for space and time.} 35 | \item{delta}{Spatial distance of inhibition/contagion. If missing, the spatial 36 | radiation is used.} 37 | \item{g}{Compute the probability of acceptance of a new point from \code{h} 38 | and \code{recent}. Must be choosen among "min", "max" and "prod". } 39 | \item{recent}{If ``\code{all}'' consider all previous events. If 40 | is an integer, say \eqn{N}{N}, consider only the \eqn{N}{N} most recent events.} 41 | \item{lambda}{Function or matrix defining the intensity of a Poisson process if 42 | s.distr is Poisson.} 43 | \item{lmax}{Upper bound for the value of lambda.} 44 | \item{nx, ny}{Define the 2-D grid on which the intensity is evaluated if 45 | \code{s.distr} is Poisson.} 46 | \item{nt}{Used to discretize time to compute the infection rate function.} 47 | \item{t0}{Minimum time used to compute the infection rate function. 48 | Default is the minimum of \code{t.region}.} 49 | \item{inhibition}{Logical. If \code{TRUE}, an inhibition process is generated. 50 | Otherwise, it is a contagious process.} 51 | \item{...}{Additional parameters if \code{lambda} is a function.} 52 | } 53 | 54 | \value{ 55 | A list containing: 56 | \item{xyt}{Matrix (or list of matrices if \code{nsim}>1) 57 | containing the points \eqn{(x,y,t)}{(x,y,t)} of the simulated point pattern. 58 | \code{xyt} (or any element of the list if \code{nsim}>1) is an object 59 | of the class \code{stpp}.} 60 | \item{s.region, t.region}{Parameters passed in argument.} 61 | } 62 | 63 | \author{ 64 | Edith Gabriel , Peter J Diggle. 65 | } 66 | 67 | \seealso{ 68 | \code{\link{plot.stpp}}, \code{\link{animation}} and \code{\link{stan}} for plotting space-time point patterns. 69 | } 70 | 71 | \examples{ 72 | # inhibition; spatial distribution: uniform 73 | inf1 = rinfec(npoints=100, alpha=0.2, beta=0.6, gamma=0.5, 74 | maxrad=c(0.075,0.5), t.region=c(0,50), s.distr="uniform", 75 | t.distr="uniform", h="gaussian", p="min", recent="all", t0=0.02, 76 | inhibition=TRUE) 77 | plot(inf1$xyt, style="elegant") 78 | 79 | \donttest{ 80 | # contagion; spatial distribution: Poisson with intensity a given matrix 81 | data(fmd) 82 | data(northcumbria) 83 | h = mse2d(as.points(fmd[,1:2]), northcumbria, nsmse=30, range=3000) 84 | h = h$h[which.min(h$mse)] 85 | Ls = kernel2d(as.points(fmd[,1:2]), northcumbria, h, nx=50, ny=50) 86 | inf2 = rinfec(npoints=100, alpha=4, beta=0.6, gamma=20, maxrad=c(12000,20), 87 | s.region=northcumbria, t.region=c(1,2000), s.distr="poisson", 88 | t.distr="uniform", h="step", p="min", recent=1, 89 | lambda=Ls$z, inhibition=FALSE) 90 | 91 | image(Ls$x, Ls$y, Ls$z, col=grey((1000:1)/1000)); polygon(northcumbria,lwd=2) 92 | animation(inf2$xyt, add=TRUE, cex=0.7, runtime=15) 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /man/rinter.Rd: -------------------------------------------------------------------------------- 1 | \name{rinter} 2 | \alias{rinter} 3 | \title{Generate interaction point patterns} 4 | 5 | \description{ 6 | Generate one (or several) realisation(s) of the inhibition or contagious process 7 | in a region \eqn{S\times T}{S x T}. 8 | } 9 | 10 | \usage{ 11 | rinter(npoints,s.region,t.region,hs="step",gs="min",thetas=0, 12 | deltas,ht="step",gt="min",thetat=1,deltat,recent="all",nsim=1, 13 | discrete.time=FALSE,replace=FALSE,inhibition=TRUE,...) 14 | } 15 | 16 | \arguments{ 17 | \item{npoints}{Number of points to simulate. } 18 | \item{s.region}{Two-column matrix specifying polygonal region containing 19 | all data locations. 20 | If \code{s.region} is missing, the unit square is considered.} 21 | \item{t.region}{Vector containing the minimum and maximum values of 22 | the time interval. 23 | If \code{t.region} is missing, the interval \eqn{[0,1]}{[0,1]} is considered.} 24 | \item{hs, ht}{Function which depends on the distance between points 25 | and \code{theta}. Can be chosen among "\code{step}" and "\code{gaussian}" 26 | or can refer to a user defined function which only depend on d, theta, and delta 27 | (see details). 28 | If \code{inhibition=TRUE}, \code{h} is monotone, increasing, and must tend 29 | to 1 when the distance tends to infinity. 0 \eqn{\leq}{<=}\code{h(d,theta)}\eqn{\leq}{<=} 1. 30 | Otherwise, \code{h} is monotone, decreasing, and must tend 31 | to 1 when the distance tends to 0.} 32 | \item{thetas, thetat}{Parameters of \code{hs} and \code{ht} functions.} 33 | \item{deltas, deltat}{Spatial and temporal distance of inhibition.} 34 | \item{gs, gt}{Compute the probability of acceptance of a new point from 35 | \code{hs} or \code{ht} and \code{recent}. Must be choosen among "\code{min}", 36 | "\code{max}" and "\code{prod}". } 37 | \item{recent}{If ``\code{all}'' consider all previous events. If 38 | is an integer, say \eqn{N}{N}, consider only the \eqn{N}{N} most recent events.} 39 | \item{nsim}{Number of simulations to generate. Default is 1. } 40 | \item{discrete.time}{If TRUE, times belong to \eqn{N}{N}, 41 | otherwise belong to \eqn{{\bf R}^+}{R^+}.} 42 | \item{replace}{Logical. If TRUE allows times repeat.} 43 | \item{inhibition}{Logical. If TRUE, an inhibition process is 44 | generated. Otherwise, it is a contagious process. } 45 | \item{...}{Additional parameters if \code{hs} and \code{ht} are defined by the user.} 46 | } 47 | 48 | \value{ 49 | A list containing: 50 | \item{xyt}{Matrix (or list of matrices if \code{nsim}>1) 51 | containing the points \eqn{(x,y,t)}{(x,y,t)} of the simulated point pattern. 52 | \code{xyt} (or any element of the list if \code{nsim}>1) is an object 53 | of the class \code{stpp}.} 54 | \item{s.region, t.region}{Parameters passed in argument.} 55 | } 56 | 57 | \author{ 58 | Edith Gabriel , Peter J Diggle. 59 | } 60 | 61 | \seealso{ 62 | \code{\link{plot.stpp}}, \code{\link{animation}} and \code{\link{stan}} for plotting space-time point patterns. 63 | } 64 | 65 | \examples{ 66 | # simple inhibition process 67 | inh1 = rinter(npoints=200,thetas=0,deltas=0.05,thetat=0,deltat=0.001, 68 | inhibition=TRUE) 69 | plot(inh1$xyt,style="elegant") 70 | 71 | \donttest{ 72 | # inhibition process using hs and ht defined by the user 73 | hs = function(d,theta,delta,mus=0.1) 74 | { 75 | res=NULL 76 | a=(1-theta)/mus 77 | b=theta-a*delta 78 | for(i in 1:length(d)) 79 | { 80 | if (d[i]<=delta) res=c(res,theta) 81 | if (d[i]>(delta+mus)) res=c(res,1) 82 | if (d[i]>delta & d[i]<=(delta+mus)) res=c(res,a*d[i]+b) 83 | } 84 | return(res) 85 | } 86 | ht = function(d,theta,delta,mut=0.3) 87 | { 88 | res=NULL 89 | a=(1-theta)/mut 90 | b=theta-a*delta 91 | for(i in 1:length(d)) 92 | { 93 | if (d[i]<=delta) res=c(res,theta) 94 | if (d[i]>(delta+mut)) res=c(res,1) 95 | if (d[i]>delta & d[i]<=(delta+mut)) res=c(res,a*d[i]+b) 96 | } 97 | return(res) 98 | } 99 | d=seq(0,1,length=100) 100 | plot(d,hs(d,theta=0.2,delta=0.1,mus=0.1),xlab="",ylab="",type="l", 101 | ylim=c(0,1),lwd=2,las=1) 102 | lines(d,ht(d,theta=0.1,delta=0.05,mut=0.3),col=2,lwd=2) 103 | legend("bottomright",col=1:2,lty=1,lwd=2,legend=c(expression(h[s]), 104 | expression(h[t])),bty="n",cex=2) 105 | 106 | inh2 = rinter(npoints=100, hs=hs, gs="min", thetas=0.2, deltas=0.1, 107 | ht=ht, gt="min", thetat=0.1, deltat=0.05, inhibition=TRUE) 108 | animation(inh2$xyt, runtime=15, cex=0.8) 109 | 110 | # simple contagious process for given spatial and temporal regions 111 | data(northcumbria) 112 | cont1 = rinter(npoints=100, s.region=northcumbria, t.region=c(1,200), 113 | thetas=0, deltas=10000, thetat=0, deltat=10, recent=1, inhibition=FALSE) 114 | plot(cont1$xyt,pch=19,s.region=cont1$s.region,mark=TRUE,mark.col=4) 115 | } 116 | } 117 | 118 | 119 | -------------------------------------------------------------------------------- /man/rpcp.Rd: -------------------------------------------------------------------------------- 1 | \name{rpcp} 2 | \alias{rpcp} 3 | \title{Generate Poisson cluster point patterns} 4 | 5 | \description{ 6 | Generate one (or several) realisation(s) of the Poisson cluster process in a region 7 | \eqn{S\times T}{S x T}. 8 | } 9 | 10 | \usage{ 11 | rpcp(s.region, t.region, nparents=NULL, npoints=NULL, lambda=NULL, 12 | mc=NULL, nsim=1, cluster="uniform", dispersion, infectious=TRUE, 13 | edge = "larger.region", larger.region=larger.region, tronc=1,...) 14 | } 15 | 16 | \arguments{ 17 | \item{s.region}{Two-column matrix specifying polygonal region containing 18 | all data locations. 19 | If \code{s.region} is missing, the unit square is considered.} 20 | \item{t.region}{Vector containing the minimum and maximum values of 21 | the time interval. If \code{t.region} is missing, the interval \eqn{[0,1]}{[0,1]} is 22 | considered.} 23 | \item{nparents}{Number of parents. If \code{NULL}, \code{nparents} is from a 24 | Poisson distribution with intensity \code{lambda}.} 25 | \item{npoints}{Number of points to simulate. If \code{NULL} (default), the 26 | number of points is from a Poisson distribution with mean the double integral 27 | of the intensity over \code{s.region} and \code{t.region}.} 28 | \item{lambda}{Intensity of the parent process. Can be either a numeric 29 | value, a function, or a 3d-array (see \code{\link{rpp}}). 30 | If \code{NULL}, it is constant and equal to \code{nparents} / volume 31 | of the domain.} 32 | \item{mc}{Average number of children per parent. It is used when 33 | \code{npoints} is \code{NULL}.} 34 | \item{nsim}{Number of simulations to generate. } 35 | \item{cluster}{Distribution of children: ``uniform'', ``normal'' and 36 | ``exponential'' are currently implemented. 37 | Either a single value if the distribution in space and time is the 38 | same, or a vector of length 2, giving first the spatial distribution of 39 | children and then the temporal distribution.} 40 | \item{dispersion}{Scale parameter. It equals twice the standard deviation of 41 | location of children relative to their parent for a normal distribution of 42 | children; the mean for an exponential distribution and half range for an uniform 43 | distribution.} 44 | \item{infectious}{If \code{TRUE}, offspring's times are always greater than 45 | parent's time.} 46 | \item{edge}{Specify the edge correction to use "larger.region" or "without".} 47 | \item{larger.region}{By default, the larger spatial region is the convex hull 48 | of \code{s.region} enlarged by the spatial related value of \code{dispersion} 49 | and the larger time interval is \code{t.region} enlarged by the temporal related 50 | value of \code{dispersion}. 51 | One can over-ride default using the 2-vector parameter \code{larger.region}.} 52 | \item{tronc}{Parameter of the truncated exponential distribution for the distribution of children.} 53 | \item{...}{Additional parameters of the intensity of the parent process.} 54 | } 55 | 56 | \value{ 57 | A list containing: 58 | \item{xyt}{Matrix (or list of matrices if \code{nsim}>1) 59 | containing the points \eqn{(x,y,t)}{(x,y,t)} of the simulated point pattern. 60 | \code{xyt} (or any element of the list if \code{nsim}>1) is an object 61 | of the class \code{stpp}.} 62 | \item{s.region, t.region}{Parameters passed in argument.} 63 | } 64 | 65 | \author{ 66 | Edith Gabriel , Peter J Diggle. 67 | } 68 | 69 | \seealso{ 70 | \code{\link{plot.stpp}}, \code{\link{animation}} and \code{\link{stan}} for plotting space-time point patterns. 71 | } 72 | 73 | \examples{ 74 | # homogeneous Poisson distribution of parents 75 | 76 | data(northcumbria) 77 | pcp1 <- rpcp(nparents=50, npoints=500, s.region=northcumbria, 78 | t.region=c(1,365), cluster=c("normal","exponential"), 79 | maxrad=c(5000,5)) 80 | \donttest{ 81 | animation(pcp1$xyt, s.region=pcp1$s.region, t.region=pcp1$t.region, 82 | runtime=5) 83 | } 84 | # inhomogeneous Poisson distribution of parents 85 | 86 | lbda <- function(x,y,t,a){a*exp(-4*y) * exp(-2*t)} 87 | pcp2 <- rpcp(nparents=50, npoints=500, cluster="normal", lambda=lbda, 88 | a=4000/((1-exp(-4))*(1-exp(-2)))) 89 | plot(pcp2$xyt, style="elegant") 90 | 91 | } 92 | -------------------------------------------------------------------------------- /man/rpp.Rd: -------------------------------------------------------------------------------- 1 | \name{rpp} 2 | \alias{rpp} 3 | \title{Generate Poisson point patterns} 4 | 5 | \description{ 6 | Generate one (or several) realisation(s) of the (homogeneous or inhomogeneous) Poisson process in a region \eqn{S\times T}{S x T}. 7 | } 8 | 9 | \usage{ 10 | rpp(lambda, s.region, t.region, npoints=NULL, nsim=1, replace=TRUE, 11 | discrete.time=FALSE, nx=100, ny=100, nt=100, lmax=NULL, ...) 12 | } 13 | 14 | \arguments{ 15 | \item{lambda}{Spatio-temporal intensity of the Poisson process. 16 | If \code{lambda} is a single positive number, the function generates 17 | realisations of a homogeneous Poisson process, whilst if \code{lambda} 18 | is a function of the form \eqn{\lambda(x,y,t,\dots)}{lambda(x,y,t,...)} 19 | or a 3D-array it generates realisations of an inhomogeneous Poisson process.} 20 | \item{s.region}{Two-column matrix specifying polygonal region containing 21 | all data locations. 22 | If \code{s.region} is missing, the unit square is considered.} 23 | \item{t.region}{Vector containing the minimum and maximum values of 24 | the time interval. 25 | If \code{t.region} is missing, the interval \eqn{[0,1]}{[0,1]} is considered.} 26 | \item{replace}{Logical allowing times repeat (should only be used when \code{discrete.time=TRUE}).} 27 | \item{npoints}{Number of points to simulate. If \code{NULL}, the 28 | number of points is from a 29 | Poisson distribution with mean the double integral of \code{lambda} over 30 | \code{s.region} and \code{t.region}.} 31 | \item{discrete.time}{If TRUE, times belong to \eqn{{\bf N}}{N}, 32 | otherwise belong to \eqn{{\bf R}^+}{R^+}.} 33 | \item{nsim}{Number of simulations to generate. Default is 1.} 34 | \item{nx,ny,nt}{Define the size of the 3-D grid on which the intensity 35 | is evaluated. } 36 | \item{lmax}{Upper bound for the value of \eqn{\lambda(x,y,t)}{lambda(x,y,t)}, if 37 | \code{lambda} is a function.} 38 | \item{...}{Additional parameters if \code{lambda} is a function.} 39 | } 40 | 41 | \value{ 42 | A list containing: 43 | \item{xyt}{Matrix (or list of matrices if \code{nsim}>1) 44 | containing the points \eqn{(x,y,t)} of the simulated point pattern. 45 | \code{xyt} (or any element of the list if \code{nsim}>1) is an object 46 | of the class \code{stpp}.} 47 | \item{Lambda}{\eqn{nx \times ny \times nt}{nx x ny x nt} array of the intensity surface at each time.} 48 | \item{s.region, t.region, lambda}{parameters passed in argument.} 49 | } 50 | 51 | \author{ 52 | Edith Gabriel and Peter J Diggle. 53 | } 54 | 55 | \seealso{ 56 | \code{\link{plot.stpp}}, \code{\link{animation}} and \code{\link{stan}} for plotting space-time point patterns. 57 | } 58 | 59 | \examples{ 60 | # Homogeneous Poisson process 61 | # --------------------------- 62 | hpp1 <- rpp(lambda=200,replace=FALSE) 63 | 64 | \donttest{stan(hpp1$xyt)} 65 | 66 | # fixed number of points, discrete time, with time repeat. 67 | data(northcumbria) 68 | hpp2 <- rpp(npoints=500, s.region=northcumbria, t.region=c(1,1000), 69 | discrete.time=TRUE) 70 | plot(hpp2$xyt, style="elegant") 71 | \donttest{ 72 | polymap(northcumbria) 73 | animation(hpp2$xyt, s.region=hpp2$s.region, t.region=hpp2$t.region, 74 | runtime=10, add=TRUE) 75 | } 76 | 77 | \donttest{ 78 | # Inhomogeneous Poisson process 79 | # ----------------------------- 80 | 81 | # intensity defined by a function 82 | lbda1 = function(x,y,t,a){a*exp(-4*y) * exp(-2*t)} 83 | ipp1 = rpp(lambda=lbda1, npoints=400, a=3200/((1-exp(-4))*(1-exp(-2)))) 84 | stan(ipp1$xyt) 85 | 86 | # intensity defined by a matrix 87 | data(fmd) 88 | data(northcumbria) 89 | h = mse2d(as.points(fmd[,1:2]), northcumbria, nsmse=30, range=3000) 90 | h = h$h[which.min(h$mse)] 91 | Ls = kernel2d(as.points(fmd[,1:2]), northcumbria, h, nx=100, ny=100) 92 | Lt = dim(fmd)[1]*density(fmd[,3], n=200)$y 93 | Lst=array(0,dim=c(100,100,200)) 94 | for(k in 1:200) Lst[,,k] <- Ls$z*Lt[k]/dim(fmd)[1] 95 | ipp2 = rpp(lambda=Lst, s.region=northcumbria, t.region=c(1,200), 96 | discrete.time=TRUE) 97 | 98 | par(mfrow=c(1,1)) 99 | image(Ls$x, Ls$y, Ls$z, col=grey((1000:1)/1000)); polygon(northcumbria) 100 | animation(ipp2$xyt, add=TRUE, cex=0.5, runtime=15) 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /man/sim.stpp.Rd: -------------------------------------------------------------------------------- 1 | \name{sim.stpp} 2 | \alias{sim.stpp} 3 | \title{Generate spatio-temporal point patterns} 4 | 5 | \description{ 6 | Generate one (or several) realisation(s) of a spatio-temporal point process in a region \eqn{S\times T}{S x T}. 7 | } 8 | 9 | \usage{ 10 | sim.stpp(class="poisson", s.region, t.region, npoints=NULL, 11 | nsim=1, ...) 12 | } 13 | 14 | \arguments{ 15 | \item{class}{Must be chosen among "poisson", "cluster", "cox", "infectious" and "inhibition".} 16 | \item{s.region}{Two-column matrix specifying polygonal region containing 17 | all data locations. 18 | If \code{s.region} is missing, the unit square is considered.} 19 | \item{t.region}{Vector containing the minimum and maximum values of 20 | the time interval. 21 | If \code{t.region} is missing, the interval \eqn{[0,1]}{[0,1]} is considered.} 22 | \item{npoints}{Number of points to simulate.} 23 | \item{nsim}{Number of simulations to generate. Default is 1.} 24 | \item{...}{Additional parameters related to the \code{class} parameter. 25 | See \code{\link{rpp}} for the Poisson process; \code{\link{rpcp}} for the Poisson 26 | cluster process; \code{\link{rlgcp}} for the Log-Gaussian Cox process; 27 | \code{\link{rinter}} for the interaction (inhibition or contagious) 28 | process and \code{\link{rinfec}} for the infectious process.} 29 | } 30 | 31 | \value{ 32 | A list containing: 33 | \item{xyt}{Matrix (or list of matrices if \code{nsim}>1) 34 | containing the points \eqn{(x,y,t)}{(x,y,t)} of the simulated point pattern. 35 | \code{xyt} (or any element of the list if \code{nsim}>1) is an object 36 | of the class \code{stpp}.} 37 | \item{s.region, t.region}{Parameters passed in argument.} 38 | } 39 | 40 | \author{ 41 | Edith Gabriel 42 | } 43 | 44 | \seealso{ 45 | \code{\link{rpp}}, \code{\link{rinfec}}, \code{\link{rinter}}, 46 | \code{\link{rpcp}} and \code{\link{rlgcp}} for the simulation of 47 | Poisson, infectious, interaction, Poisson cluster and log-gaussian 48 | Cox processes respectively; and \code{\link{plot.stpp}}, 49 | \code{\link{animation}} and \code{\link{stan}} for plotting space-time 50 | point patterns. } 51 | 52 | -------------------------------------------------------------------------------- /man/stan.Rd: -------------------------------------------------------------------------------- 1 | \name{stan} 2 | \alias{stan} 3 | \title{(3D) space-time data animation} 4 | \description{ 5 | Displays \eqn{(x,y,t)}{(x,y,t)} point data and enables dynamic highlighting of time slices. 6 | } 7 | \usage{ 8 | stan(xyt,tlim=range(xyt[,3],na.rm=TRUE),twid=diff(tlim)/20, 9 | persist=FALSE,states,bgpoly,bgframe=TRUE,bgimage, 10 | bgcol=gray(seq(0,1,len=12)),axes=TRUE) 11 | } 12 | \arguments{ 13 | \item{xyt}{A 3-column matrix of \eqn{x}{x}, \eqn{y}{y}, \eqn{t}{t} coordinates} 14 | \item{tlim}{A two-element vector of upper and lower time limits} 15 | \item{twid}{The initial time window width} 16 | \item{persist}{Whether to display points before time window} 17 | \item{states}{How to display points - see Details} 18 | \item{bgpoly}{A polygon to draw on the background plane} 19 | \item{bgframe}{Whether to extend the bgpoly to the front plane} 20 | \item{bgimage}{An list with \eqn{x}{x}, \eqn{y}{y} vectors and \eqn{z}{z} matrix to display on the background plane} 21 | \item{bgcol}{A colour palette vector with which to draw the bgimage} 22 | \item{axes}{Logical value indicating whether labels should be added.} 23 | } 24 | \details{ 25 | This function requires the \code{rpanel} and \code{rgl} packages. It uses \code{rpanel} for the sliders to control the graphics, and \code{rgl} for its ability to do flicker-free graphics. 26 | 27 | The sliders set the position and width of the temporal highlight window. For 'time' slider set to time \eqn{T}{T} and 'width' slider set to \eqn{S}{S}, highlighted points are those with time coordinate \eqn{t}{t} such that \eqn{T-S< t< T}{T-S< t< T}. 28 | 29 | How points are shown is configured with the states parameter. This is a list of length 3 specifying how points before the time window, inside the time window, and after the time window are displayed. Each element is a list of parameters as would be passed to \code{material3d()} together with a radius element. Points are drawn as spheres with the corresponding 30 | material and radius as a fraction of the spatial span of the data. 31 | 32 | By default the third state is invisible, and the first two states are different. By calling with the default for states and \code{persist=TRUE}, then the first state is set to the same as the second state. This has the effect of showing all points at time \eqn{< T}{< T} with the same sphere type. 33 | 34 | If the user specifies the states parameter, then persist is ignored. The user can emulate the persist behaviour by specifying a states list with identical parameters for states 1 and 2. 35 | 36 | Note that each state element should specify all \code{material3d} parameters used in any of the state elements. This is to make sure the parameters are reset for each of the sets of points. 37 | 38 | The background polygon must be a simple 2-column vector of \eqn{x}{x} and \eqn{y}{y} coordinates. When used with \code{bgframe=TRUE}, the polygon is also drawn on the front plane, and the convex hull points are connected front to back in order to visualise the space-time prism that the data are contained in. 39 | 40 | A raster image can be displayed on the back plane by setting the bgimage parameter. This must be a list with \eqn{x}{x}, \eqn{y}{y} and \eqn{z}{z} components as needed by the image function. Note that \eqn{x}{x} and \eqn{y}{y} define the center of cells and so must be the same length as the dimensions of \eqn{z}{z} - the image function can accept \eqn{x}{x} and \eqn{y}{y} values that are one longer than the dimensions of \eqn{z}{z} to define the edges, but bgimage does not allow that. 41 | 42 | } 43 | \value{ 44 | A list of the slider parameters when the dialog is quitted. 45 | } 46 | \author{Barry Rowlingson , Edith Gabriel} 47 | 48 | \keyword{hplot} 49 | 50 | -------------------------------------------------------------------------------- /man/stdcpp.Rd: -------------------------------------------------------------------------------- 1 | \name{stdcpp} 2 | \alias{stdcpp} 3 | 4 | \title{Generate double-cluster point pattern} 5 | 6 | \description{Generate a realisation of the double-cluster process in a region \eqn{S\times T}{S x T}.} 7 | 8 | \usage{stdcpp(lambp, a, b, c, mu, s.region, t.region)} 9 | 10 | \arguments{ 11 | \item{s.region}{Two-column matrix specifying polygonal region containing 12 | all data locations.If \code{s.region} is missing, the unit square is considered.} 13 | \item{t.region}{Vector containing the minimum and maximum values of the time interval. If \code{t.region} is missing, the interval \eqn{[0,1]}{[0,1]} is considered.} 14 | \item{lambp}{Intensity of the parent process. Can be either a numeric value, a function, or a 3d-array (see \code{\link{rpp}}).} 15 | \item{a}{Length of the semi-axes \eqn{x}{x} of ellipsoid.} 16 | \item{b}{Length of the semi-axes \eqn{y}{y} of ellipsoid.} 17 | \item{c}{Length of the semi-axes \eqn{y}{y} of ellipsoid.} 18 | \item{mu}{Average number of daughter per parent. (a single positive number).} 19 | } 20 | 21 | \details{We consider the straightforward extension of the classical Matern cluster process on the \eqn{R^3} case (with ellipsoid or balls) by considering the \eqn{z}{z}-coordiantes as times. 22 | 23 | Consider a Poisson point process in the plane with intensity \eqn{\lambda_p}{\lambda_p} as cluster centres for all times 'parent', as well as a ellipsoid (or ball) where the semi-axes are of lengths \eqn{a}{a}, \eqn{b}{b} and \eqn{c}{c}, around of each Poisson point under a random general rotation. The scatter uniformly in all ellipsoid (or ball) of all points which are of the form \eqn{(x,y,z)}{(x,y,z)}, the number of points in each cluster being random with a Poisson (\eqn{\mu}{\mu}) distribution. The resulting point pattern is a spatio-temporal cluster point process with \eqn{t=z}{t=z}. This point process has intensity \eqn{\lambda_{p} \times \mu}{\lambda_{p} x \mu}.} 24 | 25 | \value{The simulated spatio-temporal point pattern.} 26 | 27 | \references{ 28 | Baddeley, A., Rubak, E., Turner, R. (2015). Spatial Point Patterns: Methodology and Applications with R. CRC Press, Boca Raton. 29 | 30 | Chiu, S. N., Stoyan, D., Kendall, W. S., and Mecke, J. (2013). Stochastic Geometry and its Applications. John Wiley & Sons. 31 | 32 | Gabriel, E., Rowlingson, B., Diggle P J. (2013) \code{stpp}: an R package for plotting, simulating and analyzing Spatio-Temporal Point Patterns. Journal of Statistical Software 53, 1-29. 33 | 34 | Illian, J B., Penttinen, A., Stoyan, H. and Stoyan, D. (2008). Statistical Analysis and Modelling of Spatial Point Patterns. John Wiley and Sons, London. 35 | 36 | Stoyan, D., Rodriguez-Cortes, F. J., Mateu, J., and Gille, W. (2017). Mark variograms for spatio-temporal point processes. Spatial Statistics. 20, 125-147. 37 | } 38 | 39 | \author{Francisco J. Rodriguez Cortes } 40 | 41 | \examples{ 42 | # Ellipsoid 43 | Xe <- stdcpp(lambp=20,a=0.5,b=0.09,c=0.07,mu=100) 44 | plot(Xe$xyt) 45 | 46 | # Spatio-temporal 3D scatter plot 47 | par(mfrow=c(1,1)) 48 | plot(Xe$xyt,type="scatter") 49 | 50 | # Balls 51 | Xb <- stdcpp(lambp=20,a=0.07,b=0.07,c=0.07,mu=100) 52 | plot(Xb$xyt) 53 | 54 | \donttest{ 55 | # Spatio-temporal 3D scatter plot 56 | par(mfrow=c(1,1)) 57 | plot(Xb$xyt,type="mark",style="elegant") 58 | 59 | # Northcumbria 60 | data(northcumbria) 61 | Northcumbria <- northcumbria/1000 62 | X <- stdcpp(lambp=0.00004,a=10,b=10,c=10,mu=120, 63 | s.region=Northcumbria,t.region=c(0,200)) 64 | plot(X$xyt,s.region=Northcumbria, cex=0.5) 65 | 66 | # Spatio-temporal 3D scatter plot 67 | par(mfrow=c(1,1)) 68 | plot(X$xyt,type="scatter",theta=45,phi=30,cex=0.1, 69 | ticktype="detailed",col="black",style="elegant") 70 | }} -------------------------------------------------------------------------------- /man/sthpcpp.Rd: -------------------------------------------------------------------------------- 1 | \name{sthpcpp} 2 | \alias{sthpcpp} 3 | 4 | \title{Spatio-temporal hot-spots cluster point process model} 5 | \description{Generate a realisation of the hot-spots cluster process in a region \eqn{S\times T}{S x T}.} 6 | 7 | \usage{ 8 | sthpcpp(lambp, r, mu, s.region, t.region) 9 | } 10 | 11 | \arguments{ 12 | \item{s.region}{Two-column matrix specifying polygonal region containing 13 | all data locations.If \code{s.region} is missing, the unit square is considered.} 14 | 15 | \item{t.region}{Vector containing the minimum and maximum values of the time interval. If \code{t.region} is missing, the interval \eqn{[0,1]}{[0,1]} is considered.} 16 | 17 | \item{lambp}{Intensity of the Poisson process of cluster centres. A single positive number, a function, or a pixel image.} 18 | 19 | \item{r}{Radius parameter of the clusters.} 20 | 21 | \item{mu}{Average number of daughter per parent (a single positive number) or reference intensity for the cluster points (a function or a pixel image).} 22 | } 23 | 24 | \details{This function generates a realisation of spatio-temporal cluster process, which can be considered as generalisation of the classical Matern cluster process, inside the spatio-temporal window. 25 | 26 | Consider a Poisson point process in the plane with intensity \eqn{\lambda_{p}}{\lambda_{p}} as cluster centres for all times 'parent', as well as a infinite cylinder of radius \eqn{R}{R} around of each Poisson point, orthogonal to the plane. The scatter uniformly in all cylinders of all points which are of the form \eqn{(x,y,z)}{(x,y,z)}, the number of points in each cluster being random with a Poisson (\eqn{\mu}{\mu}) distribution. The resulting point pattern is a spatio-temporal cluster point process with \eqn{t=z}{t=z}. This point process has intensity \eqn{\lambda_{p}\times\mu}{\lambda_{p} x \mu}.} 27 | 28 | \value{The simulated spatio-temporal point pattern.} 29 | 30 | \references{ 31 | Baddeley, A., Rubak, E., Turner, R. (2015). Spatial Point Patterns: Methodology and Applications with R. CRC Press, Boca Raton. 32 | 33 | Chiu, S. N., Stoyan, D., Kendall, W. S., and Mecke, J. (2013). Stochastic Geometry and its Applications. John Wiley & Sons. 34 | 35 | Gabriel, E., Rowlingson, B., Diggle P J. (2013) \code{stpp}: an R package for plotting, simulating and analyzing Spatio-Temporal Point Patterns. Journal of Statistical Software 53, 1-29. 36 | 37 | Illian, J B., Penttinen, A., Stoyan, H. and Stoyan, D. (2008). Statistical Analysis and Modelling of Spatial Point Patterns. John Wiley and Sons, London. 38 | 39 | Stoyan, D., Rodriguez-Cortes, F. J., Mateu, J., and Gille, W. (2017). Mark variograms for spatio-temporal point processes. Spatial Statistics. 20, 125-147. 40 | } 41 | \author{Francisco J. Rodriguez Cortes } 42 | 43 | \examples{ 44 | # First example 45 | X <- sthpcpp(lambp=20, r=0.05, mu=100) 46 | plot(X$xyt) 47 | 48 | # Spatio-temporal 3D scatter plot 49 | par(mfrow=c(1,1)) 50 | plot(X$xyt,type="scatter") 51 | 52 | ## Spatio-temporal hot-spots cluster point process model 53 | data(northcumbria) 54 | Northcumbria <- northcumbria/1000 55 | Xo <- sthpcpp(lambp=0.0035, r=5, mu=200, 56 | s.region=Northcumbria, t.region=c(28,198)) 57 | plot(Xo$xyt,s.region=Northcumbria) 58 | 59 | # Spatio-temporal 3D scatter plot 60 | par(mfrow=c(1,1)) 61 | plot(Xo$xyt,type="scatter",style="elegant",theta=45,phi=30,cex=0.05, 62 | ticktype="detailed",col="black") 63 | } -------------------------------------------------------------------------------- /man/stpp-package.Rd: -------------------------------------------------------------------------------- 1 | \name{stpp} 2 | \docType{package} 3 | \alias{stpp-package} 4 | \alias{stpp} 5 | 6 | \title{Space-Time Point Pattern simulation, visualisation and analysis} 7 | 8 | \description{ This package provides models of spatio-temporal point processes in a region \eqn{S\times T}{S x T} and statistical tools for analysing global and local second-order properties of such processes. It also includes static and dynamic (2D and 3D) plots. \code{stpp} is the first dedicated unified computational environment in the area of spatio-temporal point processes. 9 | 10 | The \code{stpp} package depends upon some other packages: 11 | 12 | \code{splancs}: spatial and space-time point pattern analysis 13 | 14 | \code{rgl}: interactive 3D plotting of densities and surfaces 15 | 16 | \code{rpanel}: simple interactive controls for R using \code{tcltk} package 17 | 18 | \code{KernSmooth}: functions for kernel smoothing for Wand & Jones (1995) 19 | 20 | \code{plot3D}: Tools for plotting 3-D and 2-D data 21 | 22 | \code{ggplot2}: Create Elegant Data Visualisations Using the Grammar of Graphics 23 | } 24 | 25 | \details{ 26 | \code{stpp} is a package for simulating, analysing and visualising patterns of points in space and time. 27 | 28 | Following is a summary of the main functions and the dataset in the \code{stpp} package. 29 | 30 | \emph{To visualise a spatio-temporal point pattern} 31 | 32 | \itemize{ 33 | \item \code{\link{animation}}: space-time data animation. 34 | \item \code{\link{as.3dpoints}}: create data in spatio-temporal point format. 35 | \item \code{\link{plot.stpp}}: plot spatio-temporal point object. Either a two-panels plot showing spatial locations and cumulative times, or a one-panel plot showing spatial locations with times treated as a quantitative mark attached to each location. 36 | \item \code{\link{stan}}: 3D space-time animation. 37 | } 38 | 39 | \emph{To simulate spatio-temporal point patterns} 40 | 41 | \itemize{ 42 | \item \code{\link{rinfec}}: simulate an infection point process, 43 | \item \code{\link{rinter}}: simulate an interaction (inhibition or contagious) point process, 44 | \item \code{\link{rlgcp}}: simulate a log-Gaussian Cox point process, 45 | \item \code{\link{rpcp}}: simulate a Poisson cluster point process, 46 | \item \code{\link{rpp}}: simulate a Poisson point process, 47 | \item \code{\link{stdcpp}}: simulate a double-cluster point process, 48 | \item \code{\link{sthpcpp}}: simulate a hot-spot point process. 49 | } 50 | 51 | \emph{To analyse spatio-temporal point patterns} 52 | 53 | \itemize{ 54 | \item \code{\link{PCFhat}}: space-time inhomogeneous pair correlation function, 55 | \item \code{\link{STIKhat}}: space-time inhomogeneous K-function, 56 | \item \code{\link{ASTIKhat}}: Anisotropic space-time inhomogeneous K-function, 57 | \item \code{\link{LISTAhat}}: space-time inhomogeneous pair correlation LISTA funcrions. 58 | \item \code{\link{KLISTAhat}}: space-time inhomogeneous K LISTA functions. 59 | \item \code{\link{gsp}}: Spatial mark variogram function. 60 | \item \code{\link{gte}}: Temporal mark variogram function. 61 | \item \code{\link{kmr}}: Spatial r-mark function 62 | \item \code{\link{kmt}}: Temporal t-mark function. 63 | \item \code{\link{kmmr}}: Spatial mark correlation functionn. 64 | \item \code{\link{kmmt}}: Temporal mark correlation function. 65 | } 66 | 67 | \emph{Dataset} 68 | 69 | \code{\link{fmd}}: 2001 food-and-mouth epidemic in north Cumbria (UK). 70 | } 71 | 72 | \author{ 73 | Edith Gabriel , Peter J. Diggle, Barry Rowlingson and Francisco J. Rodriguez-Cortes} 74 | 75 | \references{Baddeley, A., Rubak, E., Turner, R. (2015). Spatial Point Patterns: Methodology and Applications with R. CRC Press, Boca Raton. 76 | 77 | Chan, G. and Wood A. (1997). An algorithm for simulating stationary Gaussian random fields. Applied Statistics, Algorithm Section, 46, 171--181. 78 | 79 | Chan, G. and Wood A. (1999). Simulation of stationary Gaussian vector fields. Statistics and Computing, 9, 265--268. 80 | 81 | Diggle P. , Chedwynd A., Haggkvist R. and Morris S. (1995). Second-order analysis of space-time clustering. Statistical Methods in Medical Research, 4, 124--136. 82 | 83 | Diggle, P.J., 2013. Statistical Analysis of Spatial and Spatio-Temporal Point Patterns. CRC Press, Boca Raton. 84 | 85 | Gabriel E. (2014). Estimating second-order characteristics of inhomogeneous spatio-temporal point processes: influence ofedge correction methods and intensity estimates. Methodology and computing in Applied Probabillity, 16(1). 86 | 87 | Gabriel E., Diggle P. (2009). Second-order analysis of inhomogeneous spatio-temporal point process data. Statistica Neerlandica, 63, 43--51. 88 | 89 | Gabriel E., Rowlingson B., Diggle P. (2013). stpp: an R package for plotting, simulating and analyzing 90 | Spatio-Temporal Point Patterns. Journal of Statistical Software, 91 | 53(2), 1--29. 92 | 93 | Gneiting T. (2002). Nonseparable, stationary covariance functions for space-time data. Journal of the American Statistical Association, 97, 590--600. 94 | 95 | Gonzalez, J. A., Rodriguez-Cortes, F. J., Cronie, O. and Mateu, J. (2016). Spatio-temporal point process statistics: a review. Spatial Statiscts, 18, 505--544. 96 | 97 | Siino, M., Rodriguez-Cortes, F. J., Mateu, J. and Adelfio, G. (2017). Testing for local structure in spatio-temporal point pattern data. Environmetrics. DOI: 10.1002/env.2463. 98 | 99 | Stoyan, D., Rodriguez-Cortes, F. J., Mateu, J., and Gille, W. (2017). Mark variograms for spatio-temporal point processes. Spatial Statistics. 20, 125-147. 100 | } 101 | -------------------------------------------------------------------------------- /src/astk.f: -------------------------------------------------------------------------------- 1 | C Francisco J. Rodriguez-Cortes, September 2016 2 | C This function provides an edge-corrected estimate 3 | C of the anisotropic spatio-temporal inhomogeneous K-function 4 | 5 | subroutine astk(x,y,txy,n,lambda,ag,s,ns,t,nt,wbi,wbimod,wt, 6 | + correc,astkf) 7 | 8 | implicit double precision (a-h,o-z) 9 | 10 | integer n,ns,nt,iu,iv,i,j,k,correc 11 | double precision astkf,two,vij,wij,hij,tij,angij,ag,xi,yi,ti 12 | double precision x,y,txy,xc,yc,wbi,wbimod,wt,lambda 13 | dimension wbi(n,ns,nt),wbimod(n,ns,nt),wt(n,n),correc(4),lambda(n) 14 | dimension x(n),y(n),txy(n),s(ns),t(nt),astkf(ns,nt,4),xc(n),yc(n) 15 | 16 | two=2d0 17 | pi=3.14159265d0 18 | angij=0d0 19 | 20 | do iu=1,ns 21 | do iv=1,nt 22 | do i=1,n 23 | xi=x(i) 24 | yi=y(i) 25 | ti=txy(i) 26 | 27 | do k=1,n 28 | xc(k)=x(k)-xi 29 | yc(k)=y(k)-yi 30 | end do 31 | do j=1,n 32 | if (j.ne.i) then 33 | hij=dsqrt((xc(j))*(xc(j)) + (yc(j))*(yc(j))) 34 | tij=dabs(ti-txy(j)) 35 | c Quadrant one 36 | if ((xc(j).gt.0d0).and.(yc(j).gt.0d0)) then 37 | angij=datan(yc(j)/xc(j)) 38 | c Quadrant two 39 | else if ((xc(j).lt.0d0).and.(yc(j).gt.0d0)) then 40 | angij=datan(yc(j)/xc(j))+pi 41 | c Quadrant three 42 | else if ((xc(j).lt.0d0).and.(yc(j).lt.0d0)) then 43 | angij=datan(yc(j)/xc(j))+pi 44 | c Quadrant four 45 | else if ((xc(j).gt.0d0).and.(yc(j).lt.0d0)) then 46 | angij=datan(yc(j)/xc(j))+(two*pi) 47 | end if 48 | if ((tij.le.t(iv)).and.(hij.le.s(iu)).and.(angij.le.ag)) then 49 | c none 50 | if (correc(1).eq.1) then 51 | vij=1d0 52 | wij=vij/(lambda(i)*lambda(j)) 53 | astkf(iu,iv,1)=astkf(iu,iv,1)+wij 54 | end if 55 | c border 56 | if (correc(2).eq.1) then 57 | vij=wbi(i,iu,iv) 58 | wij=vij/(lambda(i)*lambda(j)) 59 | astkf(iu,iv,2)=astkf(iu,iv,2)+wij 60 | end if 61 | c modified border 62 | if (correc(3).eq.1) then 63 | vij=wbimod(i,iu,iv) 64 | wij=vij/(lambda(i)*lambda(j)) 65 | astkf(iu,iv,3)=astkf(iu,iv,3)+wij 66 | end if 67 | c translate 68 | if (correc(4).eq.1) then 69 | vij=wt(i,j) 70 | wij=vij/(lambda(i)*lambda(j)) 71 | astkf(iu,iv,4)=astkf(iu,iv,4)+wij 72 | end if 73 | end if 74 | end if 75 | 76 | end do 77 | end do 78 | end do 79 | end do 80 | 81 | return 82 | 83 | 84 | end 85 | -------------------------------------------------------------------------------- /src/covst.f: -------------------------------------------------------------------------------- 1 | c=========================================================== 2 | c 3 | c Computation of a spatio-temporal covariance function 4 | c 5 | c 6 | c AUTHOR : E. Gabriel 7 | c 8 | c DATE : 24/01/2006 9 | c 10 | c VERSION : 1 11 | c 12 | c last modification : 07/03/2007 13 | c 14 | c 15 | c============================================================ 16 | c 17 | subroutine covst(gs,xx,yy,tt,nx,ny,nt,model,param,sigma2,scale, 18 | & aniso,ani) 19 | 20 | c INPUT: 21 | c xx,yy,tt : spatial and temporal coordinates 22 | c model : model 23 | c param(6) : covariance parameters 24 | c aniso, ani : parameters for anisotropic covariances 25 | c 26 | c OUTPUT: gs : covariance 27 | 28 | implicit none 29 | 30 | integer nx,ny,nt 31 | integer model(3) 32 | double precision gs(nx,ny,nt) 33 | double precision xx(nx),yy(ny),tt(nt),param(6) 34 | 35 | integer i,j,k 36 | double precision covar,scale(2),sigma2,aniso,ani(2) 37 | 38 | do k=1,nt 39 | do j=1,ny 40 | do i=1,nx 41 | gs(i,j,k)=covar(xx(i),yy(j),tt(k),model,param,sigma2,scale, 42 | & aniso,ani) 43 | end do 44 | end do 45 | end do 46 | 47 | return 48 | end 49 | 50 | c --------------------------------------------------------------------------- 51 | c 52 | c program 53 | c 54 | double precision function covar(x,y,t,model,param,sigma2,scale, 55 | & aniso,ani) 56 | 57 | c implicit none 58 | 59 | integer model(3) 60 | double precision x,y,t,dx,dt,param(6),sigma2,scale(2) 61 | double precision p1,p2,p3,p4,p5,p6 62 | double precision mod,mods,modt 63 | double precision aniso,ani(2), xani,yani 64 | double precision cauchy,stable,exponential,wave,matern 65 | double precision gneiting,cesare,theta(3) 66 | 67 | p1 = param(1) 68 | p2 = param(2) 69 | p3 = param(3) 70 | p4 = param(4) 71 | p5 = param(5) 72 | p6 = param(6) 73 | 74 | if (aniso.eq.1) then 75 | xani = x*cos(ani(1)) + y*sin(ani(1)) 76 | yani = -x*sin(ani(1))/ani(2) + y*cos(ani(1))/ani(2) 77 | c dx=x*cos(ani(1))*x*cos(ani(1)) + 78 | c & (x*sin(ani(1))/ani(2))*(x*sin(ani(1))/ani(2)) 79 | c & + 2*x*y*cos(ani(1))*sin(ani(1)) 80 | c & - 2*x*y*cos(ani(1))*sin(ani(1))/(ani(2)*ani(2)) 81 | c & + y*sin(ani(1))*y*sin(ani(1)) 82 | c & + (y*cos(ani(1))/ani(2))*(y*cos(ani(1))/ani(2)) 83 | dx=dsqrt(xani*xani+yani*yani)/scale(1) 84 | c dx=dsqrt(dx)/scale(1) 85 | else 86 | dx=dsqrt(x*x+y*y)/scale(1) 87 | end if 88 | 89 | dt=dabs(t)/scale(2) 90 | 91 | mod=0d0 92 | mods=0d0 93 | modt=0d0 94 | 95 | c 96 | c model= 0 (none) 97 | c 98 | 99 | if(model(1).eq.0) then 100 | mods = 1d0 101 | endif 102 | 103 | if(model(2).eq.0) then 104 | modt = 1d0 105 | endif 106 | 107 | c 108 | c model = 1 (Exponential) 109 | c 110 | 111 | if(model(1).eq.1) then 112 | mods = exponential(dx) 113 | end if 114 | 115 | if(model(2).eq.1) then 116 | modt = exponential(dt) 117 | end if 118 | 119 | c 120 | c model = 2 (Stable) 121 | c 122 | 123 | if(model(1).eq.2) then 124 | mods = stable(dx,p1) 125 | end if 126 | 127 | if(model(2).eq.2) then 128 | modt = stable(dt,p2) 129 | end if 130 | 131 | c 132 | c model = 3 (Cauchy) 133 | c 134 | 135 | if(model(1).eq.3) then 136 | mods = cauchy(dx,p1) 137 | end if 138 | 139 | if(model(2).eq.3) then 140 | modt = cauchy(dt,p2) 141 | end if 142 | 143 | c 144 | c model = 4 (Wave) 145 | c 146 | 147 | if(model(1).eq.4) then 148 | mods = wave(dx) 149 | endif 150 | 151 | if(model(2).eq.4) then 152 | modt = wave(dt) 153 | endif 154 | 155 | c 156 | c model = 7 (Matern) 157 | c 158 | 159 | if(model(1).eq.7) then 160 | theta(1) = 1d0 161 | theta(2) = p3 162 | theta(3) = p1 163 | mods = matern(theta,dx) 164 | endif 165 | 166 | if(model(2).eq.7) then 167 | theta(1) = 1d0 168 | theta(2) = p4 169 | theta(3) = p2 170 | modt = matern(theta,dt) 171 | endif 172 | 173 | c 174 | c product 175 | c 176 | 177 | mod = mods * modt 178 | 179 | c 180 | c model = 5 (Gneiting) 181 | c 182 | 183 | if(model(3).eq.5) then 184 | mod = gneiting(dx,dt,param) 185 | endif 186 | 187 | c 188 | c model = 6 (De Cesare) 189 | c 190 | 191 | if(model(3).eq.6) then 192 | mod = cesare(dx,dt,p1,p2,p3) 193 | endif 194 | 195 | c 196 | c result 197 | c 198 | 199 | covar = sigma2*mod 200 | 201 | return 202 | end 203 | 204 | ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc 205 | -------------------------------------------------------------------------------- /src/gspcore.f: -------------------------------------------------------------------------------- 1 | C Francisco J. Rodriguez-Cortes, November 2016 2 | C 3 | C This code provides a non-parametric kernel based estimator of the 4 | C spatial mark variogram function. 5 | C 6 | 7 | subroutine gspcore(x,y,txy,n,s,ns,ks,hs,gsps) 8 | 9 | implicit double precision (a-h,o-z) 10 | 11 | integer i,j,iu,n,ns,ks 12 | double precision wij,vij,hs,kerns,gspm,gspn,gsps,x,y,txy 13 | double precision hij,mij,xi,yi,ti,two 14 | dimension x(n),y(n),txy(n),s(ns),gspm(ns),gspn(ns),gsps(ns),ks(3) 15 | 16 | gspm=0d0 17 | gspn=0d0 18 | 19 | two=2d0 20 | 21 | do iu=1,ns 22 | do i=1,n 23 | xi=x(i) 24 | yi=y(i) 25 | ti=txy(i) 26 | do j=1,n 27 | if (j.ne.i) then 28 | hij=sqrt(((xi-x(j))**two)+((yi-y(j))**two)) 29 | mij=((abs(ti-txy(j)))**two)/two 30 | if (ks(1).eq.1) then 31 | kerns=boxkernel((s(iu)-hij)/hs,hs) 32 | else if (ks(2).eq.1) then 33 | kerns=ekernel((s(iu)-hij)/hs,hs) 34 | else if (ks(3).eq.1) then 35 | kerns=qkernel((s(iu)-hij)/hs,hs) 36 | end if 37 | if (kerns.ne.0d0) then 38 | wij=mij*kerns 39 | vij=kerns 40 | gspm(iu)=gspm(iu)+wij 41 | gspn(iu)=gspn(iu)+vij 42 | end if 43 | end if 44 | end do 45 | end do 46 | gsps(iu)=gspm(iu)/gspn(iu) 47 | end do 48 | 49 | return 50 | 51 | end -------------------------------------------------------------------------------- /src/gspcoreinh.f: -------------------------------------------------------------------------------- 1 | C Francisco J. Rodriguez-Cortes, November 2016 2 | C 3 | C This code provides an edge-corrected non-parametric kernel based 4 | C estimator of the standardized spatial mark variogram function. 5 | C 6 | 7 | subroutine gspcoreinh(x,y,txy,n,s,ns,slambda,ks,hs,wrs,wts, 8 | + wbi,wbimod,wss,edg,gsps) 9 | 10 | implicit double precision (a-h,o-z) 11 | 12 | integer i,j,iu,n,ns,ks,edg 13 | double precision inhwij,inhvij,hs,kerns,gspminh,gspninh,gsps 14 | double precision hij,mij,xi,yi,ti,two,wrs,wts,wbi,x,y,txy 15 | double precision wbimod,wss,slambda 16 | dimension x(n),y(n),txy(n),s(ns),gspminh(ns),gspninh(ns) 17 | dimension wrs(n,n),wts(n,n),wbi(n,ns),wbimod(n,ns),wss(ns) 18 | dimension ks(3),edg(6),slambda(n),gsps(ns) 19 | 20 | gspminh=0d0 21 | gspninh=0d0 22 | 23 | two=2d0 24 | 25 | do iu=1,ns 26 | do i=1,n 27 | xi=x(i) 28 | yi=y(i) 29 | ti=txy(i) 30 | do j=1,n 31 | if (j.ne.i) then 32 | hij=sqrt(((xi-x(j))**two)+((yi-y(j))**two)) 33 | mij=((abs(ti-txy(j)))**two)/two 34 | if (ks(1).eq.1) then 35 | kerns=boxkernel((s(iu)-hij)/hs,hs) 36 | else if (ks(2).eq.1) then 37 | kerns=ekernel((s(iu)-hij)/hs,hs) 38 | else if (ks(3).eq.1) then 39 | kerns=qkernel((s(iu)-hij)/hs,hs) 40 | end if 41 | if (kerns.ne.0d0) then 42 | C none 43 | if (edg(1).eq.1) then 44 | inhwij=(mij*kerns)/(slambda(i)*slambda(j)) 45 | inhvij=kerns/(slambda(i)*slambda(j)) 46 | gspminh(iu)=gspminh(iu)+inhwij 47 | gspninh(iu)=gspninh(iu)+inhvij 48 | end if 49 | C isotropic 50 | if (edg(2).eq.1) then 51 | inhwij=(mij*kerns*wrs(i,j))/(slambda(i)*slambda(j)) 52 | inhvij=(kerns*wrs(i,j))/(slambda(i)*slambda(j)) 53 | gspminh(iu)=gspminh(iu)+inhwij 54 | gspninh(iu)=gspninh(iu)+inhvij 55 | end if 56 | C border 57 | if (edg(3).eq.1) then 58 | inhwij=(mij*kerns*wbi(i,iu))/(slambda(i)*slambda(j)) 59 | inhvij=(kerns*wbi(i,iu))/(slambda(i)*slambda(j)) 60 | gspminh(iu)=gspminh(iu)+inhwij 61 | gspninh(iu)=gspninh(iu)+inhvij 62 | end if 63 | C modified.border 64 | if (edg(4).eq.1) then 65 | inhwij=(mij*kerns*wbimod(i,iu))/(slambda(i)*slambda(j)) 66 | inhvij=(kerns*wbimod(i,iu))/(slambda(i)*slambda(j)) 67 | gspminh(iu)=gspminh(iu)+inhwij 68 | gspninh(iu)=gspninh(iu)+inhvij 69 | end if 70 | C translate 71 | if (edg(5).eq.1) then 72 | inhwij=(mij*kerns*wts(i,j))/(slambda(i)*slambda(j)) 73 | inhvij=(kerns*wts(i,j))/(slambda(i)*slambda(j)) 74 | gspminh(iu)=gspminh(iu)+inhwij 75 | gspninh(iu)=gspninh(iu)+inhvij 76 | end if 77 | C setcovf 78 | if (edg(6).eq.1) then 79 | inhwij=(mij*kerns*wss(iu))/(slambda(i)*slambda(j)) 80 | inhvij=(kerns*wss(iu))/(slambda(i)*slambda(j)) 81 | gspminh(iu)=gspminh(iu)+inhwij 82 | gspninh(iu)=gspninh(iu)+inhvij 83 | end if 84 | end if 85 | end if 86 | end do 87 | end do 88 | gsps(iu)=gspminh(iu)/gspninh(iu) 89 | end do 90 | 91 | return 92 | 93 | end 94 | -------------------------------------------------------------------------------- /src/gtecore.f: -------------------------------------------------------------------------------- 1 | C Francisco J. Rodriguez-Cortes, November 2016 2 | C 3 | C This code provides a non-parametric kernel based estimator of the 4 | C temporal mark variogram function. 5 | C 6 | 7 | subroutine gtecore(x,y,txy,n,t,nt,kt,ht,gtet) 8 | 9 | implicit double precision (a-h,o-z) 10 | 11 | integer i,j,iv,n,nt,kt 12 | double precision wij,vij,ht,kernt,gtem,gten,gtet,x,y,txy 13 | double precision tij,mij,ti,xi,yi 14 | dimension x(n),y(n),txy(n),t(nt),gtem(nt),gten(nt),gtet(nt),kt(3) 15 | 16 | gtem=0d0 17 | gten=0d0 18 | 19 | two=2d0 20 | 21 | do iv=1,nt 22 | do i=1,n 23 | xi=x(i) 24 | yi=y(i) 25 | ti=txy(i) 26 | do j=1,n 27 | if (j.ne.i) then 28 | tij=abs(ti-txy(j)) 29 | mij=((sqrt(((xi-x(j))**two)+((yi-y(j))**two)))**two)/two 30 | if (kt(1).eq.1) then 31 | kernt=boxkernel((t(iv)-tij)/ht,ht) 32 | else if (kt(2).eq.1) then 33 | kernt=ekernel((t(iv)-tij)/ht,ht) 34 | else if (kt(3).eq.1) then 35 | kernt=qkernel((t(iv)-tij)/ht,ht) 36 | end if 37 | if (kernt.ne.0d0) then 38 | wij=mij*kernt 39 | vij=kernt 40 | gtem(iv)=gtem(iv)+wij 41 | gten(iv)=gten(iv)+vij 42 | end if 43 | end if 44 | end do 45 | end do 46 | gtet(iv)=gtem(iv)/gten(iv) 47 | end do 48 | 49 | return 50 | 51 | end 52 | -------------------------------------------------------------------------------- /src/gtecoreinh.f: -------------------------------------------------------------------------------- 1 | C Francisco J. Rodriguez-Cortes, November 2016 2 | C 3 | C This code provides an edge-corrected non-parametric kernel based 4 | C estimator of the standardized temporal mark variogram function. 5 | C 6 | 7 | subroutine gtecoreinh(x,y,txy,n,t,nt,tlambda,kt,ht,wrt,wtt, 8 | + wbit,wbimodt,wst,edg,gtet) 9 | 10 | implicit double precision (a-h,o-z) 11 | 12 | integer i,j,iv,n,nt,kt,edg 13 | double precision inhwij,inhvij,ht,kernt,gteminh,gteninh,gtet 14 | double precision tij,mij,xi,yi,ti,wrt,wtt,wbit,x,y,txy 15 | double precision wbimodt,wst,tlambda 16 | dimension x(n),y(n),txy(n),t(nt),gteminh(nt),gteninh(nt) 17 | dimension wrt(n,n),wtt(n,n),wbit(n,nt),wbimodt(n,nt),wst(nt) 18 | dimension kt(3),edg(6),tlambda(n),gtet(nt) 19 | 20 | gteminh=0d0 21 | gteninh=0d0 22 | 23 | two=2d0 24 | 25 | do iv=1,nt 26 | do i=1,n 27 | xi=x(i) 28 | yi=y(i) 29 | ti=txy(i) 30 | do j=1,n 31 | if (j.ne.i) then 32 | tij=abs(ti-txy(j)) 33 | mij=((sqrt(((xi-x(j))**two)+((yi-y(j))**two)))**two)/two 34 | if (kt(1).eq.1) then 35 | kernt=boxkernel((t(iv)-tij)/ht,ht) 36 | else if (kt(2).eq.1) then 37 | kernt=ekernel((t(iv)-tij)/ht,ht) 38 | else if (kt(3).eq.1) then 39 | kernt=qkernel((t(iv)-tij)/ht,ht) 40 | end if 41 | if (kernt.ne.0d0) then 42 | C none 43 | if (edg(1).eq.1) then 44 | inhwij=(mij*kernt)/(tlambda(i)*tlambda(j)) 45 | inhvij=kernt/(tlambda(i)*tlambda(j)) 46 | gteminh(iv)=gteminh(iv)+inhwij 47 | gteninh(iv)=gteninh(iv)+inhvij 48 | end if 49 | C isotropic 50 | if (edg(2).eq.1) then 51 | inhwij=(mij*kernt*wrt(i,j))/(tlambda(i)*tlambda(j)) 52 | inhvij=(kernt*wrt(i,j))/(tlambda(i)*tlambda(j)) 53 | gteminh(iv)=gteminh(iv)+inhwij 54 | gteninh(iv)=gteninh(iv)+inhvij 55 | end if 56 | C border 57 | if (edg(3).eq.1) then 58 | inhwij=(mij*kernt*wbit(i,iv))/(tlambda(i)*tlambda(j)) 59 | inhvij=(kernt*wbit(i,iv))/(tlambda(i)*tlambda(j)) 60 | gteminh(iv)=gteminh(iv)+inhwij 61 | gteninh(iv)=gteninh(iv)+inhvij 62 | end if 63 | C modified.border 64 | if (edg(4).eq.1) then 65 | inhwij=(mij*kernt*wbimodt(i,iv))/(tlambda(i)*tlambda(j)) 66 | inhvij=(kernt*wbimodt(i,iv))/(tlambda(i)*tlambda(j)) 67 | gteminh(iv)=gteminh(iv)+inhwij 68 | gteninh(iv)=gteninh(iv)+inhvij 69 | end if 70 | C translate 71 | if (edg(5).eq.1) then 72 | inhwij=(mij*kernt*wtt(i,j))/(tlambda(i)*tlambda(j)) 73 | inhvij=(kernt*wtt(i,j))/(tlambda(i)*tlambda(j)) 74 | gteminh(iv)=gteminh(iv)+inhwij 75 | gteninh(iv)=gteninh(iv)+inhvij 76 | end if 77 | C setcovf 78 | if (edg(6).eq.1) then 79 | inhwij=(mij*kernt*wst(iv))/(tlambda(i)*tlambda(j)) 80 | inhvij=(kernt*wst(iv))/(tlambda(i)*tlambda(j)) 81 | gteminh(iv)=gteminh(iv)+inhwij 82 | gteninh(iv)=gteninh(iv)+inhvij 83 | end if 84 | end if 85 | end if 86 | end do 87 | end do 88 | gtet(iv)=gteminh(iv)/gteninh(iv) 89 | end do 90 | 91 | return 92 | 93 | end 94 | -------------------------------------------------------------------------------- /src/init.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include // for NULL 3 | #include 4 | 5 | /* FIXME: 6 | 7 | Check these declarations against the C/Fortran source code. 8 | 9 | */ 10 | 11 | /* .Fortran calls */ 12 | extern void F77_NAME(astk)(void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *); 13 | extern void F77_NAME(circ)(void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *); 14 | extern void F77_NAME(covst)(void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *); 15 | extern void F77_NAME(listafunction)(void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *); 16 | extern void F77_NAME(klistafunction)(void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *); 17 | extern void F77_NAME(pcffunction)(void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *); 18 | extern void F77_NAME(stikfunction)(void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *); 19 | extern void F77_NAME(gspcore)(void *, void *, void *, void *, void *, void *, void *, void *, void *); 20 | extern void F77_NAME(gspcoreinh)(void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *); 21 | extern void F77_NAME(gtecore)(void *, void *, void *, void *, void *, void *, void *, void *, void *); 22 | extern void F77_NAME(gtecoreinh)(void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *); 23 | extern void F77_NAME(kmrcore)(void *, void *, void *, void *, void *, void *, void *, void *, void *); 24 | extern void F77_NAME(kmrcoreinh)(void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *); 25 | extern void F77_NAME(kmtcore)(void *, void *, void *, void *, void *, void *, void *, void *); 26 | extern void F77_NAME(kmtcoreinh)(void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *); 27 | extern void F77_NAME(kmmrcore)(void *, void *, void *, void *, void *, void *, void *, void *, void *); 28 | extern void F77_NAME(kmmrcoreinh)(void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *); 29 | extern void F77_NAME(kmmtcore)(void *, void *, void *, void *, void *, void *, void *, void *); 30 | extern void F77_NAME(kmmtcoreinh)(void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *); 31 | static const R_FortranMethodDef FortranEntries[] = { 32 | 33 | {"astk", (DL_FUNC) &F77_NAME(astk), 15}, 34 | {"circ", (DL_FUNC) &F77_NAME(circ), 12}, 35 | {"covst", (DL_FUNC) &F77_NAME(covst), 13}, 36 | {"listafunction", (DL_FUNC) &F77_NAME(listafunction), 27}, 37 | {"klistafunction", (DL_FUNC) &F77_NAME(klistafunction), 23}, 38 | {"pcffunction", (DL_FUNC) &F77_NAME(pcffunction), 23}, 39 | {"stikfunction", (DL_FUNC) &F77_NAME(stikfunction), 20}, 40 | {"gspcore", (DL_FUNC) &F77_NAME(gspcore), 9}, 41 | {"gspcoreinh", (DL_FUNC) &F77_NAME(gspcoreinh), 16}, 42 | {"gtecore", (DL_FUNC) &F77_NAME(gtecore), 9}, 43 | {"gtecoreinh", (DL_FUNC) &F77_NAME(gtecoreinh), 16}, 44 | {"kmrcore", (DL_FUNC) &F77_NAME(kmrcore), 9}, 45 | {"kmrcoreinh", (DL_FUNC) &F77_NAME(kmrcoreinh), 16}, 46 | {"kmtcore", (DL_FUNC) &F77_NAME(kmtcore), 8}, 47 | {"kmtcoreinh", (DL_FUNC) &F77_NAME(kmtcoreinh), 15}, 48 | {"kmmrcore", (DL_FUNC) &F77_NAME(kmrcore), 9}, 49 | {"kmmrcoreinh", (DL_FUNC) &F77_NAME(kmrcoreinh), 16}, 50 | {"kmmtcore", (DL_FUNC) &F77_NAME(kmtcore), 8}, 51 | {"kmmtcoreinh", (DL_FUNC) &F77_NAME(kmtcoreinh), 15}, 52 | {NULL, NULL, 0} 53 | }; 54 | 55 | void R_init_stpp(DllInfo *dll) 56 | { 57 | R_registerRoutines(dll, NULL, NULL, FortranEntries, NULL); 58 | R_useDynamicSymbols(dll, FALSE); 59 | } 60 | 61 | -------------------------------------------------------------------------------- /src/klistafunction.f: -------------------------------------------------------------------------------- 1 | C 2 | C Francisco J., Rodriguez-Cortes, March 2019 3 | C 4 | C This function provides an edge corrected estimate 5 | C of the space-time K LISTA. 6 | C 7 | 8 | subroutine klistafunction(i,xi,yi,ti,x,y,txy,n,xp,yp,np,s,ns,t,nt, 9 | + bsupt,binft,lambda,klistahat,wbi,wbimod,wt,correc) 10 | 11 | cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc 12 | c 13 | c x,y,txy: coordinates and times of the point process of length n 14 | c xp,yp: coordinates of the np points defining the polygonal 15 | c region 16 | c s: vector of the ns distances at which to calculate the ith LISTA 17 | c function, 18 | c t: vector of the nt times at which to calculate the ith LISTA 19 | c function, 20 | c bint, bsupt: lower and upper boundaries of the time domain, 21 | c klistahat: zero matrix of dimension ns x nt. 22 | c 23 | cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc 24 | 25 | implicit double precision (a-h,o-z) 26 | 27 | integer n,ns,nt,np,iu,iv,correc(5),i 28 | double precision klistahat(ns,nt,5),two,lambda(n),xi,yi,ti 29 | double precision wbi(n,ns,nt), wbimod(n,ns,nt), wt(n,n) 30 | dimension x(n),y(n),txy(n),xp(np+1),yp(np+1),s(ns),t(nt) 31 | double precision binf, binft, bsup, bsupt, tij 32 | double precision vij, wij 33 | 34 | two=2d0 35 | 36 | do j=1,n 37 | do iu=1,ns 38 | do iv=1,nt 39 | if (j.ne.i) then 40 | hij=dsqrt((xi-x(j))*(xi-x(j)) + (yi-y(j))*(yi-y(j))) 41 | tij=dabs(ti-txy(j)) 42 | if ((tij.le.t(iv)).and.(hij.le.s(iu))) then 43 | c isotropic 44 | if(correc(2).eq.1) then 45 | bsup=ti+tij 46 | binf=ti-tij 47 | if ((bsup.le.bsupt).and.(binf.ge.binft)) then 48 | vij=1d0 49 | else 50 | vij=two 51 | end if 52 | wij=weight(xi,yi,hij,xp,yp,np) 53 | wij=vij*wij/(lambda(i)*lambda(j)) 54 | klistahat(iu,iv,2)=klistahat(iu,iv,2)+wij 55 | end if 56 | c none 57 | if (correc(1).eq.1) then 58 | vij=1d0 59 | wij=vij/(lambda(i)*lambda(j)) 60 | klistahat(iu,iv,1)=klistahat(iu,iv,1)+wij 61 | end if 62 | c border 63 | if (correc(3).eq.1) then 64 | wij=wbi(i,iu,iv) 65 | wij=wij/(lambda(i)*lambda(j)) 66 | klistahat(iu,iv,3)=klistahat(iu,iv,3)+wij 67 | end if 68 | c modified border 69 | if (correc(4).eq.1) then 70 | wij=wbimod(i,iu,iv) 71 | wij=wij/(lambda(i)*lambda(j)) 72 | klistahat(iu,iv,4)=klistahat(iu,iv,4)+wij 73 | end if 74 | c translate 75 | if (correc(5).eq.1) then 76 | wij=wt(i,j)/(lambda(i)*lambda(j)) 77 | klistahat(iu,iv,5)=klistahat(iu,iv,5)+wij 78 | end if 79 | 80 | end if 81 | end if 82 | end do 83 | end do 84 | end do 85 | 86 | return 87 | 88 | end -------------------------------------------------------------------------------- /src/kmmrcore.f: -------------------------------------------------------------------------------- 1 | C Francisco J. Rodriguez-Cortes, November 2016 2 | C 3 | C This code provides a non-parametric kernel based estimator of the 4 | C spatial mark correlation function. 5 | C 6 | 7 | subroutine kmmrcore(x,y,txy,n,s,ns,ks,hs,kmmr) 8 | 9 | implicit real*8(a-h,o-z) 10 | 11 | integer i,j,iu,n,ns,ks 12 | double precision wij,vij,hs,kerns,krm,krn,kmmr,x,y,txy 13 | double precision hij,mij,xi,yi,ti,two 14 | dimension x(n),y(n),txy(n),s(ns),krm(ns),krn(ns),kmmr(ns),ks(3) 15 | 16 | krm=0d0 17 | krn=0d0 18 | 19 | two=2d0 20 | 21 | do iu=1,ns 22 | do i=1,n 23 | xi=x(i) 24 | yi=y(i) 25 | ti=txy(i) 26 | do j=1,n 27 | if (j.ne.i) then 28 | hij=sqrt(((xi-x(j))**two)+((yi-y(j))**two)) 29 | mij=ti*txy(j) 30 | if (ks(1).eq.1) then 31 | kerns=boxkernel((s(iu)-hij)/hs,hs) 32 | else if (ks(2).eq.1) then 33 | kerns=ekernel((s(iu)-hij)/hs,hs) 34 | else if (ks(3).eq.1) then 35 | kerns=qkernel((s(iu)-hij)/hs,hs) 36 | end if 37 | if (kerns.ne.0d0) then 38 | wij=mij*kerns 39 | vij=kerns 40 | krm(iu)=krm(iu)+wij 41 | krn(iu)=krn(iu)+vij 42 | end if 43 | end if 44 | end do 45 | end do 46 | kmmr(iu)=krm(iu)/krn(iu) 47 | end do 48 | 49 | return 50 | 51 | end 52 | -------------------------------------------------------------------------------- /src/kmmrcoreinh.f: -------------------------------------------------------------------------------- 1 | C Francisco J. Rodriguez-Cortes, November 2016 2 | C 3 | C This code provides an edge-corrected non-parametric kernel based 4 | C estimator of the standardized spatial mark correlation function. 5 | C 6 | 7 | subroutine kmmrcoreinh(x,y,txy,n,s,ns,slambda,ks,hs,wrs,wts, 8 | + wbi,wbimod,wss,edg,kmmr) 9 | 10 | implicit real*8(a-h,o-z) 11 | 12 | integer i,j,iu,n,ns,ks,edg 13 | double precision inhwij,inhvij,hs,kerns,kmrminh,kmrninh,kmmr 14 | double precision hij,mij,xi,yi,ti,two,wrs,wts,wbi,x,y,txy 15 | double precision wbimod,wss,slambda 16 | dimension x(n),y(n),txy(n),s(ns),kmrminh(ns),kmrninh(ns) 17 | dimension wrs(n,n),wts(n,n),wbi(n,ns),wbimod(n,ns),wss(ns) 18 | dimension ks(3),edg(6),slambda(n),kmmr(ns) 19 | 20 | kmrminh=0d0 21 | kmrninh=0d0 22 | 23 | two=2d0 24 | 25 | do iu=1,ns 26 | do i=1,n 27 | xi=x(i) 28 | yi=y(i) 29 | ti=txy(i) 30 | do j=1,n 31 | if (j.ne.i) then 32 | hij=sqrt(((xi-x(j))**two)+((yi-y(j))**two)) 33 | mij=ti*txy(j) 34 | if (ks(1).eq.1) then 35 | kerns=boxkernel((s(iu)-hij)/hs,hs) 36 | else if (ks(2).eq.1) then 37 | kerns=ekernel((s(iu)-hij)/hs,hs) 38 | else if (ks(3).eq.1) then 39 | kerns=qkernel((s(iu)-hij)/hs,hs) 40 | end if 41 | if (kerns.ne.0d0) then 42 | C none 43 | if (edg(1).eq.1) then 44 | inhwij=(mij*kerns)/(slambda(i)*slambda(j)) 45 | inhvij=kerns/(slambda(i)*slambda(j)) 46 | kmrminh(iu)=kmrminh(iu)+inhwij 47 | kmrninh(iu)=kmrninh(iu)+inhvij 48 | end if 49 | C isotropic 50 | if (edg(2).eq.1) then 51 | inhwij=(mij*kerns*wrs(i,j))/(slambda(i)*slambda(j)) 52 | inhvij=(kerns*wrs(i,j))/(slambda(i)*slambda(j)) 53 | kmrminh(iu)=kmrminh(iu)+inhwij 54 | kmrninh(iu)=kmrninh(iu)+inhvij 55 | end if 56 | C border 57 | if (edg(3).eq.1) then 58 | inhwij=(mij*kerns*wbi(i,iu))/(slambda(i)*slambda(j)) 59 | inhvij=(kerns*wbi(i,iu))/(slambda(i)*slambda(j)) 60 | kmrminh(iu)=kmrminh(iu)+inhwij 61 | kmrninh(iu)=kmrninh(iu)+inhvij 62 | end if 63 | C modified.border 64 | if (edg(4).eq.1) then 65 | inhwij=(mij*kerns*wbimod(i,iu))/(slambda(i)*slambda(j)) 66 | inhvij=(kerns*wbimod(i,iu))/(slambda(i)*slambda(j)) 67 | kmrminh(iu)=kmrminh(iu)+inhwij 68 | kmrninh(iu)=kmrninh(iu)+inhvij 69 | end if 70 | C translate 71 | if (edg(5).eq.1) then 72 | inhwij=(mij*kerns*wts(i,j))/(slambda(i)*slambda(j)) 73 | inhvij=(kerns*wts(i,j))/(slambda(i)*slambda(j)) 74 | kmrminh(iu)=kmrminh(iu)+inhwij 75 | kmrninh(iu)=kmrninh(iu)+inhvij 76 | end if 77 | C setcovf 78 | if (edg(6).eq.1) then 79 | inhwij=(mij*kerns*wss(iu))/(slambda(i)*slambda(j)) 80 | inhvij=(kerns*wss(iu))/(slambda(i)*slambda(j)) 81 | kmrminh(iu)=kmrminh(iu)+inhwij 82 | kmrninh(iu)=kmrninh(iu)+inhvij 83 | end if 84 | end if 85 | end if 86 | end do 87 | end do 88 | kmmr(iu)=kmrminh(iu)/kmrninh(iu) 89 | end do 90 | 91 | return 92 | 93 | end 94 | -------------------------------------------------------------------------------- /src/kmmtcore.f: -------------------------------------------------------------------------------- 1 | C Francisco J. Rodriguez-Cortes, November 2016 2 | C 3 | C This code provides a non-parametric kernel based estimator of the 4 | C temporal mark correlation function. 5 | C 6 | 7 | subroutine kmmtcore(snorm,txy,n,t,nt,kt,ht,kmmt) 8 | 9 | implicit double precision (a-h,o-z) 10 | 11 | integer i,j,iv,n,nt,kt 12 | double precision wij,vij,ht,kernt,ktm,ktn,kmmt,snorm,txy 13 | double precision tij,mij,snormi,ti 14 | dimension snorm(n),txy(n),t(nt),ktm(nt),ktn(nt),kmmt(nt),kt(3) 15 | 16 | ktm=0d0 17 | ktn=0d0 18 | 19 | do iv=1,nt 20 | do i=1,n 21 | snormi=snorm(i) 22 | ti=txy(i) 23 | do j=1,n 24 | if (j.ne.i) then 25 | tij=abs(ti-txy(j)) 26 | mij=snormi*snorm(j) 27 | if (kt(1).eq.1) then 28 | kernt=boxkernel((t(iv)-tij)/ht,ht) 29 | else if (kt(2).eq.1) then 30 | kernt=ekernel((t(iv)-tij)/ht,ht) 31 | else if (kt(3).eq.1) then 32 | kernt=qkernel((t(iv)-tij)/ht,ht) 33 | end if 34 | if (kernt.ne.0d0) then 35 | wij=mij*kernt 36 | vij=kernt 37 | ktm(iv)=ktm(iv)+wij 38 | ktn(iv)=ktn(iv)+vij 39 | end if 40 | end if 41 | end do 42 | end do 43 | kmmt(iv)=ktm(iv)/ktn(iv) 44 | end do 45 | 46 | return 47 | 48 | end 49 | -------------------------------------------------------------------------------- /src/kmmtcoreinh.f: -------------------------------------------------------------------------------- 1 | C Francisco J. Rodriguez-Cortes, November 2016 2 | C 3 | C This code provides an edge-corrected non-parametric kernel based 4 | C estimator of the standardized temporal mark correlation function. 5 | C 6 | 7 | subroutine kmmtcoreinh(snorm,txy,n,t,nt,tlambda,kt,ht,wrt,wtt, 8 | + wbit,wbimodt,wst,edg,kmmt) 9 | 10 | implicit double precision (a-h,o-z) 11 | 12 | integer i,j,iv,n,nt,kt,edg 13 | double precision inhwij,inhvij,ht,kernt,kmtminh,kmtninh,kmmt 14 | double precision tij,mij,snormi,ti,wrt,wtt,wbit,txy,snorm 15 | double precision wbimodt,wst,tlambda 16 | dimension snorm(n),txy(n),t(nt),kmtminh(nt),kmtninh(nt) 17 | dimension wrt(n,n),wtt(n,n),wbit(n,nt),wbimodt(n,nt),wst(nt) 18 | dimension kt(3),edg(6),tlambda(n),kmmt(nt) 19 | 20 | kmtminh=0d0 21 | kmtninh=0d0 22 | 23 | do iv=1,nt 24 | do i=1,n 25 | snormi=snorm(i) 26 | ti=txy(i) 27 | do j=1,n 28 | if (j.ne.i) then 29 | tij=abs(ti-txy(j)) 30 | mij=snormi*snorm(j) 31 | if (kt(1).eq.1) then 32 | kernt=boxkernel((t(iv)-tij)/ht,ht) 33 | else if (kt(2).eq.1) then 34 | kernt=ekernel((t(iv)-tij)/ht,ht) 35 | else if (kt(3).eq.1) then 36 | kernt=qkernel((t(iv)-tij)/ht,ht) 37 | end if 38 | if (kernt.ne.0d0) then 39 | C none 40 | if (edg(1).eq.1) then 41 | inhwij=(mij*kernt)/(tlambda(i)*tlambda(j)) 42 | inhvij=kernt/(tlambda(i)*tlambda(j)) 43 | kmtminh(iv)=kmtminh(iv)+inhwij 44 | kmtninh(iv)=kmtninh(iv)+inhvij 45 | end if 46 | C isotropic 47 | if (edg(2).eq.1) then 48 | inhwij=(mij*kernt*wrt(i,j))/(tlambda(i)*tlambda(j)) 49 | inhvij=(kernt*wrt(i,j))/(tlambda(i)*tlambda(j)) 50 | kmtminh(iv)=kmtminh(iv)+inhwij 51 | kmtninh(iv)=kmtninh(iv)+inhvij 52 | end if 53 | C border 54 | if (edg(3).eq.1) then 55 | inhwij=(mij*kernt*wbit(i,iv))/(tlambda(i)*tlambda(j)) 56 | inhvij=(kernt*wbit(i,iv))/(tlambda(i)*tlambda(j)) 57 | kmtminh(iv)=kmtminh(iv)+inhwij 58 | kmtninh(iv)=kmtninh(iv)+inhvij 59 | end if 60 | C modified.border 61 | if (edg(4).eq.1) then 62 | inhwij=(mij*kernt*wbimodt(i,iv))/(tlambda(i)*tlambda(j)) 63 | inhvij=(kernt*wbimodt(i,iv))/(tlambda(i)*tlambda(j)) 64 | kmtminh(iv)=kmtminh(iv)+inhwij 65 | kmtninh(iv)=kmtninh(iv)+inhvij 66 | end if 67 | C translate 68 | if (edg(5).eq.1) then 69 | inhwij=(mij*kernt*wtt(i,j))/(tlambda(i)*tlambda(j)) 70 | inhvij=(kernt*wtt(i,j))/(tlambda(i)*tlambda(j)) 71 | kmtminh(iv)=kmtminh(iv)+inhwij 72 | kmtninh(iv)=kmtninh(iv)+inhvij 73 | end if 74 | C setcovf 75 | if (edg(6).eq.1) then 76 | inhwij=(mij*kernt*wst(iv))/(tlambda(i)*tlambda(j)) 77 | inhvij=(kernt*wst(iv))/(tlambda(i)*tlambda(j)) 78 | kmtminh(iv)=kmtminh(iv)+inhwij 79 | kmtninh(iv)=kmtninh(iv)+inhvij 80 | end if 81 | end if 82 | end if 83 | end do 84 | end do 85 | kmmt(iv)=kmtminh(iv)/kmtninh(iv) 86 | end do 87 | 88 | return 89 | 90 | end 91 | -------------------------------------------------------------------------------- /src/kmrcore.f: -------------------------------------------------------------------------------- 1 | C Francisco J. Rodriguez-Cortes, November 2016 2 | C 3 | C This code provides a non-parametric kernel based estimator of the 4 | C spatial r-mark function. 5 | C 6 | 7 | subroutine kmrcore(x,y,txy,n,s,ns,ks,hs,kmr) 8 | 9 | implicit double precision (a-h,o-z) 10 | 11 | integer i,j,iu,n,ns,ks 12 | double precision wij,vij,hs,kerns,krm,krn,kmr,x,y,txy 13 | double precision hij,mij,xi,yi,ti,two 14 | dimension x(n),y(n),txy(n),s(ns),krm(ns),krn(ns),kmr(ns),ks(3) 15 | 16 | krm=0d0 17 | krn=0d0 18 | 19 | two=2d0 20 | 21 | do iu=1,ns 22 | do i=1,n 23 | xi=x(i) 24 | yi=y(i) 25 | ti=txy(i) 26 | do j=1,n 27 | if (j.ne.i) then 28 | hij=sqrt(((xi-x(j))**two)+((yi-y(j))**two)) 29 | mij=ti 30 | if (ks(1).eq.1) then 31 | kerns=boxkernel((s(iu)-hij)/hs,hs) 32 | else if (ks(2).eq.1) then 33 | kerns=ekernel((s(iu)-hij)/hs,hs) 34 | else if (ks(3).eq.1) then 35 | kerns=qkernel((s(iu)-hij)/hs,hs) 36 | end if 37 | if (kerns.ne.0d0) then 38 | wij=mij*kerns 39 | vij=kerns 40 | krm(iu)=krm(iu)+wij 41 | krn(iu)=krn(iu)+vij 42 | end if 43 | end if 44 | end do 45 | end do 46 | kmr(iu)=krm(iu)/krn(iu) 47 | end do 48 | 49 | return 50 | 51 | end 52 | -------------------------------------------------------------------------------- /src/kmrcoreinh.f: -------------------------------------------------------------------------------- 1 | C Francisco J. Rodriguez-Cortes, November 2016 2 | C 3 | C This code provides an edge-corrected non-parametric kernel based 4 | C estimator of the standardized spatial r-mark function. 5 | C 6 | 7 | subroutine kmrcoreinh(x,y,txy,n,s,ns,slambda,ks,hs,wrs,wts, 8 | + wbi,wbimod,wss,edg,kmr) 9 | 10 | implicit double precision (a-h,o-z) 11 | 12 | integer i,j,iu,n,ns,ks,edg 13 | double precision inhwij,inhvij,hs,kerns,kmrminh,kmrninh,kmr 14 | double precision hij,mij,xi,yi,ti,two,wrs,wts,wbi,x,y,txy 15 | double precision wbimod,wss,slambda 16 | dimension x(n),y(n),txy(n),s(ns),kmrminh(ns),kmrninh(ns) 17 | dimension wrs(n,n),wts(n,n),wbi(n,ns),wbimod(n,ns),wss(ns) 18 | dimension ks(3),edg(6),slambda(n),kmr(ns) 19 | 20 | kmrminh=0d0 21 | kmrninh=0d0 22 | 23 | two=2d0 24 | 25 | do iu=1,ns 26 | do i=1,n 27 | xi=x(i) 28 | yi=y(i) 29 | ti=txy(i) 30 | do j=1,n 31 | if (j.ne.i) then 32 | hij=sqrt(((xi-x(j))**two)+((yi-y(j))**two)) 33 | mij=ti 34 | if (ks(1).eq.1) then 35 | kerns=boxkernel((s(iu)-hij)/hs,hs) 36 | else if (ks(2).eq.1) then 37 | kerns=ekernel((s(iu)-hij)/hs,hs) 38 | else if (ks(3).eq.1) then 39 | kerns=qkernel((s(iu)-hij)/hs,hs) 40 | end if 41 | if (kerns.ne.0d0) then 42 | C none 43 | if (edg(1).eq.1) then 44 | inhwij=(mij*kerns)/(slambda(i)*slambda(j)) 45 | inhvij=kerns/(slambda(i)*slambda(j)) 46 | kmrminh(iu)=kmrminh(iu)+inhwij 47 | kmrninh(iu)=kmrninh(iu)+inhvij 48 | end if 49 | C isotropic 50 | if (edg(2).eq.1) then 51 | inhwij=(mij*kerns*wrs(i,j))/(slambda(i)*slambda(j)) 52 | inhvij=(kerns*wrs(i,j))/(slambda(i)*slambda(j)) 53 | kmrminh(iu)=kmrminh(iu)+inhwij 54 | kmrninh(iu)=kmrninh(iu)+inhvij 55 | end if 56 | C border 57 | if (edg(3).eq.1) then 58 | inhwij=(mij*kerns*wbi(i,iu))/(slambda(i)*slambda(j)) 59 | inhvij=(kerns*wbi(i,iu))/(slambda(i)*slambda(j)) 60 | kmrminh(iu)=kmrminh(iu)+inhwij 61 | kmrninh(iu)=kmrninh(iu)+inhvij 62 | end if 63 | C modified.border 64 | if (edg(4).eq.1) then 65 | inhwij=(mij*kerns*wbimod(i,iu))/(slambda(i)*slambda(j)) 66 | inhvij=(kerns*wbimod(i,iu))/(slambda(i)*slambda(j)) 67 | kmrminh(iu)=kmrminh(iu)+inhwij 68 | kmrninh(iu)=kmrninh(iu)+inhvij 69 | end if 70 | C translate 71 | if (edg(5).eq.1) then 72 | inhwij=(mij*kerns*wts(i,j))/(slambda(i)*slambda(j)) 73 | inhvij=(kerns*wts(i,j))/(slambda(i)*slambda(j)) 74 | kmrminh(iu)=kmrminh(iu)+inhwij 75 | kmrninh(iu)=kmrninh(iu)+inhvij 76 | end if 77 | C setcovf 78 | if (edg(6).eq.1) then 79 | inhwij=(mij*kerns*wss(iu))/(slambda(i)*slambda(j)) 80 | inhvij=(kerns*wss(iu))/(slambda(i)*slambda(j)) 81 | kmrminh(iu)=kmrminh(iu)+inhwij 82 | kmrninh(iu)=kmrninh(iu)+inhvij 83 | end if 84 | end if 85 | end if 86 | end do 87 | end do 88 | kmr(iu)=kmrminh(iu)/kmrninh(iu) 89 | end do 90 | 91 | return 92 | 93 | end 94 | -------------------------------------------------------------------------------- /src/kmtcore.f: -------------------------------------------------------------------------------- 1 | C Francisco J. Rodriguez-Cortes, November 2016 2 | C 3 | C This code provides a non-parametric kernel based estimator of the 4 | C temporal t-mark function. 5 | C 6 | 7 | subroutine kmtcore(snorm,txy,n,t,nt,kt,ht,kmt) 8 | 9 | implicit double precision (a-h,o-z) 10 | 11 | integer i,j,iv,n,nt,kt 12 | double precision wij,vij,ht,kernt,ktm,ktn,kmt,snorm,txy 13 | double precision tij,mij,snormi,ti 14 | dimension snorm(n),txy(n),t(nt),ktm(nt),ktn(nt),kmt(nt),kt(3) 15 | 16 | ktm=0d0 17 | ktn=0d0 18 | 19 | do iv=1,nt 20 | do i=1,n 21 | snormi=snorm(i) 22 | ti=txy(i) 23 | do j=1,n 24 | if (j.ne.i) then 25 | tij=abs(ti-txy(j)) 26 | mij=snormi 27 | if (kt(1).eq.1) then 28 | kernt=boxkernel((t(iv)-tij)/ht,ht) 29 | else if (kt(2).eq.1) then 30 | kernt=ekernel((t(iv)-tij)/ht,ht) 31 | else if (kt(3).eq.1) then 32 | kernt=qkernel((t(iv)-tij)/ht,ht) 33 | end if 34 | if (kernt.ne.0d0) then 35 | wij=mij*kernt 36 | vij=kernt 37 | ktm(iv)=ktm(iv)+wij 38 | ktn(iv)=ktn(iv)+vij 39 | end if 40 | end if 41 | end do 42 | end do 43 | kmt(iv)=ktm(iv)/ktn(iv) 44 | end do 45 | 46 | return 47 | 48 | end 49 | -------------------------------------------------------------------------------- /src/kmtcoreinh.f: -------------------------------------------------------------------------------- 1 | C Francisco J. Rodriguez-Cortes, November 2016 2 | C 3 | C This code provides an edge-corrected non-parametric kernel based 4 | C estimator of the standardized temporal t-mark function. 5 | C 6 | 7 | subroutine kmtcoreinh(snorm,txy,n,t,nt,tlambda,kt,ht,wrt,wtt, 8 | + wbit,wbimodt,wst,edg,kmt) 9 | 10 | implicit double precision (a-h,o-z) 11 | 12 | integer i,j,iv,n,nt,kt,edg 13 | double precision inhwij,inhvij,ht,kernt,kmtminh,kmtninh,kmt 14 | double precision tij,mij,snormi,ti,wrt,wtt,wbit,txy,snorm 15 | double precision wbimodt,wst,tlambda 16 | dimension snorm(n),txy(n),t(nt),kmtminh(nt),kmtninh(nt) 17 | dimension wrt(n,n),wtt(n,n),wbit(n,nt),wbimodt(n,nt),wst(nt) 18 | dimension kt(3),edg(6),tlambda(n),kmt(nt) 19 | 20 | kmtminh=0d0 21 | kmtninh=0d0 22 | 23 | do iv=1,nt 24 | do i=1,n 25 | snormi=snorm(i) 26 | ti=txy(i) 27 | do j=1,n 28 | if (j.ne.i) then 29 | tij=abs(ti-txy(j)) 30 | mij=snormi 31 | if (kt(1).eq.1) then 32 | kernt=boxkernel((t(iv)-tij)/ht,ht) 33 | else if (kt(2).eq.1) then 34 | kernt=ekernel((t(iv)-tij)/ht,ht) 35 | else if (kt(3).eq.1) then 36 | kernt=qkernel((t(iv)-tij)/ht,ht) 37 | end if 38 | if (kernt.ne.0d0) then 39 | C none 40 | if (edg(1).eq.1) then 41 | inhwij=(mij*kernt)/(tlambda(i)*tlambda(j)) 42 | inhvij=kernt/(tlambda(i)*tlambda(j)) 43 | kmtminh(iv)=kmtminh(iv)+inhwij 44 | kmtninh(iv)=kmtninh(iv)+inhvij 45 | end if 46 | C isotropic 47 | if (edg(2).eq.1) then 48 | inhwij=(mij*kernt*wrt(i,j))/(tlambda(i)*tlambda(j)) 49 | inhvij=(kernt*wrt(i,j))/(tlambda(i)*tlambda(j)) 50 | kmtminh(iv)=kmtminh(iv)+inhwij 51 | kmtninh(iv)=kmtninh(iv)+inhvij 52 | end if 53 | C border 54 | if (edg(3).eq.1) then 55 | inhwij=(mij*kernt*wbit(i,iv))/(tlambda(i)*tlambda(j)) 56 | inhvij=(kernt*wbit(i,iv))/(tlambda(i)*tlambda(j)) 57 | kmtminh(iv)=kmtminh(iv)+inhwij 58 | kmtninh(iv)=kmtninh(iv)+inhvij 59 | end if 60 | C modified.border 61 | if (edg(4).eq.1) then 62 | inhwij=(mij*kernt*wbimodt(i,iv))/(tlambda(i)*tlambda(j)) 63 | inhvij=(kernt*wbimodt(i,iv))/(tlambda(i)*tlambda(j)) 64 | kmtminh(iv)=kmtminh(iv)+inhwij 65 | kmtninh(iv)=kmtninh(iv)+inhvij 66 | end if 67 | C translate 68 | if (edg(5).eq.1) then 69 | inhwij=(mij*kernt*wtt(i,j))/(tlambda(i)*tlambda(j)) 70 | inhvij=(kernt*wtt(i,j))/(tlambda(i)*tlambda(j)) 71 | kmtminh(iv)=kmtminh(iv)+inhwij 72 | kmtninh(iv)=kmtninh(iv)+inhvij 73 | end if 74 | C setcovf 75 | if (edg(6).eq.1) then 76 | inhwij=(mij*kernt*wst(iv))/(tlambda(i)*tlambda(j)) 77 | inhvij=(kernt*wst(iv))/(tlambda(i)*tlambda(j)) 78 | kmtminh(iv)=kmtminh(iv)+inhwij 79 | kmtninh(iv)=kmtninh(iv)+inhvij 80 | end if 81 | end if 82 | end if 83 | end do 84 | end do 85 | kmt(iv)=kmtminh(iv)/kmtninh(iv) 86 | end do 87 | 88 | return 89 | 90 | end 91 | -------------------------------------------------------------------------------- /src/listafunction.f: -------------------------------------------------------------------------------- 1 | C 2 | C Francisco J., Rodriguez-Cortes, November 2017 3 | C 4 | C This function provides an edge corrected estimate 5 | C of the space-time LISTA pair correlation function. 6 | C 7 | 8 | subroutine listafunction(i,xi,yi,ti,x,y,txy,n,xp,yp,np,s,ns,t,nt, 9 | + bsupt,binft,lambda,ks,kt,hs,ht,listahat,wbi,wbimod,wt,correc) 10 | 11 | cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc 12 | c 13 | c x,y,txy: coordinates and times of the point process of length n 14 | c xp,yp: coordinates of the np points defining the polygonal 15 | c region 16 | c s: vector of the ns distances at which to calculate the ith LISTA 17 | c function, 18 | c t: vector of the nt times at which to calculate the ith LISTA 19 | c function, 20 | c bint, bsupt: lower and upper boundaries of the time domain, 21 | c listahat: zero matrix of dimension ns x nt. 22 | c 23 | cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc 24 | 25 | implicit double precision (a-h,o-z) 26 | 27 | integer n,ns,nt,np,iu,iv,ks,kt,correc(5),i 28 | double precision listahat(ns,nt,5),two,hs,ht,lambda(n),xi,yi,ti 29 | double precision wbi(n,ns,nt), wbimod(n,ns,nt), wt(n,n) 30 | dimension x(n),y(n),txy(n),xp(np+1),yp(np+1),s(ns),t(nt) 31 | double precision binf, binft, bsup, bsupt, tij 32 | double precision vij, wij 33 | double precision kern, kerns, kernt 34 | 35 | two=2d0 36 | kerns=0d0 37 | kernt=0d0 38 | 39 | do j=1,n 40 | do iu=1,ns 41 | do iv=1,nt 42 | if (j.ne.i) then 43 | hij=dsqrt((xi-x(j))*(xi-x(j)) + (yi-y(j))*(yi-y(j))) 44 | tij=dabs(ti-txy(j)) 45 | if (ks.eq.1) then 46 | kerns=boxkernel((s(iu)-hij)/hs,hs) 47 | else if (ks.eq.2) then 48 | kerns=ekernel((s(iu)-hij)/hs,hs) 49 | else if (ks.eq.3) then 50 | kerns=gausskernel((s(iu)-hij)/hs,hs) 51 | else if (ks.eq.4) then 52 | kerns=qkernel((s(iu)-hij)/hs,hs) 53 | end if 54 | if (kt.eq.1) then 55 | kernt=boxkernel((t(iv)-tij)/ht,ht) 56 | else if (kt.eq.2) then 57 | kernt=ekernel((t(iv)-tij)/ht,ht) 58 | else if (kt.eq.3) then 59 | kernt=gausskernel((t(iv)-tij)/ht,ht) 60 | else if (kt.eq.4) then 61 | kernt=qkernel((t(iv)-tij)/ht,ht) 62 | end if 63 | kern=kerns*kernt 64 | if (kern.ne.0) then 65 | c isotropic 66 | if(correc(2).eq.1) then 67 | bsup=ti+tij 68 | binf=ti-tij 69 | if ((bsup.le.bsupt).and.(binf.ge.binft)) then 70 | vij=1d0 71 | else 72 | vij=two 73 | end if 74 | wij=weight(xi,yi,hij,xp,yp,np) 75 | wij=kern*vij*wij/(lambda(i)*lambda(j)) 76 | listahat(iu,iv,2)=listahat(iu,iv,2)+wij 77 | end if 78 | c None 79 | if (correc(1).eq.1) then 80 | wij=kern/(lambda(i)*lambda(j)) 81 | listahat(iu,iv,1)=listahat(iu,iv,1)+wij 82 | end if 83 | c border 84 | if (correc(3).eq.1) then 85 | wij=wbi(i,iu,iv) 86 | wij=kern*wij/(lambda(i)*lambda(j)) 87 | listahat(iu,iv,3)=listahat(iu,iv,3)+wij 88 | end if 89 | c modified border 90 | if (correc(4).eq.1) then 91 | wij=wbimod(i,iu,iv) 92 | wij=kern*wij/(lambda(i)*lambda(j)) 93 | listahat(iu,iv,4)=listahat(iu,iv,4)+wij 94 | end if 95 | c translate 96 | if (correc(5).eq.1) then 97 | wij=wt(i,j) 98 | wij=kern*wij/(lambda(i)*lambda(j)) 99 | listahat(iu,iv,5)=listahat(iu,iv,5)+wij 100 | end if 101 | end if 102 | end if 103 | end do 104 | end do 105 | end do 106 | 107 | 108 | return 109 | 110 | end 111 | -------------------------------------------------------------------------------- /src/pcffunction.f: -------------------------------------------------------------------------------- 1 | C 2 | C E. Gabriel, August 2012 3 | C 4 | C This function provides an edge corrected estimate 5 | C of the space-time pair correlation function. 6 | C 7 | 8 | subroutine pcffunction(x,y,txy,n,xp,yp,np,s,ns,t,nt, 9 | + bsupt,binft,lambda,ks,kt,hs,ht,pcfhat, 10 | + wbi,wbimod,wt,correc) 11 | 12 | cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc 13 | c 14 | c x,y,txy: coordinates and times of the point process of length n 15 | c xp,yp: coordinates of the np points defining the polygonal 16 | c region 17 | c s: vector of the ns distances at which to calculate the K 18 | c function, 19 | c t: vector of the nt times at which to calculate the K function, 20 | c bint, bsupt: lower and upper boundaries of the time domain, 21 | c pcfhat: zero matrix of dimension ns x nt. 22 | c 23 | cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc 24 | 25 | implicit double precision (a-h,o-z) 26 | 27 | integer n,ns,nt,np,iu,iv,ks,kt,correc(5) 28 | double precision pcfhat(ns,nt,5), two, hs, ht, lambda(n) 29 | double precision wbi(n,ns,nt), wbimod(n,ns,nt), wt(n,n) 30 | dimension x(n),y(n),txy(n),xp(np+1),yp(np+1),s(ns),t(nt) 31 | double precision binf, binft, bsup, bsupt, ti, tij 32 | double precision vij, wij 33 | double precision kern, kerns, kernt 34 | 35 | two=2d0 36 | kerns=0d0 37 | kernt=0d0 38 | 39 | do iu=1,ns 40 | do iv=1,nt 41 | do i=1,n 42 | xi=x(i) 43 | yi=y(i) 44 | ti=txy(i) 45 | do j=1,n 46 | if (j.ne.i) then 47 | hij=dsqrt((xi-x(j))*(xi-x(j)) + (yi-y(j))*(yi-y(j))) 48 | tij=dabs(ti-txy(j)) 49 | if (ks.eq.1) then 50 | kerns=boxkernel((s(iu)-hij)/hs,hs) 51 | else if (ks.eq.2) then 52 | kerns=ekernel((s(iu)-hij)/hs,hs) 53 | else if (ks.eq.3) then 54 | kerns=gausskernel((s(iu)-hij)/hs,hs) 55 | else if (ks.eq.4) then 56 | kerns=qkernel((s(iu)-hij)/hs,hs) 57 | end if 58 | if (kt.eq.1) then 59 | kernt=boxkernel((t(iv)-tij)/ht,ht) 60 | else if (kt.eq.2) then 61 | kernt=ekernel((t(iv)-tij)/ht,ht) 62 | else if (kt.eq.3) then 63 | kernt=gausskernel((t(iv)-tij)/ht,ht) 64 | else if (kt.eq.4) then 65 | kernt=qkernel((t(iv)-tij)/ht,ht) 66 | end if 67 | kern=kerns*kernt 68 | if (kern.ne.0) then 69 | c isotropic 70 | if(correc(2).eq.1) then 71 | bsup=ti+tij 72 | binf=ti-tij 73 | if ((bsup.le.bsupt).and.(binf.ge.binft)) then 74 | vij=1d0 75 | else 76 | vij=two 77 | end if 78 | wij=weight(xi,yi,hij,xp,yp,np) 79 | wij=kern*vij*wij/(lambda(i)*lambda(j)) 80 | pcfhat(iu,iv,2)=pcfhat(iu,iv,2)+wij 81 | end if 82 | c None 83 | if (correc(1).eq.1) then 84 | wij=kern/(lambda(i)*lambda(j)) 85 | pcfhat(iu,iv,1)=pcfhat(iu,iv,1)+wij 86 | end if 87 | c border 88 | if (correc(3).eq.1) then 89 | wij=wbi(i,iu,iv) 90 | wij=kern*wij/(lambda(i)*lambda(j)) 91 | pcfhat(iu,iv,3)=pcfhat(iu,iv,3)+wij 92 | end if 93 | c modified border 94 | if (correc(4).eq.1) then 95 | wij=wbimod(i,iu,iv) 96 | wij=kern*wij/(lambda(i)*lambda(j)) 97 | pcfhat(iu,iv,4)=pcfhat(iu,iv,4)+wij 98 | end if 99 | c translate 100 | if (correc(5).eq.1) then 101 | wij=wt(i,j) 102 | wij=kern*wij/(lambda(i)*lambda(j)) 103 | pcfhat(iu,iv,5)=pcfhat(iu,iv,5)+wij 104 | end if 105 | end if 106 | end if 107 | end do 108 | end do 109 | end do 110 | end do 111 | 112 | 113 | return 114 | 115 | end 116 | 117 | c-------------------------------------------------------------------- 118 | c 119 | c boxkernel 120 | c 121 | c-------------------------------------------------------------------- 122 | 123 | function boxkernel(x,h) 124 | 125 | implicit real*8 (a-h,o-z) 126 | 127 | double precision x, h 128 | 129 | if (dabs(x).le.1) then 130 | boxkernel=1d0/2d0 131 | else 132 | boxkernel=0d0 133 | end if 134 | boxkernel=boxkernel/h 135 | 136 | return 137 | end 138 | 139 | c-------------------------------------------------------------------- 140 | c 141 | c Epanechnikov kernel 142 | c 143 | c-------------------------------------------------------------------- 144 | 145 | function ekernel(x,h) 146 | 147 | implicit real*8 (a-h,o-z) 148 | 149 | double precision x, h 150 | 151 | if (dabs(x).le.1) then 152 | ekernel=(3d0/4d0)*(1-x**2) 153 | else 154 | ekernel=0d0 155 | end if 156 | ekernel=ekernel/h 157 | 158 | return 159 | end 160 | 161 | c-------------------------------------------------------------------- 162 | c 163 | c Gaussian kernel 164 | c 165 | c-------------------------------------------------------------------- 166 | 167 | function gausskernel(x,h) 168 | 169 | implicit real*8 (a-h,o-z) 170 | 171 | double precision x, h 172 | pi=3.14159265d0 173 | 174 | gausskernel=exp(-(x**2)/2d0)/sqrt(pi*2d0) 175 | gausskernel=gausskernel/h 176 | 177 | return 178 | end 179 | 180 | 181 | c-------------------------------------------------------------------- 182 | c 183 | c quartic (biweight) kernel 184 | c 185 | c-------------------------------------------------------------------- 186 | 187 | function qkernel(x,h) 188 | 189 | implicit real*8 (a-h,o-z) 190 | 191 | double precision x, h 192 | 193 | if (dabs(x).le.1) then 194 | qkernel=(15d0/16d0)*(1-x**2)**2 195 | else 196 | qkernel=0d0 197 | end if 198 | qkernel=qkernel/h 199 | 200 | return 201 | end 202 | -------------------------------------------------------------------------------- /vignettes/docs.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "stpp Documentation" 3 | subtitle: "Space-Time Point Pattern Simulation, Visualisation and Analysis" 4 | author: "Edith Gabriel, Peter J Diggle, Barry Rowlingson and Francisco J Rodriguez-Cortes" 5 | copyright: "Edith Gabriel" 6 | date: "`r Sys.Date()`" 7 | output: rmarkdown::html_vignette 8 | vignette: > 9 | %\VignetteIndexEntry{stpp Documentation} 10 | %\VignetteEngine{knitr::rmarkdown} 11 | \usepackage[utf8]{inputenc} 12 | --- 13 | 14 | Many of the models encountered in applications of point process methods to the study of spatio-temporal phenomena are covered in 'stpp'. This package provides statistical tools for analyzing the global and local second-order properties of spatio-temporal point processes, including estimators of the space-time inhomogeneous K-function and pair correlation function among others. It also includes tools to get static and dynamic display of spatio-temporal point patterns. 15 | 16 | ### References 17 | 18 | - [Baddeley, A., Rubak, E., Turner, R. (2015). Spatial Point Patterns: Methodology and Applications with R. CRC Press, Boca Raton.](https://www.routledge.com/Spatial-Point-Patterns-Methodology-and-Applications-with-R/Baddeley-Rubak-Turner/p/book/9781482210200/) 19 | 20 | - [Chan, G. and Wood A. (1997). An algorithm for simulating stationary Gaussian random fields. *Applied Statistics, Algorithm Section*, **46**, 171–181.](https://rss.onlinelibrary.wiley.com/doi/abs/10.1111/1467-9876.00057) 21 | 22 | - [Chan, G. and Wood A. (1999). Simulation of stationary Gaussian vector fields. *Statistics and Computing*, **9**, 265–268.](https://link.springer.com/article/10.1023/A:1008903804954) 23 | 24 | - [Diggle P. , Chedwynd A., Haggkvist R. and Morris S. (1995). Second-order analysis of space-time clustering. *Statistical Methods in Medical Research*, **4**, 124–136.](https://journals.sagepub.com/doi/abs/10.1177/096228029500400203/) 25 | 26 | - [Diggle, P.J., 2013. Statistical Analysis of Spatial and Spatio-Temporal Point Patterns. CRC Press, Boca Raton.](https://www.routledge.com/Statistical-Analysis-of-Spatial-and-Spatio-Temporal-Point-Patterns-Third/Diggle/p/book/9781466560239/) 27 | 28 | - [Gabriel E., Rowlingson B., Diggle P. (2013). stpp: an R package for plotting, simulating and analyzing Spatio-Temporal Point Patterns. *Journal of Statistical Software*, **53**(2), 1-29.](https://www.jstatsoft.org/article/view/v053i02/) 29 | 30 | - [Gabriel E., Diggle P. (2009). Second-order analysis of inhomogeneous spatio-temporal point process data. *Statistica Neerlandica*, *63*, 43–51.](https://onlinelibrary.wiley.com/doi/abs/10.1111/j.1467-9574.2008.00407.x) 31 | 32 | - [Gabriel E. (2014). Estimating second-order characteristics of inhomogeneous spatio-temporal point processes: influence ofedge correction methods and intensity estimates. *Methodology and computing in Applied Probabillity*, **16**(2), 411–431.](https://link.springer.com/article/10.1007/s11009-013-9358-3) 33 | 34 | - [Gneiting T. (2002). Nonseparable, stationary covariance functions for space-time data. *Journal of the American Statistical Association*, **97**, 590–600.](https://www.tandfonline.com/doi/abs/10.1198/016214502760047113) 35 | 36 | - [Gonzalez, J. A., Rodriguez-Cortes, F. J., Cronie, O. and Mateu, J. (2016). Spatio-temporal point process statistics: a review. *Spatial Statiscts*, **18**, 505–544.](https://www.sciencedirect.com/science/article/pii/S2211675316301130/) 37 | 38 | - [Siino, M., Rodriguez-Cortes, F. J., Mateu, J. and Adelfio, G. (2017). Testing for local structure in spatio-temporal point pattern data. *Environmetrics*. DOI: 10.1002/env.2463.](https://onlinelibrary.wiley.com/doi/abs/10.1002/env.2463) 39 | 40 | - [Stoyan, D., Rodriguez-Cortes, F. J., Mateu, J., and Gille, W. (2017). Mark variograms for spatio-temporal point processes. *Spatial Statistics*. **20**, 125-147.](https://www.sciencedirect.com/science/article/pii/S2211675317300696/) 41 | --------------------------------------------------------------------------------