bcgov / ssdtools

An R package to fit and plot Species Sensitivity Distributions (SSDs)
https://bcgov.github.io/ssdtools/
Apache License 2.0
30 stars 16 forks source link

Add check to see if multiple identical minimum values suggesting censoring #371

Open joethorley opened 1 month ago

joethorley commented 1 month ago

Treating as non-censoring is both invalid and can cause convergence failure.

joethorley commented 1 month ago
x  <- structure(list(original.CAS = c(75058, 75058, 75058, 75058, 75058, 
75058, 75058, 75058, 75058, 75058, 75058, 75058, 75058, 75058
), Test.type = c("A", "A", "A", "A", "A", "A", "A", "A", "A", 
"A", "A", "A", "A", "A"), Latin.name = c("Artemia salina", "Asellus intermedius", 
"Daphnia magna", "Dugesia tigrina", "Gammarus fasciatus", "Helisoma trivolvis", 
"Lepomis macrochirus", "Leuciscus idus", "Leuciscus idus melanotus", 
"Lumbriculus variegatus", "Oryzias latipes", "Pimephales promelas", 
"Poecilia reticulata", "Raphidocelis subcapitata"), Effect.value = c(399650, 
1e+05, 3589986.07239638, 1e+05, 1e+05, 1e+05, 1850000, 5800000, 
6422032.3885823, 1e+05, 1e+06, 1289765.53208085, 1650000, 7940000
), Trophic.Level = c("INVERT", "INVERT", "INVERT", "INVERT", 
"INVERT", "INVERT", "FISH", "FISH", "FISH", "INVERT", "FISH", 
"FISH", "FISH", "ALGAE"), Short_name = c("Acetonitrile", "Acetonitrile", 
"Acetonitrile", "Acetonitrile", "Acetonitrile", "Acetonitrile", 
"Acetonitrile", "Acetonitrile", "Acetonitrile", "Acetonitrile", 
"Acetonitrile", "Acetonitrile", "Acetonitrile", "Acetonitrile"
), Conc = c(399650, 1e+05, 3589986.07239638, 1e+05, 1e+05, 1e+05, 
1850000, 5800000, 6422032.3885823, 1e+05, 1e+06, 1289765.53208085, 
1650000, 7940000)), class = c("grouped_df", "tbl_df", "tbl", 
"data.frame"), row.names = c(NA, -14L), groups = structure(list(
    original.CAS = 75058, Test.type = "A", .rows = structure(list(
        1:14), ptype = integer(0), class = c("vctrs_list_of", 
    "vctrs_vctr", "list"))), row.names = c(NA, -1L), .drop = TRUE, class = c("tbl_df", 
"tbl", "data.frame")))
ssd_fit_dists(data = x, dists = "lnorm_lnorm", left = "Left", right = "Right",
              silent = FALSE, min_pmix = 3/nrow(x),
              computable = FALSE, at_boundary_ok = TRUE)

x$Right <- x$Conc
x$Left <- x$Conc

x$Left[x$Left == min(x$Left)] <- 0

ssd_fit_dists(data = x, dists = "lnorm_lnorm", left = "Left", right = "Right",
              silent = FALSE, min_pmix = 3/nrow(x),
              computable = FALSE, at_boundary_ok = TRUE)