220 likes | 386 Views
Early Warning Signals Workshop. Chris Boulton C.A.Boulton@exeter.ac.uk. Overview. Creating a time series which exhibits a tipping point. Testing generic indicators on this time series (AR(1 ) and variance). Using the ‘Early Warning Signals’ toolbox created by Vasilis Dakos. Setting Up R.
E N D
Early Warning Signals Workshop Chris Boulton C.A.Boulton@exeter.ac.uk
Overview • Creating a time series which exhibits a tipping point. • Testing generic indicators on this time series (AR(1) and variance). • Using the ‘Early Warning Signals’ toolbox created by VasilisDakos.
Setting Up R • Once R is open, you need to open a new script file • Click ‘File’ -> ‘New Script’ • This should open a new window where you can create a script full of commands.
Creating the Tipping Point • Change in x (time series) is dependent on a potential U of the system. • This U contains m which changes over time. • When m, reaches critical value μ, system reaches tipping point.
Creating the Tipping Point • In R, you can use either ‘=‘ or ‘<-’ to assign values to variables. • Time runs from 1 to 1000 in steps of 2. • This sets up the value for μand m which is going to reach the critical value at time t=900.
Creating the Tipping Point • Highlight the lines typed out in the script and press ‘Crtl+R’ to copy and paste them into the console. • In the console you can type a variable out to see it’s value.
Creating the Tipping Point • We need to create an array to store time series x. • These lines repeat ‘NA’ a number of times equal to the length of t (500). • Then assigns the first value to ‘-1’ as this is near the equilibrium of the state which will lose stability.
Creating the Tipping Point • Now we loop through using a forward Euler scheme, with a time step of ½ (not to be confused with jumping up in steps of 2 when creating t. • Add a noise term on, rnorm is a random-normal value with mean=0 and sd=1. • Also note we are using –U’ not U.
Creating the Tipping Point • Now we have a time series for x which we can plot it
Preparing for Using EWS • Now we have a time series which exhibits a tipping point and we want to use EWS on it. • We only want to use information prior to the tipping point in our analysis. • Can work out where tipping point is from graph and then checking values individually.
Preparing for Using EWS • We cut and check our time series now doesn’t include a tip. • Note that x[1:a] will select values 1 to ‘a’ of x.
Preparing for Using EWS • We want to know the length l of our time series for the analysis. • To start with we will chose a window length (WL) equal to half this (floor function rounds number down) • We also use a Kernal smoother with a bandwidth (BW) equal to 30.
Using AR(1) Coefficient Estimation • We need to detrend the time series with the Kernal smoother (ksmooth). • ksmooth takes x and y values, a bandwidth and points to calculate the smoothing function on (supplied in this order in the code). • We also need to create an array to store our AR(1) estimation over time. This will have length equal to l-wl+1.
Using AR(1) Coefficient Estimation • Now we use the sliding window to test AR(1) over time. • We do the analysis in a for loop which moves the sliding window up once each time. • ar.ols fits a model of the form x(t+1) = a*x(t) + e. • ‘a’ is an object called ar embedded in arfit which is found with arfit$ar.
Plotting AR(1) • We can now plot our AR(1) coefficient estimation. • Plotting at the end of your window length makes sense for early warning. • Knowing the plotting commands is not essential.
Using Variance • We can also use the same for loop to look how variance changes on a sliding window length. • This is more simple as we do not need to use the ar.ols model fit before. It also has less inputs (i.e. no ‘aic=FALSE’ or ‘order.max=1’).
Plotting AR(1) and Variance • We can now plot both AR(1) and variance indicators together.
Kendall Tau Correlation Coefficient • We now want to know how strong the trends in our indicators are. • This is done with Kendall Tau Correlation Coefficient which measures tendency. • We can load a package which calculates this for us called ‘Kendall’ (may need to use install.packages line).
Kendall Tau Correlation Coefficient • Tau measures the number of concordant pairs (both x and y greater or both less than their previous values) against the number of discordant (where this does not hold), over all pairs. • We treat one variable as time which is always increasing to measure tendency.
Early Warning Signals Toolbox (Dakos) • The early warning signals toolbox does these calculations amongst others. • Like ‘Kendall’, we also need to install it. • It has a lot of dependencies which will also download at the same time. • Typing ‘??earlywarnings’ will give you a list of the functions included in the package.
Early Warning Signals Toolbox • We will be using the ‘generic_ews’ function. • Inputs can be found by typing ‘?generic_ews’. • The example here uses the same time series as before, with the same window length and similar detrending (window length bandwidth has to be expressed as a percentage).
Early Warning Signals Toolbox • Now we have an object called ‘ews’ which contains all values of the indicators at any time so you’re free to plot them or use them how you wish. • You also get a plot of them all as an output. • If you’re feeling brave, type ‘generic_ews’ to see how each indicator is calculated.