[R] question about nlminb

Spencer Graves spencer.graves at pdf.com
Wed Apr 9 05:13:45 CEST 2008


      Have you considered optimizing over x1 = x[1:(length(x)-1]?   You 
could feed a wrapper function 'f2(x1, ...)' that computes xFull = c(x1, 
1-sum(x1)) and feeds that to your 'fn'. 

      If this makes sense, great.  Else, if my answer is not useful, be 
so kind as to PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html and provide commented, 
minimal, self-contained, reproducible code. 

      Spencer

John Pitchard wrote:
>  Dear All,
>
> I wanted to post some more details about the query I sent to s-news last
> week.
>
> I have a vector with a constraint. The constraint is that the sum of the
> vector must add up to 1 - but not necessarily positive, i.e.
>
> x[n] <- 1 -(x[1] + ...+x[n-1])
>
> I perform the optimisation on the vector x such that
>
> x <- c(x, 1-sum(x))
>
> In other words,
>
> fn <- function(x){
>   x <- c(x, 1 - sum(x))
>   # other calculations here
> }
>
> then feed this into nlminb()
>
> out <- nlminb(x, fn)
> out.x <- out$parameters
> out.x <- c(out.x, 1 - sum(out.x))
> out.x
>
> I would like to calculate standard errors for each of the components of x.
> Is this possible by outputing the Hessian matrix? Furthermore, how would I
> calculate this for the last component (if this is indeed possible) which has
> the restriction (i.e. 1-sum(out.x))?
>
> Any help would be much appreciated.
>
> Regards,
> John
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list