Skip to content

Instantly share code, notes, and snippets.

@pablogarciadiaz
Last active January 21, 2019 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pablogarciadiaz/0ea50ffd31bb33263572dcfbcd3658ff to your computer and use it in GitHub Desktop.
Save pablogarciadiaz/0ea50ffd31bb33263572dcfbcd3658ff to your computer and use it in GitHub Desktop.
#################################################################################################################################################
##### R script for producing Figure 3 of Garcia-Diaz et al. 'A guide to developing and using quantitative models in conservation management' ####
#################################################################################################################################################
### Define the number of values to simulate (1000 in this case)
sample.size<-1000
### Simulate 1000 values from a Poisson distibution with mean = 5
sim1<-rpois(sample.size, lambda=5)
### Produce 1000 values, with values spanning the same range as 'sim1'.
sim2<-c(rep(min(sim1), 150), rep(min(sim1)+2, 150), rep(5, 200), rep(5+2, 100), rep(10, 100), rep(max(sim1)-2, 100), rep(max(sim1), 200))
mean(sim2)
length(sim2)
### Plotting the histrograms in a multipanel figure
### Define the number and position of the two panels ('mfrow'), and the margins of the figures
par(mfrow=c(1, 2), mar=c(5, 7, 5, 6))
#### Histogram of the Poisson distributed values with custom figure specifications (refer to the R documentatoin and help for details)
hist(sim1, axes=FALSE, xlab="", ylab="", main="")
axis(1, at = round(seq(from=min(sim1), to=max(sim1), length.out=5), digits=0), cex.axis= 1.5, font=1, family='serif', las=1)
axis(2, at = c (0, 50, 100, 150, 200), cex.axis = 1.5, las=2, font=1, family='serif')
mtext("Frequency", side=2, line=4, cex=2, font=1, family='serif')
mtext("Poisson distribution", side=3,line=1, cex=3, font=1, family='serif')
box()
#### Histogram,with custom figure specifications, of the other 1000 values not following a distribution (refer to the R documentation and help for details)
hist(sim2, axes=FALSE, xlab="", ylab="", main="")
axis(1, at = round(seq(from=min(sim2), to=max(sim2), length.out=5), digits=0), cex.axis= 1.5, font=1, family='serif', las=1)
axis(2, at = c (0, 50, 100, 150, 200), cex.axis = 1.5, las=2, font=1, family='serif')
mtext("Frequency", side=2, line=4, cex=2, font=1, family='serif')
mtext("No probability distribution", side=3,line=1, cex=3, font=1, family='serif')
box()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment