I'm trying to run the next algorithm in R:
simulation <- function(n){
f <- function(x){.7*h(x)+.3*g(x)}
x <- vector("numeric", 2)
w <- vector("numeric", 2)
x0 <- c(3,3)
for(i in 0:n){
ifelse(i==0,w<-x0,w<-x) #After this line w=(3,3) (on the first iteration)
y <- rnorm(2, mean = w, sd = S1) #Also this line gives a non-zero value to y
alfa <- (f(y))/(f(w))
ifelse(runif(1)<alfa,x<-y,x<-w) //Here the variables y and w are a two dimension zero vector.
}
return(alfa[n])
}
I don't understand why at the second "ifelse" the vectors w and y are equal to (0,0). Maybe there is another way to initialize the vector x. But I don't get how the first "ifelse" works fine. Any suggestions would be great!