# [R] Help with debugging

Sundar Dorai-Raj sundar.dorai-raj at PDF.COM
Fri Apr 23 00:06:53 CEST 2004

```
Phillip Good wrote:

> Once the IF triggers in the following program, it just won't turn off:
>
> #Get p-value from permutation distribution
> N = 64
> cnt = 0
> for (i in 1:N){
>  pdata = sample (data)
>  statp=F1(size,pdata,gmean,samps)
>  if (stat0 <= statp ){
>           cnt=cnt+1
>           print(i)
>           print (statb)
>            }
>  }
> cnt/N
> #print statements are soley for debugging purposes
>
>
> #Here are the function code and test data needed to run the program:
> F1=function(size,data, gmean, samps){
> stat=0
> start=0
> end=0
> for (i in 1:samps){
>      end=end+size[i]
>      term=mean(data[start:end])
>      stat= stat +abs(term-gmean)
>      start=end+1
>      }
> list(stat=stat)
> }
>
> samps = 4
> size = c(4,4,3,5)
> data = rnorm(16, 2*rbinom(16,1, .4))
> data = data +c(2,2,2,2, 0,0,0,0, 0,0,0, 0,0,0,0,0)
> gmean = mean(data)
> stat0=F1(size,data,gmean,samps)
>

stat0 is a list, so the comparison in the "if" statement should be

if(stat0\$stat <= statp\$stat)

Also, you should be more clear about the statement, "it just won't turn
off...". I have no idea what that means.

--sundar

N = 64
cnt = 0
for (i in 1:N){
pdata = sample (data)
statp=F1(size,pdata,gmean,samps)
if (stat0\$stat <= statp\$stat ){
cnt=cnt+1
print(i)
print (statp) # you had "statb", which I'm assuming was a typo
}
}
cnt/N

```