diff options
author | Suraj Yerramilli | 2015-06-06 09:48:16 +0530 |
---|---|---|
committer | Suraj Yerramilli | 2015-06-06 09:48:16 +0530 |
commit | 587cdac17e2af0f4e507d17cf1ac00736d7f5d84 (patch) | |
tree | 00cea8e405e965fa62299598845d3b26084b0457 /R | |
parent | b088c8ed9e19e0f406875364b2ee3f3695824f78 (diff) | |
download | SysID-R-code-587cdac17e2af0f4e507d17cf1ac00736d7f5d84.tar.gz SysID-R-code-587cdac17e2af0f4e507d17cf1ac00736d7f5d84.tar.bz2 SysID-R-code-587cdac17e2af0f4e507d17cf1ac00736d7f5d84.zip |
Plot function updated
Diffstat (limited to 'R')
-rw-r--r-- | R/estpoly.R | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/R/estpoly.R b/R/estpoly.R index 8e07e4a..25047ac 100644 --- a/R/estpoly.R +++ b/R/estpoly.R @@ -1,11 +1,22 @@ #' @export -plot.estPoly <- function(model,newdata=NULL,...){ +plot.estPoly <- function(model,newdata=NULL){ + require(ggplot2) + require(reshape2) + if(is.null(newdata)){ - - } else{ - + ypred <- fitted(model) + yact <- fitted(model) + resid(model) + time <- model$time + } else{ if(class(newdata)!="idframe") stop("Only idframe objects allowed") + ypred <- sim(coef(model),newdata$input[,1,drop=F]) + yact <- newdata$output[,1,drop=F] + time <- seq(from=newdata$t.start,to=newdata$t.end,by=newdata$Ts) } + df <- data.frame(Predicted=ypred,Actual=yact,Time=time) + meltdf <- melt(df,id="Time") + ggplot(df, aes(x = Time,y=value,colour=variable,group=variable)) + + theme_bw() } #' Estimate ARX Models @@ -31,10 +42,12 @@ estARX <- function(data,order=c(0,1,0)){ vcov <- sigma2 * chol2inv(qx$qr) model <- arx(A = c(1,coef[1:na]),B = coef[na+1:nb1],ioDelay = nk) + time <- seq(from=data$t.start,to=data$t.end,by=data$Ts) est <- list(coefficients = model,vcov = vcov, sigma = sqrt(sigma2), df = df,fitted.values=(X%*%coef)[1:N,], - residuals=(Y-X%*%coef)[1:N,],call=match.call()) + residuals=(Y-X%*%coef)[1:N,],call=match.call(), + time=time) class(est) <- c("estARX","estPoly") est } |