[R] how to increase speed for function?/time efficiency of below function
R. Michael Weylandt
michael.weylandt at gmail.com
Thu Mar 29 16:02:10 CEST 2012
It's rather inappropriate to use someone else's code and not to give
them credit:
http://www.mirrorservice.org/sites/lib.stat.cmu.edu/general/tsa2/Rcode/itall.R
Michael
On Thu, Mar 29, 2012 at 7:54 AM, sagarnikam123 <sagarnikam123 at gmail.com> wrote:
> i am using sarima() function as below
> ___________________________________________________________________________________________
> sarima=function(data,p,d,q,P=0,D=0,Q=0,S=-1,tol=.001){
> n=length(data)
> constant=1:n
> xmean=matrix(1,n,1)
> if (d>0 & D>0)
> fitit=arima(data, order=c(p,d,q), seasonal=list(order=c(P,D,Q),
> period=S),
> optim.control=list(trace=1,REPORT=1,reltol=tol))
> if (d>0 & D==0)
> fitit=arima(data, order=c(p,d,q), seasonal=list(order=c(P,D,Q),
> period=S),
> xreg=constant,include.mean=F,
> optim.control=list(trace=1,REPORT=1,reltol=tol))
> if (d==0 & D==0)
> fitit=arima(data, order=c(p,d,q), seasonal=list(order=c(P,D,Q),
> period=S),
> xreg=xmean,include.mean=F,
> optim.control=list(trace=1,REPORT=1,reltol=tol))
> if (d==0 & D>0)
> fitit=arima(data, order=c(p,d,q), seasonal=list(order=c(P,D,Q),
> period=S),
> xreg=constant,include.mean=F,
> optim.control=list(trace=1,REPORT=1,reltol=tol))
> if (S < 0) goof=20 else goof=3*S
> tsdiag(fitit,gof.lag=goof)
> k=length(fitit$coef)
> BIC=log(fitit$sigma2)+(k*log(n)/n)
> AICc=log(fitit$sigma2)+((n+k)/(n-k-2))
> AIC=log(fitit$sigma2)+((n+2*k)/n)
> innov<<-fitit$resid
> list(fit=fitit, AIC=AIC, AICc=AICc, BIC=BIC)
> }
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> it takes 1-2 minutes for one time series,i have 4500 times series data,how
> to increase speed/time of execution
> is there any concept of threading/parallel computing in R
> Please..Please.....can u suggest me code for above function,which will be
> time efficient,i am frustrated with time consumption & reading material on
> parallel computing, but i cant understand it properly
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/how-to-increase-speed-for-function-time-efficiency-of-below-function-tp4515201p4515201.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
More information about the R-help
mailing list