Problem 1

Make a plot with one column and two rows. On the top row, make a histogram of number of survivors across all experiements.On the bottom row, make a plot of the expected probabilities for a binomial distribution with n=10 and p=mean proportion of survivors across all experiements.

First, calculate mean number of surivors across all experiments.

meanSurvivors<-mean(Survival)

Mean number of survivors equals 1.383232.

#find expected binomial distribution
expectedSurvivalbinom<-dbinom(Survival, size=10, prob=0.138323)
#Plot histogram of survival and expected probabilities for a binomial distribution
par(mfrow=c(2,1))
discrete.hist(Survival, freq=TRUE, xlab="Number of Survivors", main="number of survivors across all experiments")
plot(Survival,expectedSurvivalbinom, xlab="Number of Survivors",ylab="Expected Probability")

Histogram of observed number of survivors shows in most trials, there were 0 survivors.But expected probabilities for a binomial distribution says greatest probability is for 1 survivor per trial.

what is the variance of the binomial distribution? Use the formula variance=p*(1-p)

#var=p*(1-P)
binomvar<-0.138323*(1-0.138323)
binomvar
## [1] 0.1191897
#variance of the binomial distribution is 0.1191897

Variance of the binomial distribution is 0.1191897, variance from the observed data is 3.065598. Why is variance in the observed data larger than predicted variance from binomial distribution? Binomial uses the same probability of success for every trial, so there is less variance from trial to trial. But in the observed data set there are factors of region, population, sex, etc. that could make it so the actual probability of survival is different for each fly and thus each trial.

Problem 2

Use curve() to show how the logistic curve changes as each parameter (a and b) varies from positive to negative. Vary a over a number of values (positive to negative) and see how function changes.

#define function
eq=function(x){(exp(a+b*x))/(1+(exp(a+b*x)))}
#define 8 values of a
a.values=c(-4,-3,-2,-1,1,2,3,4)
a.colors=c('red','orange','darkgreen','green','blue', 'dodgerblue','purple','violet','hotpink')
#plot 1 plot
par(mfrow=c(1,1))
#use a for loop to draw a curve for each a value while holding b constant at 1
for(i in 1:length(a.values)){
  if(i==1)add.the.curve=FALSE
  if(i>1)add.the.curve=TRUE
  a=a.values[i]
  b=1
  curve(eq, from=-10, to=10,col=a.colors[i], main="logistic curve",lwd=2, ylim=c(0,1), add=add.the.curve)
}
legend('right',lty=1, col=a.colors, legend=a.values, cex=1)

#define 8 values of b to look at
b.values=c(-4,-3,-2,-1,1,2,3,4)
b.colors=c('red','orange','darkgreen','green','blue', 'dodgerblue','purple','violet','hotpink')
#use a for loop to draw a curve for each b value while holding a constant at 1
for(i in 1:length(b.values)){
  if(i==1)add.the.curve=FALSE
  if(i>1)add.the.curve=TRUE
  b=b.values[i]
  a=1
  curve(eq, from=-5, to=5,col=b.colors[i], main="logistic curve",lwd=2, ylim=c(0,1), add=add.the.curve)
}
legend('right',lty=1, col=b.colors, legend=b.values, cex=1)

Problem 3

plot a type II functional response, f(R)=aR/1+ahR; where h=handling time, a=attack rate, R=#caribou

First, plot variable attack rate with a constant handling time.

caribou.eq=function(x){(a*x)/(1+(a*h*x))}

#set a, attack rate values
attack.values=c(0.1,0.2,0.3,0.4)
attack.colors=c('red','blue','green','black')
#varying attack rates...constant h
for(i in 1:length(attack.values)){
  if(i==1)add.the.curve=FALSE
  if(i>1)add.the.curve=TRUE
  a=attack.values[i]
  h=1
  curve(caribou.eq, from=0, to=300,col=attack.colors[i] ,lwd=2, ylim=c(0,1), main="Variable Attack Rate", xlab="Number of Caribou", ylab="Caribou Killed per Wolf",  add=add.the.curve)
}
legend('bottomright',lty=1, col=attack.colors, legend=attack.values, cex=1)

When prey density is very low,a greater attack rate will result in more caribou killed. At a higher prey density, the number of caribou killed per wolf is all the same regardless of attack rate.

Next, plot variable handling times with a constant attack rate.

#varying handling times, constant attack rates
#set h, handling time values 
handling.values=c(1,2,3,4)
handling.colors=c('red','blue','green','black')
for(i in 1:length(handling.values)){
  if(i==1)add.the.curve=FALSE
  if(i>1)add.the.curve=TRUE
  a=0.1
  h=handling.values[i]
  curve(caribou.eq, from=0, to=300,col=handling.colors[i] ,lwd=2, ylim=c(0,1), main="Variable Handling Time", xlab="Number of Caribou", ylab="Caribou Killed per Wolf",add=add.the.curve)
}
legend('bottomright',lty=1, col=handling.colors, legend=handling.values, cex=0.8)

Changing attack rates changes the rate at which you hit the saturation point (maximum number of caribou killed per wolf). Changing handling times changes the maximum number of caribou killed per wolf that is possible (changes asymptotes). So it makes more sense at a low density of caribou to increase attack rates instead of decreasing handling time.