[R] potential BUG in BBMM

T.D. Rudolph tylerdeanrudolph at gmail.com
Tue Jul 13 22:47:51 CEST 2010


http://r.789695.n4.nabble.com/file/n2287976/BBMM_BUG.RData BBMM_BUG.RData 

I've been constructing utilization distributions for 63 animal movement
trajectories using a Brownian bridge movement model with BBMM.  I started
noticing after running the routine numerous times at different resolutions
that certain UDs would be grossly wrong, meaning instead of returning a
strongly negative exponential distribution of probabilities (UD$probability)
that sums to 1, there might be two big modes in opposite places, or negative
probability values, or simply "NaN" across the board.  I have found this
problem on Mac, Linux, and Windows machines in various versions of R
(including the most recent), and I was hoping someone in the R community
would be able to verify this and perhaps speculate on why this is occurring.  

The problem appears to originate either 1) in the FORTRAN code that
estimates BMVar and calculates the BBMM, or 2) in the way R handles its
operation.  I've broken down BBMM into its essential parts, and in the
attached environment are all of the objects necessary to run the FORTRAN
code.  I have set it up in a loop here so it continually estimates a UD on
the same data then and produces a histogram, which I have found to be most
revealing in identifying problems.  If the code stops running it's because
the result was all "NaN".  If you run the loop repeatedly you may find, as I
have, that while the results may initially appear more-or-less consistent,
at other moments they will change, sometimes gradually, and sometimes
quickly.  If you are looking at it and it is not changing, I encourage you
to remove all objects, close and reopen R, reload the workspace and run the
same loop again.  If you do this numerous times you should eventually see
unusual results, meaning inconsistent estimation, or wacky probability
distributions, or "NaN".

################################################################################
##  Run the Fortran routine repeatedly with identical data
##  - all required objects are in workspace "BBMM_BUG.RData" -

require(BBMM)

par(mfrow=c(2,2))


repeat {
        ans <- .Fortran("BBMM", as.integer(n.locs), as.integer(grid.size),
        as.double(time.lag), as.double(T.Total), as.double(x),
        as.double(y), as.double(BMvar), as.double(location.error),
        as.double(area.grid$x), as.double(area.grid$y),
as.double(time.step),
        as.double(probability), PACKAGE = "BBMM")

    if(!sum(ans[[12]])=="NaN") { hist(ans[[12]]) } else { break }
}
#################################################################################


Tyler
-- 
View this message in context: http://r.789695.n4.nabble.com/potential-BUG-in-BBMM-tp2287976p2287976.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list