ClearAll;
$DefaultFont = {"Times-Roman",10};
Needs["Statistics`DataManipulation`"];
Needs["Graphics`Graphics`"];
cumulative = {312/545,413/545,487/545,522/545,537/545,1};
datapoints = {{0,0},{1,312/545},{2,413/545},
			  {3,487/545},{4,522/545},{5,537/545},{6,1}};
density = {312/545,101/545,74/545,35/545,15/545,8/545};

Q[s_]:= -545 Log[s] - 713/s;
plotllf = Plot[Q[s],{s,1.1,1.57},
	PlotRange->{{1.1,1.57},Automatic},
	AxesLabel->{"s","Q"},
	AxesOrigin->{1.08,-700.5},
	AspectRatio->2/GoldenRatio,
	PlotLabel->"(a)  Prairie-dog loglikelihood function"];

FMLE[x_]:= 1 - E^(-545x/713);
fmle[x_]:= (545/713) E^(-545x/713);
F[a_,x_]:= 1 - E^(-a x);
f[a_,x_]:= a E^(-a x);
error[a_] = Apply[Plus,Table[(F[a,n]-cumulative[[n]])^2,{n,1,5}]];
leasterror = FindMinimum[error[a],{a,1,0,2}];
Plot[error[a],{a,0,2}];
aopt = a/.leasterror[[2]]
Print["Error is ",leasterror[[1]]];

up:= Show[Plot[f[aopt,x],{x,0,6},
			PlotRange->{{0,6.05},{0,0.8}},
			PlotStyle->Dashing[{0.001,0.01}],
			PlotLabel->FontForm["(b)  y = f(x)\n     (p.d.f.)",
				{"Courier",10}],
			Axes->True,AxesLabel->{" x","y"}],
			Plot[fmle[x],{x,0,6},
			PlotRange->{{0,6.05},{0,0.8}}]];
			
down:= Show[Plot[F[aopt,x],{x,0,6},
			PlotRange->{{0,6.05},{0,1.05}},
			PlotStyle->Dashing[{0.001,0.01}],
			PlotLabel->FontForm["(c)  y = F(x)\n     (c.d.f.)",{"Courier",10}],
			Axes->True,AxesLabel->{" x","y"}],
			Plot[FMLE[x],{x,0,6},
			PlotRange->{{0,6.05},{0,0.8}}],
			ListPlot[datapoints]];
Show[GraphicsArray[{plotllf,GraphicsArray[{{up},{down}}]}],
		PlotLabel->"Figure 31.2"]