Logistic Growth Model with R

Figure 1. Example.

Figure 1. This graph was produced by the R script provided below.

Models like the discrete logistic growth model are famous for producing complex behaviour from simple equations. You can cut and paste the R script provided below onto the R command line, to produce a graph like the one given Figure 1. Try varying the parameter r to see what happens; for example, to set the parameter r to 1.5, enter the following:

> LogisticGrowthExample( r = 1.5 );

References

Logistic Equation. Wolfram Mathworld: mathworld.wolfram.com/LogisticEquation.html
Logistic Map. Wikipedia: en.wikipedia.org/wiki/Logistic_map

R Script

#NOTE: You will need to replace the right and left quotation marks with
#straight quotes before running this script in R.

LogisticGrowthExample <- function(r = 3.7, N0 = 0.1, steps = 100){
#Implemention by Allan Roberts, March 2013.

N <- numeric(steps);
N[1] <- N0; #the initial population

Next <- function(N) {N <-  N + (r-1)*N*(1-N)};
for (i in 2:(steps)) N[i] <- Next(N[i-1]);

plot(N~seq(0,(steps-1)),type=”l”,xlab=quote(time), ylim=c(0,1.5), las = 1 );
title(main=”Discrete Logistic Growth Model”, font.main=1, cex.main=2);
text(80,0.2,paste(“r =”,as.character(r) ), adj=c(0,0.5));
text(80,0.1, expression(“N”[0]), adj=c(0,0.5 ) );
text(84.14,0.1, paste(” =”,as.character(N[1])), adj=c(0,0.5) );
}

LogisticGrowthExample( );

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s