diff --git a/earlywarnings/R/generic_ews.R b/earlywarnings/R/generic_ews.R index 74692f6..8ce1b1b 100644 --- a/earlywarnings/R/generic_ews.R +++ b/earlywarnings/R/generic_ews.R @@ -48,7 +48,7 @@ # Author: Vasilis Dakos, January 2, 2012 -generic_ews<-function(timeseries,winsize=50,detrending=c("no","gaussian","linear","first-diff"),bandwidth=NULL,logtransform=FALSE,interpolate=FALSE,AR_n=FALSE,powerspectrum=FALSE){ +generic_ews<-function(timeseries,winsize=50,detrending=c("no","gaussian","linear","first-diff"),bandwidth=NULL,logtransform=FALSE,interpolate=FALSE,AR_n=FALSE,powerspectrum=FALSE, create.plots = FALSE){ require(lmtest) require(nortest) @@ -166,6 +166,7 @@ generic_ews<-function(timeseries,winsize=50,detrending=c("no","gaussian","linear # Plotting # Generic Early-Warnings + if(create.plots == T){ dev.new() par(mar=(c(0,2,0,1)+0),oma=c(7,2,3,1),mfrow=c(5,2)) plot(timeindex,Y,type="l",ylab="",xlab="",xaxt="n",las=1,xlim=c(timeindex[1],timeindex[length(timeindex)])) @@ -239,9 +240,10 @@ generic_ews<-function(timeseries,winsize=50,detrending=c("no","gaussian","linear contour(x=(spectfft$freq[2:length(spectfft$freq)]),y=(seq(1,ncol (nSPECT),by=1)),log(nSPECT[2:length(spectfft$freq),]),add=TRUE) mtext("Power spectrum within rolling windows",side=3,line=0.2, outer=TRUE) } + } # End plotting # Output out<-data.frame(timeindex[mw:length(nsmY)],nARR,nSD,nSK,nKURT,nCV,nRETURNRATE,nDENSITYRATIO,nACF) colnames(out)<-c("timeindex","ar1","sd","sk","kurt","cv","returnrate","densratio","acf1") return(out) - } \ No newline at end of file + } diff --git a/earlywarnings/R/sensitivity_ews.R b/earlywarnings/R/sensitivity_ews.R index 501a172..69d4804 100644 --- a/earlywarnings/R/sensitivity_ews.R +++ b/earlywarnings/R/sensitivity_ews.R @@ -49,7 +49,8 @@ sensitivity_ews<-function(timeseries,indicator=c("ar1","sd","acf1","sk","kurt"," require(moments) require(fields) -#timeseries<-ts(timeseries) #strict data-types the input data as tseries object for use in later steps + # Ensure obj timeseries is of class "timeseries" + if(!is.ts(timeseries)) timeseries <- ts(timeseries) #strict data-types the input data as tseries object for use in later steps timeseries<-data.matrix(timeseries) if (dim(timeseries)[2]==1){ Y=timeseries @@ -218,4 +219,4 @@ for (ti in 1:length(tw)){ out<-data.frame(Ktauestind) rownames(out)<-tw return(out) -} \ No newline at end of file +}