Following is my code, can some one help on the error at the bottom?

> mh<-function(iterations,alpha,beta){
+ data<-read.table("epidemic.txt",header = TRUE)
+ attach(data, warn.conflicts = F)
+     k<-97
+     d <- (sqrt((x-x[k])^2 + (y-y[k])^2))
+     p <- 1-exp(-alpha*d^(-beta))
+     p.alpha<-1 - exp(-3*d^(-beta))
+     p.beta <- 1 - exp(alpha*d^(-2))
+     iterations<-1000
+     mu.lambda <- c(0,0);s.lambda <- c(100,100)
+     prop.s <- c(0.1,0.1)
+     lambda <- matrix(nrow=iterations, ncol=2)
+     acc.prob<-0
+     current.lambda <- c(0,0)
+     for(t in 1:iterations){
+         prop.lambda <- rnorm(2,current.lambda,prop.s)
+         a <- p.beta/p.alpha
*(dnorm(prop.lambda,mu.lambda,s.lambda))*dnorm(current.lambda,mu.lambda,s.lambda)
+         accept <- min(1,a)
+         u<-runif(1)
+         if(u[t]<=accept[t]){
+             current.lambda <- prop.lambda
+             acc.prob <- acc.prob +1
+                 }
+         lambda[t,] <- current.lambda
+     }
+     lambda
+ }
> mh(1000,0,0)
Error in if (u[t] <= accept[t]) { : missing value where TRUE/FALSE needed

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to