[R] Optim routine loses function name
ewbank at pop.upenn.edu
Fri Oct 5 17:50:01 CEST 2007
I am trying to write a rather complex maximum likelihood program.
One of the complexities is that I want to create a program that can
accept user-written routines to calculate likelihood values from
different types of data.
The program uses several functions I have written. First there is a
main function that reads in what kind of data will be used. It then
calls OPTIM. which uses a function called "A" for simplicity. "A"
then calls "B" which returns life tables. "A" then calls "C" which uses
the life tables to calculate the log-likelihood. This set up allows for
telling "A" to call other user-define functions (e.g., "C1", "C2", etc.)
to calculate the likelihood from other types of data. Having the life
tables generated in a different subroutine makes this function available
for producing useful output based on the parameter estimates.
The program flow should go like this:
the main program to OPTIM to A to B to A to C to A then back to OPTIM
which should continue this chain repeatedly to test new values of the
The program successfully gets through the initial calculation of the
log likelihood and gets to the end of A where it prints out the correct
value. It doesn't print a second estimate of the log likelihood based
on a new set of parameters. The program ends at this point. The output
looks like this (with my annotations at the far right):
 "call LL"
trace: optim(param.est, LogLikelihood(param.est, nMx, N.genes, N.RR,
N.pop, N.lt, N.ages, N.alleles, N.types, N.a, a.base, a.assign,
R, sigma, genotype.frq, lx.base, lx, popXlt, N.Data, data.pop,
female, data.lt, years, age.1st, age.2nd, pop, deaths))
 "Start LL"
(i.e., start A)
 "start lt"
(i.e., start B)
 "Start LL_Basic"
(i.e., start C)
 "end LL"
(i.e., end A)
Error in function (par) : could not find function "fn"
Any suggestions would be greatly appreciated.
Douglas Ewbank, Ph.D.
Population Studies Center
University of Pennsylvania
More information about the R-help