I have a problem to calculate the AIC. Indeed, I estimate the parameters of my 3 models: "mod_linear", which is a linear model and "mod_exp" and "mod_logis" which are two non linear models.
I used the function AIC():
AIC(mod_linear,mod_exp,mod_logis)
df AIC
mod_linear 4 3.015378
mod_exp 5 -11.010469
mod_logis 5 54.015746
But I tried to calculate the AIC with the formule AIC=2k+nlog(RSS/n) where K is the number of parameters, n the number of the sample and RSS the residual sum of squares.
k=4
n=21
#Calcul of nls for the linear model:
mod_linear=nls(data$P~P_linear(P0,K0,a),data=data,
start=c(P0=4.2,K0=4.5,a=0.)
2*k+n*log(sum(residuals(mod_linear)^2)/n)
-56.58004
As you can see, is not the same result and It's the same thing for the two other models. Someone could help me?
Regards