QML Ex-gauss estimation
fit.exgauss(rexgauss(20)) and see the number of warnings). To mitigate this problem, Andrew Heathcote et al. (2002), proposed to use a modified maximum likelihood procedure, what they call "quantile maximum likelihood". Judith Dirk asked me if I had R code for that procedure as well. I didn't, so I wrote some. The code below implements this procedure for the Ex-Gauss distribution. You need to hand the routine two vectors: The vector of observations rt, and a vector p that specifies the percentiles that you want to use for quantile estimation. Although, I'm not sure about the statistical properties of this estimator, there seems to be some justification for asymptotic ML (Heathcote & Browne (2004) Psychon. Bul. and Rev.)
# Maximum Likelihood method of Heathcote (2002). It relies on
# the R routines defined on
# /rpages/2007/07/ex-gaussian-distribution-for-reaction.html
#
# example use:
# rt = rexgauss(150);
# p = seq(0, 1, len=13) # should contain 0 and 1!
# fit.exgauss.QMLE(rt, p)
#
function(rt, p, start =fit.exgauss.mom(rt), ...)
{
p = sort(unique(c(0,1,p)));
RT = sort(rt);
N = diff(p)*length(rt);
I = p[-c(1,length(p))]*length(rt)+ 0.5;
Im = trunc(I);
Ip=trunc(Im+1);
qhat = c(-Inf,RT[Im] + (RT[Ip]-RT[Im])*(I-Im), Inf);
f=function(theta, q, N) {
P=pexgauss(qhat,mu=theta[1],sigma=theta[2],lambda=theta[3]);
P[1]=0;
-sum(N*log(diff(P)));
}
optim(start, f, q=qhat, N=N, ...);
}
Update (Sep 18, 2008)
Because of stability issues it is advisable to restart the estimation procedure a number of times and retain the fit with the smallest objective function value. Furthermore, sometimes a different parameterization may be desirable. In particular, often θ = 1/λ is used for the exponential part of the ex-gaussian distribution. To facilitate the use of the above routine, and the earlier routines (including those for method-of-moments and ML), I have defined a new function, fitExgauss that will automate repeated fitting the ex-gauss using either standard ML or QMLE, and returns both parameterizations plus standard errors. The routine is defined in the file exgauss.R that you can download here: exgauss.R
The use is as follows:
rt = rexgauss(150, mu=500, sigma=100, lambda=1/80); # simulate response times
fitExgauss(rt); # gives ML estimates
fitExgauss(rt, seq(0,1, len=9)); # gives QMLE estimates using 9 bins
You can specify the number of repeated fitting rounds (nrepeat argument), different starting values (set start parameter to either a 3-vector of starting values or a function that accepts the array of response times and returns a 3-vector of starting values), or any of the optional arguments of optim (see ?optim for more).
Update (September, 2009): Update: Please read this report on a comparison between the estimates obtained with these routines and other software.
Labels: ex-gauss, fitting, maximum likelihood, reaction times, response times