Elsa Youngsteadt
2013-Oct-05 21:41 UTC
[R] goodness of fit for nonlinear quantile regression
Hello, I am having trouble obtaining AIC or pseudo R2 for nonlinear quantile regression fits. I would like to use one of these measures to compare non-nested models (each with a unique predictor variable). For example, 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 want to compare this model at each tau to a similar model that has, say, "x1" in place of "x" as its predictor variable.) Parameter estimates and predictions for these models look 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") [1] 0 Similarly, logLik(fit1.nlrq) yields 'log Lik.' (df=0) I unfortunately do not understand why there are 0 df for the log likelihood. Can someone advise? As an alternative, I could perhaps calculate a 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. Any code or advice on this front would also be greatly appreciated. (Also confused about why I can obtain deviance but not AIC or logLik, I thought these three values were closely related to one another; I would be uneasy to calculate AIC by hand from deviance when the package refuses to do so, until I understand better what is going on.) If there is a more desirable alternative for comparing among non-nested, nonlinear, quantile regression models, I would be glad to hear it. I am new to R and to R-help and would be happy to provide more details of my code or output if this would be useful. Many thanks for any insight. sessionInfo is as follows: R version 3.0.0 (2013-04-03) Platform: x86_64-w64-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] quantreg_4.98 SparseM_1.02 loaded via a namespace (and not attached): [1] tools_3.0.0 -- Elsa Youngsteadt Department of Entomology North Carolina State University [[alternative HTML version deleted]]
Elsa Youngsteadt
2013-Oct-08 13:36 UTC
[R] goodness of fit for nonlinear quantile regression
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") [1] 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: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] quantreg_4.98 SparseM_1.02 loaded via a namespace (and not attached): [1] tools_3.0.0 -- Elsa Youngsteadt Research Associate Department of Entomology North Carolina State University Campus Box 7613 Raleigh, NC 27695 919-515-1661
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") > [1] 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: > [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 > [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C > [5] LC_TIME=English_United States.1252 > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > other attached packages: > [1] quantreg_4.98 SparseM_1.02 > > loaded via a namespace (and not attached): > [1] tools_3.0.0 > > > > -- > Elsa Youngsteadt > 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 > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.