Estimates the distribution of physiological results from a mixed distribution of physiological and abnormal results, such as those found in laboratory databases.

kosmic(data, ...)

# S3 method for default
kosmic(data, ...)

# S3 method for numeric
kosmic(
  data,
  decimals,
  t1min = 0.05,
  t1max = 0.3,
  t2min = 0.7,
  t2max = 0.95,
  sd_guess = 0.8,
  abstol = 1e-07,
  na.rm = FALSE,
  ...
)

Arguments

data

A numeric vector. A mixed distribution of physiological and abnormal results.

decimals

An integer. The number of digits of precision to calculate the results to. Increasing this makes the algorithm take longer.

t1min

A quantile. Start of the search range for T1.

t1max

A quantile. End of the search range for T1.

t2min

A quantile. Start of the search range for T2.

t2max

A quantile. End of the search range for T1.

sd_guess

A quantile. The quantile used for the initial guess of the standard deviation.

na.rm

Logical. If true, any NA and NaNs are removed from data before calling kosmic.

tol

The absolute convergence tolerance for the optimizer. The algorithm stops if it is unable to reduce the cost by more than this amount.

Value

kosmic returns an object of class "kosmic". This contains the following components:

n The number of data points used to estimate the distribution.

data A frequency table of the original data, with columns result and n.

estimates A named vector of estimates for the ditribution: lambda, mean, sd, t1 and t2

settings A named vector of the settings passed to kosmic.

Examples

set.seed(1) k <- kosmic(haemoglobin$result, 1) quantile(k)
#> 2.5% 50.0% 97.5% #> 12.14464 13.94471 15.95217