From cb1897e4769ad69a9b7180839784970364694e23 Mon Sep 17 00:00:00 2001 From: gilesjohnr Date: Thu, 14 Nov 2019 09:47:32 -0500 Subject: [PATCH] optional data.frame output for pi/theta/tau --- DESCRIPTION | 2 +- R/spatialfuncs.r | 242 +++++++++++++++++++++++------- inst/tests/test-getthetapermute.r | 8 +- man/get.pi.Rd | 5 +- man/get.pi.bootstrap.Rd | 4 +- man/get.pi.ci.Rd | 5 +- man/get.pi.permute.Rd | 4 +- man/get.pi.typed.Rd | 4 +- man/get.pi.typed.bootstrap.Rd | 4 +- man/get.pi.typed.permute.Rd | 4 +- man/get.tau.Rd | 4 +- man/get.tau.bootstrap.Rd | 4 +- man/get.tau.ci.Rd | 4 +- man/get.tau.permute.Rd | 4 +- man/get.tau.typed.Rd | 4 +- man/get.tau.typed.bootstrap.Rd | 4 +- man/get.tau.typed.permute.Rd | 4 +- man/get.theta.Rd | 5 +- man/get.theta.bootstrap.Rd | 4 +- man/get.theta.ci.Rd | 5 +- man/get.theta.permute.Rd | 4 +- man/get.theta.typed.Rd | 4 +- man/get.theta.typed.bootstrap.Rd | 4 +- man/get.theta.typed.permute.Rd | 4 +- 24 files changed, 259 insertions(+), 81 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 4054d37..008ddf2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: IDSpatialStats -Version: 0.3.8 +Version: 0.3.9 Date: 2019-11-13 Title: Estimate Global Clustering in Infectious Disease Author: Justin Lessler , Henrik Salje , John Giles diff --git a/R/spatialfuncs.r b/R/spatialfuncs.r index 8a27d0f..6b830ca 100644 --- a/R/spatialfuncs.r +++ b/R/spatialfuncs.r @@ -17,6 +17,7 @@ ##' @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 +##' @param data.frame logical indicating whether to return results as a data frame (default = TRUE) ##' ##' @return pi value for each distance range that we look at. Where: ##' @@ -33,7 +34,8 @@ get.pi <- function(posmat, fun, r = 1, - r.low=rep(0,length(r))) { + r.low=rep(0,length(r)), + data.frame=TRUE) { xcol <- which(colnames(posmat) == "x") ycol <- which(colnames(posmat) == "y") @@ -51,7 +53,12 @@ get.pi <- function(posmat, 1:nrow(posmat), xcol, ycol) - return(data.frame(r.low=r.low, r=r, pi=rc)) + + if (data.frame == FALSE) { + return(rc) + } else if (data.frame == TRUE) { + return(data.frame(r.low=r.low, r=r, pi=rc)) + } } @@ -76,6 +83,7 @@ get.pi <- function(posmat, ##' @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 +##' @param data.frame logical indicating whether to return results as a data frame (default = TRUE) ##' ##' @return theta value for each distance range that we look at. Where: ##' @@ -92,7 +100,8 @@ get.pi <- function(posmat, get.theta <- function(posmat, fun, r = 1, - r.low=rep(0,length(r))) { + r.low=rep(0,length(r)), + data.frame=TRUE) { xcol <- which(colnames(posmat)=="x") ycol <- which(colnames(posmat)=="y") @@ -110,7 +119,12 @@ get.theta <- function(posmat, 1:nrow(posmat), xcol, ycol) - return(data.frame(r.low=r.low, r=r, theta=rc)) + + if (data.frame == FALSE) { + return(rc) + } else if (data.frame == TRUE) { + return(data.frame(r.low=r.low, r=r, theta=rc)) + } } @@ -126,6 +140,7 @@ get.theta <- function(posmat, ##' @param typeB the "to" type that we are interested i, -1 is wildcard ##' @param r the series of spatial distances wer are interested in ##' @param r.low the low end of each range....0 by default +##' @param data.frame logical indicating whether to return results as a data frame (default = TRUE) ##' ##' @return pi values for all the distances we looked at ##' @@ -140,7 +155,8 @@ get.pi.typed <- function(posmat, typeA = -1, typeB = -1, r=1, - r.low=rep(0,length(r))) { + r.low=rep(0,length(r)), + data.frame=TRUE) { rc <- .C("get_pi_typed", as.integer(posmat[,"type"]), @@ -155,7 +171,11 @@ get.pi.typed <- function(posmat, as.integer(1:nrow(posmat)), rc=double(length(r))) - return(data.frame(r.low=r.low, r=r, pi=rc$rc)) + if (data.frame == FALSE) { + return(rc) + } else if (data.frame == TRUE) { + return(data.frame(r.low=r.low, r=r, pi=rc$rc)) + } } @@ -171,6 +191,7 @@ get.pi.typed <- function(posmat, ##' @param typeB the "to" type that we are interested i, -1 is wildcard ##' @param r the series of spatial distances wer are interested in ##' @param r.low the low end of each range....0 by default +##' @param data.frame logical indicating whether to return results as a data frame (default = TRUE) ##' ##' @return theta values for all the distances we looked at ##' @@ -185,7 +206,8 @@ get.theta.typed <- function(posmat, typeA = -1, typeB = -1, r=1, - r.low=rep(0,length(r))) { + r.low=rep(0,length(r)), + data.frame=TRUE) { rc <- .C("get_theta_typed", as.integer(posmat[,"type"]), @@ -200,7 +222,11 @@ get.theta.typed <- function(posmat, as.integer(1:nrow(posmat)), rc=double(length(r))) - return(data.frame(r.low=r.low, r=r, theta=rc$rc)) + if (data.frame == FALSE) { + return(rc) + } else if (data.frame == TRUE) { + return(data.frame(r.low=r.low, r=r, theta=rc$rc)) + } } @@ -217,6 +243,7 @@ get.theta.typed <- function(posmat, ##' @param boot.iter the number of bootstrap iterations ##' @param ci.low the low end of the ci...0.025 by default ##' @param ci.high the high end of the ci...0.975 by default +##' @param data.frame logical indicating whether to return results as a data frame (default = TRUE) ##' ##' @return a matrix with a row for the high and low values and ##' a column per distance @@ -234,17 +261,22 @@ get.pi.ci <- function(posmat, r.low=rep(0,length(r)), boot.iter = 1000, ci.low=0.025, - ci.high=0.975) { + ci.high=0.975, + data.frame=TRUE) { boots <- get.pi.bootstrap(posmat, fun, r, r.low, boot.iter) rc <- apply(boots[,-(1:2)], 1, quantile, probs=c(ci.low, ci.high)) - return(data.frame(r.low=r.low, - r=r, - pt.est=get.pi(posmat, fun, r, r.low)$pi, - ci.low=rc[1,], - ci.high=rc[2,])) + if (data.frame == FALSE) { + return(rc) + } else if (data.frame == TRUE) { + return(data.frame(r.low=r.low, + r=r, + pt.est=get.pi(posmat, fun, r, r.low)$pi, + ci.low=rc[1,], + ci.high=rc[2,])) + } } @@ -261,6 +293,7 @@ get.pi.ci <- function(posmat, ##' @param boot.iter the number of bootstrap iterations ##' @param ci.low the low end of the ci...0.025 by default ##' @param ci.high the high end of the ci...0.975 by default +##' @param data.frame logical indicating whether to return results as a data frame (default = TRUE) ##' ##' @return a matrix with a row for the high and low values and ##' a column per distance @@ -278,16 +311,22 @@ get.theta.ci <- function(posmat, r.low=rep(0,length(r)), boot.iter = 1000, ci.low=0.025, - ci.high=0.975) { + ci.high=0.975, + data.frame=TRUE) { + boots <- get.theta.bootstrap(posmat, fun, r, r.low, boot.iter) rc <- apply(boots[,-(1:2)], 1, quantile, probs=c(ci.low, ci.high)) - return(data.frame(r.low=r.low, - r=r, - pt.est=get.theta(posmat, fun, r, r.low)$theta, - ci.low=rc[1,], - ci.high=rc[2,])) + if (data.frame == FALSE) { + return(rc) + } else if (data.frame == TRUE) { + return(data.frame(r.low=r.low, + r=r, + pt.est=get.theta(posmat, fun, r, r.low)$theta, + ci.low=rc[1,], + ci.high=rc[2,])) + } } @@ -302,6 +341,7 @@ get.theta.ci <- function(posmat, ##' @param r the series of spatial distances we are interested in ##' @param r.low the low end of each range. 0 by default ##' @param boot.iter the number of bootstrap iterations +##' @param data.frame logical indicating whether to return results as a data frame (default = TRUE) ##' ##' @return pi values for all the distances we looked at ##' @@ -320,7 +360,8 @@ get.pi.bootstrap <- function(posmat, fun, r=1, r.low=rep(0,length(r)), - boot.iter = 500) { + boot.iter=500, + data.frame=TRUE) { xcol <- which(colnames(posmat)=="x") @@ -343,7 +384,12 @@ get.pi.bootstrap <- function(posmat, xcol, ycol) } - return(data.frame(r.low=r.low, r=r, t(rc))) + + if (data.frame == FALSE) { + return(rc) + } else if (data.frame == TRUE) { + return(data.frame(r.low=r.low, r=r, t(rc))) + } } @@ -358,6 +404,7 @@ get.pi.bootstrap <- function(posmat, ##' @param r the series of spatial distances we are interested in ##' @param r.low the low end of each range. 0 by default ##' @param boot.iter the number of bootstrap iterations +##' @param data.frame logical indicating whether to return results as a data frame (default = TRUE) ##' ##' @return theta values for all the distances we looked at ##' @@ -376,7 +423,8 @@ get.theta.bootstrap <- function(posmat, fun, r=1, r.low=rep(0,length(r)), - boot.iter = 500) { + boot.iter=500, + data.frame=TRUE) { xcol <- which(colnames(posmat)=="x") @@ -399,7 +447,12 @@ get.theta.bootstrap <- function(posmat, xcol, ycol) } - return(data.frame(r.low=r.low, r=r, t(rc))) + + if (data.frame == FALSE) { + return(rc) + } else if (data.frame == TRUE) { + return(data.frame(r.low=r.low, r=r, t(rc))) + } } @@ -414,6 +467,7 @@ get.theta.bootstrap <- function(posmat, ##' @param typeB the "to" type that we are interested i, -1 is wildcard ##' @param r the series of spatial distances we are interested in ##' @param r.low the low end of each range....0 by default +##' @param data.frame logical indicating whether to return results as a data frame (default = TRUE) ##' ##' @return pi values for all the distances we looked at ##' @@ -427,7 +481,8 @@ get.pi.typed.bootstrap <- function(posmat, typeB = -1, r=1, r.low=rep(0,length(r)), - boot.iter) { + boot.iter, + data.frame=TRUE) { rc <- matrix(nrow=boot.iter, ncol=length(r)) @@ -448,7 +503,11 @@ get.pi.typed.bootstrap <- function(posmat, )$rc } - return(data.frame(r.low=r.low, r=r, t(rc))) + if (data.frame == FALSE) { + return(rc) + } else if (data.frame == TRUE) { + return(data.frame(r.low=r.low, r=r, t(rc))) + } } @@ -463,6 +522,7 @@ get.pi.typed.bootstrap <- function(posmat, ##' @param typeB the "to" type that we are interested i, -1 is wildcard ##' @param r the series of spatial distances we are interested in ##' @param r.low the low end of each range....0 by default +##' @param data.frame logical indicating whether to return results as a data frame (default = TRUE) ##' ##' @return theta values for all the distances we looked at ##' @@ -476,7 +536,8 @@ get.theta.typed.bootstrap <- function(posmat, typeB = -1, r=1, r.low=rep(0,length(r)), - boot.iter) { + boot.iter, + data.frame=TRUE) { rc <- matrix(nrow=boot.iter, ncol=length(r)) @@ -497,7 +558,11 @@ get.theta.typed.bootstrap <- function(posmat, )$rc } - return(data.frame(r.low=r.low, r=r, t(rc))) + if (data.frame == FALSE) { + return(rc) + } else if (data.frame == TRUE) { + return(data.frame(r.low=r.low, r=r, t(rc))) + } } @@ -512,6 +577,7 @@ get.theta.typed.bootstrap <- function(posmat, ##' @param r the series of spatial distances we are interested in ##' @param r.low the low end of each range....0 by default ##' @param permutations the number of permute iterations +##' @param data.frame logical indicating whether to return results as a data frame (default = TRUE) ##' ##' @return pi values for all the distances we looked at ##' @@ -524,7 +590,8 @@ get.pi.permute <- function(posmat, fun, r=1, r.low=rep(0,length(r)), - permutations) { + permutations, + data.frame=TRUE) { xcol <- which(colnames(posmat)=="x") @@ -551,7 +618,11 @@ get.pi.permute <- function(posmat, ycol) } - return(data.frame(r.low=r.low, r=r, t(rc))) + if (data.frame == FALSE) { + return(rc) + } else if (data.frame == TRUE) { + return(data.frame(r.low=r.low, r=r, t(rc))) + } } @@ -566,6 +637,7 @@ get.pi.permute <- function(posmat, ##' @param r the series of spatial distances we are interested in ##' @param r.low the low end of each range....0 by default ##' @param permutations the number of permute iterations +##' @param data.frame logical indicating whether to return results as a data frame (default = TRUE) ##' ##' @return theta values for all the distances we looked at ##' @@ -578,7 +650,8 @@ get.theta.permute <- function(posmat, fun, r=1, r.low=rep(0,length(r)), - permutations) { + permutations, + data.frame=TRUE) { xcol <- which(colnames(posmat)=="x") @@ -605,7 +678,11 @@ get.theta.permute <- function(posmat, ycol) } - return(data.frame(r.low=r.low, r=r, t(rc))) + if (data.frame == FALSE) { + return(rc) + } else if (data.frame == TRUE) { + return(data.frame(r.low=r.low, r=r, t(rc))) + } } @@ -621,6 +698,7 @@ get.theta.permute <- function(posmat, ##' @param r the series of spatial distances we are interested in ##' @param r.low the low end of each range....0 by default ##' @param permutations the number of permute iterations +##' @param data.frame logical indicating whether to return results as a data frame (default = TRUE) ##' ##' @return pi values for all the distances we looked at ##' @@ -636,7 +714,8 @@ get.pi.typed.permute <- function(posmat, typeB = -1, r=1, r.low=rep(0,length(r)), - permutations) { + permutations, + data.frame=TRUE) { xcol <- which(colnames(posmat)=="x") ycol <- which(colnames(posmat)=="y") @@ -665,7 +744,11 @@ get.pi.typed.permute <- function(posmat, )$rc } - return(data.frame(r.low=r.low, r=r, t(rc))) + if (data.frame == FALSE) { + return(rc) + } else if (data.frame == TRUE) { + return(data.frame(r.low=r.low, r=r, t(rc))) + } } @@ -681,6 +764,7 @@ get.pi.typed.permute <- function(posmat, ##' @param r the series of spatial distances we are interested in ##' @param r.low the low end of each range....0 by default ##' @param permutations the number of permute iterations +##' @param data.frame logical indicating whether to return results as a data frame (default = TRUE) ##' ##' @return theta values for all the distances we looked at ##' @@ -696,7 +780,8 @@ get.theta.typed.permute <- function(posmat, typeB = -1, r=1, r.low=rep(0,length(r)), - permutations) { + permutations, + data.frame=TRUE) { xcol <- which(colnames(posmat)=="x") ycol <- which(colnames(posmat)=="y") @@ -725,7 +810,11 @@ get.theta.typed.permute <- function(posmat, )$rc } - return(data.frame(r.low=r.low, r=r, t(rc))) + if (data.frame == FALSE) { + return(rc) + } else if (data.frame == TRUE) { + return(data.frame(r.low=r.low, r=r, t(rc))) + } } @@ -754,6 +843,7 @@ get.theta.typed.permute <- function(posmat, ##' \item "representative" if comparison set is representative of the underlying population ##' \item "independent" if comparison set is cases/events coming from an indepedent process ##' } +##' @param data.frame logical indicating whether to return results as a data frame (default = TRUE) ##' ##' @return The tau value for each distance we look at. If \code{comparison.type} is "representative", this is: ##' @@ -775,7 +865,8 @@ get.tau <- function(posmat, fun, r = 1, r.low=rep(0,length(r)), - comparison.type = "representative") { + comparison.type = "representative", + data.frame=TRUE) { xcol <- which(colnames(posmat)=="x") ycol <- which(colnames(posmat)=="y") @@ -803,7 +894,11 @@ get.tau <- function(posmat, xcol, ycol) - return(data.frame(r.low=r.low, r=r, tau=rc)) + if (data.frame == FALSE) { + return(rc) + } else if (data.frame == TRUE) { + return(data.frame(r.low=r.low, r=r, tau=rc)) + } } @@ -823,6 +918,7 @@ get.tau <- function(posmat, ##' \item "representative" if comparison set is representative of the underlying population ##' \item "independent" if comparison set is cases/events coming from an indepedent process ##' } +##' @param data.frame logical indicating whether to return results as a data frame (default = TRUE) ##' ##' @return data frame of tau values for all the distances ##' @@ -838,7 +934,8 @@ get.tau.typed <- function(posmat, typeB = -1, r=1, r.low=rep(0,length(r)), - comparison.type = "representative") { + comparison.type = "representative", + data.frame=TRUE) { if (comparison.type == "representative") { comp.type.int <- 0 @@ -862,7 +959,11 @@ get.tau.typed <- function(posmat, as.integer(comp.type.int), rc=double(length(r))) - return(data.frame(r.low=r.low, r=r, tau=rc$rc)) + if (data.frame == FALSE) { + return(rc) + } else if (data.frame == TRUE) { + return(data.frame(r.low=r.low, r=r, tau=rc$rc)) + } } @@ -879,6 +980,7 @@ get.tau.typed <- function(posmat, ##' @param comparison.type the comparison type to pass to get.tau ##' @param ci.low the low end of the ci...0.025 by default ##' @param ci.high the high end of the ci...0.975 by default +##' @param data.frame logical indicating whether to return results as a data frame (default = TRUE) ##' ##' @return a data frame with the point estimate of tau and its low and high confidence interval at each distance ##' @@ -896,7 +998,8 @@ get.tau.ci <- function(posmat, boot.iter = 1000, comparison.type = "representative", ci.low=0.025, - ci.high=0.975) { + ci.high=0.975, + data.frame=TRUE) { boots <- get.tau.bootstrap(posmat, fun, r, r.low, boot.iter, @@ -904,11 +1007,15 @@ get.tau.ci <- function(posmat, rc <- apply(boots[,-(1:2)], 1, quantile, probs=c(ci.low, ci.high)) - return(data.frame(r.low=r.low, - r=r, - pt.est=get.tau(posmat, fun, r, r.low)$tau, - ci.low=rc[1,], - ci.high=rc[2,])) + if (data.frame == FALSE) { + return(rc) + } else if (data.frame == TRUE) { + return(data.frame(r.low=r.low, + r=r, + pt.est=get.tau(posmat, fun, r, r.low)$tau, + ci.low=rc[1,], + ci.high=rc[2,])) + } } @@ -925,6 +1032,7 @@ get.tau.ci <- function(posmat, ##' @param r.low the low end of each range....0 by default ##' @param boot.iter the number of bootstrap iterations ##' @param comparison.type the comparison type to pass as input to \code{get.pi} +##' @param data.frame logical indicating whether to return results as a data frame (default = TRUE) ##' ##' @return a matrix containing all bootstrapped values of tau for each distance interval ##' @@ -940,7 +1048,8 @@ get.tau.bootstrap <- function(posmat, r=1, r.low=rep(0,length(r)), boot.iter, - comparison.type = "representative") { + comparison.type = "representative", + data.frame=TRUE) { xcol <- which(colnames(posmat)=="x") @@ -972,7 +1081,12 @@ get.tau.bootstrap <- function(posmat, xcol, ycol) } - return(data.frame(r.low=r.low, r=r, t(rc))) + + if (data.frame == FALSE) { + return(rc) + } else if (data.frame == TRUE) { + return(data.frame(r.low=r.low, r=r, t(rc))) + } } @@ -989,6 +1103,7 @@ get.tau.bootstrap <- function(posmat, ##' \item "representative" if comparison set is representative of the underlying population ##' \item "independent" if comparison set is cases/events coming from an independent process ##' } +##' @param data.frame logical indicating whether to return results as a data frame (default = TRUE) ##' ##' @return tau values for all the distances we looked at ##' @@ -1005,7 +1120,8 @@ get.tau.typed.bootstrap <- function(posmat, r=1, r.low=rep(0,length(r)), boot.iter, - comparison.type = "representative") { + comparison.type = "representative", + data.frame=TRUE) { if (comparison.type == "representative") { @@ -1034,7 +1150,12 @@ get.tau.typed.bootstrap <- function(posmat, rc=double(length(r)) )$rc } - return(data.frame(r.low=r.low, r=r, t(rc))) + + if (data.frame == FALSE) { + return(rc) + } else if (data.frame == TRUE) { + return(data.frame(r.low=r.low, r=r, t(rc))) + } } @@ -1050,6 +1171,7 @@ get.tau.typed.bootstrap <- function(posmat, ##' @param r.low the low end of each range....0 by default ##' @param permutations the number of permute iterations ##' @param comparison.type the comparison type to pass as input to \code{get.pi} +##' @param data.frame logical indicating whether to return results as a data frame (default = TRUE) ##' ##' @return tau values for all the distances we looked at ##' @@ -1065,7 +1187,8 @@ get.tau.permute <- function(posmat, r=1, r.low=rep(0,length(r)), permutations, - comparison.type = "representative") { + comparison.type = "representative", + data.frame=TRUE) { xcol <- which(colnames(posmat)=="x") @@ -1101,7 +1224,12 @@ get.tau.permute <- function(posmat, ycol) } - return(data.frame(r.low=r.low, r=r, t(rc))) + + if (data.frame == FALSE) { + return(rc) + } else if (data.frame == TRUE) { + return(data.frame(r.low=r.low, r=r, t(rc))) + } } @@ -1119,6 +1247,7 @@ get.tau.permute <- function(posmat, ##' \item "representative" if comparison set is representative of the underlying population ##' \item "independent" if comparison set is cases/events coming from an indepedent process ##' } +##' @param data.frame logical indicating whether to return results as a data frame (default = TRUE) ##' ##' @return a matrix with permutation tau values for each distance specified ##' @@ -1135,7 +1264,8 @@ get.tau.typed.permute <- function(posmat, r=1, r.low=rep(0,length(r)), permutations, - comparison.type = "representative") { + comparison.type = "representative", + data.frame=TRUE) { xcol <- which(colnames(posmat)=="x") ycol <- which(colnames(posmat)=="y") @@ -1172,7 +1302,11 @@ get.tau.typed.permute <- function(posmat, )$rc } - return(data.frame(r.low=r.low, r=r, t(rc))) + if (data.frame == FALSE) { + return(rc) + } else if (data.frame == TRUE) { + return(data.frame(r.low=r.low, r=r, t(rc))) + } } NULL diff --git a/inst/tests/test-getthetapermute.r b/inst/tests/test-getthetapermute.r index 6dd8459..7444711 100644 --- a/inst/tests/test-getthetapermute.r +++ b/inst/tests/test-getthetapermute.r @@ -11,20 +11,18 @@ test_that("get.theta.permute returns appropriate values for test case 1 (equilat return(2) } - #should return 1 for every permutation res <- get.theta.permute(x, test, 1.5, 0, 500)[,-(1:2)] res2 <- get.theta.typed.permute(x, 1, 2, 1.5, 0, 500)[,-(1:2)] - expect_that(as.numeric(res), equals(rep(1,500))) expect_that(as.numeric(res2), equals(rep(1,500))) }) - test_that("get.theta.permute returns appropriate values for test case 2 (points on a line)" ,{ + x<-rbind(c(1,0,0), c(2,1,0), c(2,-1,0), c(3,2,0), c(2,-2,0), c(3,3,0),c(3,-3,0)) @@ -42,8 +40,8 @@ test_that("get.theta.permute returns appropriate values for test case 2 (points res <- get.theta.permute(x, test, c(1.5,2.5,3.5), c(0,1.5,2.5), 500)[,-(1:2)] res2 <- get.theta.typed.permute(x, 1, 2, c(1.5,2.5,3.5), c(0,1.5,2.5), 500)[,-(1:2)] - expect_that(apply(res,2,median,na.rm=T), equals(rep(1,3), tolerance=0.1)) - expect_that(apply(res2, 2, median, na.rm=T), equals(rep(1,3), tolerance=0.1)) + expect_that(apply(res, 1, median, na.rm=T), equals(rep(1,3), tolerance=0.1)) + expect_that(apply(res2, 1, median, na.rm=T), equals(rep(1,3), tolerance=0.1)) for (i in 1:3) { expect_that(as.numeric(quantile(res[i,], probs=c(.025,.975))), diff --git a/man/get.pi.Rd b/man/get.pi.Rd index 8e8fc2d..de6dbc0 100644 --- a/man/get.pi.Rd +++ b/man/get.pi.Rd @@ -4,7 +4,8 @@ \alias{get.pi} \title{Generalized version of \code{get.pi}} \usage{ -get.pi(posmat, fun, r = 1, r.low = rep(0, length(r))) +get.pi(posmat, fun, r = 1, r.low = rep(0, length(r)), + data.frame = TRUE) } \arguments{ \item{posmat}{a matrix with columns x, y and any other named columns @@ -23,6 +24,8 @@ so this is not available to the \code{fun}} interested in} \item{r.low}{the low end of each range, 0 by default} + +\item{data.frame}{logical indicating whether to return results as a data frame (default = TRUE)} } \value{ pi value for each distance range that we look at. Where: diff --git a/man/get.pi.bootstrap.Rd b/man/get.pi.bootstrap.Rd index 4294044..170dd04 100644 --- a/man/get.pi.bootstrap.Rd +++ b/man/get.pi.bootstrap.Rd @@ -5,7 +5,7 @@ \title{Bootstrap \code{get.pi} values.} \usage{ get.pi.bootstrap(posmat, fun, r = 1, r.low = rep(0, length(r)), - boot.iter = 500) + boot.iter = 500, data.frame = TRUE) } \arguments{ \item{posmat}{a matrix with columns type, x and y} @@ -17,6 +17,8 @@ get.pi.bootstrap(posmat, fun, r = 1, r.low = rep(0, length(r)), \item{r.low}{the low end of each range. 0 by default} \item{boot.iter}{the number of bootstrap iterations} + +\item{data.frame}{logical indicating whether to return results as a data frame (default = TRUE)} } \value{ pi values for all the distances we looked at diff --git a/man/get.pi.ci.Rd b/man/get.pi.ci.Rd index 209775e..4662900 100644 --- a/man/get.pi.ci.Rd +++ b/man/get.pi.ci.Rd @@ -5,7 +5,8 @@ \title{Calculate bootstrapped confidence intervals for \code{get.pi} values.} \usage{ get.pi.ci(posmat, fun, r = 1, r.low = rep(0, length(r)), - boot.iter = 1000, ci.low = 0.025, ci.high = 0.975) + boot.iter = 1000, ci.low = 0.025, ci.high = 0.975, + data.frame = TRUE) } \arguments{ \item{posmat}{a matrix with columns type, x and y} @@ -21,6 +22,8 @@ get.pi.ci(posmat, fun, r = 1, r.low = rep(0, length(r)), \item{ci.low}{the low end of the ci...0.025 by default} \item{ci.high}{the high end of the ci...0.975 by default} + +\item{data.frame}{logical indicating whether to return results as a data frame (default = TRUE)} } \value{ a matrix with a row for the high and low values and diff --git a/man/get.pi.permute.Rd b/man/get.pi.permute.Rd index 2878728..3fef8cc 100644 --- a/man/get.pi.permute.Rd +++ b/man/get.pi.permute.Rd @@ -5,7 +5,7 @@ \title{get the null distribution of the \code{get.pi} function} \usage{ get.pi.permute(posmat, fun, r = 1, r.low = rep(0, length(r)), - permutations) + permutations, data.frame = TRUE) } \arguments{ \item{posmat}{a matrix with columns type, x and y} @@ -17,6 +17,8 @@ get.pi.permute(posmat, fun, r = 1, r.low = rep(0, length(r)), \item{r.low}{the low end of each range....0 by default} \item{permutations}{the number of permute iterations} + +\item{data.frame}{logical indicating whether to return results as a data frame (default = TRUE)} } \value{ pi values for all the distances we looked at diff --git a/man/get.pi.typed.Rd b/man/get.pi.typed.Rd index 355a16f..a5acf4f 100644 --- a/man/get.pi.typed.Rd +++ b/man/get.pi.typed.Rd @@ -5,7 +5,7 @@ \title{Optimized version of \code{get.pi} for typed data.} \usage{ get.pi.typed(posmat, typeA = -1, typeB = -1, r = 1, r.low = rep(0, - length(r))) + length(r)), data.frame = TRUE) } \arguments{ \item{posmat}{a matrix with columns type, x and y} @@ -17,6 +17,8 @@ get.pi.typed(posmat, typeA = -1, typeB = -1, r = 1, r.low = rep(0, \item{r}{the series of spatial distances wer are interested in} \item{r.low}{the low end of each range....0 by default} + +\item{data.frame}{logical indicating whether to return results as a data frame (default = TRUE)} } \value{ pi values for all the distances we looked at diff --git a/man/get.pi.typed.bootstrap.Rd b/man/get.pi.typed.bootstrap.Rd index aaf32f2..3a7f3fe 100644 --- a/man/get.pi.typed.bootstrap.Rd +++ b/man/get.pi.typed.bootstrap.Rd @@ -5,7 +5,7 @@ \title{runs bootstrapping on \code{get.pi.typed}} \usage{ get.pi.typed.bootstrap(posmat, typeA = -1, typeB = -1, r = 1, - r.low = rep(0, length(r)), boot.iter) + r.low = rep(0, length(r)), boot.iter, data.frame = TRUE) } \arguments{ \item{posmat}{a matrix with columns type, x and y} @@ -19,6 +19,8 @@ get.pi.typed.bootstrap(posmat, typeA = -1, typeB = -1, r = 1, \item{r.low}{the low end of each range....0 by default} \item{boot.iter}{the number of bootstrap iterations} + +\item{data.frame}{logical indicating whether to return results as a data frame (default = TRUE)} } \value{ pi values for all the distances we looked at diff --git a/man/get.pi.typed.permute.Rd b/man/get.pi.typed.permute.Rd index a5f67a6..eed0f5e 100644 --- a/man/get.pi.typed.permute.Rd +++ b/man/get.pi.typed.permute.Rd @@ -5,7 +5,7 @@ \title{get the null distribution of the get.pi.typed function} \usage{ get.pi.typed.permute(posmat, typeA = -1, typeB = -1, r = 1, - r.low = rep(0, length(r)), permutations) + r.low = rep(0, length(r)), permutations, data.frame = TRUE) } \arguments{ \item{posmat}{a matrix with columns type, x and y} @@ -19,6 +19,8 @@ get.pi.typed.permute(posmat, typeA = -1, typeB = -1, r = 1, \item{r.low}{the low end of each range....0 by default} \item{permutations}{the number of permute iterations} + +\item{data.frame}{logical indicating whether to return results as a data frame (default = TRUE)} } \value{ pi values for all the distances we looked at diff --git a/man/get.tau.Rd b/man/get.tau.Rd index 0dd6af4..0ca43f4 100644 --- a/man/get.tau.Rd +++ b/man/get.tau.Rd @@ -5,7 +5,7 @@ \title{generalized version of \code{get.tau}} \usage{ get.tau(posmat, fun, r = 1, r.low = rep(0, length(r)), - comparison.type = "representative") + comparison.type = "representative", data.frame = TRUE) } \arguments{ \item{posmat}{a matrix with columns x, y and any other named columns @@ -30,6 +30,8 @@ interested in} \item "representative" if comparison set is representative of the underlying population \item "independent" if comparison set is cases/events coming from an indepedent process }} + +\item{data.frame}{logical indicating whether to return results as a data frame (default = TRUE)} } \value{ The tau value for each distance we look at. If \code{comparison.type} is "representative", this is: diff --git a/man/get.tau.bootstrap.Rd b/man/get.tau.bootstrap.Rd index 0dc8b25..8500992 100644 --- a/man/get.tau.bootstrap.Rd +++ b/man/get.tau.bootstrap.Rd @@ -5,7 +5,7 @@ \title{Bootstrap \code{get.tau} values.} \usage{ get.tau.bootstrap(posmat, fun, r = 1, r.low = rep(0, length(r)), - boot.iter, comparison.type = "representative") + boot.iter, comparison.type = "representative", data.frame = TRUE) } \arguments{ \item{posmat}{a matrix appropriate for input to \code{get.tau}} @@ -19,6 +19,8 @@ get.tau.bootstrap(posmat, fun, r = 1, r.low = rep(0, length(r)), \item{boot.iter}{the number of bootstrap iterations} \item{comparison.type}{the comparison type to pass as input to \code{get.pi}} + +\item{data.frame}{logical indicating whether to return results as a data frame (default = TRUE)} } \value{ a matrix containing all bootstrapped values of tau for each distance interval diff --git a/man/get.tau.ci.Rd b/man/get.tau.ci.Rd index 9e4813e..decba6e 100644 --- a/man/get.tau.ci.Rd +++ b/man/get.tau.ci.Rd @@ -6,7 +6,7 @@ \usage{ get.tau.ci(posmat, fun, r = 1, r.low = rep(0, length(r)), boot.iter = 1000, comparison.type = "representative", - ci.low = 0.025, ci.high = 0.975) + ci.low = 0.025, ci.high = 0.975, data.frame = TRUE) } \arguments{ \item{posmat}{a matrix appropriate for input to \code{get.tau}} @@ -24,6 +24,8 @@ get.tau.ci(posmat, fun, r = 1, r.low = rep(0, length(r)), \item{ci.low}{the low end of the ci...0.025 by default} \item{ci.high}{the high end of the ci...0.975 by default} + +\item{data.frame}{logical indicating whether to return results as a data frame (default = TRUE)} } \value{ a data frame with the point estimate of tau and its low and high confidence interval at each distance diff --git a/man/get.tau.permute.Rd b/man/get.tau.permute.Rd index 354adf0..170f116 100644 --- a/man/get.tau.permute.Rd +++ b/man/get.tau.permute.Rd @@ -5,7 +5,7 @@ \title{get the null distribution of the \code{get.tau} function} \usage{ get.tau.permute(posmat, fun, r = 1, r.low = rep(0, length(r)), - permutations, comparison.type = "representative") + permutations, comparison.type = "representative", data.frame = TRUE) } \arguments{ \item{posmat}{a matrix appropriate for input to \code{get.tau}} @@ -19,6 +19,8 @@ get.tau.permute(posmat, fun, r = 1, r.low = rep(0, length(r)), \item{permutations}{the number of permute iterations} \item{comparison.type}{the comparison type to pass as input to \code{get.pi}} + +\item{data.frame}{logical indicating whether to return results as a data frame (default = TRUE)} } \value{ tau values for all the distances we looked at diff --git a/man/get.tau.typed.Rd b/man/get.tau.typed.Rd index daa5e3f..c5a4121 100644 --- a/man/get.tau.typed.Rd +++ b/man/get.tau.typed.Rd @@ -5,7 +5,7 @@ \title{Optimized version of \code{get.tau} for typed data} \usage{ get.tau.typed(posmat, typeA = -1, typeB = -1, r = 1, r.low = rep(0, - length(r)), comparison.type = "representative") + length(r)), comparison.type = "representative", data.frame = TRUE) } \arguments{ \item{posmat}{a matrix with columns type, x and y} @@ -23,6 +23,8 @@ get.tau.typed(posmat, typeA = -1, typeB = -1, r = 1, r.low = rep(0, \item "representative" if comparison set is representative of the underlying population \item "independent" if comparison set is cases/events coming from an indepedent process }} + +\item{data.frame}{logical indicating whether to return results as a data frame (default = TRUE)} } \value{ data frame of tau values for all the distances diff --git a/man/get.tau.typed.bootstrap.Rd b/man/get.tau.typed.bootstrap.Rd index 3c5c160..9b62a4c 100644 --- a/man/get.tau.typed.bootstrap.Rd +++ b/man/get.tau.typed.bootstrap.Rd @@ -6,7 +6,7 @@ \usage{ get.tau.typed.bootstrap(posmat, typeA = -1, typeB = -1, r = 1, r.low = rep(0, length(r)), boot.iter, - comparison.type = "representative") + comparison.type = "representative", data.frame = TRUE) } \arguments{ \item{posmat}{a matrix with columns type, x and y} @@ -26,6 +26,8 @@ get.tau.typed.bootstrap(posmat, typeA = -1, typeB = -1, r = 1, \item "representative" if comparison set is representative of the underlying population \item "independent" if comparison set is cases/events coming from an independent process }} + +\item{data.frame}{logical indicating whether to return results as a data frame (default = TRUE)} } \value{ tau values for all the distances we looked at diff --git a/man/get.tau.typed.permute.Rd b/man/get.tau.typed.permute.Rd index f4e7f16..9958292 100644 --- a/man/get.tau.typed.permute.Rd +++ b/man/get.tau.typed.permute.Rd @@ -6,7 +6,7 @@ \usage{ get.tau.typed.permute(posmat, typeA = -1, typeB = -1, r = 1, r.low = rep(0, length(r)), permutations, - comparison.type = "representative") + comparison.type = "representative", data.frame = TRUE) } \arguments{ \item{posmat}{a matrix with columns type, x and y} @@ -26,6 +26,8 @@ get.tau.typed.permute(posmat, typeA = -1, typeB = -1, r = 1, \item "representative" if comparison set is representative of the underlying population \item "independent" if comparison set is cases/events coming from an indepedent process }} + +\item{data.frame}{logical indicating whether to return results as a data frame (default = TRUE)} } \value{ a matrix with permutation tau values for each distance specified diff --git a/man/get.theta.Rd b/man/get.theta.Rd index ea49b90..8d38a0d 100644 --- a/man/get.theta.Rd +++ b/man/get.theta.Rd @@ -4,7 +4,8 @@ \alias{get.theta} \title{Generalized version of \code{get.theta}} \usage{ -get.theta(posmat, fun, r = 1, r.low = rep(0, length(r))) +get.theta(posmat, fun, r = 1, r.low = rep(0, length(r)), + data.frame = TRUE) } \arguments{ \item{posmat}{a matrix with columns x, y and any other named columns @@ -23,6 +24,8 @@ so this is not available to the fun} interested in} \item{r.low}{the low end of each range, 0 by default} + +\item{data.frame}{logical indicating whether to return results as a data frame (default = TRUE)} } \value{ theta value for each distance range that we look at. Where: diff --git a/man/get.theta.bootstrap.Rd b/man/get.theta.bootstrap.Rd index 4ccaf76..9c4a76c 100644 --- a/man/get.theta.bootstrap.Rd +++ b/man/get.theta.bootstrap.Rd @@ -5,7 +5,7 @@ \title{Bootstrap \code{get.theta} values.} \usage{ get.theta.bootstrap(posmat, fun, r = 1, r.low = rep(0, length(r)), - boot.iter = 500) + boot.iter = 500, data.frame = TRUE) } \arguments{ \item{posmat}{a matrix with columns type, x and y} @@ -17,6 +17,8 @@ get.theta.bootstrap(posmat, fun, r = 1, r.low = rep(0, length(r)), \item{r.low}{the low end of each range. 0 by default} \item{boot.iter}{the number of bootstrap iterations} + +\item{data.frame}{logical indicating whether to return results as a data frame (default = TRUE)} } \value{ theta values for all the distances we looked at diff --git a/man/get.theta.ci.Rd b/man/get.theta.ci.Rd index 743e7b5..3818a53 100644 --- a/man/get.theta.ci.Rd +++ b/man/get.theta.ci.Rd @@ -5,7 +5,8 @@ \title{Calculate bootstrapped confidence intervals for \code{get.theta} values.} \usage{ get.theta.ci(posmat, fun, r = 1, r.low = rep(0, length(r)), - boot.iter = 1000, ci.low = 0.025, ci.high = 0.975) + boot.iter = 1000, ci.low = 0.025, ci.high = 0.975, + data.frame = TRUE) } \arguments{ \item{posmat}{a matrix with columns type, x and y} @@ -21,6 +22,8 @@ get.theta.ci(posmat, fun, r = 1, r.low = rep(0, length(r)), \item{ci.low}{the low end of the ci...0.025 by default} \item{ci.high}{the high end of the ci...0.975 by default} + +\item{data.frame}{logical indicating whether to return results as a data frame (default = TRUE)} } \value{ a matrix with a row for the high and low values and diff --git a/man/get.theta.permute.Rd b/man/get.theta.permute.Rd index 4ed0cec..970bc4a 100644 --- a/man/get.theta.permute.Rd +++ b/man/get.theta.permute.Rd @@ -5,7 +5,7 @@ \title{get the null distribution of the \code{get.theta} function} \usage{ get.theta.permute(posmat, fun, r = 1, r.low = rep(0, length(r)), - permutations) + permutations, data.frame = TRUE) } \arguments{ \item{posmat}{a matrix with columns type, x and y} @@ -17,6 +17,8 @@ get.theta.permute(posmat, fun, r = 1, r.low = rep(0, length(r)), \item{r.low}{the low end of each range....0 by default} \item{permutations}{the number of permute iterations} + +\item{data.frame}{logical indicating whether to return results as a data frame (default = TRUE)} } \value{ theta values for all the distances we looked at diff --git a/man/get.theta.typed.Rd b/man/get.theta.typed.Rd index c044ff7..fa4136e 100644 --- a/man/get.theta.typed.Rd +++ b/man/get.theta.typed.Rd @@ -5,7 +5,7 @@ \title{Optimized version of \code{get.theta} for typed data.} \usage{ get.theta.typed(posmat, typeA = -1, typeB = -1, r = 1, - r.low = rep(0, length(r))) + r.low = rep(0, length(r)), data.frame = TRUE) } \arguments{ \item{posmat}{a matrix with columns type, x and y} @@ -17,6 +17,8 @@ get.theta.typed(posmat, typeA = -1, typeB = -1, r = 1, \item{r}{the series of spatial distances wer are interested in} \item{r.low}{the low end of each range....0 by default} + +\item{data.frame}{logical indicating whether to return results as a data frame (default = TRUE)} } \value{ theta values for all the distances we looked at diff --git a/man/get.theta.typed.bootstrap.Rd b/man/get.theta.typed.bootstrap.Rd index 6313ed2..a1a6c30 100644 --- a/man/get.theta.typed.bootstrap.Rd +++ b/man/get.theta.typed.bootstrap.Rd @@ -5,7 +5,7 @@ \title{runs bootstrapping on \code{get.theta.typed}} \usage{ get.theta.typed.bootstrap(posmat, typeA = -1, typeB = -1, r = 1, - r.low = rep(0, length(r)), boot.iter) + r.low = rep(0, length(r)), boot.iter, data.frame = TRUE) } \arguments{ \item{posmat}{a matrix with columns type, x and y} @@ -19,6 +19,8 @@ get.theta.typed.bootstrap(posmat, typeA = -1, typeB = -1, r = 1, \item{r.low}{the low end of each range....0 by default} \item{boot.iter}{the number of bootstrap iterations} + +\item{data.frame}{logical indicating whether to return results as a data frame (default = TRUE)} } \value{ theta values for all the distances we looked at diff --git a/man/get.theta.typed.permute.Rd b/man/get.theta.typed.permute.Rd index 749735f..8204db5 100644 --- a/man/get.theta.typed.permute.Rd +++ b/man/get.theta.typed.permute.Rd @@ -5,7 +5,7 @@ \title{get the null distribution of the get.theta.typed function} \usage{ get.theta.typed.permute(posmat, typeA = -1, typeB = -1, r = 1, - r.low = rep(0, length(r)), permutations) + r.low = rep(0, length(r)), permutations, data.frame = TRUE) } \arguments{ \item{posmat}{a matrix with columns type, x and y} @@ -19,6 +19,8 @@ get.theta.typed.permute(posmat, typeA = -1, typeB = -1, r = 1, \item{r.low}{the low end of each range....0 by default} \item{permutations}{the number of permute iterations} + +\item{data.frame}{logical indicating whether to return results as a data frame (default = TRUE)} } \value{ theta values for all the distances we looked at