Mathematica file for Midterm Take Home

Thanks to Donna for the format of this page.

Your Name Here
Spring, 2018

Your job:
	1. You are to complete this file, by incorporating two additional “missing” models for kill rate (two others are already determined for you, the linear regression model and the General Power Model): you are to add in the models 
		a. Hollings Type III
		b. The “Rachel Model” -- a square root model
		
		
Note that the independent variable is the ratio of moose to wolves.
	2. At the bottom of this file you will compare all four models, using the residual plots and adjusted RSquared values. 
	3. Note the difference between the adjusted RSquared values produced by the NonlinearModelFit algorithms, and our values discussed in class. Which seem more reasonable? Why?
	4. Once you have these models for kill rate, you will turn your attention to InsightMaker, and try each of these models in a compartmental model you will clone from me, at
	https://insightmaker.com/insight/102161/Final-Midterm-Student-version-of-A-More-Realistic-Model-of-Isle-Royale-Predator-Prey-Interactions

Clear["Global`*"]

Let’s read in the data, obtained from the website 
http://www.isleroyalewolf.org/data/data/home.html
and the specific link
http://www.isleroyalewolf.org/sites/default/files/documents/isleroyale_graph_data_28Dec2011.xlsx

I always make my own copy, because you never know when data you’re using on the web will disappear....

mooseWolf=Import["http://ceadserv1.nku.edu/longa/classes/2018spring/mat375/docs/WolfMoose/isleroyale_graph_data_28Dec2011.xlsx"];

moose=mooseWolf[[1,Table[i,{i,15,55,1}],3]];
wolves=mooseWolf[[1,Table[i,{i,15,55,1}],2]];
kills=mooseWolf[[1,Table[i,{i,15,55,1}],14]];
ybar=Mean[kills];
ratio=moose/wolves;
data=Transpose[{ratio,kills}];
p1=ListPlot[data,PlotRange->{{0,150},{0,1.5}},AxesLabel->{"moose per wolf per month","kill rate"}]

Use non-linear regression to fit a general power model to the Kill Rate:

i. Power model: f(x)=a x^b

Clear[a,b]
Manipulate[
Module[
{},
p2=Plot[a x^b,{x,0,150}];
Show[p1,p2]
]
,{{a,.09},0,1,.01}
,{{b,.5},0,1,.01}
]

NLM2=NonlinearModelFit[data,a x^b,{{a,.09},{b,0.5}},x]
NLM2["ParameterConfidenceIntervalTable"]
NLM2["ParameterTable"]
rsq2=NLM2["AdjustedRSquared"]
yhat=Table[NLM2[r], {r,ratio}];
residuals=kills-yhat;
rsquared2=1-residuals.residuals/((kills-ybar).(kills-ybar))
n=Length[ratio];
p=2; (* number of parameters estimated *)
rsquaredadj2=1-(n-1)/(n-p) (1-rsquared2)

Show[p1, Plot[NLM2[x],{x,0,150}]]
r2=ListPlot[NLM2["FitResiduals"],PlotLabel->"Power Model",AxesLabel->{"Fitted Value", "Residual"},PlotRange->{Automatic,{-.5,.5}}];

Use linear regression to fit model to the Kill Rate:

LM2=LinearModelFit[data, {x},x]
LM2["ParameterConfidenceIntervalTable"]
LM2["ParameterTable"]
rsq4=LM2["AdjustedRSquared"]
yhat=Table[LM2[r], {r,ratio}];
residuals=kills-yhat;
rsquared4=1-residuals.residuals/((kills-ybar).(kills-ybar))
n=Length[ratio];
p=2; (* number of parameters estimated *)
rsquaredadj4=1-(n-1)/(n-p) (1-rsquared4)

Show[p1, Plot[LM2[x],{x,0,150}]]
r4=ListPlot[LM2["FitResiduals"],PlotLabel->"Linear Model",AxesLabel->{"Fitted Value", "Residual"},PlotRange->{Automatic,{-.5,.5}}];

Now let’s graph the residuals:

GraphicsGrid[{{r1,r2},{r3,r4}},Frame->True]

Grid[{{"Model","Nominal Adjusted (R^2)","Our Adjusted (R^2)"},{"Hollings III", rsq1,rsquaredadj1},{"Power Model", rsq2,rsquaredadj2},{"Square Root",rsq3,rsquaredadj3},{"Linear", rsq4,rsquaredadj4}},Frame->All]