data("", package = "dse") 
 data("", package = "dse") 

  cat("truncate sample to 240 periods.\n") <- TSdata(input= inputData([1:240,, drop=F], 
  seriesNames(  <- seriesNames(

  cat("estimates a VAR model using the truncated sample.\n")
  V.1 <- estVARXar(
  cat("calculate the likelihood, one step ahead predictions, etc.\n")
  l.V.1 <-l(V.1,
  cat("Likelihood and components for VAR model\n")
  # (with a breakdown for the 3 terms of the likelihood function).
  print(l.V.1$estimates$like, digits=16)

  #cat("Likelihood and components for VAR model\n")
  #l.V.1$estimates$like # also prints the value but not as many digits.

  cat("likelihood, one step ahead predictions, etc., based on the full sample.\n")
  o.V.1 <-l(V.1, 

  cat("convert the VAR model to a state space model balanced by Mittnik's technique.\n")
  SS.V.1 <- toSS(V.1) 

  cat("likelihood, one step ahead predictions, etc., based on truncated sample.\n")
  l.SS.V.1 <-l(SS.V.1, 

  cat("Likelihood and components for state space model\n")

  cat("Maximum difference in one-step predictions of VAR and state space model ")
  # calculate the difference of the absolute values of the predictions of 
  #      the two models.
  cat(max(abs(l.V.1$estimates$pred - l.SS.V.1$estimates$pred))) 

  cat("Exhibit 2. Mittnik reduction from VAR model: \n")
  M5.SS.V.1 <- MittnikReduction(SS.V.1,, criterion="taic")  
   "  If criterion is not specified the program prompts for a state dimension\n",
   "  and returns that model. Results is put in the variable M5.SS.V.1."))

  cat("Exhibit 3. Mittnik estimation lag=3: \n")
  M12.shift3 <- estSSMittnik(, max.lag=3, n=12)
  M12.shift3 <- MittnikReduction(M12.shift3,, criterion="taic")  

  cat("Exhibit 4. Mittnik estimation lag=4: \n")
  M12.shift4 <- estSSMittnik(,max.lag=4, n=15)
  M12.shift4 <- MittnikReduction(M12.shift4,, criterion="taic")  

    "Plot cpi in year over year % change.\n",
    "Prediction is relative to previous month's actual (\n",
    "and % change is relative to actual.\n",
    "240 is the starting point for plotting.\n",
    "base is the start value of the undif, un logged series.\n"))
        i <- 3 # cpi is the third variable
	base <-$output[1, i]
	pred <- o.V.1$estimates$pred[, i]
	y <- o.V.1$data$output[, i]
	y <- cumsum(c(log(base), y))
	pred <- c(log(base), pred)	# cumsum using pred relative to actual
	pred[2:length(pred)] <- pred[2:length(pred)] + y[1:(length(pred) - 1)]
	pred <- exp(pred)
	y <- exp(y)
	pred <- 100 * ((pred[13:length(pred)] - y[1:(length(y) - 12)])/y[1:(
		length(y) - 12)])
	y <- 100 * ((y[13:length(y)] - y[1:(length(y) - 12)])/y[1:(length(y) - 
	tfplot(tfwindow(y, start=240),tfwindow(pred, start=240)) 

Try the dse package in your browser

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

dse documentation built on May 2, 2019, 4:59 p.m.