AIC with weighted nonlinear regression (nls)

◇◆丶佛笑我妖孽 提交于 2019-12-07 21:14:15

问题


I encounter some discrepancies when comparing the deviance of a weighted and unweigthed model with the AIC values. A general example (from ‘nls’):

DNase1 <- subset(DNase, Run == 1)
fm1DNase1 <- nls(density ~ SSlogis(log(conc), Asym, xmid, scal), DNase1)

This is the unweighted fit, in the code of ‘nls’ one can see that ‘nls’ generates a vector wts <- rep(1, n).

Now for a weighted fit:

 fm2DNase1 <- nls(density ~ SSlogis(log(conc), Asym, xmid, scal), 
                 DNase1, weights = rep(1:8, each = 2))

in which I assign increasing weights for each of the 8 concentrations with 2 replicates.

Now with deviance I get:

deviance(fm1DNase1)
[1] 0.004789569

> deviance(fm2DNase1)
[1] 0.0164259

telling me that the weighted fit has a significantly higher deviance (is a worse fit).

Now with AIC (or BIC) I get

> AIC(fm1DNase1)
[1] -76.41642

> AIC(fm2DNase1)
[1] -372.5437

which tells me that the second fit is by orders of magnitude the better one (lower AIC). Why so?

If I define AIC based on residual sum-of-squares as found in the textbooks

RSS <- function (object) 
{
    w <- object$weights
    r <- residuals(object)
    if (is.null(w)) 
        w <- rep(1, length(r))
    sum(w * residuals(object)^2)
}

AICrss <- function(object)
{
  n <- nobs(object)
  k <- length(coef(object))
  rss <- RSS(object)
  n * log((2 * pi)/n) + n + 2 + n * log(rss) + 2 * k
}

I get

> AICrss(fm1DNase1)
[1] -76.41642

which is the same value as the above AIC (stats:::AIC.logLik) based on log-likelihood

but

> AICrss(fm2DNase1)
[1] -56.69772

which is higher and fits perfectly to the also higher deviance of the second model.

Could anyone enlighten me? Is the standard AIC implementation for ‘nls’ models not applicable in case of weighted fitting?

Cheers, Andrej

来源:https://stackoverflow.com/questions/12566905/aic-with-weighted-nonlinear-regression-nls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!