I'm trying to run this code with R, but it gives me error:
rm(list = ls())
gibbs <- function (n, k, y0, m, alpha, beta){
z <- array (0,n)
for (i in 1 : n) {
x <- array (0,k)
y <- array (0, k+1)
y[1] <- y0
for (j in 1 : k) {
x[j] <- rbinom (1, m, y[j])
y[j+1] <- rbeta (1, x[j]+alpha, m-x[j]beta)
}
z[i]=x[k]
}
print (mean(z))
print (var(z))
}
gibbs(1000, 50, 0.5, 3, 8.5, 4.5)
What exactly is wrong with it? here's the error it gives:
source("E:\Program Files\R\test.R")
Error in source("E:\Program Files\R\test.R") :
E:Program FilesR est.R:11:39: unexpected symbol
10: x[j] <- rbinom (1, m, y[j])
11: y[j+1] <- rbeta (1, x[j]+alpha, m-x[j]beta
Thanks in Advance
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…