Correction in error
Hi: In your function call, x[1, 1] = theta = 0. In the first line of the loop, your rbinom() call works out to be x[2, 1] <- rbinom(x[1, 3], 1, x[1, 1]) <=> rbinom(10, 1, 0) That likely accounts for the error message: Error in x[t, 1] <- rbinom(x[t - 1, 3], 1, x[t - 1, 1]) : replacement has length zero HTH, Dennis On Mon, Nov 7, 2011 at 12:10 PM, Gyanendra Pokharel
<gyanendra.pokharel at gmail.com> wrote:
Hello R community, following is my code and it shows error, can some one
fix this error and explain why this occurs?
gibbs <-function(m,n, theta = 0, lambda = 1){
? ?alpha <- 1.5
? ?beta <- 1.5
? ?gamma <- 1.5
? ?x<- array(0,c(m+1, 3))
? ?x[1,1] <- theta
? ?x[1,2] <- lambda
? ?x[1,3]<- n
? ?for(t in 2:m+1){
? ? ? ?x[t,1] <- rbinom(x[t-1,3], 1, x[t-1,1])
? ? ? ?x[t,2]<-rbeta(m, x[t-1,1] + alpha, tx[t-1,3] - x[t-1,1] + beta)
? ? ? ?x[t,3] <- rpois(x[t-1,3] - x[t-1,1],(1 - x[t-1,2])*gamma)
? ?}
? ?x
}
gibbs(100, 10)
Gyn
? ? ? ?[[alternative HTML version deleted]]
______________________________________________ R-help at 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.