s-news
[Top] [All Lists]

Summation problem

To: s-news@lists.biostat.wustl.edu
Subject: Summation problem
From: Isabelle Gaboury <isabelle.gaboury@tr.cgocable.ca>
Date: Fri, 26 Feb 1999 17:27:11 -0500
Hi,

I wrote this function:
add5 <- function(i, epsilon, pi, pij)
{
resr <- 0;
for (j in 1:(n-1))
        {denomi <- 0;
         for (k in 1 :(n-1))
                denomi <- ((1-epsilon[k])*pi[k]*pij[k,j]) + denomi;
         resr <<- ((x[n,j]*(1-epsilon[i])*pi[i]*pij[i,j])/denomi) + resr;
        }
}

from which I would expect to get the value "resr", which is in fact a sum
of j "resr" terms. But, if I print the value of "resr" at each step j, I
got 0 all the time. Outside of the function, if I use the value of "resr",
it gives me the first term of the sum over the j terms... How come???

I tried to put "resr <- 0;" outside of the function. But, problem: it works
only (i.e. "resr" contains the correct sum) only if this function is asked
directly in the commands window. If I put "resr <- 0;" plus function add5
(without resr <- 0;) in another function, I go back to my first problem,
i.e. the sum is incorrect.

What a stange problem... Any help will be really appreciated!
Isabelle Gaboury


 


<Prev in Thread] Current Thread [Next in Thread>
  • Summation problem, Isabelle Gaboury <=