I have a problem in this code when I want to compare the sum of x with s1 and sum y with s2 I got the NA. I storage the sum of x in xx and the sum of y in yy then compear that with s1 and s2 by using && operators why I got NA could someone help me to correct this problem. Thank you.
rm(list = ls())
options(scipen=999)
exactpois <- data.frame(X = numeric(0),
Y = numeric(0))
lambda=4
B1=2
B2=4
set.seed(0)
for(s1 in seq(from = 1.5, to = 7.5, by = 2))
{
for(s2 in seq(from = 1.5, to = 13.5, by = 4))
{
count=0
l=0
xx=0
yy=0
for (j in 1:100)
{
f = rpois(1,lambda)
if(f == 0)
{
count = count + 1
next
}
x = rexp(f,1/B1)
y = rexp(f,1/B2)
data_a1 <-exactpois[1:50,]
xx=sum(data_a1$X)
yy=sum(data_a1$Y)
if(xx== s1 && yy<= s2)
{
l = l + 1
}
if(xx< s1 && yy== s2)
{
l = l + 1
}
if(xx< s1 && yy< s2)
{
count=count+1
}
newrow <- data.frame(X = x,
Y = y)
exactpois <- rbind(exactpois, newrow)
}
p2=(count+l)/10
rho=cor(data_a1$X,data_a1$Y)
z=pbivnorm(s1,s2,rho)
print(paste0("s1 =",s1))
print(paste0("s2 =",s2))
print(paste0("The true p-value =",p2))
print(paste0("The Normal =",z))
}
}