Dear David,

I run into the same problem when trying to calculate HR overlap with UDs from the brownian bridge. I ended up modifying the existing kerneloverlap function. The parameters are the same as for kerneloverlaphr only that x is an UD object. It would be nice to  add this more generic function to adehabitat. I also had to write my own getarea function to make it work with UDs from brownian bridges.

##Generic HROverlap function

hroverlap<-function (x, method = c("HR", "PHR", "VI", "BA",
    "UDOI", "HD"), lev = 95, conditional = FALSE, ...)
{
    method <- match.arg(method)
    vol <- getvolumeUD(x)
    res <- matrix(0, ncol = length(x), nrow = length(x))
    for (i in 1:length(x)) {
        for (j in 1:i) {
            if (method == "HR") {
                vi <- vol[[i]]$UD
                vj <- vol[[j]]$UD
                vi[vi <= lev] <- 1
                vi[vi > lev] <- 0
                vj[vj <= lev] <- 1
                vj[vj > lev] <- 0
                vk <- vi * vj
                res[i, j] <- sum(vk)/sum(vi)
                res[j, i] <- sum(vk)/sum(vj)
            }
            if (method == "PHR") {
                vi <- x[[i]]$UD
                vj <- x[[j]]$UD
                ai <- vol[[i]]$UD
                aj <- vol[[j]]$UD
                ai[ai <= lev] <- 1
                ai[ai > lev] <- 0
                aj[aj <= lev] <- 1
                aj[aj > lev] <- 0
                if (conditional) {
                  vi <- vi * ai
                  vj <- vj * aj
                  res[j, i] <- sum(vi * aj) * (attr(vi, "cellsize")^2)
                  res[i, j] <- sum(vj * ai) * (attr(vi, "cellsize")^2)
                }
                else {
                  res[j, i] <- sum(vi * aj) * (attr(vi, "cellsize")^2)
                  res[i, j] <- sum(vj * ai) * (attr(vi, "cellsize")^2)
                }
            }
            if (method == "VI") {
                vi <- c(x[[i]]$UD)
                vj <- c(x[[j]]$UD)
                ai <- vol[[i]]$UD
                aj <- vol[[j]]$UD
                ai[ai <= lev] <- 1
                ai[ai > lev] <- 0
                aj[aj <= lev] <- 1
                aj[aj > lev] <- 0
                if (conditional) {
                  vi <- vi * ai
                  vj <- vj * aj
                  res[i, j] <- res[j, i] <- sum(pmin(vi, vj)) *
                    (attr(x[[i]]$UD, "cellsize")^2)
                }
                else {
                  res[i, j] <- res[j, i] <- sum(pmin(vi, vj)) *
                    (attr(x[[i]]$UD, "cellsize")^2)
                }
            }
            if (method == "BA") {
                vi <- x[[i]]$UD
                vj <- x[[j]]$UD
                ai <- vol[[i]]$UD
                aj <- vol[[j]]$UD
                ai[ai <= lev] <- 1
                ai[ai > lev] <- 0
                aj[aj <= lev] <- 1
                aj[aj > lev] <- 0
                if (conditional) {
                  vi <- vi * ai
                  vj <- vj * aj
                  res[j, i] <- res[i, j] <- sum(sqrt(vi) * sqrt(vj)) *
                    (attr(vi, "cellsize")^2)
                }
                else {
                  res[j, i] <- res[i, j] <- sum(sqrt(vi) * sqrt(vj)) *
                    (attr(vi, "cellsize")^2)
                }
            }
            if (method == "UDOI") {
                vi <- x[[i]]$UD
                vj <- x[[j]]$UD
                ai <- vol[[i]]$UD
                aj <- vol[[j]]$UD
                ai[ai <= lev] <- 1
                ai[ai > lev] <- 0
                aj[aj <= lev] <- 1
                aj[aj > lev] <- 0
                if (conditional) {
                  vi <- vi * ai
                  vj <- vj * aj
                  ak <- sum(ai * aj) * (attr(vi, "cellsize")^2)
                  res[j, i] <- res[i, j] <- ak * sum(vi * vj) *
                    (attr(vi, "cellsize")^2)
                }
                else {
                  ak <- sum(ai * aj) * (attr(vi, "cellsize")^2)
                  res[j, i] <- res[i, j] <- ak * sum(vi * vj) *
                    (attr(vi, "cellsize")^2)
                }
            }
            if (method == "HD") {
                vi <- x[[i]]$UD
                vj <- x[[j]]$UD
                ai <- vol[[i]]$UD
                aj <- vol[[j]]$UD
                ai[ai <= lev] <- 1
                ai[ai > lev] <- 0
                aj[aj <= lev] <- 1
                aj[aj > lev] <- 0
                if (conditional) {
                  vi <- vi * ai
                  vj <- vj * aj
                  res[j, i] <- res[i, j] <- sqrt(sum((sqrt(vi) -
                    sqrt(vj))^2 * (attr(vi, "cellsize")^2)))
                }
                else {
                  res[j, i] <- res[i, j] <- sqrt(sum((sqrt(vi) -
                    sqrt(vj))^2 * (attr(vi, "cellsize")^2)))
                }
            }
        }
    }
    rownames(res) <- names(x)
    colnames(res) <- names(x)
    return(res)
}


At 19:23 24.04.2009, David Douglas wrote:
Clément Calenge-2 wrote: > > Hi all, > > Yes, you are right: kernel UDs are often computed as a basis for further > analysis, including kernel overlap, but not only... It would be more > sensible to estimate UD once, and then using them for other analyses. I > planned to upload a new version of adehabitat to CRAN before the end of > the week, and I will include, on the help page of kerneloverlap, a new > function accepting a "khrud" object to perform this computation." > Many thanks for the suggestion, > Regards, > > Clément > > Greetings, I was taking the course described above to create a set of khrud objects for input to kerneloverlaphr. However, I was using kernelbb (rather than kernelud) to create the ud objects, on a fixed-grid. sig1a <- liker(trj1, sig2 = 1000, rangesig1 = c(10, 1000)) bbridge1 <- kernelbb(trj1, as.data.frame(sig1a[1])[1,1], sig2 = 1000, grid=ascall ) sig1b <- liker(trj2, sig2 = 1000, rangesig1 = c(10, 1000)) bbridge2 <- kernelbb(trj1, as.data.frame(sig1b[1])[1,1], sig2 = 1000, grid=ascall ) While I remain unsure of how to integrate 2 or more individual UD objects (say, bbridge1 and bbridge2) into an object that is compatible with kerneloverlaphr, it would seem that I'm up against a bigger problem: kerneloverlaphr requires an object type = khr, subclass=khrud, but kernelbb produces UD objects that have type=khr, subclass=kbbhrud. It appears kerneloverlaphr will not accept a kbbhrud object. Is there any way to change a kbbhrud object so it can be compatible with kerneloverlaphr? Or, are there reasons why Brownian Bridge UDs should not be candidates for kerneloverlaphr? David Douglas -- View this message in context: http://www.nabble.com/overlap-tp21929181p23226781.html Sent from the AniMov mailing list archive at Nabble.com. _______________________________________________ AniMov mailing list [email protected] http://lists.faunalia.it/cgi-bin/mailman/listinfo/animov
_______________________________________________
AniMov mailing list
[email protected]
http://lists.faunalia.it/cgi-bin/mailman/listinfo/animov

Reply via email to