summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSuraj Yerramilli2017-01-06 17:15:39 -0600
committerSuraj Yerramilli2017-01-06 17:15:39 -0600
commita4cec768a4ed5fe4355a03340af544f2f8a6ba0c (patch)
treea3ca404593ccc4a2ea81fdaf64be0cac7efad18c
parent5f0a48d074abe1785b7a98deb2ecff2b90beca33 (diff)
downloadSysID-R-code-a4cec768a4ed5fe4355a03340af544f2f8a6ba0c.tar.gz
SysID-R-code-a4cec768a4ed5fe4355a03340af544f2f8a6ba0c.tar.bz2
SysID-R-code-a4cec768a4ed5fe4355a03340af544f2f8a6ba0c.zip
S3 methods consistency part 1
-rw-r--r--R/estpoly.R22
-rw-r--r--R/poly.R2
-rw-r--r--R/predict.R29
-rw-r--r--man/predict.estpoly.Rd6
4 files changed, 31 insertions, 28 deletions
diff --git a/R/estpoly.R b/R/estpoly.R
index 5d5de76..e37ad1d 100644
--- a/R/estpoly.R
+++ b/R/estpoly.R
@@ -35,15 +35,15 @@ print.estpoly <- function(x,...){
}
#' @export
-summary.estpoly <- function(x)
+summary.estpoly <- function(object,...)
{
- model <- x$sys
+ model <- object$sys
coefs <- params(model)
- se <- sqrt(diag(getcov(x)))
+ se <- sqrt(diag(getcov(object)))
params <- data.frame(Estimated=coefs,se=se)
- report <- list(fit=fitch(x),params=params)
+ report <- list(fit=fitch(object),params=params)
res <- list(model=model,report=report)
class(res) <- "summary.estpoly"
res
@@ -87,24 +87,24 @@ fitch <- function(x){
}
#' @export
-print.summary.estpoly <- function(x,digits=4){
+print.summary.estpoly <- function(x,digits=4,...){
print(x$model,se=x$report$params[,2],dig=digits)
cat("\n Fit Characteristics \n")
print(data.frame(x$report$fit),digits=digits)
}
+#' @import ggplot2
#' @export
-plot.estpoly <- function(model,newdata=NULL){
- loadNamespace("ggplot2")
+plot.estpoly <- function(x,newdata=NULL,...){
if(is.null(newdata)){
- ypred <- ts(fitted(model),names="Predicted")
- yact <- ts(fitted(model) + resid(model),names="Actual")
- time <- time(model$input)
+ ypred <- ts(fitted(x),names="Predicted")
+ yact <- ts(fitted(x) + resid(x),names="Actual")
+ time <- time(x$input)
titstr <- "Predictions of Model on Training Set"
} else{
if(class(newdata)!="idframe") stop("Only idframe objects allowed")
- ypred <- predict(model,newdata)
+ ypred <- predict(x,newdata)
yact <- outputData(newdata)[,1]
time <- time(newdata)
titstr <- "Predictions of Model on Test Set"
diff --git a/R/poly.R b/R/poly.R
index ea38487..528a599 100644
--- a/R/poly.R
+++ b/R/poly.R
@@ -71,7 +71,7 @@ checkUnity <- function(x){
}
#' @export
-print.idpoly <- function(x,se=NULL,dig=3){
+print.idpoly <- function(x,se=NULL,dig=3,...){
main <- paste("Discrete-time",toupper(x$type),"model:")
if(x$type=="oe" || x$type=="bj"){
main <- paste(main,"y[k] = B(z)/F(z) u[k] +")
diff --git a/R/predict.R b/R/predict.R
index 5c8213a..b56fa8f 100644
--- a/R/predict.R
+++ b/R/predict.R
@@ -1,17 +1,17 @@
-predict.idpoly <- function(x,data,nahead=1){
+predict.idpoly <- function(object,data,nahead=1){
y <- outputData(data); u<- inputData(data)
- G <- signal::Arma(b=c(rep(0,x$ioDelay),x$B),
- a= as.numeric(polynom::polynomial(x$A)*
- polynom::polynomial(x$F1)))
+ G <- signal::Arma(b=c(rep(0,object$ioDelay),object$B),
+ a= as.numeric(polynom::polynomial(object$A)*
+ polynom::polynomial(object$F1)))
det_sys <- as.numeric(signal::filter(G,u))
- if(x$type=="oe" || nahead==Inf){
+ if(object$type=="oe" || nahead==Inf){
ypred <- det_sys
} else{
- Hden <- as.numeric(polynom::polynomial(x$A)*polynom::polynomial(x$D))
- Hinv <- signal::Arma(b=Hden,a=x$C)
+ Hden <- as.numeric(polynom::polynomial(object$A)*polynom::polynomial(object$D))
+ Hinv <- signal::Arma(b=Hden,a=object$C)
filtered <- as.numeric(signal::filter(Hinv,as.numeric(y)-det_sys))
if(nahead!=1){
- H <- as.numeric(polynom::polynomial(x$C)*polyinv(Hden,nahead))
+ H <- as.numeric(polynom::polynomial(object$C)*polyinv(Hden,nahead))
Hl <- signal::Ma(H[1:nahead])
filtered <- as.numeric(signal::filter(Hl,filtered))
}
@@ -41,11 +41,12 @@ polyinv <- function(x,k){
#'
#' Predicts the output of an identified model (\code{estpoly}) object K steps ahead.
#'
-#' @param x \code{estpoly} object containing the identified model
+#' @param object \code{estpoly} object containing the identified model
#' @param newdata optional dataset to be used for predictions. If not supplied,
#' predictions are made on the training set.
#' @param nahead number of steps ahead at which to predict (Default:1). For infinite-
#' step ahead predictions or pure simulation, supply \code{Inf}.
+#' @param \ldots other arguments
#'
#' @return
#' Time-series containing the predictions
@@ -62,14 +63,14 @@ polyinv <- function(x,k){
#' and Practice}, CRC Press, Boca Raton. Chapter 18
#'
#' @export
-predict.estpoly <- function(x,newdata=NULL,nahead=1){
+predict.estpoly <- function(object,newdata=NULL,nahead=1,...){
if(is.null(newdata)&& nahead==1){
- return(matrix(fitted(x)))
+ return(matrix(fitted(object)))
} else{
- model <- x$sys
+ model <- object$sys
if(is.null(newdata)){
- y <- fitted(x)+resid(x)
- u <- x$input
+ y <- fitted(object)+resid(object)
+ u <- object$input
z <- idframe(y,u,Ts = deltat(y),start=start(y))
} else{
z <- newdata
diff --git a/man/predict.estpoly.Rd b/man/predict.estpoly.Rd
index 4c19ed5..53371e6 100644
--- a/man/predict.estpoly.Rd
+++ b/man/predict.estpoly.Rd
@@ -4,16 +4,18 @@
\alias{predict.estpoly}
\title{Predictions of identified model}
\usage{
-\method{predict}{estpoly}(x, newdata = NULL, nahead = 1)
+\method{predict}{estpoly}(object, newdata = NULL, nahead = 1, ...)
}
\arguments{
-\item{x}{\code{estpoly} object containing the identified model}
+\item{object}{\code{estpoly} object containing the identified model}
\item{newdata}{optional dataset to be used for predictions. If not supplied,
predictions are made on the training set.}
\item{nahead}{number of steps ahead at which to predict (Default:1). For infinite-
step ahead predictions or pure simulation, supply \code{Inf}.}
+
+\item{\ldots}{other arguments}
}
\value{
Time-series containing the predictions