summedWgt() function in RPresence

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:
According to ChatGPT:
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.
I hope this helps anyone else running into this issue!
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!