s-news
[Top] [All Lists]

iteration within loop

To: "S-News@Lists. Biostat. Wustl. Edu \(E-mail\)" <s-news@lists.biostat.wustl.edu>
Subject: iteration within loop
From: "Kwang-Lee Chu" <chu_kwanglee@hotmail.com>
Date: Sat, 24 Feb 2001 10:55:23 -0500
References: <15104802790BD411A2C100D0B73EA33CA8386D@remailnt3-re01.westat.com>
Hi,

I tried to run iteration within a loop. After an iteration converged, a new
iteration should begin with the next value in "Xest". The program is shown
below. First, I am not sure the iteration part is right or not. Second, the
S-Plus gave me "Error in parse(text = txt): Syntax error: "^" used illegally
at this point:
script.run(exprs.literal={  ^ dumped".  I assume it is about the iteration
part, but I don't know how to fix it. Could anyone help?

By the way, if I want the iteration to stop only when it meets the stopping
criteria, what should I do?

Thanks!
Kwang-lee

Xest <- c(-3,0,3)
b <- c(1,2,3)
iteration <- 20

XP <- matrix(nrow=length(b), ncol=iteration)
XsumP <- matrix(nrow=1, ncol=iteration)
XP1 <- matrix(nrow=length(b), ncol=iteration)
XsumP1 <- matrix(nrow=1, ncol=iteration)
Xture <- matrix(nrow=1, ncol=length(Xest))

dos.time(for (i in 1:length(Xest))
{
Xest1 <- Xest[i]

for (j in 1:iteration)
{
Xest2 <-rep(Xest1,length(b))
P <- 1/(1+ exp((-1)*(Xest2-b)))
P1 <- P(1-P)
XP[,i] <- P
XP1[,i] <- P1
XsumP[,i] <- colSums(P)
XsumP1[,i] <- colSums(P1)
difPP <- P[,i]- P[,i-1]
if (difPP > 0.0001) Xest2<-rep((sumP[,i]-sumP1[,i]),length(b)) else stop
}

## retrive the last iter value
Xend <- Xest[i] - XsumP[,i]/XsumP1[,i]
Xtrue[,i] <- sumP1(Xest[i]-Xend)+ sumP
})



<Prev in Thread] Current Thread [Next in Thread>