| Title: | Likelihood-Based Statistical Inference in the Fisherian Tradition |
|---|---|
| Description: | Facilitates building likelihood models in the Fisherian tradition following Richard Royall (1997, ISBN:978-0412044113) "Statistical Evidence: A Likelihood Paradigm". Defines generic methods for working with likelihoods (loglik(), score(), hess_loglik(), fim()) and provides functions for pure likelihood-based inference (support(), relative_likelihood(), likelihood_interval(), profile_loglik()). |
| Authors: | Alexander Towell [aut, cre] (ORCID: <https://orcid.org/0000-0001-6443-9897>) |
| Maintainer: | Alexander Towell <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.0.1 |
| Built: | 2026-05-24 09:23:04 UTC |
| Source: | https://github.com/queelius/likelihood.model |
The likelihood.model package provides a framework for likelihood-based
inference. The package is organized in layers:
Core Concept (core-generics.R):
The likelihood_model "concept" – an abstract interface that any model
can implement. At minimum, implement loglik(). Optionally provide
score() and hess_loglik() for analytical derivatives; defaults use
numerical differentiation via numDeriv.
Core Infrastructure:
fisher_mle / fisher_boot: Result objects from MLE fitting, with
methods for coef(), vcov(), confint(), algebraic.mle::se(), stats::AIC(), stats::BIC(),
summary().
fit(): Default MLE solver using optim(). Models can override this
with closed-form solutions (see exponential_lifetime for an example).
Fisherian inference: support(), relative_likelihood(),
likelihood_interval(), profile_loglik(), evidence() – pure
likelihood-based inference without probability statements.
lrt(): Likelihood ratio test for nested models.
Example Implementation:
exponential_lifetime: Exponential with right-censoring support.
Demonstrates closed-form MLE (no optim needed), analytical FIM,
and rdata() for Monte Carlo validation.
For contribution-based models with heterogeneous observation types, see the companion package likelihood.contr.
Maintainer: Alexander Towell [email protected] (ORCID)
Useful links:
Report bugs at https://github.com/queelius/likelihood.model/issues
Retrieve the assumptions the likelihood model makes about the data.
assumptions(model, ...)assumptions(model, ...)
model |
The likelihood model |
... |
Additional arguments |
A list of assumptions
Assumptions for exponential_lifetime
## S3 method for class 'exponential_lifetime' assumptions(model, ...)## S3 method for class 'exponential_lifetime' assumptions(model, ...)
model |
An exponential_lifetime model |
... |
Additional arguments (ignored) |
Character vector of assumptions
Estimates bias from bootstrap replicates: bias = mean(bootstrap estimates) - original estimate
## S3 method for class 'fisher_boot' bias(x, theta = NULL, ...)## S3 method for class 'fisher_boot' bias(x, theta = NULL, ...)
x |
A fisher_boot object |
theta |
Ignored (for compatibility) |
... |
Additional arguments (ignored) |
Bias estimate vector
Estimates the bias of the MLE. Without a model and true parameter value,
returns zeros (asymptotic bias is zero under regularity conditions).
When both theta and model are provided, performs a Monte Carlo
simulation study to estimate finite-sample bias.
## S3 method for class 'fisher_mle' bias(x, theta = NULL, model = NULL, n_sim = 1000, ...)## S3 method for class 'fisher_mle' bias(x, theta = NULL, model = NULL, n_sim = 1000, ...)
x |
A fisher_mle object |
theta |
True parameter value (for simulation studies) |
model |
A likelihood model with |
n_sim |
Number of Monte Carlo replicates (default 1000) |
... |
Additional arguments (ignored) |
Bias estimate vector
Extract coefficients from fisher_mle object
## S3 method for class 'fisher_mle' coef(object, ...)## S3 method for class 'fisher_mle' coef(object, ...)
object |
A fisher_mle object |
... |
Additional arguments (ignored) |
Named numeric vector of parameter estimates
Computes bootstrap confidence intervals using various methods.
## S3 method for class 'fisher_boot' confint( object, parm = NULL, level = 0.95, type = c("perc", "bca", "norm", "basic"), ... )## S3 method for class 'fisher_boot' confint( object, parm = NULL, level = 0.95, type = c("perc", "bca", "norm", "basic"), ... )
object |
A fisher_boot object |
parm |
Parameter names or indices (NULL for all) |
level |
Confidence level (default 0.95) |
type |
Type of bootstrap CI: "perc", "bca", "norm", or "basic" |
... |
Additional arguments passed to boot::boot.ci |
Matrix with columns for lower and upper bounds
Computes asymptotic Wald confidence intervals based on the estimated variance-covariance matrix.
## S3 method for class 'fisher_mle' confint(object, parm = NULL, level = 0.95, ...)## S3 method for class 'fisher_mle' confint(object, parm = NULL, level = 0.95, ...)
object |
A fisher_mle object |
parm |
Parameter names or indices (NULL for all) |
level |
Confidence level (default 0.95) |
... |
Additional arguments (ignored) |
Matrix with columns for lower and upper bounds
Computes the deviance, which is useful for model comparison.
## S3 method for class 'fisher_mle' deviance(object, null_model = NULL, ...)## S3 method for class 'fisher_mle' deviance(object, null_model = NULL, ...)
object |
A fisher_mle object |
null_model |
Optional reduced/null model for comparison |
... |
Additional arguments (ignored) |
When called with a single model, returns -2 * logL (the deviance relative to a saturated model).
When called with two models, returns the deviance difference: D = 2 * (logL_full - logL_reduced)
Under the null hypothesis that the reduced model is correct, D is asymptotically chi-squared with df = p_full - p_reduced.
Deviance value
Computes the strength of evidence for theta1 vs theta2: E(theta1, theta2) = logL(theta1) - logL(theta2)
evidence(model, ...) ## S3 method for class 'likelihood_model' evidence(model, data, theta1, theta2, ...)evidence(model, ...) ## S3 method for class 'likelihood_model' evidence(model, data, theta1, theta2, ...)
model |
The likelihood model |
... |
Additional arguments |
data |
Data frame for likelihood computation |
theta1 |
First parameter value |
theta2 |
Second parameter value |
Positive values favor theta1, negative values favor theta2.
Conventional interpretation (following Royall):
|E| > log(8) ~ 2.08: Strong evidence
|E| > log(32) ~ 3.47: Very strong evidence
Evidence value (log likelihood ratio)
A likelihood model for the Exponential(lambda) distribution with optional right-censoring. This is a reference implementation demonstrating:
Closed-form MLE: Overrides fit() to compute lambda_hat = d/T
directly, bypassing optim entirely.
Analytical derivatives: score, Hessian, and FIM in closed form.
Right-censoring: Natural handling via the sufficient statistic (d, T) where d = number of exact observations and T = total time.
rdata() method: For Monte Carlo validation and FIM estimation.
The log-likelihood is:
where d is the number of exact (uncensored) observations and T is the total observation time (sum of all times, whether censored or not).
exponential_lifetime(ob_col, censor_col = NULL)exponential_lifetime(ob_col, censor_col = NULL)
ob_col |
The name of the column containing observation times. |
censor_col |
Optional column name indicating censoring status.
When provided, values should be |
An exponential_lifetime likelihood model object
# Uncensored exponential data model <- exponential_lifetime("t") df <- data.frame(t = rexp(100, rate = 2)) mle <- fit(model)(df) coef(mle) # should be close to 2 # Right-censored data model_c <- exponential_lifetime("t", censor_col = "status") df_c <- data.frame( t = c(rexp(80, 2), rep(0.5, 20)), status = c(rep("exact", 80), rep("right", 20)) ) mle_c <- fit(model_c)(df_c) coef(mle_c)# Uncensored exponential data model <- exponential_lifetime("t") df <- data.frame(t = rexp(100, rate = 2)) mle <- fit(model)(df) coef(mle) # should be close to 2 # Right-censored data model_c <- exponential_lifetime("t", censor_col = "status") df_c <- data.frame( t = c(rexp(80, 2), rep(0.5, 20)), status = c(rep("exact", 80), rep("right", 20)) ) mle_c <- fit(model_c)(df_c) coef(mle_c)
This function calculates the Fisher information matrix (FIM), an expectation over the data-generating process (DGP). The FIM is a crucial concept in statistics because it provides information about the precision of estimates and the amount of information that data carries about an unknown parameter.
fim(model, ...)fim(model, ...)
model |
A likelihood model |
... |
Additional arguments |
FIM is a function of the parameters, and is used to compute the standard errors of the parameters. It is also used to compute the covariance matrix of the parameters, which is in turn used to compute standard errors of the parameters.
Additionally, FIM is used to compute the Cramer-Rao lower bound (CRLB), the inverse of the FIM. CRLB represents the lower limit of the variance that an unbiased estimator can attain. This is used to compute the asymptotic relative efficiency (ARE) of an estimator of the parameters, which is the ratio of the variance of the estimator to the CRLB.
The function computes FIM(x)(theta), the FIM of the likelihood model x, is
based on the following formulas:
FIM(x)(theta) = E[-loglik_hessian(x)(ob,theta)] FIM(x)(theta) = E[score(x)(ob,theta) %*% t(score(x)(ob,theta))]
where the expectation is taken with respect to ob ~ DGP. The first formula is the expected hessian of the log-likelihood function, and the second formula is the expected outer product of the score function. The two formulas are equivalent.
Function that computes the FIM given a parameter vector and sample size
Returns the analytical FIM: n / lambda^2 (1x1 matrix).
## S3 method for class 'exponential_lifetime' fim(model, ...)## S3 method for class 'exponential_lifetime' fim(model, ...)
model |
An exponential_lifetime model |
... |
Additional arguments (ignored) |
A function(theta, n_obs, ...) computing the FIM
Computes the Fisher information matrix by Monte Carlo simulation using
the negative expected Hessian approach. For each of n_samples replicates,
generates a single-observation dataset via rdata, computes
-hess_loglik(single_obs, theta), and averages. The result is
n_obs * I_1(theta) where I_1(theta) is the per-observation FIM.
## S3 method for class 'likelihood_model' fim(model, ...)## S3 method for class 'likelihood_model' fim(model, ...)
model |
A likelihood model |
... |
Additional arguments (currently unused; reserved for future extension at closure-construction time) |
This default requires the model to implement rdata and hess_loglik
(or loglik, since hess_loglik falls back to numerical differentiation).
Extra arguments via ... to the returned FIM function are forwarded
to rdata only (i.e., they parameterize the data-generating process:
censoring time, masking probability, observation functor, etc.) and
are NOT passed to the likelihood evaluator hess_loglik. This honors
the separation between the DGP layer and the likelihood layer: the
likelihood is computed on data, not on the DGP knobs that produced it.
Forwarding DGP kwargs into the likelihood layer was both an axiom
violation (under masking condition C3 the likelihood does not depend
on the masking probability) and a partial-matching footgun (a kwarg
named p would collide with the formal par).
Function that takes (theta, n_obs, n_samples, ...) and returns
FIM matrix. The inner ... is forwarded to rdata only.
Creates a fisher_boot object representing bootstrap-based inference
for maximum likelihood estimates.
fisher_boot(boot_result, original_mle)fisher_boot(boot_result, original_mle)
boot_result |
Result from boot::boot() |
original_mle |
The original fisher_mle object |
An object of class c("fisher_boot", "fisher_mle", "mle_fit", "boot")
Creates a fisher_mle object representing a maximum likelihood estimate
with methods for standard inference. This class emphasizes the Fisherian
approach to likelihood-based inference.
fisher_mle( par, vcov = NULL, loglik_val, hessian = NULL, score_val = NULL, nobs = NULL, converged = TRUE, optim_result = NULL )fisher_mle( par, vcov = NULL, loglik_val, hessian = NULL, score_val = NULL, nobs = NULL, converged = TRUE, optim_result = NULL )
par |
Numeric vector of parameter estimates (may be named) |
vcov |
Variance-covariance matrix of the estimates |
loglik_val |
Log-likelihood value at the MLE |
hessian |
Hessian matrix of the log-likelihood at the MLE |
score_val |
Optional score vector at the MLE (should be near zero) |
nobs |
Number of observations used in estimation |
converged |
Logical indicating if optimization converged |
optim_result |
Raw result from optim() for diagnostics |
An object of class c("fisher_mle", "mle_fit")
Functions for pure likelihood-based inference in the Fisherian tradition. These emphasize the likelihood function itself as the primary object of inference, without requiring probability statements about parameters.
Computes the MLE directly as lambda_hat = d / T, bypassing optim.
This demonstrates that specialized models can provide exact solutions.
## S3 method for class 'exponential_lifetime' fit(object, ...)## S3 method for class 'exponential_lifetime' fit(object, ...)
object |
An exponential_lifetime model |
... |
Additional arguments (ignored) |
A solver function that takes (df, par, ...) and returns a
fisher_mle object. The par argument is accepted but ignored
since the MLE is computed in closed form.
likelihood_model.Note that likelihood_model is not a class, but a concept,
that other likelihood models implement. They should add
likelihood_model to their class definition, and then
they can use this function to compute the MLE.
## S3 method for class 'likelihood_model' fit(object, ...)## S3 method for class 'likelihood_model' fit(object, ...)
object |
The |
... |
Additional arguments to pass into the likelihood model's
|
This function uses the optim function to find the MLE of the
parameters of a likelihood model. It uses the loglik and score
methods to compute the log-likelihood and score function, respectively.
There are a few interesting options for the control argument:
method: The optimization method to use. The default is Nelder-Mead,
which is a derivative-free method. Other options like include BFGS
are gradient-based methods, which may be preferable if you provide
a score function (rather than using the default finite-difference). There
is also the SANN method, which is a simulated annealing method. This
method is useful for multimodal likelihood functions, where the MLE
may be sensitive to the initial guess. The SANN method is a more global
method, but it is slower and may require some tweaking. Regardless,
if you do use SANN, you should follow it up with a local search
method like Nelder-Mead to refine the solution.
An MLE solver (function) that returns an MLE object and accepts as arguments:
df: The data frame
par: The initial guess for the parameters
control: Control parameters for the optimization algorithm
...: Additional arguments to pass into the likelihood model's
constructed functions from loglik, score, and hess_loglik.
This function returns the hessian of the log-likelihood function of a model
hess_loglik(model, ...)hess_loglik(model, ...)
model |
The likelihood model |
... |
Additional arguments |
A function to compute the hessian of the log-likelihood given a data frame and parameters
Returns a function computing the 1x1 Hessian: -d/lambda^2.
## S3 method for class 'exponential_lifetime' hess_loglik(model, ...)## S3 method for class 'exponential_lifetime' hess_loglik(model, ...)
model |
An exponential_lifetime model |
... |
Additional arguments (ignored) |
A function(df, par, ...) computing the Hessian matrix
In case a hess_loglik method is not provided, this function will be
used.
It computes the hessian of the log-likelihood function using numerical
differentiation.
## S3 method for class 'likelihood_model' hess_loglik(model, control = list(), ...)## S3 method for class 'likelihood_model' hess_loglik(model, control = list(), ...)
model |
The likelihood model |
control |
Custom arguments to pass to |
... |
Additional arguments (to pass into |
A function(df, par, ...) that computes the Hessian matrix of the
log-likelihood evaluated at par given data df.
Tests whether an object satisfies the likelihood_model concept by
checking if "likelihood_model" is in its class hierarchy. To be a
likelihood model, at a minimum the object must implement loglik().
For optimal results, it may also provide score() and hess_loglik().
is_likelihood_model(x)is_likelihood_model(x)
x |
An object to test |
Logical indicating whether x is a likelihood model
Computes the likelihood interval for a parameter:
LI(k) = {theta : R(theta) >= 1/k} = {theta : S(theta) >= -log(k)}
likelihood_interval(x, ...) ## S3 method for class 'fisher_mle' likelihood_interval(x, data, model, k = 8, param = NULL, ...)likelihood_interval(x, ...) ## S3 method for class 'fisher_mle' likelihood_interval(x, data, model, k = 8, param = NULL, ...)
x |
A fisher_mle object |
... |
Additional arguments passed to optimization |
data |
Data frame used for likelihood computation |
model |
The likelihood model used for fitting |
k |
Likelihood ratio cutoff (default 8, giving 1/8 interval) |
param |
Index or name of parameter for profile interval (NULL for all) |
Unlike confidence intervals, likelihood intervals make no probability statements about the parameter. They simply identify the set of parameter values that are well-supported by the data.
Common choices for k:
k = 8: 1/8 likelihood interval (~95% CI equivalent)
k = 15: 1/15 likelihood interval (~99% CI equivalent)
k = 32: 1/32 likelihood interval (~99.9% CI equivalent)
For multivariate parameters, specify param to get a profile likelihood
interval for that parameter (profiling over the others).
Matrix with lower and upper bounds for each parameter
This function returns the log-likelihood function of a model
loglik(model, ...)loglik(model, ...)
model |
The likelihood model |
... |
Additional arguments |
A log-likelihood function to compute the log-likelihood given a data frame and parameters.
Returns a function computing ell(lambda) = d * log(lambda) - lambda * T.
## S3 method for class 'exponential_lifetime' loglik(model, ...)## S3 method for class 'exponential_lifetime' loglik(model, ...)
model |
An exponential_lifetime model |
... |
Additional arguments (ignored) |
A function(df, par, ...) computing the log-likelihood
Extract log-likelihood from fisher_mle object
## S3 method for class 'fisher_mle' logLik(object, ...)## S3 method for class 'fisher_mle' logLik(object, ...)
object |
A fisher_mle object |
... |
Additional arguments (ignored) |
A logLik object
Provides a clear error when a model class does not implement loglik.
## S3 method for class 'likelihood_model' loglik(model, ...)## S3 method for class 'likelihood_model' loglik(model, ...)
model |
A likelihood model |
... |
Additional arguments |
Never returns; always errors.
Computes the likelihood ratio test statistic and p-value for nested models.
lrt(null, alt, data, null_par, alt_par, dof = NULL, ...)lrt(null, alt, data, null_par, alt_par, dof = NULL, ...)
null |
the likelihood model for the simpler (null) hypothesis nested within the alternative model |
alt |
the likelihood model for the more complicated (alternative) hypothesis |
data |
a data frame |
null_par |
parameter values under the null model |
alt_par |
parameter values under the alternative model |
dof |
degrees of freedom (computed automatically if NULL) |
... |
additional arguments passed to loglik |
An lrt_result object with components stat, p.value, and dof
Computes MSE = Var + Bias^2 (scalar) or Vcov + bias %*% t(bias) (matrix).
Under regularity conditions, asymptotic bias is zero, so MSE equals the
variance-covariance matrix. When model is provided, uses Monte Carlo
bias estimation via bias.fisher_mle().
## S3 method for class 'fisher_mle' mse(x, theta = NULL, ..., model = NULL, n_sim = 1000)## S3 method for class 'fisher_mle' mse(x, theta = NULL, ..., model = NULL, n_sim = 1000)
x |
A fisher_mle object |
theta |
True parameter value (for simulation studies) |
... |
Additional arguments (ignored) |
model |
A likelihood model (optional, enables MC bias estimation) |
n_sim |
Number of MC replicates for bias estimation (default 1000) |
MSE matrix or scalar
Extract number of observations from fisher_mle object
## S3 method for class 'fisher_mle' nobs(object, ...)## S3 method for class 'fisher_mle' nobs(object, ...)
object |
A fisher_mle object |
... |
Additional arguments (ignored) |
Number of observations
Number of parameters in fisher_mle
## S3 method for class 'fisher_mle' nparams(x)## S3 method for class 'fisher_mle' nparams(x)
x |
A fisher_mle object |
Integer count of parameters
fisher_mle objects do not store observed data by design, so this
always returns NULL.
## S3 method for class 'fisher_mle' obs(x)## S3 method for class 'fisher_mle' obs(x)
x |
A fisher_mle object |
Always NULL. fisher_mle objects do not store the observed data.
Returns the negative Hessian of the log-likelihood evaluated at the MLE, which estimates the Fisher information matrix.
## S3 method for class 'fisher_mle' observed_fim(x, ...)## S3 method for class 'fisher_mle' observed_fim(x, ...)
x |
A fisher_mle object |
... |
Additional arguments (ignored) |
A matrix, or NULL if the Hessian was not computed
Extract parameter estimates from fisher_mle
## S3 method for class 'fisher_mle' params(x)## S3 method for class 'fisher_mle' params(x)
x |
A fisher_mle object |
Named numeric vector of parameter estimates
Print fisher_boot object
## S3 method for class 'fisher_boot' print(x, ...)## S3 method for class 'fisher_boot' print(x, ...)
x |
A fisher_boot object |
... |
Additional arguments (ignored) |
The fisher_boot object, invisibly
Print fisher_mle object
## S3 method for class 'fisher_mle' print(x, ...)## S3 method for class 'fisher_mle' print(x, ...)
x |
A fisher_mle object |
... |
Additional arguments (ignored) |
The fisher_mle object, invisibly
Print likelihood interval
## S3 method for class 'likelihood_interval' print(x, ...)## S3 method for class 'likelihood_interval' print(x, ...)
x |
A likelihood_interval object |
... |
Additional arguments (ignored) |
The likelihood_interval object, invisibly
Print method for likelihood models
## S3 method for class 'likelihood_model' print(x, show.loglik = FALSE, ...)## S3 method for class 'likelihood_model' print(x, show.loglik = FALSE, ...)
x |
A likelihood model |
show.loglik |
Logical; if TRUE, print the log-likelihood function |
... |
Additional arguments (ignored) |
The likelihood model object, invisibly
Print method for likelihood ratio test results
## S3 method for class 'lrt_result' print(x, ...)## S3 method for class 'lrt_result' print(x, ...)
x |
An lrt_result object |
... |
Additional arguments (ignored) |
The lrt_result object, invisibly
Print profile log-likelihood
## S3 method for class 'profile_loglik' print(x, ...)## S3 method for class 'profile_loglik' print(x, ...)
x |
A profile_loglik object |
... |
Additional arguments (ignored) |
The profile_loglik object, invisibly
Print summary of fisher_mle
## S3 method for class 'summary_fisher_mle' print(x, ...)## S3 method for class 'summary_fisher_mle' print(x, ...)
x |
A summary_fisher_mle object |
... |
Additional arguments (ignored) |
The summary_fisher_mle object, invisibly
Computes the profile log-likelihood for a subset of parameters. For each value of the parameters of interest, the remaining (nuisance) parameters are optimized out.
profile_loglik(x, ...) ## S3 method for class 'fisher_mle' profile_loglik( x, data, model, param, grid = NULL, n_grid = 50, range_mult = 4, ... )profile_loglik(x, ...) ## S3 method for class 'fisher_mle' profile_loglik( x, data, model, param, grid = NULL, n_grid = 50, range_mult = 4, ... )
x |
A fisher_mle object |
... |
Additional arguments passed to loglik |
data |
Data frame used for likelihood computation |
model |
The likelihood model used for fitting |
param |
Index or name of parameter(s) to profile |
grid |
Optional grid of values to evaluate (vector or matrix) |
n_grid |
Number of grid points if grid not specified (default 50) |
range_mult |
Multiplier for grid range based on SE (default 4) |
The profile likelihood is useful for:
Visualizing the likelihood surface
Computing likelihood intervals
Eliminating nuisance parameters
A data frame with parameter values and profile log-likelihood
Returns a function that generates random data from the model's data-generating process (DGP) at a given parameter value.
rdata(model, ...)rdata(model, ...)
model |
A likelihood model |
... |
Additional arguments |
This is used by the default fim method for Monte Carlo estimation
of the Fisher information matrix.
Function that takes (theta, n, ...) and returns a data frame
Generates exponential data, optionally with right-censoring at a fixed censoring time.
## S3 method for class 'exponential_lifetime' rdata(model, ...)## S3 method for class 'exponential_lifetime' rdata(model, ...)
model |
An exponential_lifetime model |
... |
Additional arguments (ignored) |
A function(theta, n, censor_time, ...) that returns a data frame
Provides a clear error when a model class does not implement rdata.
The rdata method is required by the default fim.likelihood_model()
for Monte Carlo FIM estimation.
## S3 method for class 'likelihood_model' rdata(model, ...)## S3 method for class 'likelihood_model' rdata(model, ...)
model |
A likelihood model |
... |
Additional arguments |
Never returns; always errors.
Computes the relative likelihood (likelihood ratio) for theta: R(theta) = L(theta) / L(theta_hat) = exp(S(theta))
relative_likelihood(x, ...) ## S3 method for class 'fisher_mle' relative_likelihood(x, theta, data, model, ...)relative_likelihood(x, ...) ## S3 method for class 'fisher_mle' relative_likelihood(x, theta, data, model, ...)
x |
A fisher_mle object |
... |
Additional arguments passed to loglik |
theta |
Parameter value(s) to evaluate |
data |
Data frame used for likelihood computation |
model |
The likelihood model used for fitting |
The relative likelihood is always between 0 and 1, with maximum 1 at the MLE. Common cutoff values:
R >= 0.15 (k=8): roughly equivalent to 95% confidence
R >= 0.10 (k=10): more conservative
R >= 0.05 (k=20): very conservative
Relative likelihood value(s): L(theta)/L(theta_hat)
Returns a function that resamples from the bootstrap distribution.
## S3 method for class 'fisher_boot' sampler(x, ...)## S3 method for class 'fisher_boot' sampler(x, ...)
x |
A fisher_boot object |
... |
Additional arguments (ignored) |
Function that takes n and returns n x p matrix of resampled estimates
Returns a function that samples from the asymptotic normal distribution of the MLE: N(theta_hat, vcov).
## S3 method for class 'fisher_mle' sampler(x, ...)## S3 method for class 'fisher_mle' sampler(x, ...)
x |
A fisher_mle object |
... |
Additional arguments (ignored) |
Function that takes n and returns n x p matrix of samples
We use the bootstrap method. In other words, we treat the data as an empirical distribution and sample from it to get a new dataset, then we fit the model to that dataset and return the MLE. We do this R times and return the R MLEs.
## S3 method for class 'likelihood_model' sampler(x, df, par, ..., nthreads = 1L)## S3 method for class 'likelihood_model' sampler(x, df, par, ..., nthreads = 1L)
x |
The likelihood model |
df |
Data frame to bootstrap from |
par |
Initial parameter values |
... |
Additional arguments to pass into the likelihood model |
nthreads |
The number of threads to use for parallelization |
This is the default method, but if you want to use a different method, you should define your own method for your likelihood model.
A function that returns a bootstrapped sampling distribution of an MLE (fisher_boot object).
This function returns the score function of a model
score(model, ...)score(model, ...)
model |
The likelihood model |
... |
Additional arguments |
A function to compute the score given a data frame and parameters
Extract score vector from fisher_mle
## S3 method for class 'fisher_mle' score_val(x, ...)## S3 method for class 'fisher_mle' score_val(x, ...)
x |
A fisher_mle object |
... |
Additional arguments (ignored) |
The score vector at the MLE (should be near zero)
Returns a function computing d/lambda - T.
## S3 method for class 'exponential_lifetime' score(model, ...)## S3 method for class 'exponential_lifetime' score(model, ...)
model |
An exponential_lifetime model |
... |
Additional arguments (ignored) |
A function(df, par, ...) computing the score vector
In case a score method is not provided, this function will be used.
It computes the score by numerical differentiation of the log-likelihood.
## S3 method for class 'likelihood_model' score(model, control = list(), ...)## S3 method for class 'likelihood_model' score(model, control = list(), ...)
model |
The likelihood model |
control |
Custom arguments to pass to |
... |
Additional arguments (to pass into |
A function to compute the score given a data frame and parameters
Computes standard errors as the square root of the diagonal of the variance-covariance matrix.
## S3 method for class 'fisher_mle' se(x, ...)## S3 method for class 'fisher_mle' se(x, ...)
x |
A fisher_mle object |
... |
Additional arguments (ignored) |
Numeric vector of standard errors, or NA values if vcov is NULL
Summarize fisher_mle object
## S3 method for class 'fisher_mle' summary(object, ...)## S3 method for class 'fisher_mle' summary(object, ...)
object |
A fisher_mle object |
... |
Additional arguments (ignored) |
A summary_fisher_mle object
Computes the support for parameter value theta relative to the MLE: S(theta) = logL(theta) - logL(theta_hat)
support(x, ...) ## S3 method for class 'fisher_mle' support(x, theta, data, model, ...)support(x, ...) ## S3 method for class 'fisher_mle' support(x, theta, data, model, ...)
x |
A fisher_mle object |
... |
Additional arguments passed to loglik |
theta |
Parameter value(s) to evaluate |
data |
Data frame used for likelihood computation |
model |
The likelihood model used for fitting |
The support function is always <= 0, with maximum at the MLE. Values of theta with support > -2 are considered well-supported. Values with support > -log(8) ~ -2.08 correspond roughly to a 95% likelihood interval.
Support value(s): logL(theta) - logL(theta_hat)
Extract variance-covariance matrix from fisher_mle object
## S3 method for class 'fisher_mle' vcov(object, ...)## S3 method for class 'fisher_mle' vcov(object, ...)
object |
A fisher_mle object |
... |
Additional arguments (ignored) |
Variance-covariance matrix