summedWgt() function in RPresence

announcements (new versions, changes, bugs, installation problems...) related to program PRESENCE

summedWgt() function in RPresence

Postby kdavis79 » Tue Feb 11, 2025 10:40 pm

I believe I found a small bug in the summedWgt() function in RPresence. When using it on my model set, I saw that one variable of interest had a summed weight of 0.2275, despite the fact that the two models it belonged to had weights of 0.003 and 0.001 each.

After some digging, I believe this is attributable to an issue with the grepl() and deparse() components of the summedWgt function (as seen when using getAnywhere(summedWgt()) to view the underlying code). In addition to my illogical variable weights, I was also getting the following warning:
Code: Select all
In ind * aic.tab$table$wgt :
  longer object length is not a multiple of shorter object length


According to ChatGPT:
deparse(get(param, model$model)) turns the formula into a character vector, but sometimes deparse() splits it into multiple lines (which is why grepl() returns multiple values).


With the following modification (note the any() wrapped around grepl()), the problem seems to be resolved. I have stopped getting the warning and my model weights now make sense.

Code: Select all
summedWgt_KD <- function(covnames, param, aic.tab) {
    temp <- unlist(lapply(covnames, function(cvn) {
        ind <- unlist(lapply(aic.tab$models, function(model) {
            any(grepl(cvn, paste(deparse(get(param, model$model)), collapse = " ")))
        }))  # Closing bracket for second lapply
        return(sum(ind * aic.tab$table$wgt))
    }))  # Closing bracket for first lapply
    return(data.frame(covnames = covnames, sum.wgt = temp, ER = temp / (1 - temp)))
}


I hope this helps anyone else running into this issue!
kdavis79
 
Posts: 6
Joined: Tue Aug 13, 2024 9:53 am

Re: summedWgt() function in RPresence

Postby jhines » Wed Feb 12, 2025 2:30 pm

Thanks for diagnosing the error. I was unable to replicate the problem. Would you be able to send me (jhines@usgs.gov) the code/data which produced this?
jhines
 
Posts: 631
Joined: Fri May 16, 2003 9:24 am
Location: Laurel, MD, USA

Re: summedWgt() function in RPresence

Postby jhines » Wed Feb 12, 2025 2:30 pm

Thanks for diagnosing the error. I was unable to replicate the problem. Would you be able to send me (jhines@usgs.gov) the code/data which produced this?
jhines
 
Posts: 631
Joined: Fri May 16, 2003 9:24 am
Location: Laurel, MD, USA


Return to software problems/news

Who is online

Users browsing this forum: No registered users and 1 guest

cron