require(knitr) require(formatR) require(dplyr) options(width=200) knitr::opts_chunk$set(cache=FALSE,prompt=FALSE,comment=">",message=FALSE,echo=TRUE,warning=FALSE,tidy=TRUE,strip.white=TRUE,size="small", fig.align = "center",fig.show='hold')
In this assignment you will build two (relatively) simple one-dimensional maps in Excel and look at their behaviour and properties. We start with the Linear Map and then proceed to the slightly more complicated Logistic Map (aka Quadratic map). If your are experienced in R
or Matlab
you can try to code the models following the instructions at the end of this document.
Before you begin, be sure to check the following settings:
$
symbol fixes rows and columns when it used in a formula in your preferred spreadsheet program. The ordinary difference equation discussed in the lecture (see lecture notes) is called the Linear Map:
$$ Y_{t+1} = Y_{t=0} + r*Y_t $$
In these excersises you will simulate time series produced by this change process for different parameter settings of the growth-rate parameter $r$ (the control parameter) and the initial conditions $Y_0$. This is different from a statistical analysis in which parameters are estimated from a data set. The goal of the assignments is to get a feeling for what a dynamical model is, and how it is different from a linear statistical regression model like GLM.
r
in cell A5
. This is the control parameter. It receives the value $1.08$ in cellB5
.A6
. This is the initial value. It receives the value $0.1$ in cell B6
. A10
. This cell marks time $t=0$.=$B$6
. The =
means that (in principle) there is a 'calculation' going on (a function is applied). The $
determines that column ($B
) as well as the row ($6
) keep the same value (i.e., constant) for each time step.=$B$5*A10
in cell A11
.A11
(i.e. $Y_{t=1}$) will be calculated by multiplying the value of cell B5
(parameter r
) with the value of cell A10
(previous value, here: $Y_{t=0}$). If everything is all right, cell A11
now shows the value $0.108$.A12
.r
.100
further steps. Instead of typing everything over and over again, copy-paste the whole thing.Most spreadsheet programs will automatically adjust the formula by advancing each row or column number that aren't fixed by $
.A12
all the way from A13
to A110
(keep the SHIFT
button pressed to select all cells). You have just simulated a time series based on a theoretical change process!
A10
to A110
Create a line graph (Insert
, 2D-line, Scatter). This will show you the graph. (There are otherways to do this, by the way, which work just as well.) You can play with the setting to make the best suitable view, like rescaling the axes.
+ $a = -1.08$ + $a = 1,08$ + $a = 1$ + $a = -1$
B6
to $10$. Subsequently give the growth parameter in cell B5
the following values $0.95$ and $–0.95$.The Logistic Map has the following form:
$$ Y_{t+1} = rY_t(1-Y_t) $$
To get started, copy the spreadsheet from the previous assignment to a new sheet. The parameters are the same as for the Linear Map, there has to be an initial value $Y_{t=0}$ (no longer explicit as a constant in the equation) and the control parameter $r$. What will have to change is
A6
).$
must be used, and what must change on every iterative step (variable $Y_t$).To study the behavior of the Logistic Map you can start playing around with the values for the parameters and the initial values in cells B5
and B6
.
Be sure to try the following settings for $r$:
Set $r$ at $4.0$:
A10
to A310
(300 steps)A10:A310
to B9:B309
(i.e., move it one cell to the right, and one cell up)A10
to B309
!) and make a scatter-plotThe plot you just produced is a so called return plot, in which you have plotted $Y_{t+1}$ against $Y_t$.
A5
).The meaning and use of this plot was discussed in the next session
R
or Matlab
to do the exercises.The best (and easiest) way to simulate these simple 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.
For example for the Linear Map:
# In R linearMap <- function(Y0 = 0, r = 1, N = 100){ Y <- c(Y0, rep(NA,N-1)) for(t in 1:N){ Y[i+1] <- # Implement the function here } return(Y) } # In Matlab function linearMap(Y0,r,N) # Implement the function here end
Creating the time series graphs and the return plot should be easy if the function linearMap
returns the time series. Both R
and Matlab
have a plot()
function you can call.[^tseries]
[^tseries]: Both R
and Matlab
have specialized objects to represent timeseries, and functions and packages for timeseries analysis. They are especially convenient for plotting time and date information on the X-axis. See Mathematics of Change 1 - SOLUTIONS
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.