fitErrorModel: Fit an error model using maximum likelihood estimation

View source: R/statistics.R

fitErrorModelR Documentation

Fit an error model using maximum likelihood estimation

Description

Fit an error model to reduced replicate data using maximum likelihood estimation (MLE). The model estimates the variance of replicate measurements as a function of the mean, based on a chi-square distribution.

Usage

fitErrorModel(
  data,
  factors,
  errorModel = "exp(s0)+exp(srel)*x^2",
  par = c(s0 = 1, srel = 0.1),
  lower = NULL,
  upper = NULL,
  plotting = TRUE,
  blather = FALSE,
  ...
)

Arguments

data

A data frame containing reduced replicate data. Must include columns "value" (mean of replicates), "sigma" (sample standard deviation), and "n" (number of replicates per condition).

factors

Character vector specifying the columns in data that define pooling conditions. The model is fit separately for each unique combination of these factors.

errorModel

A character string defining the error model in terms of variance. The mean is referenced as x, e.g., "exp(s0) + exp(srel) * x^2".

par

Named numeric vector of initial values for the parameters in errorModel.

lower

Optional named numeric vector specifying lower bounds for parameters. Defaults to NULL (no bounds).

upper

Optional named numeric vector specifying upper bounds for parameters. Defaults to NULL (no bounds).

plotting

Logical. If TRUE, a plot of the pooled variance and the fitted error model is displayed.

blather

Logical. If TRUE, additional information is returned, including fitted parameter values, original sigma values, and confidence intervals.

...

Additional arguments passed to the optimizer optimr.

Details

The model assumes that the sample variance of replicate measurements follows a chi-square distribution with n-1 degrees of freedom. The variance is estimated by maximizing the log-likelihood function derived from this distribution. Given multiple replicates, the variance can be modeled as a function of the mean.

The errorModel parameter defines this functional relationship. It should be expressed as a character string, using x to represent the mean.

The optimization is performed using optimr with the "L-BFGS-B" method, which supports bound constraints. If lower and upper are not specified, the parameters are assumed to be unconstrained.

If plotting = TRUE, the function produces a log-scale variance plot for each condition, showing the pooled variance, the fitted model, and 68% and 95% confidence bounds.

Value

By default, a data frame is returned, containing the original data with updated sigma values estimated from the error model.

If blather = TRUE, additional information is returned, including: - The fitted parameter values. - The error model used. - Confidence intervals for sigma at 68% and 95% levels. - Effective pooling conditions.

Author(s)

Wolfgang Mader, Wolfgang.Mader@fdm.uni-freiburg.de

Simon Beyer, simon.beyer@fdm.uni-freiburg.de


dkaschek/dMod documentation built on March 1, 2025, 9:04 p.m.