Last chance! 50% off unlimited learning
Sale ends in
Minimization based on the R-stat functions nlm
, nlminb
, and optim
.
Model parameters are scaled and can be active or not in the minimization.
calcMin(pvec, func, method="nlm", trace=0, maxit=1000, reltol=1e-8,
steptol=1e-6, temp=10, repN=0, …)
Initial values of the model parameters to be optimized.
pvec
is a data frame comprising four columns (
"val","min","max","active"
) and as many rows as there are model
parameters. The "active"
field (logical) determines whether the
parameters are estimated (T
) or remain fixed (F
).
The user-defined function to be minimized (or maximized). The function should return a scalar result.
The minimization method to use: one of nlm
, nlminb
,
Nelder-Mead
, BFGS
, CG
, L-BFGS-B
, or
SANN
. Default is nlm
.
Non-negative integer. If positive, tracing information on the
progress of the minimization is produced. Higher values may produce more
tracing information: for method "L-BFGS-B"
there are six levels of
tracing. Default is 0
.
The maximum number of iterations. Default is 1000
.
Relative convergence tolerance. The algorithm stops if it is
unable to reduce the value by a factor of reltol*(abs(val)+reltol)
at a step. Default is 1e-8
.
A positive scalar providing the minimum allowable relative step length.
Default is 1e-6
.
Temperature controlling the "SANN"
method. It is the
starting temperature for the cooling schedule. Default is 10
.
Reports the parameter and objective function values on the R-console
every repN
evaluations. Default is 0
for no reporting.
Further arguments to be passed to the optimizing function chosen:
nlm
, nlminb
, or optim
.
Beware of partial matching to earlier arguments.
A list with components:
The output list from the optimizer function chosen through method
.
Number of iterations.
Number of evaluations.
The user CPU time to execute the minimization.
The total elapsed time to execute the minimization.
The objective function value calculated at the start of the minimization.
The objective function value calculated at the end of the minimization.
Starting values for the model parameters.
Final values estimated for the model parameters from the minimization.
Akaike's Information Criterion
Convergence message from the minimization routine.
See optim
for details on the following methods: Nelder-Mead
,
BFGS
, CG
, L-BFGS-B
, and SANN
.
scalePar
, restorePar
, calcMin
, GT0
In the stats
package: nlm
, nlminb
, and optim
.
# NOT RUN {
local(envir=.PBSmodEnv,expr={
Ufun <- function(P) {
Linf <- P[1]; K <- P[2]; t0 <- P[3]; obs <- afile$len;
pred <- Linf * (1 - exp(-K*(afile$age-t0)));
n <- length(obs); ssq <- sum((obs-pred)^2 );
return(n*log(ssq)); };
oldpar = par(no.readonly = TRUE)
afile <- data.frame(age=1:16,len=c(7.36,14.3,21.8,27.6,31.5,35.3,39,
41.1,43.8,45.1,47.4,48.9,50.1,51.7,51.7,54.1));
pvec <- data.frame(val=c(70,0.5,0),min=c(40,0.01,-2),max=c(100,2,2),
active=c(TRUE,TRUE,TRUE),row.names=c("Linf","K","t0"),
stringsAsFactors=FALSE);
alist <- calcMin(pvec=pvec,func=Ufun,method="nlm",steptol=1e-4,repN=10);
print(alist[-1]); P <- alist$Pend;
#resetGraph();
expandGraph();
xnew <- seq(afile$age[1],afile$age[nrow(afile)],len=100);
ynew <- P[1] * (1 - exp(-P[2]*(xnew-P[3])) );
plot(afile); lines(xnew,ynew,col="red",lwd=2);
addLabel(.05,.88,paste(paste(c("Linf","K","t0"),round(P,c(2,4,4)),
sep=" = "),collapse="\n"),adj=0,cex=0.9);
par(oldpar)
})
# }
Run the code above in your browser using DataLab