In fact it was necessary to change the default step tolerance steptol from 1e-6
to 1e-5 to achieve this (further changes did not change the result). Notice also that
minpts in adapt has been changed from its default of 100 to 1,000. These
changes were made to try and make the two optimization routines agree as
much as possible. It is very important to carefully check the results of numerical
methods by several pathways, if at all possible.
MATLAB CODE: See Section 2.18.14.
2.8.5 Finding the maximum using a numerical approach
The approach used here is a mixture of a brute force approach and non-linear
optimization. For each value of x 10,000 values are calculated and nlm then used to
locate the value of x at which fitness is maximized (i.e., –W is minimized). To check
on consistency the process is replicated 10 times and the mean and standard
deviation calculated. Note that the random number seed is given outside the
replication loop (or we would just be generating the same sequence each time)
and that the same set of random parameter values are used within a replicate run.
R CODE:
rm(list¼ls()) # Remove all objects from memory
FITNESS <- function(x,As,Bs)
{
Af <-2;Bf<- 2 # Invariant parameter values
Surv <-AsBs*x # Vector of survivals
# Check that no survival < 0. If so then set to zero
Surv[Surv<0] <-0
# Check that no survival > 1. If so then set to 1
Surv[Surv>1] <-1
W <- mean((AfþBf*x)*Surv)
return(-W)
}
# MAIN PROGRAM
Amin <- 0.3; Amax <- 1 # Min and max values of aS
Bmin <- 0; Bmax <- 0.2 # Min and max values of bS
# Calculate n parameter combinations
n <- 10000 # Number of values of a
S
and b
S
to generate
# We are assuming a uniform distribution of values
# Make several runs. Here we use 10
REP <- matrix(0,10) # Create matrix to hold replicate
set.seed(10) # Set seed for random number generator
for(i in 1:10) # Iterate over replicates
{
Bs <- runif(n, min¼Bmin, max¼Bmax) # Vector of values of Bf
As <- runif(n, min¼Amin, max¼Amax) # Vector of values of As
REP[i]<- nlm(FITNESS,p¼REP[i],As,Bs)$estimate # Optimum for
this run
FISHERIAN OPTIMALITY MODELS 99