In this assignment you will examine two (relatively) simple one-dimensional maps based on the models implemented in a spreadsheet. Just copy the linked Google Sheet to a new on-line Google Sheet, or, save it to your computer and use your favourite spreadsheet software (e.g., Excel, Numbers) to explore the behaviour of the model.
We will start with the Linear Map and then proceed to the slightly more complicated Logistic Map (aka Quadratic map). You can also use R
to model the dynamical processes, but for now we will assume you’ll use the spreadsheets linked to in the assignments.
Equation (1.1) is the ordinary difference equation (ODE) discussed in the course book and is called the Linear Map:
\[\begin{equation} Y_{i+1} = Y_{i=0} + r*Y_i \tag{1.1} \end{equation}\]
In these exercises you will simulate time series produced by the change process in equation (1.1) for different parameter settings of the growth-rate parameter \(r\) (the control parameter) and the initial conditions \(Y_0\). Simulation is obviously different from a statistical analysis in which parameters are estimated from a data set. The goal of these assignments is to get a feeling for what a dynamical model is, and in what way it is different from a linear statistical regression model like GLM.
If you want to modify the spreadsheets and use them as a template for other assignments, be sure to check the following settings:
$
symbol fixes rows and columns when it used in a formula in your preferred spreadsheet program.
First study the behaviour of the Linear map in a spreadsheet and if you want to, try to implement it in R
.
r
in cell A5
is the control parameter, it currently has the value \(1.08\) in cellB5
.A6
is the initial value at \(i=0\). It has the value \(0.1\) in cell B6
.A
column also contains \(Y_i\), the output of the linear map.
A10
, in the formula bar you can see that this cell simply refers to the initial value given in B6
. So, this will be the first input value to the iterative process.A11
, this corresponds to time step \(i=1\). In the formula bar you can see the very simple implementation of the linear map which calculates the value at \(i=1\) from the initial value at \(i=0\) and the value of \(r\) in B5
. The value of cell A11
is the product of the value in cell B5
(parameter r
) and the value of cell A10
(\(Y_{i=0}\)).A reminder of what the model represents:
r
(the growth rate)Y
If you make a copy of the Google Sheet you should be able to edit the cells. If this does not work, download the spreadsheet from GitHub
B5
and B6
and you will see an immediate change in the graph. To study model behaviour, try the following growth parameters:
The labels assigned to behavioural modes that are clearly qualitatively distinct from one another, are know as the order parameter. The order parameter will change its value to indicate the system has transitioned to a new behavioural regime. Such changes often occur suddenly with gradual changes in the control parameter.
For example, the (most familiar) phases that describe matter are an order parameter (solid, liquid, gas and plasma). We know water will transition from a liquid state to a gas state if we increase the control parameter beyond a certain point (e.g. temperature rises above \(100^\circ\text{C}\)).
Other names you might encounter that refer to the change of the label of an order parameter:
B6
to \(10\) and compare to \(0.1\) (if you want to directly compare different settings, just create a new copy of the sheet)B5
the following values:
R
to simulate the Linear MapThe best (and easiest) way to simulate these simple models in R
is to create a function, which takes as input arguments the parameters (\(Y_0\), \(r\)) and a variable indicating the length of the time series.
For the Linear Map you could use this template (also see the notes in the course book):
# TEMPLATE
# Modify this function
linearMap <- function(Y0 = 0, r = 1, N = 100){
# Y0, r and N are arguments to this function, they have been given default values
# When you call the function you can pass different values to these arguments
# Initialize Y as vector of Y0, followed by N-1 empty slots (NA).
Y <- c(Y0, rep(NA,N-1))
# Then, you need create the iteration using a for(... in ...){...} loop
for(i in 1:(N-1)){
Y[i+1] <- # !!Implement the code for the linear or Quadratic map here!!
}
return(Y)
}
R
and implement the Linear Map by looking at the formula, or the spreadsheet.linearMap
# Linear Map
linearMap <- function(Y0 = 0, r = 1, N = 100){
# Initialize Y as vector of Y0, followed by N-1 empty slots (NA).
Y <- c(Y0, rep(NA,N-1))
# Then, you need create the iteration
for(i in 1:(N-1)){
Y[i+1] <- r * Y[i] # The linear difference equation
}
return(Y)
}
Creating a time series plot is easy if the function linearMap
returns the time series as a numeric vector. You could just use:
plot(linearMap(Y0=0.1,r=1.08,N=100), type = "l")
But perhaps better to first save the output of the function and then plot it:
Y <- linearMap(Y0=0.1,r=1.08,N=100)
plot(Y, type = "l")
R
in the course book
plot(linearMap(Y0=0.1,r=1.08,N=100), type = "l")
R
has specialized objects to represent time series, and functions and packages for time series analysis. These are especially convenient for plotting time and date information on the X-axis. See the examples on plotting time series in R
in Chapter 3.
The Logistic Map takes the following functional form:
\[\begin{equation} Y_{i+1} = r*Y_i*(1-Y_i) \tag{1.2} \end{equation}\]
A
column contains \(Y_i\), the output of the Logistic map. With \(r=1.3\) the behaviour looks a lot like an S-curve, a logistic function.A10
, in the formula bar you can see this refers to the initial value B6
.A11
, in the formula bar you can see the very simple implementation of the Logistic map.A11
(\(Y_{i=1}\)) is calculated by multiplying the value of cell B5
(parameter r
) with the value of cell A10
(the current value \(Y_i\), in this case \(Y_{i=0}\)). The only difference is we are also multiplying by \((1-Y_i)\).r
controls growth, what could be the function of \((1-Y_t)\)?
To study the behaviour of the Logistic Map you can start changing the values in B5
.
A10
to B309
) and create a scatter-plot (no lines, just points).
The plot you just produced is a so called return plot, in which you have plotted \(Y_{i+1}\) against \(Y_i\). We shifted the time series by 1 time step, which is why this is also called a lag 1 plot.
Can you explain the pattern you see (a ‘parabola’) by looking closely at the functional form of the Logistic Map? (hint: another name for this equation is the Quadratic Map).
If you change the control parameter to a lower value the return plot will seem to display a shape that is no longer a parabola, but this is not the case, all values produced by by the Logistic Map must be a point on a parabola. Some parameter settings just do not produce enought different points for the parabola to show itself in the return plot.The return plot is an important tool for getting a ‘first impression’ of the nature of the dynamic process that generated the observed values:
A10
to B309
) and create a scatter-plot (no lines, just points).
Why a parabola? Think about what the iterative process represents: It is the rule that changes the value of Y at one point in time, into a value at the next point in time. The only relationship that can exist between two points is the difference equation… work out the brackets, what kind of equation is this?
For the linear map, the same thing holds, what kind of equation is the linear map? Now you can probably also deduce what the return maps of a cubic and quartic equation look like… try it!
Go to the following GoogleSheet and download or copy it.
D6
of \(0.01\).By making the discrepancy smaller the two time series will become more similar.
This sheet displays the extreme sensitivity to changes in initial conditions displayed by the Logistic Map for specific parameter settings. This specific phenomenon is more commonly referred to as The Butterfly Effect. It is a characteristic of a very interesting and rather mysterious behaviour displayed by deterministic dynamical equations known as deterministic chaos.
However, perhaps even more important to notice here, is the fact that a wide range of qualitatively different behaviourial modes can be understood as originating from one and the same, rather simple, dynamical system. The different behavioural modes were observed for different values of a control parameter, which, in real-world models, often represents an observable (physical) quantity (e.g. temperature, available resources, chemical gradient, etc.)
The Logistic Map is the simplest nontrivial model that can display deterministic chaos.R
to simulate the Logistic MapThe best (and easiest) way to simulate the discrete time models is to create a function which takes as input the parameters (\(Y_0\), \(r\)) and a variable indicating the length of the time series.
To model the Logistic Map, use this template:
# TEMPLATE
# Modify this function
logisticMap <- function(Y0 = 0.01, r = 1, N = 100){
# Initialize Y as vector of Y0, followed by N-1 empty slots (NA).
Y <- c(Y0, rep(NA,N-1))
# Then, you need create the iteratation
for(i in 1:(N-1)){
Y[i+1] <- # !!Implement the linear or logistic map here!!
}
return(Y)
}
logisticMap
# Logistic Map
logisticMap <- function(Y0 = 0.01, r = 1, N = 100){
# Initialize Y as vector of Y0, followed by N-1 empty slots (NA).
Y <- c(Y0, rep(NA,N-1))
# Then, you need create the iteratation
for(i in 1:(N-1)){
Y[i+1] <- r * Y[i] * (1 - Y[i]) # The quadratic difference equation
}
return(Y)
}
Creating a time series plot is easy if the function linearMap
returns the time series as a numeric vector. You could just use:
plot(logisticMap(Y0=0.01,r=1.9,N=100), type = "l")
library(plyr)
rs <- c(0.9,1.9,2.9,3.3,3.52,3.9)
op<-par(mfrow=c(2,3))
l_ply(rs,function(r) plot(logisticMap(r=r),ylab = paste("r =",r) ,type = "l"))
par(op)
lags <- c(1,2,3,4)
N <- 1000
op <- par(mfrow = c(2,2), pty = "s")
l_ply(lags, function(l) {plot(dplyr::lag(logisticMap(r=4,N=N),l), logisticMap(r=4,N=N), pch = ".", xlim = c(0,1), ylim = c(0,1), xlab = "Y(t)", ylab = "Y(t+1)", main = paste("lag =",l))})
par(op)
casnet
has some built in functions called ‘toy models’ you can use to generate the models in these assignments:
* growth_ac()
* growth_ac_cond()