### Install ssdtools from r-universe Source: https://github.com/bcgov/ssdtools/blob/main/README.md Installs the 'ssdtools' package, potentially a development or pre-release version, from a custom R-universe repository. This method allows for installation directly using install.packages, specifying the repository. ```r install.packages("ssdtools", repos = c("https://bcgov.r-universe.dev", "https://cloud.r-project.org")) ``` -------------------------------- ### Load and Display Example Data in R Source: https://github.com/bcgov/ssdtools/blob/main/README.md Demonstrates how to load the 'ccme_boron' dataset from the ssddata package and display its structure and first few rows. This dataset contains toxicity concentrations for Boron across different species and units. ```r library(ssdtools) ssddata::ccme_boron #> # A tibble: 28 × 5 #> Chemical Species Conc Group Units #> #> 1 Boron Oncorhynchus mykiss 2.1 Fish mg/L #> 2 Boron Ictalurus punctatus 2.4 Fish mg/L #> 3 Boron Micropterus salmoides 4.1 Fish mg/L #> 4 Boron Brachydanio rerio 10 Fish mg/L #> 5 Boron Carassius auratus 15.6 Fish mg/L #> 6 Boron Pimephales promelas 18.3 Fish mg/L #> 7 Boron Daphnia magna 6 Invertebrate mg/L #> 8 Boron Opercularia bimarginata 10 Invertebrate mg/L #> 9 Boron Ceriodaphnia dubia 13.4 Invertebrate mg/L #> 10 Boron Entosiphon sulcatum 15 Invertebrate mg/L #> # ℹ 18 more rows ``` -------------------------------- ### Install Development Version of ssdtools from GitHub Source: https://github.com/bcgov/ssdtools/blob/main/README.md Installs the latest development version of the 'ssdtools' R package from its GitHub repository. This requires the 'remotes' package to be installed first. Use this for accessing the newest features or bug fixes, but be aware it might be less stable than the CRAN release. ```r # install.packages("remotes") remotes::install_github("bcgov/ssdtools") ``` -------------------------------- ### Fit Distribution to Data (lnorm) - Shortened Input Source: https://github.com/bcgov/ssdtools/blob/main/tests/testthat/_snaps/operators.md This example demonstrates fitting the 'lnorm' distribution using a shortened input 'x1'. The output confirms the 'lnorm' distribution with estimated meanlog and sdlog parameters. ```r library(ssdtools) x1 <- "some_data_here" fit_lnorm_short <- ssd_fit_dist(x1, dist = "lnorm") print(fit_lnorm_short) ``` -------------------------------- ### Starting Value Generation for dlnorm in ssdtools Source: https://github.com/bcgov/ssdtools/blob/main/NEWS.md The `slnorm()` function has been added to ssdtools to provide starting values for fitting the 'dlnorm' (log-normal) distribution, potentially simplifying the fitting process. ```r starting_values <- slnorm(data) ssd_fit_dists(data, dists = "dlnorm", start = starting_values) ``` -------------------------------- ### Install Latest Release of ssdtools from CRAN Source: https://github.com/bcgov/ssdtools/blob/main/README.md Installs the most recent stable version of the 'ssdtools' R package directly from the Comprehensive R Archive Network (CRAN). This is the recommended method for most users seeking a reliable version. ```r install.packages("ssdtools") ``` -------------------------------- ### Inv-Pareto Initial Shape and Scale (MLEs) Source: https://github.com/bcgov/ssdtools/blob/main/tests/testthat/_snaps/invpareto.md Calculates the initial shape and scale parameters for the Inverse Pareto distribution using Maximum Likelihood Estimation (MLEs). This is often a starting point for optimization algorithms in fitting the distribution. The output is a list containing log-scale and log-shape estimates. ```r list(log_scale = 0.961975263550564, log_shape = 2.94009311871754) ``` -------------------------------- ### Get BCANZ Recommended Distributions Source: https://github.com/bcgov/ssdtools/blob/main/NEWS.md Retrieves a character vector of the recommended distributions for model averaging and settings in British Columbia, Canada, Australia, and New Zealand. This function is part of the ssdtools package and helps in selecting appropriate distributions for ecological risk assessment. ```r ssd_dists_bcanz() [1] "gamma" "lgumbel" "llogis" "lnorm" "lnorm_lnorm" "weibull" ``` -------------------------------- ### Add Bootstrap Sample and Save Options to ssd_hc() and ssd_hp() Source: https://github.com/bcgov/ssdtools/blob/main/NEWS.md This snippet highlights the addition of `samples` and `save_to` arguments to `ssd_hc()` and `ssd_hp()`. `samples = FALSE` can be set to `TRUE` to include bootstrap samples. `save_to` allows specifying a directory to save bootstrap datasets and parameter estimates. ```r ssd_hc(data, samples = TRUE, save_to = "/path/to/directory") ssd_hp(data, samples = TRUE, save_to = "/path/to/directory") ``` -------------------------------- ### Fit Distribution to Data (lgumbel, llogis) Source: https://github.com/bcgov/ssdtools/blob/main/tests/testthat/_snaps/operators.md This code snippet demonstrates fitting 'lgumbel' and 'llogis' distributions to data. It takes a dataset (implicitly 'x2') and outputs the estimated location and scale parameters for the fitted distributions. The process uses 28 rows of data for parameter estimation. ```r library(ssdtools) x2 <- "some_data_here" fit_lgumbel <- ssd_fit_dist(x2, dist = "lgumbel") print(fit_lgumbel) fit_llogis <- ssd_fit_dist(x2, dist = "llogis") print(fit_llogis) ``` -------------------------------- ### Fit Distributions and Goodness-of-Fit Table Source: https://github.com/bcgov/ssdtools/blob/main/paper/paper.md This snippet demonstrates fitting default Species Sensitivity Distributions (SSDs) to a dataset and then generating a goodness-of-fit table. It utilizes the `ssd_fit_dists` function to perform the fitting and `ssd_gof` to display the results, including information criteria. ```r library(ssdtools) fits <- ssd_fit_dists(ssddata::ccme_boron) ssd_gof(fits) ``` -------------------------------- ### SSD Rate Multi-distribution all fitting Source: https://github.com/bcgov/ssdtools/blob/main/tests/testthat/_snaps/multi.md This snippet shows results from 'ssd_rmulti' with an 'all' parameter, suggesting a comprehensive fitting across all distributions. The output includes three numerical values, likely representing overall model fit or aggregated parameters. ```r 0.00303329119967302 140.072019810613 4.1688296624039 ``` -------------------------------- ### Introduce ssd_exx() Family for Default Parameter Estimates Source: https://github.com/bcgov/ssdtools/blob/main/NEWS.md This snippet presents the new `ssd_exx()` family of functions (e.g., `ssd_elnorm()`, `ssd_egamma()`) designed to retrieve default parameter estimates for various distributions. ```r ssd_elnorm(mean, sd) ssd_egamma(shape, rate) ``` -------------------------------- ### SSD Estimated Multi-distribution parameters Source: https://github.com/bcgov/ssdtools/blob/main/tests/testthat/_snaps/multi.md This snippet demonstrates the 'ssd_emulti' function, which appears to estimate parameters for multiple distributions. The output is a list of estimated parameters (weight, shape, scale, etc.) for various distributions like BurrIII3, gamma, gompertz, lgumbel, llogis, lnorm, and weibull. ```r ## Output # $burrIII3.weight # [1] 0 # # $burrIII3.shape1 # [1] 1 # # $burrIII3.shape2 # [1] 1 # # $burrIII3.scale # [1] 1 # # $gamma.weight # [1] 0.1666667 # # $gamma.shape # [1] 1 # # $gamma.scale # [1] 1 # # $gompertz.weight # [1] 0 # # $gompertz.location # [1] 1 # # $gompertz.shape # [1] 1 # # $lgumbel.weight # [1] 0.1666667 # # $lgumbel.locationlog # [1] 0 # # $lgumbel.scalelog # [1] 1 # # $llogis.weight # [1] 0.1666667 # # $llogis.locationlog # [1] 0 # # $llogis.scalelog # [1] 1 # # $llogis_llogis.weight # [1] 0 # # $llogis_llogis.locationlog1 # [1] 0 # # $llogis_llogis.scalelog1 # [1] 1 # # $llogis_llogis.locationlog2 # [1] 1 # # $llogis_llogis.scalelog2 # [1] 1 # # $llogis_llogis.pmix # [1] 0.5 # # $lnorm.weight # [1] 0.1666667 # # $lnorm.meanlog # [1] 0 # # $lnorm.sdlog # [1] 1 # # $lnorm_lnorm.weight # [1] 0.1666667 # # $lnorm_lnorm.meanlog1 # [1] 0 # # $lnorm_lnorm.sdlog1 # [1] 1 # # $lnorm_lnorm.meanlog2 # [1] 1 # # $lnorm_lnorm.sdlog2 # [1] 1 # # $lnorm_lnorm.pmix # [1] 0.5 # # $weibull.weight # [1] 0.1666667 # # $weibull.shape # [1] 1 # # $weibull.scale # [1] 1 ``` -------------------------------- ### Probability Distribution Functions for Multiple Distributions Source: https://github.com/bcgov/ssdtools/blob/main/paper/paper.md Provides functions for probability density (`ssd_pmulti`), cumulative distribution (`ssd_qmulti`), and random generation (`ssd_rmulti`) for multiple distributions. These are essential for implementing the 'multi' method of bootstrapping in confidence interval calculations within ssdtools v2, particularly when dealing with non-censored data and aiming to adhere to the inversion principle. ```r library(ssdtools) # Example usage: # Calculate probability density density <- ssd_pmulti(q = 10, dists = c("lgumbel", "llogis"), params = list(SSDtools::ssd_parms_lgumbel(ssddata::ccme_boron), SSDtools::ssd_parms_llogis(ssddata::ccme_boron))) # Calculate cumulative distribution cum_dist <- ssd_qmulti(p = 0.05, dists = c("lgumbel", "llogis"), params = list(SSDtools::ssd_parms_lgumbel(ssddata::ccme_boron), SSDtools::ssd_parms_llogis(ssddata::ccme_boron))) # Generate random samples random_samples <- ssd_rmulti(n = 100, dists = c("lgumbel", "llogis"), params = list(SSDtools::ssd_parms_lgumbel(ssddata::ccme_boron), SSDtools::ssd_parms_llogis(ssddata::ccme_boron))) ``` -------------------------------- ### Update ssd_fit_dists() Arguments for Distribution Stability Source: https://github.com/bcgov/ssdtools/blob/main/NEWS.md This snippet describes changes to the `ssd_fit_dists()` function aimed at preventing the `lnorm_lnorm` bimodal distribution from being dropped. The `min_pmix` argument is now set dynamically, `at_boundary_ok` and `computable` are set to `TRUE`. These changes also benefit the BurrIII distribution and allow for a higher `min_pboot` value for bootstrapping functions. ```r ssd_fit_dists(data, min_pmix = ssd_min_pmix(nrow(data)), at_boundary_ok = TRUE, computable = TRUE) ``` -------------------------------- ### SSD Rate Multi-distribution fitting Source: https://github.com/bcgov/ssdtools/blob/main/tests/testthat/_snaps/multi.md This snippet illustrates the 'ssd_rmulti' function, presumably for fitting distributions based on rates or hazard functions. The output shows various numerical results, including a vector of two values and a large value possibly representing an extreme fit or parameter. ```r 28.5551532137488 c(28.5551532137488, 12.5960130427869) 0.0488589998529118 240.430274490865 23.4379668609469 ``` -------------------------------- ### SSD Quantile Multi-distribution fitting Source: https://github.com/bcgov/ssdtools/blob/main/tests/testthat/_snaps/multi.md This snippet demonstrates the 'ssd_qmulti' function, likely for fitting distributions based on quantiles. The output shows numerical values and a vector with multiple quantile-based results. ```r 15.3257945029983 c(15.3257945029983, 32.4740136500934) 32.4740136500934 32.4740136500934 32.4740136500934 ``` -------------------------------- ### Fit Distribution to Data (lnorm) Source: https://github.com/bcgov/ssdtools/blob/main/tests/testthat/_snaps/operators.md This code snippet illustrates fitting the 'lnorm' (log-normal) distribution to data represented by 'x1'. It calculates and outputs the meanlog and sdlog parameters estimated from 28 rows of data. ```r library(ssdtools) x1 <- "some_data_here" fit_lnorm <- ssd_fit_dist(x1, dist = "lnorm") print(fit_lnorm) ``` -------------------------------- ### Add New Functions for Hazard Proportions and Mixture Distributions Source: https://github.com/bcgov/ssdtools/blob/main/NEWS.md This snippet introduces new functions for calculating hazard proportions (`ssd_hp_bcanz()`, `ssd_hp.fitburrlioz()`) and for handling combined mixture distributions (`ssd_pmulti()`, `ssd_qmulti()`, `ssd_rmulti()`). ```r ssd_hp_bcanz(data) ssd_hp.fitburrlioz(data) sd_pmulti(q, mean, sd, pn) sd_qmulti(p, mean, sd, pn) sd_rmulti(n, mean, sd, pn) ``` -------------------------------- ### Generics for fitdists Objects in ssdtools Source: https://github.com/bcgov/ssdtools/blob/main/NEWS.md Implements several generic functions for `fitdists` objects to provide model summaries and data retrieval. These include `glance()` for model statistics, `augment()` to return original data, `logLik()` for log-likelihood values, and `summary.fitdists()` for a comprehensive summary. ```r glance(fitdists_object) augment(fitdists_object) logLik(fitdists_object) summary(fitdists_object) ``` -------------------------------- ### SSD Quantile Multi-distribution weights Source: https://github.com/bcgov/ssdtools/blob/main/tests/testthat/_snaps/multi.md This snippet displays weights associated with the 'ssd_qmulti' function. Similar to 'ssd_pmulti' weights, these are likely used in weighted modeling, emphasizing specific quantiles or distributions. ```r 6.1824272690439 5.60825250963428 5.60825250963428 5.60825250963428 ``` -------------------------------- ### SSD Probability Multi-distribution fitting Source: https://github.com/bcgov/ssdtools/blob/main/tests/testthat/_snaps/multi.md This snippet showcases the 'ssd_pmulti' function, likely used for fitting probability distributions to data where probabilities are a key input. The output includes numerical results and a vector with a potential NA value, indicating missing data or an undefined state. ```r 0.0389878051502311 0.999954703139038 c(0.0389878051502311, 0.0830181001146927) c(0.0389878051502311, NA) 0.961012194849769 -3.24450637020533 -0.0397681803423391 ``` -------------------------------- ### Goodness of Fit Testing with ssd_gof() Source: https://github.com/bcgov/ssdtools/blob/main/NEWS.md The `ssd_gof()` function is used for goodness-of-fit testing. The 'pvalue' argument can be set to TRUE to return p-values for the test statistics instead of the statistics themselves. ```R ssd_gof(fits) ssd_gof(fits, pvalue = TRUE) ``` -------------------------------- ### Fitting Burrlioz Distribution with ssd_fit_burrlioz() Source: https://github.com/bcgov/ssdtools/blob/main/NEWS.md The `ssd_fit_burrlioz()` function has been added to the ssdtools package to approximate the behavior of the Burrlioz software. This allows for fitting the Burrlioz distribution to data. ```R ssd_fit_burrlioz(data) ``` -------------------------------- ### Fit Distribution to Data (lnorm) - Distribution Name Only Source: https://github.com/bcgov/ssdtools/blob/main/tests/testthat/_snaps/operators.md This code snippet shows fitting the 'lnorm' distribution by providing only the distribution name. It outputs the estimated meanlog and sdlog parameters for the log-normal distribution. ```r library(ssdtools) fit_lnorm_name <- ssd_fit_dist(dist = "lnorm") print(fit_lnorm_name) ``` -------------------------------- ### Distribution Parameterization Changes in ssdtools Source: https://github.com/bcgov/ssdtools/blob/main/NEWS.md Several distributions in ssdtools have undergone reparameterization. 'llogis' is now in terms of `locationlog` and `scalelog`. 'burrIII3' uses `lshape1`, `lshape2`, and `lscale`. 'burrIII2', 'lgumbel', and 'gompertz' have also been reparameterized for consistency. ```r # Using the reparameterized 'llogis' distribution dllogis(x, locationlog = 0, scalelog = 1) pllogis(q, locationlog = 0, scalelog = 1) # Similar usage applies to other reparameterized distributions ``` -------------------------------- ### Modifying ssd_hc() and ssd_hp() Arguments in SSDTools Source: https://github.com/bcgov/ssdtools/blob/main/NEWS.md The `ssd_hc()` and `ssd_hp()` functions include new arguments such as 'delta', 'min_pboot', 'parametric', and 'control' to customize the estimation process, including the selection of distributions and the bootstrapping procedure. ```R ssd_hc(fits, delta = 5) ssd_hp(fits, min_pboot = 0.95) ssd_hc(fits, control = list(maxit = 500)) ``` -------------------------------- ### Fit Distributions to Data using R Source: https://github.com/bcgov/ssdtools/blob/main/README.md Fits a set of default statistical distributions to the provided toxicity data using the ssd_fit_dists() function from the ssdtools package. This is a core step in building a Species Sensitivity Distribution (SSD). ```r fits <- ssd_fit_dists(ssddata::ccme_boron) ``` -------------------------------- ### Displaying Distribution Estimates in R Source: https://github.com/bcgov/ssdtools/blob/main/tests/testthat/_snaps/estimates.md This code snippet demonstrates how to display estimated parameters for various probability distributions. It shows the weight, scale, shape, location, and other relevant parameters for distributions like Gamma, Gumbel, Logis, Normal, and Weibull. This output is typically generated by functions within the SSDTools R package. ```R $gamma.weight [1] 0.3565737 $gamma.scale [1] 25.12683 $gamma.shape [1] 0.9501795 $lgumbel.weight [1] 0.01344657 $lgumbel.locationlog [1] 1.922631 $lgumbel.scalelog [1] 1.232239 $llogis.weight [1] 0.06564519 $llogis.locationlog [1] 2.626276 $llogis.scalelog [1] 0.7404264 $lnorm.weight [1] 0.1772362 $lnorm.meanlog [1] 2.561646 $lnorm.sdlog [1] 1.241541 $lnorm_lnorm.weight [1] 0.02962678 $lnorm_lnorm.meanlog1 [1] 0.9494834 $lnorm_lnorm.meanlog2 [1] 3.201021 $lnorm_lnorm.pmix [1] 0.2839679 $lnorm_lnorm.sdlog1 [1] 0.5544649 $lnorm_lnorm.sdlog2 [1] 0.7688617 $weibull.weight [1] 0.3574716 $weibull.scale [1] 23.51397 $weibull.shape [1] 0.9660997 ``` -------------------------------- ### Fit Distribution to Data (No specific distribution) Source: https://github.com/bcgov/ssdtools/blob/main/tests/testthat/_snaps/operators.md This code snippet shows fitting a distribution to data represented by 'x0' without specifying a particular distribution. The output indicates that parameters have been estimated from 28 rows of data, implying a default or automatically selected distribution. ```r library(ssdtools) x0 <- "some_data_here" fit_default <- ssd_fit(x0) print(fit_default) ``` -------------------------------- ### Hazard Protection Estimation with ssd_hp() Source: https://github.com/bcgov/ssdtools/blob/main/NEWS.md Hazard protection estimation is performed using the `ssd_hp()` function. Similar to `ssd_hc()`, it supports bootstrapping for confidence intervals and parallelization. ```R ssd_hp(fits) ssd_hp(fits, parametric = FALSE, nboot = 1000) ``` -------------------------------- ### Modify ssd_hc() and ssd_hp() Arguments for Model Averaging and CI Source: https://github.com/bcgov/ssdtools/blob/main/NEWS.md This snippet details the modifications to the `ssd_hc()` and `ssd_hp()` functions. The `multi_est` argument now defaults to `TRUE` for model-averaged estimates, treating distributions as a single mixture. The `method_ci` argument allows selection of different methods for confidence interval generation. The output data frame now includes a 'proportion' column instead of 'percentage'. ```r ssd_hc(data, multi_est = TRUE, method_ci = c("weighted_samples", "weighted_arithmetic", "multi_free", "multi_fixed")) ssd_hp(data, multi_est = TRUE, method_ci = c("weighted_samples", "weighted_arithmetic", "multi_free", "multi_fixed")) ``` -------------------------------- ### C++ Implementation for Distributions in ssdtools Source: https://github.com/bcgov/ssdtools/blob/main/NEWS.md Internal changes in ssdtools v0.3.0 include a switch to C++ for implementing distribution functions. This is expected to improve performance and potentially numerical stability. ```r # No direct user-facing R code, but affects internal function calls. # Example of using distribution functions: distribution_function(x, ...) ``` -------------------------------- ### Adding New Distributions to SSDTools Source: https://github.com/bcgov/ssdtools/blob/main/NEWS.md The ssdtools package now supports several new distributions, including 'burrIII3', 'invpareto', 'lnorm_lnorm', and 'llogis_llogis'. These distributions can be used for fitting and analysis within the package. ```R ssd_fit_dists(data, dist = "burrIII3") ssd_fit_dists(data, dist = "invpareto") ssd_fit_dists(data, dist = "lnorm_lnorm") ssd_fit_dists(data, dist = "llogis_llogis") ``` -------------------------------- ### Plot Species Sensitivity Distributions (R) Source: https://github.com/bcgov/ssdtools/blob/main/paper/paper.md Generates plots for all fitted species sensitivity distributions using the autoplot function. This provides a visual comparison of the default distributions against the data. ```r autoplot(fits) ``` -------------------------------- ### Displaying All Distribution Estimates (SSDTools R) Source: https://github.com/bcgov/ssdtools/blob/main/tests/testthat/_snaps/estimates.md This R code snippet shows how to display a comprehensive set of estimated parameters for multiple probability distributions, including BurrIII3 and Gompertz, when 'all_estimates' is set to TRUE. It lists weights, shapes, scales, and locations for distributions like Gamma, Gumbel, Logis, Normal, and Weibull, alongside the newly included distributions. ```R # estimates all_estimates = TRUE $burrIII3.weight [1] 0 $burrIII3.shape1 [1] 1 $burrIII3.shape2 [1] 1 $burrIII3.scale [1] 1 $gamma.weight [1] 0.3565737 $gamma.scale [1] 25.12683 $gamma.shape [1] 0.9501795 $gompertz.weight [1] 0 $gompertz.location [1] 1 $gompertz.shape [1] 1 $lgumbel.weight [1] 0.01344657 $lgumbel.locationlog [1] 1.922631 $lgumbel.scalelog [1] 1.232239 $llogis.weight [1] 0.06564519 $llogis.locationlog [1] 2.626276 $llogis.scalelog [1] 0.7404264 $llogis_llogis.weight [1] 0 $llogis_llogis.locationlog1 [1] 0 $llogis_llogis.scalelog1 [1] 1 $llogis_llogis.locationlog2 [1] 1 $llogis_llogis.scalelog2 [1] 1 $llogis_llogis.pmix [1] 0.5 $lnorm.weight [1] 0.1772362 $lnorm.meanlog [1] 2.561646 $lnorm.sdlog [1] 1.241541 $lnorm_lnorm.weight [1] 0.02962678 $lnorm_lnorm.meanlog1 [1] 0.9494834 $lnorm_lnorm.meanlog2 [1] 3.201021 $lnorm_lnorm.pmix [1] 0.2839679 $lnorm_lnorm.sdlog1 [1] 0.5544649 $lnorm_lnorm.sdlog2 [1] 0.7688617 $weibull.weight [1] 0.3574716 $weibull.scale [1] 23.51397 $weibull.shape [1] 0.9660997 ``` -------------------------------- ### SSD Probability Multi-distribution weights Source: https://github.com/bcgov/ssdtools/blob/main/tests/testthat/_snaps/multi.md This snippet displays weights associated with the 'ssd_pmulti' function. These weights are likely used in a weighted regression or model fitting process, indicating the relative importance of different data points or distributions. ```r 0.0389878051502311 0.0195430585953852 0.0195430585953852 0.0195430585953852 ``` -------------------------------- ### Deprecate ssd_wqg_bc() and ssd_wqg_burrlioz() Source: https://github.com/bcgov/ssdtools/blob/main/NEWS.md This snippet notes the deprecation of the `ssd_wqg_bc()` and `ssd_wqg_burrlioz()` functions. Users are advised to use alternative functions if available. ```r # Deprecated functions: # ssd_wqg_bc() # ssd_wqg_burrlioz() ``` -------------------------------- ### Add scale_fill_ssd() for Color-Blind Friendly Scales Source: https://github.com/bcgov/ssdtools/blob/main/NEWS.md This snippet introduces `scale_fill_ssd()`, a new function for creating color-blind friendly fill scales in plots. ```r library(ggplot2) ggplot(data, aes(x = ssd_data$conc, fill = ssd_data$group)) + geom_ssd() + scale_fill_ssd() ``` -------------------------------- ### Multi-distribution fitting with ssdtools Source: https://github.com/bcgov/ssdtools/blob/main/tests/testthat/_snaps/multi.md This snippet demonstrates the use of the 'multi' function in ssdtools, which is likely used for fitting multiple probability distributions to data. The output shows numerical values representing some measure of fit or parameter estimates. ```r 0.5 1.96303108415826 c(1.73268096178239, 0.854785267720722) 1.46462124292546 1.46462124292546 c(0, 0.1, 0.5, 0.9, 0.99) c(0, 0.1, 0.5, 0.9, 0.99) ``` -------------------------------- ### Data Handling Functions in ssdtools Source: https://github.com/bcgov/ssdtools/blob/main/NEWS.md Introduces new functions for data management within the ssdtools package. `ssd_data()` retrieves original data from a `fitdists` object, `ssd_ecd_data()` calculates empirical cumulative density, and `ssd_sort_data()` sorts data based on this density. ```r ssd_data(fitdists_object) ssd_ecd_data(data) ssd_sort_data(data) ``` -------------------------------- ### Assess Goodness of Fit in R Source: https://github.com/bcgov/ssdtools/blob/main/README.md Calculates and displays goodness-of-fit statistics for the fitted distributions using the ssd_gof() function. This includes metrics like AIC, BIC, and weights, allowing for model comparison. ```r ssd_gof(fits, wt = TRUE) #> # A tibble: 6 × 14 #> dist npars nobs log_lik aic aicc delta wt bic ad ks cvm #> #> 1 gamma 2 28 -117. 238. 238. 0.005 0.357 240. 0.440 0.117 0.0554 #> 2 lgumbel 2 28 -120. 244. 245. 6.56 0.013 247. 0.829 0.158 0.134 #> 3 llogis 2 28 -119. 241. 241. 3.39 0.066 244. 0.487 0.0994 0.0595 #> 4 lnorm 2 28 -118. 239. 240. 1.40 0.177 242. 0.507 0.107 0.0703 #> 5 lnorm_l… 5 28 -115. 240. 243. 4.98 0.03 247. 0.320 0.116 0.0414 #> 6 weibull 2 28 -117. 238. 238. 0 0.357 240. 0.434 0.117 0.0542 #> # ℹ 2 more variables: at_bound , computable ``` -------------------------------- ### Data Set Relocation in ssdtools Source: https://github.com/bcgov/ssdtools/blob/main/NEWS.md The `boron_data` dataset has been renamed to `ccme_boron` and moved to the `ssddata` R package. This package consolidates datasets for testing species sensitivity distribution fitting software. ```r # Load the ssddata package and access datasets library(ssddata) head(ccme_boron) ``` -------------------------------- ### Predict Hazard Concentrations with Confidence Intervals in R Source: https://github.com/bcgov/ssdtools/blob/main/README.md Generates model-averaged predictions with confidence intervals for the fitted distributions using the generic predict function. This allows for estimation of concentrations associated with specific hazard levels. ```r boron_pred <- predict(fits, ci = TRUE) ``` -------------------------------- ### Soft-Deprecated Percent Argument in ssd_hc() and predict() Source: https://github.com/bcgov/ssdtools/blob/main/NEWS.md This snippet indicates that the `percent` argument in `ssd_hc()` and `predict()` has been soft-deprecated in favor of `proportion`. The old argument `percent = 5` is now equivalent to `proportion = 0.05`. ```r # Old usage (deprecated): # ssd_hc(data, percent = 5) # predict(model, percent = 5) # New usage: ssd_hc(data, proportion = 0.05) predict(model, proportion = 0.05) ``` -------------------------------- ### Fit Logistic Distribution using Moment Matching Source: https://github.com/bcgov/ssdtools/blob/main/tests/testthat/_snaps/match-moments.md Estimates the location (log) and scale (log) parameters for the Logistic distribution using moment matching. The Logistic distribution is similar to the normal distribution but has heavier tails. ```R $llogis locationlog scalelog 0.96875 0.52500 ``` -------------------------------- ### Specifying Subsets of Distributions with ssd_dists() Source: https://github.com/bcgov/ssdtools/blob/main/NEWS.md The `ssd_dists()` function allows users to specify subsets of available distributions for analysis. Combined with the `delta` argument in `subset()`, this enables filtering of distributions based on their AIC(c) difference from the best supported distribution. ```R ssd_dists(c("norm", "lnorm", "llogis")) subset(fits, delta = 2) ``` -------------------------------- ### Modifying ssd_fit_dists() Arguments in SSDTools Source: https://github.com/bcgov/ssdtools/blob/main/NEWS.md The `ssd_fit_dists()` function in ssdtools has several new arguments to control the fitting process, including 'rescale', 'reweight', 'at_boundary_ok', 'min_pmix', 'range_shape1', 'range_shape2', and 'control'. These arguments provide finer control over parameter estimation and convergence. ```R ssd_fit_dists(data, rescale = TRUE) ssd_fit_dists(data, reweight = TRUE) ssd_fit_dists(data, at_boundary_ok = TRUE) ssd_fit_dists(data, min_pmix = 0.1) ssd_fit_dists(data, range_shape1 = c(0.1, 10)) ssd_fit_dists(data, range_shape2 = c(0.1, 10)) ssd_fit_dists(data, control = list(maxit = 1000)) ``` -------------------------------- ### Fit Mixture of Two Lognormal Distributions using Moment Matching Source: https://github.com/bcgov/ssdtools/blob/main/tests/testthat/_snaps/match-moments.md Estimates the mean (log), standard deviation (log), and mixing proportion (pmix) parameters for a mixture of two Lognormal distributions. This allows for modeling complex, positively skewed data with multiple underlying components. ```R $lnorm_lnorm meanlog1 sdlog1 meanlog2 sdlog2 pmix 0.2077798 1.0783014 1.1693798 1.0027238 0.1202752 ``` -------------------------------- ### Distribution Deprecations in ssdtools Source: https://github.com/bcgov/ssdtools/blob/main/NEWS.md The 'burrIII3' distribution is soft-deprecated due to being poorly defined, and the 'pareto' distribution is soft-deprecated because it often results in a poor fit on SSD data. ```r # When fitting distributions, avoid 'burrIII3' and 'pareto'. # ssd_fit_dists(..., dists = c('llogis', 'lgumbel', ...)) ``` -------------------------------- ### Fit Gamma Distribution using Moment Matching Source: https://github.com/bcgov/ssdtools/blob/main/tests/testthat/_snaps/match-moments.md Estimates the shape and scale parameters for the Gamma distribution by matching the first two moments of the empirical data. The Gamma distribution is commonly used for modeling waiting times or continuous positive data. ```R $gamma shape scale 1.639795 2.389697 ``` -------------------------------- ### Plot Data and Model Predictions in R using ggplot2 Source: https://github.com/bcgov/ssdtools/blob/main/README.md Plots the original toxicity data along with the model-averaged predictions and confidence intervals using the ssd_plot function, which leverages ggplot2. Customizations include mapping shapes and colors to data groups and adding labels. ```r library(ggplot2) theme_set(theme_bw()) ssd_plot(ssddata::ccme_boron, boron_pred, shape = "Group", color = "Group", label = "Species", xlab = "Concentration (mg/L)", ribbon = TRUE ) + expand_limits(x = 3000) + scale_colour_ssd() ``` -------------------------------- ### Fit Weibull Distribution using Moment Matching Source: https://github.com/bcgov/ssdtools/blob/main/tests/testthat/_snaps/match-moments.md Estimates the shape and scale parameters for the Weibull distribution through moment matching. The Weibull distribution is widely used in reliability engineering to model the time until failure of components. ```R $weibull shape scale 1.263672 4.325391 ``` -------------------------------- ### Fit Mixture of Two Logistic Distributions using Moment Matching Source: https://github.com/bcgov/ssdtools/blob/main/tests/testthat/_snaps/match-moments.md Estimates the location (log), scale (log), and mixing proportion (pmix) parameters for a mixture of two Logistic distributions. This is useful for modeling data that may arise from two distinct populations. ```R $llogis_llogis locationlog1 scalelog1 locationlog2 scalelog2 pmix 0.5487772 0.5011361 1.2939879 0.5558022 0.4524088 ``` -------------------------------- ### Hazard Concentration Estimation with ssd_hc() Source: https://github.com/bcgov/ssdtools/blob/main/NEWS.md Hazard concentration estimation is performed using the `ssd_hc()` function, which is wrapped by `predict()`. This function estimates hazard concentrations and can optionally calculate confidence intervals using parametric or non-parametric bootstrapping, with parallelization support via the 'future' package. ```R ssd_hc(fits) predict(fits) ssd_hc(fits, parametric = FALSE, nboot = 1000) ``` -------------------------------- ### Inv-Pareto Parameters from MLEs Source: https://github.com/bcgov/ssdtools/blob/main/tests/testthat/_snaps/invpareto.md Represents the Inverse Pareto distribution parameters derived from Maximum Likelihood Estimation (MLEs). This output is typically used as input for other functions requiring pre-estimated distribution parameters, such as weight, scale, and shape. ```r list(invpareto.weight = 1, invpareto.scale = 0.961975263550564, invpareto.shape = 2.94009311871754) ``` -------------------------------- ### Fit Gumbel Distribution using Moment Matching Source: https://github.com/bcgov/ssdtools/blob/main/tests/testthat/_snaps/match-moments.md Estimates the location (log) and scale (log) parameters for the Gumbel distribution (extreme value type I) via moment matching. This distribution is suitable for modeling the maximum or minimum values of a random variable. ```R $lgumbel locationlog scalelog 0.534375 0.762500 ``` -------------------------------- ### Estimate 5% Hazard Concentration (HC5) in R Source: https://github.com/bcgov/ssdtools/blob/main/README.md Estimates the 5% hazard concentration (HC5) using model-averaged predictions, with confidence intervals calculated via bootstrapping. The function ssd_hc() is used for this purpose, employing a specified seed for reproducibility. ```r withr::with_seed(99, { hc5 <- ssd_hc(fits, ci = TRUE) }) print(hc5) #> # A tibble: 1 × 15 #> dist proportion est se lcl ucl wt level est_method ci_method #> #> 1 average 0.05 1.26 0.782 0.407 3.29 1 0.95 multi weighted_sa… #> # ℹ 5 more variables: boot_method , nboot , pboot , #> # dists , samples ``` -------------------------------- ### Modify ssd_dists_bcanz() and ssd_fit_bcanz() Arguments Source: https://github.com/bcgov/ssdtools/blob/main/NEWS.md This snippet details modifications to `ssd_dists_bcanz()` and `ssd_fit_bcanz()`. `npars` argument is added to `ssd_dists_bcanz()` to specify the number of parameters. `dists` argument is added to `ssd_fit_bcanz()` to allow external modification of distributions. ```r ssd_dists_bcanz(npars = c(2L, 5L)) ssd_fit_bcanz(data, dists = ssd_dists_bcanz()) ``` -------------------------------- ### Modify Rescaling in ssd_fit_bcanz() Source: https://github.com/bcgov/ssdtools/blob/main/NEWS.md This snippet shows the change in the `rescale` argument for `ssd_fit_bcanz()`. When `rescale = TRUE`, data is now divided by the geometric mean of the minimum and maximum positive finite values to improve convergence. Note that `ssd_fit_bcanz()` no longer rescales by default. ```r ssd_fit_bcanz(data, rescale = TRUE) ``` -------------------------------- ### Distribution Reparameterization in ssdtools Source: https://github.com/bcgov/ssdtools/blob/main/NEWS.md Major changes in ssdtools v0.3.0 involve reparameterizing several distributions for improved definition and handling. 'llogis', 'burrIII3', 'burrIII2', 'lgumbel', and 'gompertz' distributions have been modified, and standardized argument handling is now in place for distribution functions. ```r # Example for llogis distribution reparameterization dllogis(x, locationlog, scalelog) pllogis(x, locationlog, scalelog) // ... and other distribution functions ``` -------------------------------- ### Inv-Pareto Unbiased Scale Estimator (Small n) Source: https://github.com/bcgov/ssdtools/blob/main/tests/testthat/_snaps/invpareto.md Provides the unbiased estimator for the scale parameter of the Inverse Pareto distribution when dealing with small sample sizes. This estimator is important for accurate parameter estimation in limited data scenarios. ```r 0.994110689165773 ``` -------------------------------- ### Inv-Pareto Biased Shape Estimator (Small n) Source: https://github.com/bcgov/ssdtools/blob/main/tests/testthat/_snaps/invpareto.md Presents the biased estimator for the shape parameter of the Inverse Pareto distribution for small sample sizes. While biased, this estimator can sometimes offer a simpler computation or be used in specific contexts where bias is understood and acceptable. ```r 3.69530846370174 ``` -------------------------------- ### Distribution Functions Renamed in SSDTools Source: https://github.com/bcgov/ssdtools/blob/main/NEWS.md Distribution, quantile, and random generation functions in the ssdtools package have been renamed with an 'ssd_' prefix to prevent naming conflicts with other R packages. This change ensures better namespace management and clarity when using these functions. ```R ssd_plnorm() ssd_qlnorm() ssd_rlnorm() ``` -------------------------------- ### Fit Lognormal Distribution using Moment Matching Source: https://github.com/bcgov/ssdtools/blob/main/tests/testthat/_snaps/match-moments.md Estimates the mean (log) and standard deviation (log) parameters for the Lognormal distribution via moment matching. This distribution is often used for positively skewed data, such as income or biological measurements. ```R $lnorm meanlog sdlog 0.9812500 0.9515625 ``` -------------------------------- ### Control X-axis Scale with trans and add_x in ssd_plot() Source: https://github.com/bcgov/ssdtools/blob/main/NEWS.md This snippet details the addition of `trans` and `add_x` arguments to `ssd_plot()` and `ssd_plot_data()`. `trans` controls the x-axis transformation (e.g., 'log10'), and `add_x` adds a constant to the x-axis values. ```r ssd_plot(data, trans = "log10", add_x = 0) ssd_plot_data(data, trans = "log10", add_x = 0) ``` -------------------------------- ### Calculate Hazard Concentration with Confidence Intervals (R) Source: https://github.com/bcgov/ssdtools/blob/main/paper/paper.md Calculates the average Hazard Concentration (HC) estimate with 95% confidence intervals using the ssd_hc function. This function is used after fitting multiple distribution models to species sensitivity data. ```r ssd_hc(fits, ci = TRUE) ```