From f1b4017b0f0e07dfa8e24c14834af49bb71c4a3f Mon Sep 17 00:00:00 2001 From: Suraj Yerramilli Date: Mon, 25 May 2015 18:37:19 +0530 Subject: Basic features added --- R/impulse.R | 18 +++++++++++------- man/impulseest.Rd | 5 +++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/R/impulse.R b/R/impulse.R index 2066c4f..fccce3d 100644 --- a/R/impulse.R +++ b/R/impulse.R @@ -5,23 +5,24 @@ #' #' @param data an object of class \code{idframe} #' @param M Order of the FIR Model (Default:\code{30}) -#' @param K Transport delay in the estimated impulse response +#' @param K Transport delay in the estimated impulse response +#' (Default:\code{0}) #' #' @seealso \code{\link{plot.impulseest}}, \code{\link{step}} #' @export -impulseest <- function(data,M=30,K){ +impulseest <- function(data,M=30,K=0){ N <- dim(data$output)[1] - ind <- (M+1):N + ind <- (M+K+1):N - z_reg <- function(i) data$input[i:(i-M),] + z_reg <- function(i) data$input[(i-K):(i-M-K),] Z <- t(sapply(ind,z_reg)) Y <- data$output[ind,] fit <- lm(Y~Z-1) - out <- list(coefficients=coef(fit),residuals=resid(fit), - lags=0:M) + out <- list(coefficients=coef(fit),residuals=resid(fit),lags=K:M+K, + x=colnames(data$input),y=colnames(data$output)) class(out) <- "impulseest" return(out) } @@ -35,7 +36,10 @@ impulseest <- function(data,M=30,K){ #' @seealso \code{\link{impulseest}},\code{\link{step}} #' @export plot.impulseest <- function(model){ - plot(model$lags,coef(model),type="h");abline(h=0) + title <- paste("Impulse Response \n From",model$x,"to",model$y) + plot(model$lags,coef(model),type="h",xlab="Lag",ylab= model$y, + main = title) + abline(h=0) } diff --git a/man/impulseest.Rd b/man/impulseest.Rd index c831cc3..7d36f99 100644 --- a/man/impulseest.Rd +++ b/man/impulseest.Rd @@ -4,14 +4,15 @@ \alias{impulseest} \title{Estimate Impulse Response Models} \usage{ -impulseest(data, M = 30, K) +impulseest(data, M = 30, K = 0) } \arguments{ \item{data}{an object of class \code{idframe}} \item{M}{Order of the FIR Model (Default:\code{30})} -\item{K}{Transport delay in the estimated impulse response} +\item{K}{Transport delay in the estimated impulse response +(Default:\code{0})} } \description{ \code{impulseest} is used to estimate impulse response models in the -- cgit