[R] probl with optimization

fc502 at york.ac.uk fc502 at york.ac.uk
Sun Apr 29 19:48:27 CEST 2007


ok...beta and lambda are the parameters that i ve to find. beta is a scalar 
and lambda is a 2x1 vector i ll have a look to the debugging tools, thnx! f

On Apr 29 2007, Prof Brian Ripley wrote:

>On Sun, 29 Apr 2007, fc502 at york.ac.uk wrote:
>
>> hi everyone!
>>
>> i've got a problem in optimizing the following function
>>
>> fun <- function(theta){
>> theta <- rbind(beta,lambda)
>> fun <- sum(exp(h(beta)%*%lambda))
>> fun
>> }
>
>Well, what are beta and lambda?  Trying to optimize a function that does 
>not depend on its argument is going to be difficult.
>
>> where h(beta) is
>>
>> h <- function(beta,...){
>> g1 <- matrix(0,b,M)
>> g2 <- matrix(0,b,M)
>> h1 <- matrix(0,b,1)
>> h2 <- matrix(0,b,1)
>> for(f in 1:M){
>>  for(F in 1:b){
>>   g1[F,f] <- exp(mu-beta*(z1[F,f]+z2[F,f])+3*z2[F,f])-1
>>   g2[F,f] <- z2[F,f]*(exp(mu-beta*(z1[F,f]+z2[F,f])+3*z2[F,f])-1)
>>  }
>> }
>> for(q in 1:b){
>>  h1[q] <- (1/M)*sum(g1[q,])
>>  h2[q] <- (1/M)*sum(g2[q,])
>> }
>> h <- matrix(0, b,2)
>> h[,1] <- h1
>> h[,2] <- h2
>> h
>> }
>>
>> i tried to optimize fun with optim and nlminb but i get an error:
>> Error in beta * (z1[F, f] + z2[F, f]) :
>>        non-numeric argument to binary operator
>
>Possibly that the visible 'beta' is the R function of that name?
>
>> PLEASE do read the posting guide 
>> http://www.R-project.org/posting-guide.html and provide commented, 
>> minimal, self-contained, reproducible code.
>
>It would have helped to have a complete example.  But using the debuggig 
>functions described in `Writing R Extensions' will help you debug this: 
>you could have printed the visible 'beta' for example.
>
>



More information about the R-help mailing list