[R] extracting parameters from vector

Prof Brian Ripley
Fri, 29 Dec 2000 11:35:10 -0000

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
> write
>  sigma <- param[1]
>  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