| fitverse_grouped | R Documentation |
fitverse_grouped() fits one or more parametric distributions to
data that are available only in grouped (frequency-table) or
interval-censored form. It accepts either class midpoints with counts, or
explicit lower and upper interval boundaries with counts.
read_grouped_csv() reads a two- or three-column CSV file into the
format expected by fitverse_grouped().
fitverse_grouped(midpoints = NULL,
counts,
lower = NULL,
upper = NULL,
dists = "auto",
method = "All",
xlab = "x",
top_n = 5L,
verbose = FALSE)
read_grouped_csv(file, sep = ",")
midpoints |
Numeric vector of class midpoints (one per class).
Supply either |
counts |
Integer vector of observed frequencies for each class.
Must be the same length as |
lower |
Numeric vector of lower interval boundaries. Required when
|
upper |
Numeric vector of upper interval boundaries. Required when
|
dists |
Character vector of distribution names to fit, or
|
method |
Fitting method: |
xlab |
Character label for the data axis used in output summaries.
Default |
top_n |
Integer: number of top-ranked distributions to include in
the printed summary. Default |
verbose |
Logical: print per-distribution fitting progress?
Default |
file |
Path to a CSV file. The file may contain comment lines
beginning with |
sep |
Column separator for |
fitverse_grouped() accepts two input formats.
Midpoint format: Supply midpoints and counts.
Interval boundaries are reconstructed by assuming equal-width classes.
Boundary format: Supply lower, upper, and
counts. Classes need not be equal-width. Open-ended classes
(e.g., an upper bound of Inf) are handled by replacing the
infinite bound with a large finite value for midpoint computation.
For each candidate distribution, parameters are estimated by maximising the interval-censored log-likelihood
\ell(\theta) = \sum_{j} n_j \log\bigl[F(u_j;\theta) - F(l_j;\theta)\bigr]
where n_j is the count in class j, and l_j, u_j
are its lower and upper boundaries.
read_grouped_csv()The CSV file should have either two columns (midpoint, count) or three
columns (lower, upper, count). Column names are detected automatically
from a set of common variants (mid, midpoint, lower,
upper, etc.). Lines starting with # are treated as comments
and ignored.
fitverse_grouped() returns an object of class
"fitverse_grouped" containing:
resultsA data frame of fitted distributions ranked by AIC, with columns for distribution name, AIC, BIC, log-likelihood, estimated parameters, and goodness-of-fit statistics.
bestThe name of the best-fitting distribution.
dataA list with elements midpoints,
counts, lower, and upper.
callThe matched call.
read_grouped_csv() returns a named list with elements
midpoints and counts (midpoint format) or lower,
upper, and counts (boundary format), ready to be passed
directly to fitverse_grouped().
Karuna G. Reddy karuna.reddy@auckland.ac.nz
M. G. M. Khan mgm.khan@usp.ac.fj
fitverse for fitting to individual (ungrouped) data.
fitverse_distributions for the full distribution catalogue.
## Midpoint format
mid <- c(5, 15, 25, 35, 45, 55, 65, 75)
count <- c(3, 12, 25, 30, 18, 8, 3, 1)
fit <- fitverse_grouped(midpoints = mid, counts = count,
method = "MLE", verbose = FALSE)
print(fit)
## Boundary format
low <- c(0, 10, 20, 30, 40, 50, 60, 70)
high <- c(10, 20, 30, 40, 50, 60, 70, 80)
fit2 <- fitverse_grouped(lower = low, upper = high, counts = count,
method = "MLE", verbose = FALSE)
print(fit2)
## Reading from CSV
## A file with columns: lower, upper, count
tmp <- tempfile(fileext = ".csv")
writeLines(c(
"# Example grouped data",
"lower,upper,count",
"0,10,5",
"10,20,18",
"20,30,30",
"30,40,25",
"40,50,12",
"50,60,4"
), tmp)
dat <- read_grouped_csv(tmp)
fit3 <- fitverse_grouped(lower = dat$lower, upper = dat$upper,
counts = dat$counts)
print(fit3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.