[R] extracting parameters from vector
Prof Brian Ripley
ripley at stats.ox.ac.uk
Fri Dec 29 12:35:10 CET 2000
On Sat, 30 Dec 2000, Ott Toomet wrote:
> Dear everybody!
> Minimization algorithms usually assume the parameters are in the form of a single
> vector. When calculating target function, e.g. log-likelihood, it is much more
> pleasant to extract the vector into separate parameters and program the loglik
> using them directly. Are ther any more intelligent ways to do that than just
> sigma <- param
> beta <- param[1:1+N]
I don't think that will do what you want (: is of higher precedence than +)
In general just use indexing, which is very powerful in R. So you can
have pre-computed index masks, and say
start[p1] <- sigma; start[p1] <- beta ...
call optim, and in your callback have
sigma <- param[p1]; beta <- param[p2] ...
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
More information about the R-help