Hello R community, I have been using R's inbuilt maximum likelihood functions, for the different methods (NR, BFGS, etc). I have figured out how to use all of them except the maxBHHH function. This one is different from the others as it requires an observation level gradient. I am using the following syntax: maxBHHH(logLik,grad=nuGradient,finalHessian="BHHH",start=prm,iterlim=2) where logLik is the likelihood function and returns a vector of observation level likelihoods and nuGradient is a function that returns a matrix with each row corresponding to a single observation and the columns corresponding to the gradient values for each parameter (as is mentioned in the online help). however, this gives me the following error: *Error in checkBhhhGrad(g = gr, theta = theta, analytic = (!is.null(attr(f, : the matrix returned by the gradient function (argument 'grad') must have at least as many rows as the number of parameters (10), where each row must correspond to the gradients of the log-likelihood function of an individual (independent) observation: currently, there are (is) 10 parameter(s) but the gradient matrix has only 2 row(s) * It seems it is expecting as many rows as there are parameters. So, I changed my likelihood function so that it would return the transpose of the earlier matrix (hence returning a matrix with rows equaling parameters and columns, observations). However, when I run the function again, I still get an error: *Error in gr[, fixed] <- NA : (subscript) logical subscript too long* I have verified that my gradient function, when summed across observations gives the same results as the in built numerical gradient (to the 11th decimal place - after that, they differ since R's function is numerical). I am trying to run a very large estimation (1000's of observations and 821 parameters) and all of the other methods are taking way too much time (days). This method is our last hope and so, any help will be greatly appreciated. -- Thanks in advance, Rohit Mob: 91 9819926213 [[alternative HTML version deleted]]
I suggest that you provide some commented, minimal, self-contained, reproducible code. Cheers Andrew On Wed, May 04, 2011 at 02:23:29AM +0530, Rohit Pandey wrote:> Hello R community, > > I have been using R's inbuilt maximum likelihood functions, for the > different methods (NR, BFGS, etc). > > I have figured out how to use all of them except the maxBHHH function. This > one is different from the others as it requires an observation level > gradient. > > I am using the following syntax: > > maxBHHH(logLik,grad=nuGradient,finalHessian="BHHH",start=prm,iterlim=2) > > where logLik is the likelihood function and returns a vector of observation > level likelihoods and nuGradient is a function that returns a matrix with > each row corresponding to a single observation and the columns corresponding > to the gradient values for each parameter (as is mentioned in the online > help). > > however, this gives me the following error: > > *Error in checkBhhhGrad(g = gr, theta = theta, analytic = (!is.null(attr(f, > : > the matrix returned by the gradient function (argument 'grad') must have > at least as many rows as the number of parameters (10), where each row must > correspond to the gradients of the log-likelihood function of an individual > (independent) observation: > currently, there are (is) 10 parameter(s) but the gradient matrix has only > 2 row(s) > * > It seems it is expecting as many rows as there are parameters. So, I changed > my likelihood function so that it would return the transpose of the earlier > matrix (hence returning a matrix with rows equaling parameters and columns, > observations). > > However, when I run the function again, I still get an error: > *Error in gr[, fixed] <- NA : (subscript) logical subscript too long* > > I have verified that my gradient function, when summed across observations > gives the same results as the in built numerical gradient (to the 11th > decimal place - after that, they differ since R's function is numerical). > > I am trying to run a very large estimation (1000's of observations and 821 > parameters) and all of the other methods are taking way too much time > (days). This method is our last hope and so, any help will be greatly > appreciated. > > -- > Thanks in advance, > Rohit > Mob: 91 9819926213 > > [[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.-- Andrew Robinson Program Manager, ACERA Department of Mathematics and Statistics Tel: +61-3-8344-6410 University of Melbourne, VIC 3010 Australia (prefer email) http://www.ms.unimelb.edu.au/~andrewpr Fax: +61-3-8344-4599 http://www.acera.unimelb.edu.au/ Forest Analytics with R (Springer, 2011) http://www.ms.unimelb.edu.au/FAwR/ Introduction to Scientific Programming and Simulation using R (CRC, 2009): http://www.ms.unimelb.edu.au/spuRs/
maxBHHH is *not* an in-built R function. It is in a distributed package called "maxLik". Always tell us which package is being used so that it is easier for us to help you. The error message says that the gradient function is returning a 10 x 2 matrix, whereas you say that you have 1000's of observations and 821 parameters. Show us a simplified version of your problem. It is difficult to help you without seeing an example. Also, try running w/o the gradient and see how it works. This is not the answer you wanted, but we cannot help you w/o seeing your example. Ravi. ________________________________________ From: r-help-bounces at r-project.org [r-help-bounces at r-project.org] On Behalf Of Rohit Pandey [rohitpandey576 at gmail.com] Sent: Tuesday, May 03, 2011 4:53 PM To: r-help at r-project.org Subject: [R] help with the maxBHHH routine Hello R community, I have been using R's inbuilt maximum likelihood functions, for the different methods (NR, BFGS, etc). I have figured out how to use all of them except the maxBHHH function. This one is different from the others as it requires an observation level gradient. I am using the following syntax: maxBHHH(logLik,grad=nuGradient,finalHessian="BHHH",start=prm,iterlim=2) where logLik is the likelihood function and returns a vector of observation level likelihoods and nuGradient is a function that returns a matrix with each row corresponding to a single observation and the columns corresponding to the gradient values for each parameter (as is mentioned in the online help). however, this gives me the following error: *Error in checkBhhhGrad(g = gr, theta = theta, analytic = (!is.null(attr(f, : the matrix returned by the gradient function (argument 'grad') must have at least as many rows as the number of parameters (10), where each row must correspond to the gradients of the log-likelihood function of an individual (independent) observation: currently, there are (is) 10 parameter(s) but the gradient matrix has only 2 row(s) * It seems it is expecting as many rows as there are parameters. So, I changed my likelihood function so that it would return the transpose of the earlier matrix (hence returning a matrix with rows equaling parameters and columns, observations). However, when I run the function again, I still get an error: *Error in gr[, fixed] <- NA : (subscript) logical subscript too long* I have verified that my gradient function, when summed across observations gives the same results as the in built numerical gradient (to the 11th decimal place - after that, they differ since R's function is numerical). I am trying to run a very large estimation (1000's of observations and 821 parameters) and all of the other methods are taking way too much time (days). This method is our last hope and so, any help will be greatly appreciated. -- Thanks in advance, Rohit Mob: 91 9819926213 [[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.
Dear Rohit On 3 May 2011 22:53, Rohit Pandey <rohitpandey576 at gmail.com> wrote:> Hello R community, > > I have been using R's inbuilt maximum likelihood functions, for the > different methods (NR, BFGS, etc). > > I have figured out how to use all of them except the maxBHHH function. This > one is different from the others as it requires an observation level > gradient. > > I am using the following syntax: > > maxBHHH(logLik,grad=nuGradient,finalHessian="BHHH",start=prm,iterlim=2) > > where logLik is the likelihood function and returns a vector of observation > level likelihoods and nuGradient is a function that returns a matrix with > each row corresponding to a single observation and the columns corresponding > to the gradient values for each parameter (as is mentioned in the online > help). > > however, this gives me the following error: > > *Error in checkBhhhGrad(g = gr, theta = theta, analytic = (!is.null(attr(f, > : > ?the matrix returned by the gradient function (argument 'grad') must have > at least as many rows as the number of parameters (10), where each row must > correspond to the gradients of the log-likelihood function of an individual > (independent) observation: > ?currently, there are (is) 10 parameter(s) but the gradient matrix has only > 2 row(s) > * > It seems it is expecting as many rows as there are parameters. So, I changed > my likelihood function so that it would return the transpose of the earlier > matrix (hence returning a matrix with rows equaling parameters and columns, > observations). > > However, when I run the function again, I still get an error: > *Error in gr[, fixed] <- NA : (subscript) logical subscript too long* > > I have verified that my gradient function, when summed across observations > gives the same results as the in built numerical gradient (to the 11th > decimal place - after that, they differ since R's function is numerical). > > I am trying to run a very large estimation (1000's of observations and 821 > parameters) and all of the other methods are taking way too much time > (days). This method is our last hope and so, any help will be greatly > appreciated.Please make yourself familiar with the BHHH algorithm and read the documentation of maxBHHH: it says about argument "grad": "[...] If the BHHH method is used, ?grad? must return a matrix, where rows correspond to the gradient vectors of individual observations and the columns to the individual parameters.[...]" More information of the maxLik package is available at: http://dx.doi.org/10.1007/s00180-010-0217-1 Best regards, Arne -- Arne Henningsen http://www.arne-henningsen.name
Maybe Matching Threads
- R:Maximum likelihood estimation using BHHH and BFGS
- [External] Re: unable to access index for repository...
- function censReg in panel data setting
- [External] Re: unable to access index for repository...
- [External] Re: unable to access index for repository...