# [R] goodness of fit for nonlinear quantile regression

Roger Koenker rkoenker at illinois.edu
Tue Oct 8 17:31:43 CEST 2013

```Elsa,

It is usual to write to package authors/maintainers about packages before
trying R-help.  Inference for nonlinear quantile regression is still a bit
underdeveloped.  To get logLik you can use:

logLik.nlrq <- function (object, ...)
{
n <- length(object\$m\$resid())
p <- length(object\$m\$getPars())
tau <- object\$m\$tau()
fid <- object\$m\$rho
val <- n * (log(tau * (1 - tau)) - 1 - log(fid/n))
attr(val, "n") <- n
attr(val, "df") <- p
class(val) <- "logLik"
val
}

and from there AIC should work as usual for nls models.

RK

url:    www.econ.uiuc.edu/~roger            Roger Koenker
email    rkoenker at uiuc.edu            Department of Economics
vox:     217-333-4558                University of Illinois
fax:       217-244-6678                Urbana, IL 61801

On Oct 8, 2013, at 8:36 AM, Elsa Youngsteadt wrote:

> Hello,
>
> I am having trouble obtaining AIC or pseudo R^2 for nonlinear quantile
> regression fits. I would like to use one of these measures to compare
> non-nested models (each with a single, unique predictor variable).
>
> I am trying to fit the following gaussian peak model using the quantreg package:
>
> fit1.nlrq <- nlrq(y ~ a*exp(-((x-b)/c)**2), data=data, start =
> list(a=.2,b=25.5,c=1), tau=0.5, trace=T);
>
> (and so on, for multiple tau; I would like a local goodness of fit
> measure at each tau, to help compare this model to a similar one that
> uses, say, x1 as a predictor instead of x.)
>
> Parameter estimates and predictions for the model looks as expected,
> but when I try to use AIC(fit1.nlrq) or AIC.nlrq(fit1.nlrq) I get the
> following output
>
> numeric(0)
> attr(,"edf")
>  0
>
> Similarly, logLik(fit1.nlrq)
>
> yields
>
> 'log Lik.'  (df=0)
>
> Can someone advise? (The output for deviance does exist and is a number...)
>
> As an alternative, I could perhaps calculate pseudo R2. I think this
> would be [1 - (deviance of fitted model/ deviance of null model)] but
> don't know how to obtain the deviance for the relevant null models.
> Can someone offer code or advice on this front?
>
> Perhaps someone has a more desirable alternative altogether for
> comparing among non-nested, nonlinear, quantile regression models.
>
> I am new to R and to R-help, please advise of posting mistakes or
> missing information!
>
> sessionInfo is as follows:
>
> R version 3.0.0 (2013-04-03)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
>
> locale:
>  LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252
>  LC_MONETARY=English_United States.1252 LC_NUMERIC=C
>  LC_TIME=English_United States.1252
>
> attached base packages:
>  stats     graphics  grDevices utils     datasets  methods   base
>
> other attached packages:
>  quantreg_4.98 SparseM_1.02
>
> loaded via a namespace (and not attached):
>  tools_3.0.0
>
>
>
> --
> Research Associate
> Department of Entomology
> North Carolina State University
> Campus Box 7613
> Raleigh, NC 27695
> 919-515-1661
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help