#######arima
library(forecast)
Arima(lh, order = c(1,0,1))
Series: lh
ARIMA(1,0,1) with non-zero mean
Coefficients:
ar1 ma1 intercept
0.4522 0.1982 2.4101
s.e. 0.1769 0.1705 0.1358
sigma^2 estimated as 0.1923: log likelihood=-28.76
AIC=65.52 AICc=66.45 BIC=73.01
#####
ps:
aic=65.52
npar=4
nstar=48
bic = aic + npar*(log(nstar) - 2)
bic # 73.0048
#####lm model
可以用公式算,也可以用既有 AIC, BIC function
AIC = n + n * log(2 * pi) + n * log(rss/n) + 2 * (P+1)
BIC = n + n * log(2 * pi) + n * log(rss/n) + log(n) * (p+1)
lm <- lm(Fertility ~ . , data = swiss)
n <- nrow(swiss)
rss <- sum(resid(lm) ^2)
#calculate AIC
n + n*log(2*pi) + n * log(rss / n ) + 2 * (6+1)
#[326.0716]
#call AIC function
AIC(lm)
#[326.0716]
#calculate BIC
n + n * log(2*pi) + n*log(rss/n) + log(n) * (6+1)
#[339.0226]
#call AIC function to calculate BIC
AIC(lm, k=log(n))
#[339.0226]
#call BIC function from "nlme" package
library(nlme)
BIC(lm)
#[339.0226]
问题3 eviews同R计算aic的公式,只是小不同而已.
|