[R] Tobit Fixed Effects

Arne Henningsen arne.henningsen at googlemail.com
Thu Sep 29 14:10:13 CEST 2011


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?

/Arne

-- 
Arne Henningsen
http://www.arne-henningsen.name



More information about the R-help mailing list