[R] Optim function in the loop
Ravi Varadhan
rvaradhan at jhmi.edu
Sun May 3 16:15:59 CEST 2009
Hi,
It is not clear to me what you are trying to do, but you should try `while' instead of `if':
count <- 1
while (count > 0) {
.
. # yuor code here
.
}
Ravi.
____________________________________________________________________
Ravi Varadhan, Ph.D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology
School of Medicine
Johns Hopkins University
Ph. (410) 502-2619
email: rvaradhan at jhmi.edu
----- Original Message -----
From: Rstarer <bozhao86 at hotmail.com>
Date: Sunday, May 3, 2009 5:01 am
Subject: [R] Optim function in the loop
To: r-help at r-project.org
> Hi all,
> I wrote the following lines of codes try to do some iterations to
> find the
> global optimal values, but the function does not execute properly. Every
> time codes stop after one iteration right after executing the optim()
> function. Does anyone could have me to take a look? Thanks.
> if (count>0){
>
> k=k+0.05;
>
> mu0=c(83+k,0,0)
>
> Sigma0= diag(0.4,3)
>
> initpar=c(.1+10*k,10*k,10*k,10*k) # initial parameters for Phi[1,1],
> the 2
> Q’s and R
>
> est=optim(initpar,Linn,NULL,method="BFGS",hessian=TRUE,control=list(trace=1,REPORT=1,maxit=300))
>
> stderr=sqrt(diag(solve(est$hessian)))
>
> estimate=est$par
>
> u=cbind(estimate,stderr)
>
> if (u[1]>0 & u[2]>0 & u[3]>0 & u[4]>0){
>
> print("mu0=");print(mu0);
>
> print("initpar=");print(initpar)
>
> #break
>
> } else {count=-1;
>
> }
>
> }
>
> --
> View this message in context:
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
>
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list