ap88ma
2011-Jul-29 19:39 UTC
[R] forecasting- number of items to replace is not a multiple of replacement length error
Hi all I write below code for simulation and forecasting a stochastic mortality model with parameters kappa2(t) and gamma3(t-x) where t is the time and x the age but I got this message:"Error in G3.sim[, k] = G3.aug : number of items to replace is not a multiple of replacement length" Any suggestion ? a=arima(gamma3,c(1,1,0)) D2=diff(kappa2) mu2=mean(D2) nD2=length(D2) sigma2=sum((D2-mu2)^2)/nD2 sigma2=sqrt(sigma2) Dg=diff(gamma3) mug=mean(Dg) nDg=length(Dg) sigmag=sum((Dg-mug)^2)/nDg sigmag=sqrt(sigmag) t0=1 t1=length(y) t2=t1+tmax y.aug=(t0:t2)+y[1]-1 lx=length(x) c=(y[1]-x[lx]):(y[t1]-x[1]) ct1=length(c) ct2=ct1+tmax c.aug=(y.aug[1]-x[lx]):(y.aug[t1]-x[lx]) K2.sim=array(0,c(length(y.aug),N)) G3.sim=array(0,c(length(c.aug),N)) mtx.sim.array=array(0,c(length(y.aug),lx,N)) #mtx=years x ages x simulations for(k in 1:N){ K2.aug=(t0:t2)*0 K2.aug[t0:t1]=kappa2 K2.aug[(t1+1):t2]=K2.aug[t1]+cumsum(rnorm(tmax,mu2,sigma2)) K2.sim[,k]=K2.aug G3.aug=0 G3.aug[t0:ct1]=gamma3 G3.aug[(ct1+1):ct2]=G3.aug[ct1]+mug +(a$coef)*(G3.aug[ct1]-G3.aug[ct1-1]-mug)+cumsum(rnorm(tmax,0,sigmag)) G3.sim[,k]=G3.aug for(i in 1:lx){ mtx.sim.array[,i,k]=exp(beta1[i]+beta2[i]*K2.aug+G3.aug) } } list(x=x,y=y,y.aug=y.aug,dtx=dtx,etx=etx,wtx=wtx,beta1=beta1,beta2=beta2, kappa2=K2.sim,gamma3=G3.sim,mtx=mtx.sim.array) } Thanks for your time and your help -- View this message in context: http://r.789695.n4.nabble.com/forecasting-number-of-items-to-replace-is-not-a-multiple-of-replacement-length-error-tp3705100p3705100.html Sent from the R help mailing list archive at Nabble.com.