Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions earlywarnings/R/generic_ews.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)]))
Expand Down Expand Up @@ -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)
}
}
5 changes: 3 additions & 2 deletions earlywarnings/R/sensitivity_ews.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -218,4 +219,4 @@ for (ti in 1:length(tw)){
out<-data.frame(Ktauestind)
rownames(out)<-tw
return(out)
}
}