{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"source": [
"# Marima R library in CoCalc\n",
"\n",
"> Multivariate ARIMA and ARIMA-X estimation using Spliid's algorithm (marima()) and simulation (marima.sim()).\n",
"\n",
"\n",
"\n",
"https://cran.r-project.org/package=marima"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
" _ \n",
"platform x86_64-pc-linux-gnu \n",
"arch x86_64 \n",
"os linux-gnu \n",
"system x86_64, linux-gnu \n",
"status \n",
"major 3 \n",
"minor 4.4 \n",
"year 2018 \n",
"month 03 \n",
"day 15 \n",
"svn rev 74408 \n",
"language R \n",
"version.string R version 3.4.4 (2018-03-15)\n",
"nickname Someone to Lean On "
]
},
"execution_count": 1,
"metadata": {
},
"output_type": "execute_result"
}
],
"source": [
"R.version"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"All cases in data, 1 to 90 accepted for completeness.\n",
"90 7 = MARIMA - dimension of data \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"arma.filter is being called \n",
"indicators for means= 1 1 1 1 1 1 1 \n",
" dim(yseries) 7 94 \n"
]
},
{
"data": {
"image/svg+xml": "\n\n"
},
"execution_count": 2,
"metadata": {
"image/svg+xml": {
"isolated": true
}
},
"output_type": "execute_result"
}
],
"source": [
"library(marima)\n",
"data(austr)\n",
"series<-t(austr)[,1:90]\n",
"# Define marima model\n",
"Model5 <- define.model(kvar=7,ar=1,ma=1,rem.var=1,reg.var=6:7)\n",
"# Estimate marima model\n",
"Marima5 <- marima(series,Model5$ar.pattern,Model5$ma.pattern,penalty=1)\n",
"# Calculate residuals by filtering\n",
"Resid <- arma.filter(series, Marima5$ar.estimates,\n",
"Marima5$ma.estimates)\n",
"# Compare residuals\n",
"plot(Marima5$residuals[2, 5:90], Resid$residuals[2, 5:90], xlab='marima residuals', ylab='arma.filter residuals')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Input data is transformed from type = 'time series' (is.ts)\n",
" to matrix).Sampling information is ignored. One line is one sample at a\n",
" certain time point.All cases in data, 1 to 90 accepted for completeness.\n",
"90 7 = MARIMA - dimension of data \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Calling arma.forecast.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"In the example the input series is dim(length,kvar).\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"and of type ts() (timeseries) for illustration. \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
" Input series is type ts (timeseries).\n",
" It will be changed to matrix(...) using as.matrix(...). \n",
"\n",
" Data matrix is to be transposed. Done! \n",
"7 Variables in series , with required length = 100 . \n",
"\n",
" print AR-model: \n",
", , 1\n",
"\n",
" [,1] [,2] [,3] [,4] [,5] [,6] [,7]\n",
"[1,] 1 0 0 0 0 0 0\n",
"[2,] 0 1 0 0 0 0 0\n",
"[3,] 0 0 1 0 0 0 0\n",
"[4,] 0 0 0 1 0 0 0\n",
"[5,] 0 0 0 0 1 0 0\n",
"[6,] 0 0 0 0 0 1 0\n",
"[7,] 0 0 0 0 0 0 1\n",
"\n",
", , 2\n",
"\n",
" [,1] [,2] [,3] [,4] [,5] [,6] [,7]\n",
"[1,] 0 0.00000000 0.0000000 0.00000000 0.00000000 0.00000000 0.0000000\n",
"[2,] 0 -0.56193313 -0.8153282 0.03416575 0.00000000 0.57325886 0.0000000\n",
"[3,] 0 -0.06075435 -0.3170937 0.00000000 -0.06694902 0.09659622 0.0000000\n",
"[4,] 0 0.65334775 -1.6631316 -0.82681628 -0.47195995 -0.96665683 0.3252574\n",
"[5,] 0 0.00000000 0.0000000 0.00000000 -0.98009562 0.00000000 0.0000000\n",
"[6,] 0 0.00000000 0.0000000 0.00000000 0.00000000 0.00000000 0.0000000\n",
"[7,] 0 0.00000000 0.0000000 0.00000000 0.00000000 0.00000000 0.0000000\n",
"\n",
"\n",
" print MA-model: \n",
", , 1\n",
"\n",
" [,1] [,2] [,3] [,4] [,5] [,6] [,7]\n",
"[1,] 1 0 0 0 0 0 0\n",
"[2,] 0 1 0 0 0 0 0\n",
"[3,] 0 0 1 0 0 0 0\n",
"[4,] 0 0 0 1 0 0 0\n",
"[5,] 0 0 0 0 1 0 0\n",
"[6,] 0 0 0 0 0 1 0\n",
"[7,] 0 0 0 0 0 0 1\n",
"\n",
", , 2\n",
"\n",
" [,1] [,2] [,3] [,4] [,5] [,6] [,7]\n",
"[1,] 0 0.0000000 0 0.00000000 0.0000000 0 0\n",
"[2,] 0 0.0000000 0 0.13025444 -0.2351108 0 0\n",
"[3,] 0 0.0000000 0 0.03905407 0.0000000 0 0\n",
"[4,] 0 0.5857279 0 0.00000000 0.0000000 0 0\n",
"[5,] 0 0.0000000 0 0.00000000 -0.7163302 0 0\n",
"[6,] 0 0.0000000 0 0.00000000 0.0000000 0 0\n",
"[7,] 0 0.0000000 0 0.00000000 0.0000000 0 0\n",
"\n",
"variable no. 6 not random and regressor.\n",
"Variable no. 6 : future values seem OK.\n",
"variable no. 7 not random and regressor.\n",
"Variable no. 7 : future values seem OK.\n",
"Constant = 1959.5 1.192804 0.0959164 2.100926 0.02197434 0.1 0.5 \n",
"Calculation of forecasting variances. \n"
]
},
{
"data": {
"text/html": [
"
\n",
"\t- 1959.5
\n",
"\t- 1.00077878331063
\n",
"\t- 0.197060905030581
\n",
"\t- 8.22351229278395
\n",
"\t- 1.28373981144414
\n",
"\t- 0.1
\n",
"\t- 0.5
\n",
"
\n"
]
},
"execution_count": 3,
"metadata": {
},
"output_type": "execute_result"
},
{
"data": {
"text/html": [
"\n",
"\t- 1.00077878331063
\n",
"\t- 1.06162305060619
\n",
"\t- 1.15060432312317
\n",
"\t- 1.255825600993
\n",
"\t- 1.37462646550024
\n",
"\t- 1.5057582811964
\n",
"\t- 1.64816732488692
\n",
"\t- 1.80084140982766
\n",
"\t- 1.96281212350129
\n",
"\t- 2.13316980065769
\n",
"
\n"
]
},
"execution_count": 3,
"metadata": {
},
"output_type": "execute_result"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" [,1] [,2] [,3] [,4] [,5]\n",
"Year 2005.0000000 2006.0000000 2007.0000000 2008.000000 2009.0000000\n",
"Predict 1.0007788 1.0616231 1.1506043 1.255826 1.3746265\n",
"upper.lim 1.4853282 1.7435373 1.9073152 2.044681 2.1785422\n",
"lower.lim 0.5162294 0.3797088 0.3938934 0.466970 0.5707108\n",
" [,6] [,7] [,8] [,9] [,10]\n",
"Year 2010.000000 2011.0000000 2012.0000000 2013.000000 2014.000000\n",
"Predict 1.505758 1.6481673 1.8008414 1.962812 2.133170\n",
"upper.lim 2.317438 2.4642980 2.6198021 2.783731 2.955526\n",
"lower.lim 0.694079 0.8320367 0.9818807 1.141893 1.310814\n"
]
},
{
"data": {
"image/svg+xml": "\n\n"
},
"execution_count": 3,
"metadata": {
"image/svg+xml": {
"isolated": true
}
},
"output_type": "execute_result"
}
],
"source": [
"library(marima)\n",
"data(austr)\n",
"series<-austr\n",
"Model5 <- define.model(kvar=7, ar=1, ma=1, rem.var=1, reg.var=6:7)\n",
"Marima5 <- marima(ts(series[1:90, ]), Model5$ar.pattern, Model5$ma.pattern,\n",
"penalty=1)\n",
"nstart <- 90\n",
"nstep <- 10\n",
"cat(\"Calling arma.forecast.\\n\")\n",
"cat(\"In the example the input series is dim(length,kvar).\\n\")\n",
"cat(\"and of type ts() (timeseries) for illustration. \\n\")\n",
"Forecasts <- arma.forecast(series=ts(series), marima=Marima5,\n",
"nstart=nstart, nstep=nstep )\n",
"Year<-series[91:100,1]\n",
"One.step <- Forecasts$forecasts[, (nstart+1)]\n",
"One.step\n",
"Predict <- Forecasts$forecasts[ 2, 91:100]\n",
"Predict\n",
"stdv<-sqrt(Forecasts$pred.var[2, 2, ])\n",
"upper.lim=Predict+stdv*1.645\n",
"lower.lim=Predict-stdv*1.645\n",
"Out<-rbind(Year, Predict, upper.lim, lower.lim)\n",
"print(Out)\n",
"# plot results:\n",
"plot(series[1:100, 1], Forecasts$forecasts[2, ], type='l', xlab='Year',\n",
"ylab='Rate of armed suicides', main='Prediction of suicides by firearms',\n",
"ylim=c(0.0, 4.1))\n",
"lines(series[1:90, 1], series[1:90, 2], type='p')\n",
"grid(lty=2, lwd=1, col='black')\n",
"Years<-2005:2014\n",
"lines(Years, Predict, type='l')\n",
"lines(Years, upper.lim, type='l')\n",
"lines(Years, lower.lim, type='l')\n",
"lines(c(2004.5, 2004.5), c(0.0, 2.0), lty = 2)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\t- 2
\n",
"\t- 1
\n",
"\t- 2
\n",
"\t- 1
\n",
"\t- 3
\n",
"\t- 12
\n",
"
\n"
]
},
"execution_count": 4,
"metadata": {
},
"output_type": "execute_result"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"arma.filter is being called \n",
"indicators for means= 1 1 1 1 \n",
" dim(yseries) 4 16 \n"
]
},
{
"data": {
"text/html": [
"\n",
"\t- $y.dif
\n",
"\t\t\n",
"\n",
"\t 6 | 14 | -37 | 81 | -127 | -57 | 124 | -19 |
\n",
"\t 198 | -5 | -4 | -30 | 12 | 68 | -147 | -197 |
\n",
"\t-142 | 298 | -191 | 224 | -370 | 362 | -227 | -38 |
\n",
"\t-147 | 168 | 113 | -16 | -6 | 187 | -66 | 177 |
\n",
"\n",
"
\n",
" \n",
"\t- $y.lost
\n",
"\t\t\n",
"\n",
"\t192.0 | -51.0 |
\n",
"\t145.6 | -288.0 |
\n",
"\t137.6 | -175.6 |
\n",
"\t-31.0 | -86.0 |
\n",
"\n",
"
\n",
" \n",
"\t- $dif.poly
\n",
"\t\t\n",
"\t- 1
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 1
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 1
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 1
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- -1
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- -2
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 1
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"
\n",
" \n",
"\t- $averages
\n",
"\t\t\n",
"\t- 12.6
\n",
"\t- 1.4
\n",
"\t- -7.6
\n",
"\t- 29.3
\n",
"
\n",
" \n",
"\t- $dif.series
\n",
"\t\t\n",
"\n",
"\t192.0 | -51.0 | 6 | 14 | -37 | 81 | -127 | -57 | 124 | -19 |
\n",
"\t145.6 | -288.0 | 198 | -5 | -4 | -30 | 12 | 68 | -147 | -197 |
\n",
"\t137.6 | -175.6 | -142 | 298 | -191 | 224 | -370 | 362 | -227 | -38 |
\n",
"\t-31.0 | -86.0 | -147 | 168 | 113 | -16 | -6 | 187 | -66 | 177 |
\n",
"\n",
"
\n",
" \n",
"
\n"
]
},
"execution_count": 4,
"metadata": {
},
"output_type": "execute_result"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"arma.filter is being called \n",
"indicators for means= 1 1 1 1 \n",
" dim(yseries) 4 28 \n"
]
},
{
"data": {
"text/html": [
"\n",
"\t- 1
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 1
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 1
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 1
\n",
"\t- 1
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 2
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- -1
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 1
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- -1
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- -1
\n",
"\t- -1
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- -1
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- -2
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- -1
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"
\n"
]
},
"execution_count": 4,
"metadata": {
},
"output_type": "execute_result"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"arma.filter is being called \n",
"indicators for means= 1 1 1 1 \n",
" dim(yseries) 4 24 \n"
]
},
{
"data": {
"text/html": [
"\n",
"\t- $y.dif
\n",
"\t\t\n",
"\n",
"\t-208 | 70 | 181 | -143 |
\n",
"\t-117 | 239 | -106 | -298 |
\n",
"\t-111 | 32 | -52 | -174 |
\n",
"\t -6 | 187 | -66 | 177 |
\n",
"\n",
"
\n",
" \n",
"\t- $y.lost
\n",
"\t\t\n",
"\n",
"\t179.4 | -243.0 | 57.0 | 8.0 | -51.0 | 118.0 |
\n",
"\t145.6 | -142.4 | 55.6 | 50.6 | 46.6 | 16.6 |
\n",
"\t130.0 | 92.0 | -88.0 | 30.0 | -43.0 | 108.0 |
\n",
"\t-31.0 | -86.0 | -147.0 | 168.0 | 113.0 | -16.0 |
\n",
"\n",
"
\n",
" \n",
"\t- $dif.poly
\n",
"\t\t\n",
"\t- 1
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 1
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 1
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 1
\n",
"\t- -1
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- -1
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"\t- 0
\n",
"
\n",
" \n",
"\t- $averages
\n",
"\t\t\n",
"\t- 12.6
\n",
"\t- 1.4
\n",
"\t- -7.6
\n",
"\t- 29.3
\n",
"
\n",
" \n",
"\t- $dif.series
\n",
"\t\t\n",
"\n",
"\t179.4 | -243.0 | 57.0 | 8.0 | -51.0 | 118.0 | -208 | 70 | 181 | -143 |
\n",
"\t145.6 | -142.4 | 55.6 | 50.6 | 46.6 | 16.6 | -117 | 239 | -106 | -298 |
\n",
"\t130.0 | 92.0 | -88.0 | 30.0 | -43.0 | 108.0 | -111 | 32 | -52 | -174 |
\n",
"\t-31.0 | -86.0 | -147.0 | 168.0 | 113.0 | -16.0 | -6 | 187 | -66 | 177 |
\n",
"\n",
"
\n",
" \n",
"
\n"
]
},
"execution_count": 4,
"metadata": {
},
"output_type": "execute_result"
},
{
"data": {
"text/html": [
"\n",
"\n",
"\t3 | 4 | 5 | 6 |
\n",
"\t2 | 0 | 0 | 7 |
\n",
"\n",
"
\n"
]
},
"execution_count": 4,
"metadata": {
},
"output_type": "execute_result"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"arma.filter is being called \n",
"indicators for means= 1 1 1 1 1 1 \n",
" dim(yseries) 6 220 \n"
]
},
{
"data": {
"text/html": [
"\n",
"\t- 44.7
\n",
"\t- 45.72
\n",
"\t- 4.12
\n",
"\t- 0.72
\n",
"\t- 0.25
\n",
"\t- 2.13
\n",
"
\n"
]
},
"execution_count": 4,
"metadata": {
},
"output_type": "execute_result"
},
{
"data": {
"text/html": [
"\n",
"\t- 45.14
\n",
"\t- 45.38
\n",
"\t- 51.83
\n",
"\t- 52.97
\n",
"\t- 48.83
\n",
"\t- 49.66
\n",
"
\n"
]
},
"execution_count": 4,
"metadata": {
},
"output_type": "execute_result"
}
],
"source": [
"# Generate Y=series with 4 variables for illustration:\n",
"set.seed(4711)\n",
"Y<-matrix(round(100*rnorm(40)+10), nrow=4)\n",
"# Example 1: use of difference parameter: If\n",
"difference=c(2, 1, 2, 1, 3, 12)\n",
"difference\n",
"# the variable 2 is differenced\n",
"# twice, and variable 3 is differenced once with lag=12.\n",
"# Example 2:\n",
"poly <- define.dif(series=Y, difference=c(2, 1, 3, 1, 3, 1))\n",
"poly\n",
"# Generates a (4-variate) polynomial differencing array (with a leading\n",
"# unity matrix corresponding to lag=0, and (in the example) differencing\n",
"# of variable 2 for lag 1 and variable 3 for lag 1 but twice. Afterwards\n",
"# the series Y is differenced accordingly. Results in poly$series and\n",
"# poly$dif.poly .\n",
"# Example 3: Generation and application of multivariate differencing\n",
"# polynomial. Re-use the 4-variate time series and use the\n",
"# differencing polynomial (ar-form):\n",
"# var=1, dif=1, var=2, dif=6, and var=3 and 4, no differencing.\n",
"dif.y <-define.dif(Y, c(1, 1, 2, 6, 3, 0, 4, 0))\n",
"# Now dif.y contains the differenced series and the differencing\n",
"# polynomial. Print the generated polynomial in short form:\n",
"short.form(dif.y$dif.poly)\n",
"# Specifying no differencing (3, 0 and 4, 0) may be omitted:\n",
"dif.y <-define.dif(Y, c(1, 1, 2, 6))\n",
"dif.y\n",
"# Example 4:\n",
"y<-matrix(round(rnorm(1200)*100+50), nrow=6)\n",
"library(marima)\n",
"difference<-c(3, 2, 4, 0, 5, 0, 6, 7)\n",
"matrix(difference, nrow=2)\n",
"Y<-define.dif(y, difference=difference)\n",
"round(rowMeans(Y$dif.series), 2)\n",
"round(Y$averages, 2)"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
]
}
],
"metadata": {
"kernelspec": {
"display_name": "R (R-Project)",
"language": "r",
"name": "ir"
},
"language_info": {
"codemirror_mode": "r",
"file_extension": ".r",
"mimetype": "text/x-r-source",
"name": "R",
"pygments_lexer": "r",
"version": "3.4.4"
}
},
"nbformat": 4,
"nbformat_minor": 0
}