rminuit2 | R Documentation |
Performs function minimization using Minuit2
rminuit2(
mll,
start = formals(mll),
err = NULL,
lower = NULL,
upper = NULL,
fix = NULL,
opt = "h",
maxcalls = 0L,
nsigma = 1,
...
)
mll |
The function to be minimized. The full potential of this package is attained when the function corresponds to the negative logarithm of a likelihood or minus-log-likelihood (MLL). |
start |
numeric vector, initial values of the function parameters |
err |
numeric vector, expected uncertainty of function parameters |
lower |
numeric vector, lower bounds for the parameters (default none) |
upper |
numeric vector, upper bounds for the parameters (default none) |
fix |
boolean vector, each TRUE element fixes the corresponding parameter |
opt |
string, pass fit options, default "h" (compute HESSE errors)
|
maxcalls |
integer, maximum number of calls, defaults to |
nsigma |
numeric, number of standard deviations for Minos errors |
... |
extra arguments for the mll function. |
A list with the following components:
fval
:Value of function at found minimum (1/2 * chi square if the function is the negative log-likelihood of a Gaussian likelihood.
Edm
:Estimated distance from the value of the function true minimum
par
:Fitted parameters
err
:Estimated uncertainties of fitted parameters
cov
:Covariance matrix of the fitted parameters
cor
:Correlation matrix of the fitted parameters
err_minos_pos
:Minos-estimated positive parameters' uncertainties (if Minos errors were requested)
err_minos_neg
:Minos-estimated negative parameters' uncertainties (if Minos errors requested)
err_minos_pos_valid
:boolean vector, TRUE if Minos positive uncertainties are valid (if Minos errors were requested)
err_minos_neg_valid
:boolean vector, TRUE if Minos negative uncertainties are valid (if Minos errors were requested)
allOK
:TRUE if the fit converged and the parameters and their covariance are OK
MinosErrorsValid
:TRUE if the MINOS errors are all valid
IsValid
:TRUE if the fit minimization converged
IsValidFirstInvocation
:TRUE if Minuit strategy 1 succeeded (if it failed Minuit2 strategy 2 is performed)
IsAboveMaxEdm
:TRUE if the estimated distance from the true minimum is above the tolerance
HasReachedCallLimit
:TRUE if the maximum call limit was exceeded
HasValidParameters
:TRUE if the fitted parameters are considered valid
HasCovariance
:TRUE if a covariance matrix is returned
HasValidCovariance
:TRUE if the estimated covariance matrix is considered valid
HasAccurateCovar
:TRUE if the accuracy of the estimated covariance matrix is considered valid
HasPosDefCovar
:TRUE if the numerically computed covariance matrix is positive definite
HasMadePosDefCovar
:TRUE if the covariance matrix has been adjusted to make it positive definite
HesseFailed
:TRUE if the numeric computation of the HESSE matrix failed
Alberto Lusiani, alusiani@gmail.com
rminuit2_par
#
# Rosenbrock Banana function, to be minimized vs. x, y
#
rosenbrock <- function(x, y, a, b) {
(a-x)^2 + b*(y-x^2)^2
}
# minimize Rosenbrock Banana function, also setting parameters a, b
fit.rc <- rminuit2(rosenbrock, c(x=0.7, y=1.2), a=1, b=100)
fit.rc$par
#
# simulate model y = a*exp(-x/b)
#
x = seq(0, 1, length.out=31)
y.func = function(x, norm, tau) norm*exp(-x/tau)
# simulate data with Gaussian errors for specific model
model.par = c(norm=2.3, tau=0.47)
y.err = 0.01
y = do.call(y.func, c(list(x), model.par)) + rnorm(sd=y.err, n=length(x))
# negative log-likelihood for model
halfchisq = function(norm, tau, x, y, y.err) {
sum( (y - y.func(x, norm, tau))^2 / (2 * y.err^2) )
}
# fit model on data, ask to compute Minos errors too
fit.rc = rminuit2(halfchisq, c(norm=1, tau=10), opt="hm", x=x, y=y, y.err=y.err)
# chi square / number of degrees of freedom
cbind(chisq=2*fit.rc$fval, ndof=length(x) - length(model.par))
# fitted parameters and their estimated uncertainties
cbind(model.value=model.par, value=fit.rc$par, error=fit.rc$err,
minos_pos=fit.rc$err_minos_pos, minos_neg=fit.rc$err_minos_neg)
# parameters' correlation matrix
fit.rc$cor
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.