R/remove_missing.R

Defines functions remove_missing

remove_missing <- function(yt, C, R) {
  
  #   This function eliminates the rows in y and matrices C and R that correspond to missing data in y
  #
  # Input:
  #   - yt: vector of observations at time t
  #   - C:  measurement matrix
  #   - R:  covariance for measurement matrix residuals
  #
  # Output:
  #   - yt: vector of observations at time t (reduced)     
  #   - C:  measurement matrix (reduced)     
  #   - R:  covariance for measurement matrix residuals
  #   - L:  used to restore standard dimensions(n x w) where w is the number of available data in y
  
  # Returns 1 for nonmissing series
  ix <- !is.na(yt)
  
  # Index for columns with nonmissing variables
  e <- eye(length(yt))
  L <- e[, ix]
  
  # Removes missing series
  yt <- yt[ix]

  # Removes missing series from observation matrix
  C <- C[ix, ]
  
  # Removes missing series from transition matrix
  R <- R[ix, ix]
  
  # Prepare output
  return(list(yt = yt, C = C, R = R, L = L))
  
}

Try the nowcastDFM package in your browser

Any scripts or data that you put into this service are public.

nowcastDFM documentation built on Dec. 1, 2021, 5:07 p.m.