Skip to content
Back to formatted view

Raw Message

Message-ID: <1321624347.22924.53.camel@milan>
Date: 2011-11-18T13:52:27Z
From: Milan Bouchet-Valat
Subject: number of items to replace is not a multiple of replacement length
In-Reply-To: <1321620329.73569.YahooMailNeo@web161015.mail.bf1.yahoo.com>

Le vendredi 18 novembre 2011 ? 04:45 -0800, Gyanendra Pokharel a ?crit :
> Hi all, following is my R -code and shows the error given below
> > n <- 100
> > k<-2
> > x1 <-c(1, 3);x2 <- c(2,5)
> > X <- matrix(c(0,0), nrow = 2, ncol = n)
> > for(i in 1:k)
> + X[i, ] <- mh1.epidemic(n,x1[i],x2[i])
> Error in X[i, ] <- mh1.epidemic(n,x1[i],x2[i]): 
>  number of items to replace is not a multiple of replacement length
> 
> > psi <-t(apply(X, c(1,2), cumsum))
> > for(i in 1:nrow(psi)){
> + psi[i,] <psi[i,]/(1:ncol(psi))
> + print(Gelman.Rubin(psi))
> + 
> + }
> Can some one suggest me what this error means and how could I fix it?
The message is relatively clear. ;-)

It means the number of elements in the mh1.epidemic(n,x1[i],x2[i])
vector isn't a multiple of the number of elements in X[i, ]. In the
standard case, you want these two vectors to be of the same length, and
there are too many or too few elements in mh1.epidemic(n,x1[i],x2[i]).

You can check that with by looking at:
length(mh1.epidemic(n,x1[i],x2[i]))
and
length(X[i, ])


Cheers