[R] (no subject)

From: Debanjan Bhattacharjee <debanjan.bhattacharjee_at_gmail.com>
Date: Wed, 26 Nov 2008 02:44:24 -0500


Can any one help me to solve problem in my code? I am actually trying to find the stopping index N.
So first I generate random numbers from normals. There is no problem in finding the first stopping index.
Now I want to find the second stopping index using obeservation starting from the one after the first stopping index. E.g. If my first stopping index was 5. I want to set 6th observation from the generated normal variables as the first random number, and I stop at second stopping index.

This is my code,

alpha <- 0.05
beta <- 0.07
a <- log((1-beta)/alpha)
b <- log(beta/(1-alpha))
theta1 <- 2
theta2 <- 3

cumsm<-function(n)

               {y<-NULL
                for(i in 1:n)
                {y[i]=x[i]^2}
                s=sum(y)
                return(s)
               }
psum <- function(p,q)
                {z <- NULL
                 for(l in p:q)
                    { z[l-p+1] <- x[l]^2}
                 ps <- sum(z)
                 return(ps)
                }

smm <- NULL
sm <- NULL
N <- NULL
Nout <- NULL
T <- NULL
k<-0
  x <- rnorm(100,theta1,theta1)
  for(i in 1:length(x))
     {
        sm[i] <- psum(1,i)
        T[i] <-

((i/2)*log(theta1/theta2))+(((theta2-theta1)/(2*theta1*theta2))*sm[i])-(i*(theta2-theta1)/2)
if (T[i]<=b | T[i]>=a){N[1]<-i break} }

for(j in 2:200)
{
  for(k in (N[j-1]+1):length(x))
     {  smm[k] <- psum((N[j-1]+1),k)
        T[k] <-

((k/2)*log(theta1/theta2))+(((theta2-theta1)/(2*theta1*theta2))*smm[k])-(k*(theta2-theta1)/2)
if (T[k]<=b | T[k]>=a){N[j]<-k break} }

}

But I cannot get the stopping index after the first one.

Tanks

--

	[[alternative HTML version deleted]]

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Wed 26 Nov 2008 - 08:00:49 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 26 Nov 2008 - 08:30:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive