Dear All,
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)
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).
However, 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?
Do the weights have to be normalized somehow? I tried different stuff, but
to no avail.
Thanks in advance,
-ans
___________________________
Dr. rer. nat. Andrej-Nikolai Spiess
Department of Andrology
University Hospital Hamburg-Eppendorf
Martinistr. 52
20246 Hamburg
phone: +49-40-7410-51585
fax: +49-40-7410-51554
-------------- next part --------------
--
Pflichtangaben gem?? Gesetz ?ber elektronische Handelsregister und
Genossenschaftsregister sowie das Unternehmensregister (EHUG):
Universit?tsklinikum Hamburg-Eppendorf; K?rperschaft des ?ffentlichen Rechts;
Gerichtsstand: Hamburg
Vorstandsmitglieder: Prof. Dr. Martin Zeitz (Vorsitzender), Dr. Alexander
Kirstein, Joachim Pr?l?, Prof. Dr. Dr. Uwe Koch-Gromus