Skip to content

Commit

Permalink
fixing half-closed notation and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
gilesjohnr committed Dec 17, 2018
1 parent b4d113e commit 2782d6d
Show file tree
Hide file tree
Showing 40 changed files with 724 additions and 1,051 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Package: IDSpatialStats
Version: 0.3.5
Date: 2018-06-11
Version: 0.3.7
Date: 2018-12-17
Title: Estimate Global Clustering in Infectious Disease
Author: Justin Lessler <[email protected]>, Henrik Salje <[email protected]>, John Giles <[email protected]>
Author: Justin Lessler <[email protected]>, Henrik Salje <[email protected]>, John Giles <[email protected]>
Maintainer: Justin Lessler <[email protected]>
License: GPL (>=2)
Description: Implements various novel and standard
clustering statistics and other analyses useful for understanding the
spread of infectious disease.
RoxygenNote: 6.0.1
RoxygenNote: 6.1.1
Encoding: UTF-8
Imports: igraph, spatstat
Depends: doParallel, foreach, parallel, R (>= 2.10)
Expand Down
5 changes: 5 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ importFrom("igraph", "shortest.paths") # for get.transdist.theta
importFrom("igraph", "E") # for get.transdist.theta
importFrom("spatstat", "bounding.box.xy") # for est.transdist
importFrom("spatstat", "as.ppp") # for est.transdist
importFrom("spatstat", "ppp") # for est.transdist
importFrom("spatstat", "crossdist") # for est.transdist
importFrom("spatstat", "Kcross") # for get.cross.K
importFrom("spatstat", "pcf") # for get.cross.PCF
export(get.pi)
export(get.pi.ci)
export(get.pi.bootstrap)
Expand Down Expand Up @@ -40,5 +43,7 @@ export(est.transdist)
export(est.transdist.bootstrap.ci)
export(est.transdist.temporal)
export(est.transdist.temporal.bootstrap.ci)
export(get.cross.K)
export(get.cross.PCF)
useDynLib(IDSpatialStats, .registration=TRUE, .fixes="C_")

3 changes: 1 addition & 2 deletions R/examples/get_cross_k.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
data(DengueSimulationR01)

k <- get.cross.K(epi.data=DengueSimR01, type=5, hom=2, het=NULL, r=NULL, correction='border')
k.theo <- pi*(k$r)^2

plot(k.theo, type='l', col='red', lty=2, xlab='r', ylab='cross K function')
plot(k[,2], type='l', col='red', lty=2, xlab='r', ylab='cross K function')
lines(k$border)
24 changes: 12 additions & 12 deletions R/examples/get_tau.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ r.min<-seq(0,980,20)
r.mid<-(r.max+r.min)/2

sero.type.func<-function(a,b,tlimit=20){
if(a[5]==b[5]&(abs(a[3]-b[3])<=tlimit)){rc=1}
else{rc=2}
return(rc)
if(a[5]==b[5]&(abs(a[3]-b[3])<=tlimit)){rc=1}
else{rc=2}
return(rc)
}

geno.type.func<-function(a,b,tlimit=20){
if(a[4]==b[4]&(abs(a[3]-b[3])<=tlimit)){rc=1}
else{rc=2}
return(rc)
if(a[4]==b[4]&(abs(a[3]-b[3])<=tlimit)){rc=1}
else{rc=2}
return(rc)
}

sero.type.rep.func<-function(a,b,tlimit=20){
if(a[5]==1&b[5]==1&(abs(a[3]-b[3])<=tlimit)){rc=1}
else{if(a[5]==1&b[5]==-999){rc=2}else{rc=3}}
return(rc)
if(a[5]==1&b[5]==1&(abs(a[3]-b[3])<=tlimit)){rc=1}
else{if(a[5]==1&b[5]==-999){rc=2}else{rc=3}}
return(rc)
}

sero.tau.R01<-get.tau(DengueSimR01,sero.type.func,r=r.max,r.low=r.min,comparison.type="independent")
Expand All @@ -31,7 +31,7 @@ sero.tau.R02<-get.tau(DengueSimR02,sero.type.func,r=r.max,r.low=r.min,comparison
geno.tau.R02<-get.tau(DengueSimR02,geno.type.func,r=r.max,r.low=r.min,comparison.type="independent")

sero.tau.representative<-get.tau(DengueSimRepresentative,
sero.type.rep.func,r=r.max,r.low=r.min,comparison.type="representative")
sero.type.rep.func,r=r.max,r.low=r.min,comparison.type="representative")

## R0 of 1
plot(r.mid,sero.tau.R01,ylim=c(0.3,max(geno.tau.R01)),log="y",
Expand All @@ -42,8 +42,8 @@ abline(v=100,lty=1,lwd=2)
lines(r.mid,geno.tau.R01,pch=20,col=rgb(t(col2rgb("dark green")/255),alpha=0.6),lwd=1)
lines(r.mid,sero.tau.representative,pch=20,col=rgb(t(col2rgb("dark blue")/255),alpha=0.6),lty=2)
legend("topright",legend=c("Genotype","Serotype","Serotype (representative population)",
"Maximum transmission distance"),lwd=1,col=c("dark green","blue","blue","black"),
lty=c(1,1,2,1),bty="n")
"Maximum transmission distance"),lwd=1,col=c("dark green","blue","blue","black"),
lty=c(1,1,2,1),bty="n")

## R0 of 2
plot(r.mid,sero.tau.R02,ylim=c(0.3,max(geno.tau.R02)),log="y",
Expand Down
86 changes: 50 additions & 36 deletions R/spatialfuncs.r
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,32 @@
##' specified by the passed in function with that point.
##'
##' @param posmat a matrix with columns x, y and any other named columns
##' columns needed by fun
##' @param fun a function that takes in two rows of posmat and returns:
##' columns needed by \code{fun}
##' @param fun a function that takes in two rows of \code{posmat} and returns:
##' \enumerate{
##' \item for pairs included in the numerator and denominator
##' \item for pairs included in the numerator and denominator
##' \item for pairs that should only be included in the denominator
##' \item for pairs that should be ignored all together}
##' Note that names from \code{posmat} are not preserved in calls to \code{fun}, so the columns of the matrix should be
##' referenced numerically
##' so this is not available to the fun
##' so this is not available to the \code{fun}
##' @param r the series of spatial distances (or there maximums) we are
##' interested in
##' @param r.low the low end of each range, 0 by default
##'
##' @return pi value for each distance range that we look at. Where:
##'
##' \deqn{ \pi(d_1,d_2) = \frac{\sum \boldsymbol{1} (d_{ij} \in (d_1,d_2)) \boldsymbol{1} (f(i,j)=1) }{\sum \sum \boldsymbol{1} (d_{ij} \in (d_1,d_2)) \boldsymbol{1} (f(i,j) \in \{1,2\}) }}
##'\deqn{ \pi(d_1, d_2) = \frac{\sum \boldsymbol{1} (d_{ij} \in [d_1,d_2)) \boldsymbol{1} (f(i,j)=1) }{\sum \sum \boldsymbol{1} [d_{ij} \in (d_1,d_2)) \boldsymbol{1} (f(i,j) \in \{1,2\}) }}
##'
##' @author Justin Lessler and Henrik Salje
##'
##' @family get.pi
##' @family spatialtau
##'
##' @example R/examples/get_pi.R
##' @example
##' \dontrun{
##' R/examples/get_pi.R
##' }
##'

get.pi <- function(posmat,
Expand Down Expand Up @@ -79,15 +82,19 @@ get.pi <- function(posmat,
##'
##' @return theta value for each distance range that we look at. Where:
##'
##' \deqn{ \theta(d_1,d_2) = \frac{\sum \boldsymbol{1} (d_{ij} \in (d_1,d_2)) \boldsymbol{1} (f(i,j)=1) }{\sum \sum \boldsymbol{1} (d_{ij} \in (d_1,d_2)) \boldsymbol{1} (f(i,j)=2) }}
##' \deqn{ \theta(d_1,d_2) = \frac{\sum \boldsymbol{1} d_{ij} \in [d_1,d_2)) \boldsymbol{1} (f(i,j)=1) }{\sum \sum \boldsymbol{1} d_{ij} \in [d_1,d_2)) \boldsymbol{1} (f(i,j)=2) }}
##'
##' @author Justin Lessler and Henrik Salje
##'
##' @family get.theta
##' @family spatialtau
##'
##' @example R/examples/get_theta.R
##' @example
##' \dontrun{
##' R/examples/get_theta.R
##' }
##'

get.theta <- function(posmat,
fun,
r = 1,
Expand Down Expand Up @@ -132,7 +139,10 @@ get.theta <- function(posmat,
##'
##' @family get.pi
##'
##' @example R/examples/get_pi_typed.R
##' @example
##' \dontrun{
##' R/examples/get_pi_typed.R
##' }
##'
get.pi.typed <- function(posmat,
typeA = -1,
Expand Down Expand Up @@ -176,7 +186,10 @@ get.pi.typed <- function(posmat,
##'
##' @family get.theta
##'
##' @example R/examples/get_theta_typed.R
##' @example
##' \dontrun{
##' R/examples/get_theta_typed.R
##' }
##'
get.theta.typed <- function(posmat,
typeA = -1,
Expand Down Expand Up @@ -221,10 +234,10 @@ get.theta.typed <- function(posmat,
##'
##' @family get.pi
##'
##' @examples
##' @example
##' \dontrun{
##' R/examples/get_pi_ci.R
##' }
##' R/examples/get_pi_ci.R
##' }
##'
get.pi.ci <- function(posmat,
fun,
Expand Down Expand Up @@ -270,10 +283,10 @@ get.pi.ci <- function(posmat,
##'
##' @family get.theta
##'
##' @examples
##' @example
##' \dontrun{
##' R/examples/get_theta_ci.R
##' }
##' R/examples/get_theta_ci.R
##' }
##'
get.theta.ci <- function(posmat,
fun,
Expand Down Expand Up @@ -319,7 +332,7 @@ get.theta.ci <- function(posmat,
##'
##' @family get.pi
##'
##' @examples
##' @example
##' \dontrun{
##' R/examples/get_pi_bootstrap.R
##' }
Expand Down Expand Up @@ -377,7 +390,7 @@ get.pi.bootstrap <- function(posmat,
##'
##' @family get.theta
##'
##' @examples
##' @example
##' \dontrun{
##' R/examples/get_theta_bootstrap.R
##' }
Expand Down Expand Up @@ -430,7 +443,7 @@ get.theta.bootstrap <- function(posmat,
##'
##' @family get.pi
##'
##' @examples
##' @example
##' \dontrun{
##' R/examples/get_pi_typed_bootstrap.R
##' }
Expand Down Expand Up @@ -481,7 +494,7 @@ get.pi.typed.bootstrap <- function(posmat,
##'
##' @family get.theta
##'
##' @examples
##' @example
##' \dontrun{
##' R/examples/get_theta_typed_bootstrap.R
##' }
Expand Down Expand Up @@ -514,7 +527,6 @@ get.theta.typed.bootstrap <- function(posmat,
return(rc)
}


##' get the null distribution of the \code{get.pi} function
##'
##' Does permutations to calculate the null distribution of get pi
Expand All @@ -531,7 +543,7 @@ get.theta.typed.bootstrap <- function(posmat,
##'
##' @family get.pi
##'
##' @examples
##' @example
##' \dontrun{
##' R/examples/get_pi_permute.R
##' }
Expand Down Expand Up @@ -586,7 +598,7 @@ get.pi.permute <- function(posmat,
##'
##' @family get.theta
##'
##' @examples
##' @example
##' \dontrun{
##' R/examples/get_theta_permute.R
##' }
Expand Down Expand Up @@ -644,7 +656,7 @@ get.theta.permute <- function(posmat,
##'
##' @family get.pi
##'
##' @examples
##' @example
##' \dontrun{
##' R/examples/get_pi_typed_permute.R
##' }
Expand Down Expand Up @@ -705,7 +717,7 @@ get.pi.typed.permute <- function(posmat,
##'
##' @family get.theta
##'
##' @examples
##' @example
##' \dontrun{
##' R/examples/get_theta_typed_permute.R
##' }
Expand Down Expand Up @@ -776,18 +788,18 @@ get.theta.typed.permute <- function(posmat,
##'
##' @return The tau value for each distance we look at. If \code{comparison.type} is "representative", this is:
##'
##' \code{tau = get.pi(posmat, fun, r, r.low)/get.pi(posmat,fun,0,infinity)}
##' \code{tau = get.pi(posmat, fun, r, r.low)/get.pi(posmat,fun,infinity,0)}
##'
##' If \code{comparison.type} is "independent", this is:
##'
##' \code{tau = get.theta(posmat, fun, r, r.low)/get.theta(posmat,fun,0,infinity)}
##' \code{tau = get.theta(posmat, fun, r, r.low)/get.theta(posmat,fun,infinity,0)}
##'
##' @author Justin Lessler and Henrik Salje
##'
##' @family get.tau
##' @family spatialtau
##'
##' @examples
##' @example
##' \dontrun{
##' R/examples/get_tau.R
##' }
Expand Down Expand Up @@ -827,7 +839,7 @@ get.tau <- function(posmat,
return(rc)
}
##'
##' Optimizewd version of \code{get.tau} for typed data
##' Optimized version of \code{get.tau} for typed data
##'
##' Version of th e \code{get.tau} function that is optimized for
##' statically typed data. That is data where we want the relationship between
Expand All @@ -850,8 +862,10 @@ get.tau <- function(posmat,
##'
##' @family get.tau
##'
##' @example R/examples/get_tau_typed.R
##'
##' @example
##' \dontrun{
##' R/examples/get_tau_typed.R
##'}
get.tau.typed <- function(posmat,
typeA = -1,
typeB = -1,
Expand Down Expand Up @@ -906,7 +920,7 @@ get.tau.typed <- function(posmat,
##'
##' @family get.tau
##'
##' @examples
##' @example
##' \dontrun{
##' R/examples/get_tau_ci.R
##' }
Expand Down Expand Up @@ -955,7 +969,7 @@ get.tau.ci <- function(posmat,
##'
##' @family get.tau
##'
##' @examples
##' @example
##' \dontrun{
##' R/examples/get_tau_bootstrap.R
##' }
Expand Down Expand Up @@ -1022,7 +1036,7 @@ get.tau.bootstrap <- function(posmat,
##'
##' @family get.tau
##'
##' @examples
##' @example
##' \dontrun{
##' R/examples/get_tau_typed_bootstrap.R
##' }
Expand Down Expand Up @@ -1086,7 +1100,7 @@ get.tau.typed.bootstrap <- function(posmat,
##'
##' @family get.tau
##'
##' @examples
##' @example
##' \dontrun{
##' R/examples/get_tau_permute.R
##' }
Expand Down Expand Up @@ -1159,7 +1173,7 @@ get.tau.permute <- function(posmat,
##'
##' @family get.tau
##'
##' @examples
##' @example
##' \dontrun{
##' R/examples/get_tau_typed_permute.R
##' }
Expand Down
Loading

0 comments on commit 2782d6d

Please sign in to comment.