I am having issues running my R code. I keep getting the error: Error in while (Diff > 1e-06) { : missing value where TRUE/FALSE needed
Here is the code I am using:
Dose with.tumor total.animals
1 0 3 50
2 188 6 50
3 375 6 50
4 750 12 50
X1=as.matrix(rep(1,4))
X2a=as.matrix(c(0,188,375,750))
X2=as.matrix(log(X2a))
X=cbind(X1,X2)
a=1
b=1
B=matrix(c(a,b),nrow=2,ncol=1,byrow=F)
Diff=1
while(Diff>.000001){
P=(1-exp(-exp(a+b*X)))^-1
ni=c(rep(50,4))
V=diag(4)
for(i in 1:4)
{V[i,i]=diag(ni[i]%*%P[i]%*%(1-P[i]))}
R=c(3,6,6,12)
S=matrix(data=1,nrow=4,ncol=1)
for (i in 1:4)
{S[i]=R[i]-ni[i]*P[i]}
new.B=B+solve(t(X)%*%V%*%X)%*%(t(X)%*%S)
Diff=max(abs(new.B-B))
B=new.B}
Any insight would be appreciated.