[R] Tobit Fixed Effects
Arne Henningsen
arne.henningsen at googlemail.com
Fri Mar 2 11:13:10 CET 2012
Dear Felipe
On 29 September 2011 14:10, Arne Henningsen
<arne.henningsen at googlemail.com> wrote:
> Hi Felipe
>
> On 25 September 2011 00:16, Felipe Nunes <felipnunes at gmail.com> wrote:
>> Hi Arne,
>> my problem persists. I am still using censReg [version - 0.5-7] to run a
>> random effects model in my data (>50,000 cases), but I always get the
>> message.
>> tob7 <- censReg(transfers.cap ~ pt.pt + psdb.pt + pt.opp + pt.coa + psdb.coa
>> + pib.cap + transfers.cap.lag + pib.cap + ifdm + log(populat) +
>> mayor.vot.per + log(bol.fam.per+0.01) + factor(uf.name) + factor(year) - 1,
>> left=0, right=Inf, method="BHHH", nGHQ=8, iterlim=10000, data = pdata2)
>> Error in maxNRCompute(fn = logLikAttr, fnOrig = fn, gradOrig = grad,
>> hessOrig = hess, :
>> NA in the initial gradient
>> If I sent you my data set, could you try to help me? I have been struggling
>> with that for two months now.
>
> Thanks for sending me your data set. With it, I was able to figure
> out, where the NAs in the (initial) gradients come from: when
> calculating the derivatives of the standard normal density function [d
> dnorm(x) / d x = - dnorm(x) * x], values for x that are larger than
> approximately 40 (in absolute terms) result in so small values (in
> absolute terms) that R rounds them to zero. Later, these derivatives
> are multiplied by some other values and then the logarithm is taken
> ... and multiplying any number by zero and taking the logarithms gives
> not a finite number :-(
>
> When *densities* of the standard normal distribution become too small,
> one can use dnorm(x,log=TRUE) and store the logarithm of the small
> number, which is much larger (in absolute terms) than the density and
> hence, is not rounded to zero. However, in the case of the
> *derivative* of the standard normal density function, this is more
> complicated as log( d dnorm(x) / d x ) = log( dnorm(x) ) + log( - x )
> is not defined if x is positive. I will try to solve this problem by
> case distinction (x>0 vs. x<0). Or does anybody know a better
> solution?
Finally(!), I have implemented this solution in the censReg() package.
Some initial tests (including your model and data) show that the
revised calculation of the gradient of the random effects panel data
model for censored dependent variables is much more robust to rounding
errors. The improved version of the censReg package is not yet via
CRAN, but it is available at R-Forge:
https://r-forge.r-project.org/R/?group_id=256
If you have further questions or feedback regarding the censReg
package, please use a forum or "tracker" on the R-Forge site of the
sampleSelection project:
https://r-forge.r-project.org/projects/sampleselection/
Best wishes from Copenhagen,
Arne
--
Arne Henningsen
http://www.arne-henningsen.name
More information about the R-help
mailing list