error message from validate() in secrdesign; "missing values not allowed..."

84 views
Skip to first unread message

ejh20

unread,
Oct 29, 2014, 11:36:43 AM10/29/14
to secr...@googlegroups.com
Good day,
I was trying to use validate() to remove rogue values based on the SE of the density estimate.  I wanted to discard all statistics if the SE was either very small, or larger than the simulated D (where RSE > 1).
However I tried to use validate(), I got similar error messages.  The syntax in the example below was intended to mimic that in the secrdesign vignette, page 23.  BTW I'm aware that 20 replicates is probably insufficient for some statistics. Just trying to get things working before I increase it.


> Frun12X4 = run.scenarios(nrepl = 20, scenarios = Fscen1, trapset = tline12X4, maskset = knp.mask, fit = T)
> FD12X4 = select.stats(Frun12X4, parameter = "D", statistics = c("estimate", "SE.estimate", "lcl", "ucl", "ERR", "RB", "RSE", "COV"))
> FD12X4.v = validate(FD12X4, "SE.estimate", c(0.0005, 0.04), "all")
Error in `[<-.data.frame`(`*tmp*`, criterion, targets, value = NA) :
  missing values are not allowed in subscripted assignments of data frames

Thanks in advance,
Eric

ejh20

unread,
Oct 29, 2014, 11:59:01 AM10/29/14
to secr...@googlegroups.com
I noticed that "SE.estimate" includes the values Inf and NaN... could that be the problem?  maybe I should use D or RSE as the test statistic?
Also the example is on page 25 of the vignette, not 23. Sorry.
Eric

Murray Efford

unread,
Oct 29, 2014, 4:07:32 PM10/29/14
to secr...@googlegroups.com
Hi Eric
It looks like I didn't cover the NaN case... Damn. You can see the code for validate() (type name at R prompt). I haven't time to check it just now, but I expect sourcing or cutting and pasting this version will fix the problem. is.na() covers both NA and NaN. If this doesn't work... maybe troubleshoot further?
Murray

validate <- function (x, test, validrange = c(0, Inf), targets = test)
{
    onescenario
<- function(scen, minx, maxx) {
        criterion
<- (scen[, test] < minx) | (scen[, test] >
            maxx
)
       
####################################
        criterion
[is.na(criterion)] <- TRUE     ## 2014-10-30
       
####################################
        scen
[criterion, targets] <- NA
        scen
[is.na(scen[, test]), targets] <- NA
        scen
   
}
   
if (!inherits(x, "selectedstatistics"))
        stop
("requires 'selectedstatistics'")
   
if (tolower(targets) == "all")
        targets
<- colnames(x$output[[1]])
   
if (!all(c(test, targets) %in% colnames(x$output[[1]])))
        stop
("test or targets not found in input")
    nscen
<- length(x$output)
   
if (!is.matrix(validrange))
        validrange
<- matrix(validrange, byrow = TRUE, nrow = nscen,
            ncol
= 2)
   
if (nrow(validrange) != nscen)
        stop
("invalid `validrange'")
    minx
<- validrange[, 1]
    maxx
<- validrange[, 2]
    x$output
<- mapply(onescenario, x$output, minx, maxx, SIMPLIFY = FALSE)
    x
}
Reply all
Reply to author
Forward
0 new messages