diff options
Diffstat (limited to 'R')
-rw-r--r-- | R/estpoly.R | 30 | ||||
-rw-r--r-- | R/poly.R | 19 |
2 files changed, 29 insertions, 20 deletions
diff --git a/R/estpoly.R b/R/estpoly.R index 132cabf..f48766c 100644 --- a/R/estpoly.R +++ b/R/estpoly.R @@ -18,26 +18,22 @@ print.estpoly <- function(x,...){ summary.estpoly <- function(x) { model <- x$sys - if(model$type=="arx"||model$type=="armax"){ - coefs <- c(model$A[-1],model$B) - na <- length(model$A) - 1; nk <- model$ioDelay; - nb <- length(model$B) - if(model$type=="armax"){ - coefs <- c(coefs,model$C[-1]) - nc <- length(model$C)-1 - } - } else if(model$type=="oe"){ - coefs <- c(model$B,model$F1[-1]) - nf <- length(model$F1) - 1; nk <- model$ioDelay; - nb <- length(model$B) - } + coefs <- params(model) se <- sqrt(diag(getcov(x))) params <- data.frame(Estimated=coefs,se=se) + report <- list(fit=fitch(x),params=params) + res <- list(model=model,report=report) + class(res) <- "summary.estpoly" + res +} + +#' @export +fitch <- function(x){ y <- fitted(x) + resid(x) ek <- as.matrix(resid(x)) - N <- nrow(ek); np <- nrow(params) + N <- nrow(ek); np <- length(params(x$sys)) # fit characteristics mse <- det(t(ek)%*%ek)/N @@ -48,11 +44,7 @@ summary.estpoly <- function(x) nAIC <- log(mse) + 2*np/N BIC <- N*log(mse) + N*dim(matrix(y))[2]*(log(2*pi)+1) + np*log(N) - report <- list(fit=list(MSE=mse,FPE=fpe,FitPer = nrmse*100,AIC=AIC,AICc=AICc, - nAIC=nAIC,BIC=BIC),params=params) - res <- list(model=model,report=report) - class(res) <- "summary.estpoly" - res + list(MSE=mse,FPE=fpe,FitPer = nrmse*100,AIC=AIC,AICc=AICc,nAIC=nAIC,BIC=BIC) } #' @export @@ -164,4 +164,21 @@ print.idpoly <- function(mod,se=NULL,dig=3){ } } cat("\n") -}
\ No newline at end of file +} + +params <- function(x){ + if(x$type=="arx"||x$type=="armax"){ + coefs <- c(x$A[-1],x$B) + na <- length(x$A) - 1; nk <- x$ioDelay; + nb <- length(x$B) + if(x$type=="armax"){ + coefs <- c(coefs,x$C[-1]) + nc <- length(x$C)-1 + } + } else if(x$type=="oe"){ + coefs <- c(x$B,x$F1[-1]) + nf <- length(x$F1) - 1; nk <- x$ioDelay; + nb <- length(x$B) + } + coefs +}
\ No newline at end of file |