#========================================================= # Figure 15.1.R. # R script to draw a scatterplot of sustainable yield vs. # harvesting effort for shrimp data from the Gulf of Mexico, # with parabolic yield-effort curve fitted and superimposed. #========================================================= #--------------------------------------------------------- # 1. Read and plot the data. # (a data file named shrimp_yield_effort_data.txt is assumed # to be in the working directory of R) #--------------------------------------------------------- df=read.table("shrimp_yield_effort_data.txt",header=TRUE) attach(df) plot(effort,yield,type="p",xlab="harvest effort",ylab="sustainable yield") #--------------------------------------------------------- # 2. Fit parabolic yield-effort curve with least squares. #--------------------------------------------------------- X=cbind(effort,effort^2) # First column of matrix X is effort. # Second column is effort squared. b=solve(t(X)%*%X,t(X)%*%yield) # Least squares solution. h=b[1,] # Coefficient of effort. g=b[2,] # Coefficient of effort squared. #--------------------------------------------------------- # 3. Overlay fitted quadratic model on scatterplot. #--------------------------------------------------------- elo=100 # Low value of effort for calculating quadratic. ehi=350 # High value of effort. eff=elo+(0:100)*(ehi-elo)/100 # Range of effort values sy=h*eff+g*eff^2 # Sustainable yield calculated for range of # effort values. points(eff,sy,type="l") # Add the quadratic model to the plot. #--------------------------------------------------------- x0=effort y0=yield x1=effort y1=h*effort+g*effort^2 segments(x0,y0,x1,y1,lty=2) detach(df)