[R] specifying multiple parameter starting values in nlm
Michael Rennie
mrennie at utm.utoronto.ca
Tue Jul 8 06:46:03 CEST 2003
Hi there
I am having trouble figuring out how to get an nlm function to report estimates
for two parameter values in an estimation.
The way I've got it goes something like this:
f <- function (q, r)
{
here, I have a second loop which uses q, r to give me values for c, d below. a
and b are already specified; this loop is a mass-balance function where I am
trying to find values of q, r to give me c and d. I want c and d (mass-balance
model outputs) to approximate a and b (known endpoints that I want the model to
attain), respecitvely. Thus, the function I want to minimize is:
fu <- ((a^2 - c^2) + (b^2 - d^2))/2 ; fu
}
nlm (f, 1, r=1)
This doesn't return estimates for each parameter, and I get error messages
saying something like "repleaced missing value with maximum" or something. All
I did here was try (and fail, obviously) to model my needs against the examples
given in help(nlm), but they are using vectors as inputs, and I only need 2
values input, and 2 returned.
I've also tried specifying the function as
f <- function (q)
{
mass-balance loop
}
fu <- ((a^2 - c^2) + (b^2 - d^2))/2 ; fu
nlm(f, c(1,1))
Specifying 1 as the starting values, and coding q[1] and q[2] in my mass
balance loop instead of q, r.
But this doesn't work either, and I get messages that I think are indicating
that my mass balance loop isn't computing properly ("number of items to replace
is not a multiple of replacement length"- an error I don't get when I run the
mass-balance loop outside the nlm function and just specify q, r).
Does anyone know how to specify two parameters in the function, and ask for
estimates of both back from nlm? Alternatively, any hunches on how to make this
thing do what I want it to?
Thanks,
Mike
--
Michael Rennie
M.Sc. Candidate
University of Toronto at Mississauga
3359 Mississauga Rd. N.
Mississauga ON L5L 1C6
Ph: 905-828-5452 Fax: 905-828-3792
More information about the R-help
mailing list