[adegenet-commits] r168 - in pkg: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Aug 13 18:55:19 CEST 2008
Author: jombart
Date: 2008-08-13 18:55:19 +0200 (Wed, 13 Aug 2008)
New Revision: 168
Modified:
pkg/R/chooseCN.R
pkg/man/chooseCN.Rd
Log:
dmin/dmax in chooseCN now available
Modified: pkg/R/chooseCN.R
===================================================================
--- pkg/R/chooseCN.R 2008-08-12 17:04:49 UTC (rev 167)
+++ pkg/R/chooseCN.R 2008-08-13 16:55:19 UTC (rev 168)
@@ -12,6 +12,20 @@
if(!require(spdep, quiet=TRUE)) stop("spdep library is required.")
res <- list()
+
+ if(!is.null(d2)){
+ if(d2=="dmin"){
+ tempmat <- as.matrix(dist(xy))
+ d2min <- max(apply(tempmat, 1, function(r) min(r[r>1e-12])))
+ d2min <- d2min * 1.0001 # to avoid exact number problem
+ d2 <- d2min
+ } else if(d2=="dmax"){
+ d2max <- max(dist(xy))
+ d2max <- d2max * 1.0001 # to avoid exact number problem
+ d2 <- d2max
+ }
+ } # end handle d2
+
d1.first <- d1
d2.first <- d2
k.first <- k
@@ -95,13 +109,24 @@
if(is.null(d1) |is.null(d2)){
tempmat <- as.matrix(dist(xy))
d2min <- max(apply(tempmat, 1, function(r) min(r[r>1e-12])))
+ d2min <- d2min * 1.0001 # to avoid exact number problem
d2max <- max(dist(xy))
+ d2max <- d2max * 1.0001 # to avoid exact number problem
dig <- options("digits")
options("digits=5")
cat("\n Enter minimum distance: ")
d1 <- as.numeric(readLines(n = 1))
cat("\n Enter maximum distance \n(dmin=", d2min, ", dmax=", d2max, "): ")
- d2 <- as.numeric(readLines(n = 1))
+ d2 <- readLines(n = 1)
+ ## handle character
+ if(d2=="dmin") {
+ d2 <- d2min
+ } else if(d2=="dmax") {
+ d2 <- d2max
+ } else {
+ d2 <- as.numeric(d2)
+ }
+ ## restore initial digit option
options(dig)
}
# avoid that a point is its neighbour
Modified: pkg/man/chooseCN.Rd
===================================================================
--- pkg/man/chooseCN.Rd 2008-08-12 17:04:49 UTC (rev 167)
+++ pkg/man/chooseCN.Rd 2008-08-13 16:55:19 UTC (rev 168)
@@ -25,7 +25,9 @@
\item{d1}{the minimum distance between any two neighbours. Used if
\code{type=5.}}
\item{d2}{the maximum distance between any two neighbours. Used if
- \code{type=5}.}
+ \code{type=5}. Can also be a character: "dmin" for the minimum
+ distance so that each site has at least one connection, or "dmax" to
+ have all sites connected (despite the later has no sense).}
\item{k}{the number of neighbours per point. Used if
\code{type=6}.}
\item{a}{the exponent of the inverse distance matrix. Used if
More information about the adegenet-commits
mailing list