[adegenet-commits] r334 - pkg/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu May 28 16:52:48 CEST 2009
Author: jombart
Date: 2009-05-28 16:52:48 +0200 (Thu, 28 May 2009)
New Revision: 334
Modified:
pkg/R/seqTrack.R
Log:
rUnifTimeSeq can now handle vectorized arguments (was a bloody pain)
Modified: pkg/R/seqTrack.R
===================================================================
--- pkg/R/seqTrack.R 2009-05-28 14:30:11 UTC (rev 333)
+++ pkg/R/seqTrack.R 2009-05-28 14:52:48 UTC (rev 334)
@@ -299,8 +299,8 @@
## .rUnifTimeSeq
#################
.rUnifTimeSeq <- function(n, dateMin, dateMax){
- rangeSize <- as.integer(round(diff(c(dateA,dateB))))
- nbDays <- sample(1:nbDays, n, replace=TRUE)
+ rangeSize <- as.integer(difftime(dateMax,dateMin, units="days"))
+ nbDays <- round(runif(n, min=0, max=rangeSize))
res <- dateMin + nbDays*3600*24
res <- round(res, units="days")
return(res)
@@ -374,7 +374,7 @@
## optimize.seqTrack
#####################
optimize.seqTrack <- function(nsim, seq.names, seq.dates, W, optim=c("min","max"),
- proxMat=NULL, mu0, seq.length, rMissDate=NULL, ...){
+ proxMat=NULL, mu0, seq.length, rMissDate=.rUnifTimeSeq, ...){
## CHECKS ##
optim <- match.arg(optim)
@@ -461,18 +461,16 @@
## Handle distribution and its parameters ##
argList <- list(...)
- if(is.null(rMissDate)) {
- rMissDate <- runif # distribution function
- }
- if(is.null(argList$min) & identical(rMissDate, runif)){ # earliest date
- argList$min <- min(seq.dates,na.rm=TRUE)
+
+ if(is.null(argList$dateMin) & identical(rMissDate, .rUnifTimeSeq)){ # earliest date
+ argList$dateMin <- min(seq.dates,na.rm=TRUE)
} else {
- argList$min[is.na(argList$min)] <- min(seq.dates,na.rm=TRUE) - RANGE.DATES*0.5
+ argList$dateMin[is.na(argList$dateMin)] <- min(seq.dates,na.rm=TRUE) - RANGE.DATES*0.5
}
- if(is.null(argList$max) & identical(rMissDate, runif)){ # latest date
- argList$max <- max(seq.dates,na.rm=TRUE)
+ if(is.null(argList$dateMax) & identical(rMissDate, runif)){ # latest date
+ argList$dateMax <- max(seq.dates,na.rm=TRUE)
} else {
- argList$max[is.na(argList$max)] <- max(seq.dates,na.rm=TRUE) + RANGE.DATES*0.5
+ argList$dateMax[is.na(argList$dateMax)] <- max(seq.dates,na.rm=TRUE) + RANGE.DATES*0.5
}
argList$n <- sum(isMissDate)
More information about the adegenet-commits
mailing list