Skip to contents

Get density from a fit object

Usage

get_density(x, fit)

Arguments

x

A numeric vector of values at which to evaluate the density

fit

A fit data frame (one or more rows)

Value

If fit has a single row, a numeric vector of densities. If fit has multiple rows, a matrix with one column per species.

Examples

# Fit a normal distribution and evaluate its density
fit <- fit_log_ppmr(barnes_data, "Albacore", distribution = "normal")
x <- seq(0, 15, length.out = 100)
density <- get_density(x, fit)
plot(x, density, type = "l", main = "Albacore normal fit")


# Density for multiple species returns a matrix
fit2 <- fit_log_ppmr(barnes_data,
                     c("Albacore", "Atlantic cod"),
                     distribution = "normal")
densities <- get_density(x, fit2)
head(densities)
#>          Albacore Atlantic cod
#> [1,] 3.117323e-16   0.01358941
#> [2,] 9.282546e-16   0.01542328
#> [3,] 2.716256e-15   0.01744532
#> [4,] 7.810747e-15   0.01966557
#> [5,] 2.207154e-14   0.02209326
#> [6,] 6.129021e-14   0.02473653