# codeErange.r - range calculations from the Humphries (2010)
# Supplementary Table S3. 17th July 2012
# Andrew Edwards. Andrew.Edwards@dfo-mpo.gc.ca
# From my rangeQuestion.r - 26th April 2012.
# The text from our manuscript is (this code will calculate the quoted results):
# Ref.~\cite{hump10} did not use the aforementioned methods of \cite{sims08}. Their methods were based on those developed and tested more recently in \cite{csn09}. Ref.~\cite{csn09} developed a method to estimate, for the PL model (\ref{PLeqn}), the most suitable value of $a$ to be considered as the start of the tail. However, \cite{hump10} used this approach to also estimate $b$ (their $x_{\text{max}}$) for the PLB model (\ref{PLBeqn}), the maximum value of the data to be fitted to by the model. This was often less than the maximum value of the data set. To see this, compare the `Max step length (m)' column with the `Best fit Xmax' column in Table S3 of \cite{hump10}. The first example is for bigeye tuna 1 (section 2), for which the maximum step length in the data was 1,531~m but the best fit $x_{\text{max}}$ was only 466~m. Thus, for this example (which happens to be the most extreme), step lengths $>466$~m were not part of the final model fits, even though values up to 1,531~m were recorded. Of the 94 data sets (sections) analysed statistically, 66 were best fitted by the PLB model (compared to other models). Of these 66, 28 (42\%) have `Best fit Xmax' less than the `Max step length' of the data. The 28 cases have a mean ratio of `Best fit Xmax' to `Max step length' of 0.75, with five-number summary (minimum, quartiles and maximum) of 0.30, 0.59, 0.80, 0.91, 0.99.
# So the Humphries et al. (2010) Table S3 has 94 data sets
# (sections). Of these, 66 have the TP (truncated power-law)
# given as the best fit distribution. Of these 66, 28 (42%) have
# 'Best fit xmax' < max step length of the data.
rm(list=ls())
# First need the 'Max step length (m)' values and corresponding
# 'Best fit xmax' values for the 28 cases that have TP and
# 'Max step length' > 'Best fit xmax'. Typing in from the two
# appropriate columns in Table S3.
maxData = c(1531, 336, 1635, 1526, 648, 735, 324, 350, 414, 414, 327,
293, 334, 204, 177.522, 107.589, 156.004, 172.143, 209.799,
172.143, 473, 177, 482, 166.7, 166, 160.5, 161, 80)
maxFit = c(466, 297, 1601, 677, 262, 395, 286, 333, 267, 397, 291,
231, 266, 91.45, 145, 80.7, 123.7, 86.1, 166.8,
150, 435.7, 161.3, 167, 156, 129.11, 159, 146, 59.2)
ratio = maxFit/maxData
results = cbind(maxData, maxFit, ratio)
sortRatio = sort(ratio) # Sort into ascending order
plot(sortRatio)
print(results)
print(round(sortRatio, 2))
# print(summary(ratio))
print("The 28 cases have a mean ratio of `Best fit Xmax' to `Max step length' of 0.75,...")
print(mean(ratio))
print("...with five-number summary (minimum, quartiles and maximum) of 0.30, 0.59, 0.80, 0.91, 0.99.")
print(round(fivenum(ratio), 2))