summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSuraj Yerramilli2015-06-05 14:57:45 +0530
committerSuraj Yerramilli2015-06-05 14:57:45 +0530
commit52b824adf38cbd40f7eedc1b6f0fdd4ea5f80437 (patch)
tree1750a7d902377ff98e14bac5f82f484bc66e1d07
parent521f2e20dcc94457a2adbe30c29704aac507a123 (diff)
downloadSysID-R-code-52b824adf38cbd40f7eedc1b6f0fdd4ea5f80437.tar.gz
SysID-R-code-52b824adf38cbd40f7eedc1b6f0fdd4ea5f80437.tar.bz2
SysID-R-code-52b824adf38cbd40f7eedc1b6f0fdd4ea5f80437.zip
Estimation method for ARX models
-rw-r--r--R/estpoly.R20
1 files changed, 19 insertions, 1 deletions
diff --git a/R/estpoly.R b/R/estpoly.R
index f7293e8..8714ca7 100644
--- a/R/estpoly.R
+++ b/R/estpoly.R
@@ -1,7 +1,25 @@
estARX <- function(data,order=c(0,1,0)){
y <- as.matrix(data$output)
- u <- as.matrix(data$input)
+ u <- as.matrix(data$input); N <- dim(y)[1]
na <- order[1];nb <- order[2]; nk <- order[3]
+ nb1 <- nb+nk; n <- max(na,nb1); df <- N - n
+ padZeros <- function(x,n) c(rep(0,n),x,rep(0,n))
+ yout <- apply(y,2,padZeros,n=n);
+ uout <- apply(u,2,padZeros,n=n);
+ reg <- function(i) cbind(-yout[i-1:na,],uout[i-nk:nb1])
+ X <- t(sapply(n+1:(N+n),reg))
+ Y <- yout[n+1:(N+n),,drop=F]
+
+ qx <- qr(X); coef <- qr.solve(qx,Y)
+ sigma2 <- sum((Y-X%*%coef)^2)/df
+
+ vcov <- sigma2 * chol2inv(qx$qr)
+ colnames(vcov) <- rownames(vcov) <- colnames(X)
+
+ list(coefficients = coef,
+ vcov = vcov,
+ sigma = sqrt(sigma2),
+ df = df)
} \ No newline at end of file