Public documentation
Contents
Index
MEstimation.estimating_function_template
MEstimation.objective_function_template
MEstimation.estimating_function
MEstimation.get_estimating_function
MEstimation.objective_function
MEstimation.slice
MEstimation.tic
StatsAPI.aic
StatsAPI.coef
StatsAPI.coeftable
StatsAPI.fit
StatsAPI.fit
StatsAPI.stderror
StatsAPI.vcov
Public interface
MEstimation.estimating_function_template
— Typeestimating_function_template(nobs::Function,
ef_contribution::Function)
Composite type for defining an estimating_function_template
.
Arguments
nobs
: a function ofdata
that computes the number of observations of the particular data type,ef_contribution
: a function of the parameterstheta
, thedata
and the observation indexi
that returns a vector of lengthlength(theta)
.
Result
An estimating_function_template
object with fields nobs
and obj_contributions
.
MEstimation.get_estimating_function
— Functionget_estimating_function(data::Any,
template::estimating_function_template,
br::Bool = false,
concentrate::Vector{Int64} = Vector{Int64}(),
regularizer::Any = Vector{Int64}())
Construct the estimating functions by adding up all contributions in the data
according to estimating_function_template
.
Arguments
data
: typically an object of composite type with all the data required to compute theestimating_function
.template
: anestimating_function_template
object.br
: aBool
. Iffalse
(default), the estimating functions is constructed by adding up all contributions in
data
, according to estimating_function_template
, before it is evaluated at theta
. If true
then the empirical bias-reducing adjustments in Kosmidis & Lunardon, 2020 are computed and added to the estimating functions.
concentrate
: aVector{Int64}
; if specified, empirical bias-reducing adjustments are added only to the subset of estimating functions indexed byconcentrate
. The default is to add empirical bias-reducing adjustments to all estimating functions.regularizer
: a function oftheta
anddata
returning aVector
of dimension equal to the number of the estimating functions, which is added to the (bias-reducing) estimating function; the default value will result in no regularization.
Result
An in-place function that stores the value of the estimating functions inferred from template
, in a preallocated vector passed as its first argument, ready to be used withing NLsolve.nlsolve
. This is the in-place version of estimating_function
with the extra regularizer
argument.
MEstimation.estimating_function
— Functionestimating_function(theta::Vector,
data::Any,
template::estimating_function_template,
br::Bool = false,
concentrate::Vector{Int64} = Vector{Int64}())
Evaluate a vector of estimating functions at theta
by adding up all contributions in data
, according to an estimating_function_template
.
Arguments
theta
: aVector
of parameter values at which to evaluate the estimating functionsdata
: typically an object of composite type with all the data required to compute theestimating_function
.template
: anestimating_function_template
object.br
: aBool
. Iffalse
(default), the estimating functions is constructed by adding up all contributions in
data
, according to estimating_function_template
, before it is evaluated at theta
. If true
then the empirical bias-reducing adjustments in Kosmidis & Lunardon, 2020 are computed and added to the estimating functions.
concentrate
: aVector{Int64}
; if specified, empirical bias-reducing adjustments are added only to the subset of estimating functions indexed byconcentrate
. The default is to add empirical bias-reducing adjustments to all estimating functions.
Result
A Vector
.
Details
data
can be used to pass additional constants other than the actual data to the objective.
MEstimation.objective_function_template
— Typeobjective_function_template(nobs::Function,
obj_contribution::Function)
A constructor of objects of composite type for defining an objective_function_template
.
Arguments
nobs
: a function ofdata
that computes the number of observations of the particular data type,obj_contribution
: a function of the parameterstheta
, thedata
and the observation indexi
that returns aFloat64
.
Result
An objective_function_template
object with fields nobs
and obj_contributions
.
MEstimation.objective_function
— Functionobjective_function(theta::Vector,
data::Any,
template::objective_function_template,
br::Bool = false)
Evaluates the objective function at theta
by adding up all contributions in data
, according to objective_function_template
.
Arguments
theta
: aVector
of parameter values at which to evaluate the objective functiondata
: typically an object of composite type with all the data required to compute theobjective_function
.template
: anobjective_function_template
objectbr
: aBool
. Iffalse
(default), the objective function is constructed by adding up all contributions in
data
, according to objective_function_template
, before it is evaluated at theta
. If true
then the bias-reducing penalty in Kosmidis & Lunardon, 2020 is computed and added to the objective function.
Result
A Float64
.
Details
data
can be used to pass additional constants other than the actual data to the objective.
StatsAPI.fit
— Methodfit(template::objective_function_template,
data::Any,
theta::Vector{Float64};
estimation_method::String = "M",
br_method::String = "implicit_trace",
regularizer::Function = function regularizer(theta::Vector{Float64}, data::Any) Vector{Float64}() end,
lower::Vector{Float64} = Vector{Float64}(),
upper::Vector{Float64} = Vector{Float64}(),
optim_method = LBFGS(),
optim_options = Optim.Options(),
optim_arguments...)
Fit an objective_function_template
on data
using M-estimation (estimation_method = "M"
; default) or RBM-estimation (reduced-bias M estimation; Kosmidis & Lunardon, 2020; estimation_method = "RBM"
)
Arguments
template
: anobjective_function_template
object.data
: typically an object of composite type with all the data required to compute theobjective_function
.theta
: aVector{Float64}
of parameter values to use as starting values inOptim.optimize
.
estimation_method
: either "M" (default) or "RBM"; see Details.br_method
: either "implicittrace" (default) or "explicittrace"; see Details.regularizer
: a function oftheta
anddata
returning aFloat64
, which is added to the (bias-reducing penalized) objective; the default value will result in no regularization.lower
: aVector{Float64}
of dimension equal totheta
for setting box constraints for the optimization. The default will result in unconstrained optimization. See Details.upper
: aVector{Float64}
of dimension equal totheta
for setting box constraints for the optimization. The default will result in unconstrained optimization. See Details.optim_method
: the optimization method to be used; deafult isOptim.LBFGS()
. See Details.optim_options
: the result of a call toOptim.Options
to be passed toOptim.optimize
. Default isOptim.Options()
. See details.optim_arugments...
: extra keyword arguments to be passed toOptim.optimize
. See Details.
Details
Bias reduction is either through the maximization of the bias-reducing penalized objective in Kosmidis & Lunardon (2020) (br_method = "implicit_trace"
; default) or by subtracting an estimate of the bias from the M-estimates (br_method = "explicit_trace"
). The bias-reducing penalty is constructed internally using automatic differentiation (using the ForwardDiff package), and the bias estimate using a combination of automatic differentiation and numerical differentiation (using the FiniteDiff package).
The maximization of the objective or the penalized objective is done using the Optim package. Optimization methods and options can be supplied directly through the optim_method
and optim_options
, respectively. optim_options
expects an object constructed through Optim.Options
. Keyword arguments (e.g. autodiff = :forward
) can be passed directly to Optim.optimize
through extra keyword arguments. See the Optim documentation for more details on the available options.
An extra additive regularizer to either the objective or the bias-reducing penalized objective can be suplied via the keyword argument regularizer
, which must be a scalar-valued function of the parameters and the data; the default value will result in no regularization.
lower
and upper
can be used to provide box contraints. If valid lower
and upper
vectors are supplier, then the internal call to Optim.optimize
will use Fminbox(optim_method)
as a method; see the Optim documentation on box minimization for more details.
StatsAPI.fit
— Methodfit(template::estimating_function_template,
data::Any,
theta::Vector{Float64};
estimation_method::String = "M",
br_method::String = "implicit_trace",
concentrate::Vector{Int64} = Vector{Int64}(),
regularizer::Function = function regularizer(theta::Vector{Float64}, data::Any) Vector{Float64}() end,
nlsolve_arguments...)
Fit an estimating_function_template
on data
using M-estimation (estimation_method = "M"
; default) or RBM-estimation (reduced-bias M estimation; Kosmidis & Lunardon, 2020; estimation_method = "RBM"
)
Arguments
template
: anestimating_function_template
object.data
: typically an object of composite type with all the data required to compute theobjective_function
.theta
: aVector{Float64}
of parameter values to use as starting values inOptim.optimize
.
estimation_method
: either "M" (default) or "RBM"; see Details.br_method
: either "implicittrace" (default) or "explicittrace"; see Details.concentrate
: aVector{Int64}
; if specified, empirical bias-reducing adjustments are added only to the subset of estimating functions indexed byconcentrate
. The default is to add empirical bias-reducing adjustments to all estimating functions.regularizer
: a function oftheta
anddata
returning aVector{Float64}
of dimension equal to the number of the estimating functions, which is added to the (bias-reducing) estimating function; the default value will result in no regularization.nlsolve_arguments...
: extra keyword arguments to be passed toNLsolve.nlsolve
. See Details.
Details
Bias reduction is either through the solution of the empirically adjusted estimating functions in Kosmidis & Lunardon (2020) (br_method = "implicit_trace"
; default) or by subtracting an estimate of the bias from the M-estimates (br_method = "explicit_trace"
). The bias-reducing adjustments and the bias estimate are constructed internally using automatic differentiation (using the ForwardDiff package).
Bias reduction for only a subset of parameters can be performed by setting concentrate
to the vector of the indices for those parameters.
The solution of the estimating equations or the adjusted estimating equations is done using the NLsolve package. Keyword arguments can be passed directly to NLsolve.nlsolve
through extra keyword arguments. See the NLsolve README for more information on available options.
An extra additive regularizer to either the estimating functions or the bias-reducing adjusted estimating functions can be suplied via the keyword argument regularizer
, which must be a length(theta)
-valued function of the parameters and the data; the default value will result in no regularization.
StatsAPI.coef
— Functioncoef(results::MEstimation_results)
Extract the parameter estimates from a MEstimation_results
object.
Arguments
results
: aMEstimation_results
object.
Details
coef(results)
returns results.theta
StatsAPI.vcov
— Functionvcov(results::MEstimation_results)
Compute an estimate of the variance-covariance matrix of the M
-estimator or its reduced-bias version at results.theta
, from a MEstimation_results
object.
Arguments
results
: aMEstimation_results
object.
Result
The length(coef(results))
times length(coef(results))
estimated variance covariance matrix for the parameters. This matrix is the empirical sandwich variance covariance matrix for M- and RBM-estimators. See, for example, Stefanski and Boos (2002, expression 10).
StatsAPI.stderror
— Functionstderror(results::MEstimation_results)
Compute estimated standard errors from a from a MEstimation_results
object.
Arguments
results
: aMEstimation_results
object.
Details
The estimated standard errors are computed as sqrt.(diag(vcov(results)))
.
StatsAPI.coeftable
— Functioncoeftable(results::MEstimation_results;
level::Real=0.95)
Return a StatsBase.CoefTable
from a MEstimation_results
object.
Arguments
results
: aMEstimation_results
object.
level
: aReal
that determines the level of the reported confidence intervals; default is0.95
; see Details.
Details
The reported confidence intervals are Wald-type of nominal level level
, using quantiles of the standard normal distribution.
MEstimation.tic
— Functiontic(results::MEstimation_results)
Compute the Takeuchi Information Criterion at results.theta
, from a MEstimation_results
object.
Arguments
results
: aMEstimation_results
object.
Details
nothing
is returned if results.template
is an estimating_function_template
.
StatsAPI.aic
— Functionaic(results::MEstimation_results)
Compute the Akaike Information Criterion at results.theta
, from a MEstimation_results
object with an objective_function_template
.
Arguments
results
: aMEstimation_results
object.
Details
nothing
is returned if results.template
is an estimating_function_template
.
MEstimation.slice
— Functionslice(results::MEstimation_results,
what::Int64;
grid::Vector{Float64} = Vector{Float64}(),
at::Vector{Float64} = Vector{Float64}(),
n_points::Int64 = 50,
n_sd::Real = 2)
Compute 1-dimensional slices of objective functions and estimating function surfaces for the parameter what
over a grid of points grid
, from a MEstimation_results
object.
Arguments
results
: AnMEstimation_results
object.what
: the index of the parameter for which to compute a slice for
grid
: aVector{Float64}
; if supplied, the slice is computed at each element ofgrid
. The default will result in the automatic calculation of the grid; see Details.at
: aVector{Float64}
of the sample length ascoef(results)
, specifying the parameter values at which to compute the slice. The default results in computing the slice atcoef(results)
.n_points
: anInt64
specifying the number of grid points to generate. Applicable only ifgrid
is not supplied; see Details.n_sd
: anInt64
specifying the number of standard errors to be used for the grid generation. Applicable only ifgrid
is not supplied; see Details.
Result
A Dict
with keys "grid" and "slice", holding grid
and the values of the slice at grid
, respectively.
Details
The default value of grid
will result in the automatic calculation of a grid of n_points
points, between coef(results)[what] - n_sd * stderror(results)[what]
and coef(results)[what] + n_sd * stderror(results)[what]
.