MatthieuStigler / tsDyn

tsDyn
tsdyn.googlecode.com
GNU General Public License v2.0
34 stars 20 forks source link

TVAR and GIRF #37

Closed AnastaDim closed 2 years ago

AnastaDim commented 3 years ago

My name is Anastasia, and I am a PhD student. This period I am working on a project using TVAR model and GIRF functions. However, I am facing some difficulties and I would appreciate it if you could provide me some insight regarding the coding. I use the dataset attached below.

data<-read.csv("two.csv") y <- ts(data$Total, start = c(1985,1,1), frequency = 12) x <- ts(data$Core, start = c(1985,1,1), frequency = 12) library(tsDyn)

>Registered S3 method overwritten by 'quantmod':

> method from

>as.zoo.data.frame zoo

v2 <- cbind(y, x) colnames(v2) <- cbind("t","c") t5<-TVAR(v2, lag=3, nthresh=1, thDelay=1, trim=0.1, mTh=2, plot=FALSE)

>Best unique threshold 3.16

sig=apply(t5$residuals,2,sd);sig

> t c

>0.4030384 0.2723124

library(tvarGIRF) grifs.t=GIRF(t5,shock=sig) print(grifs.t)

> GIRF of tvar t5

A tibble: 20 x 2

> t c

>

> 1 0.404 0.273

> 2 0.375 0.248

> 3 0.331 0.247

>4 0.265 0.223

> 5 0.213 0.200

> 6 0.171 0.178

>7 0.135 0.159

> 8 0.106 0.141

> 9 0.0854 0.128

>10 0.0684 0.118

>11 0.0553 0.109

>12 0.0436 0.100

>13 0.0373 0.0940

>14 0.0352 0.0889

>15 0.0314 0.0840

>16 0.0253 0.0790

>17 0.0234 0.0725

>18 0.0208 0.0680

>19 0.0201 0.0651

>20 0.0194 0.0614

tt=seq(1,20,by=1) plot(grifs.t[,1,1],type='l')

>Error in grifs.t[, 1, 1] : incorrect number of dimensions

plot(tt,grifs.t[1]$responses$c,type='l') plot(tt,grifs.t[1]$responses$t,type='l')

My questions are:

  1. When I use the command "print(grifs.t)", what the numbers in the two columns mean?
  2. Why the command "plot(grifs.t[,1,1],type='l') is not working?
  3. I want the generalized impulse response functions from both regimes, but when I use "plot(tt,grifs.t[1]$responses$c,type='l')", I think that this corresponds to regime 1.

Also, I tried to install " install_github("MatthieuStigler/tsDyn/tsDyn", ref = "Dev94", force = T)", and this is the outcome:

library(devtools) install_github("MatthieuStigler/tsDyn/tsDyn", ref = "Dev94", force = T)

>WARNING: Rtools is required to build R packages, but no version of Rtools compatible with R 4.1.2 was found. (Only the following #>incompatible version(s) of Rtools were found:3.5)

>Please download and install Rtools 4.0 from https://cran.r-project.org/bin/windows/Rtools/.#>

>Downloading GitHub repo MatthieuStigler/tsDyn@Dev94

>Please download and install Rtools 4.0 from https://cran.r-project.org/bin/windows/Rtools/.

>Error: Failed to install 'tsDyn' from GitHub:

>Could not find tools necessary to compile a package

>Call pkgbuild::check_build_tools(debug = TRUE) to diagnose the problem.

install_github("MatthieuStigler/tsDyn/tsDyn", ref = "Dev94", force = T)

>Downloading GitHub repo MatthieuStigler/tsDyn@Dev94

>These packages have more recent versions available.

>It is recommended to update all of them.

>Which would you like to update?

>1: All

>2: CRAN packages only

>3: None

>4: tibble (3.1.5 -> 3.1.6 ) [CRAN]

>5: glue (1.4.2 -> 1.5.0 ) [CRAN]

>6: RcppArmad... (0.10.7.0.0 -> 0.10.7.3.0) [CRAN]

>7: tseries (0.10-48 -> 0.10-49 ) [CRAN]

>8: lmtest (0.9-38 -> 0.9-39 ) [CRAN]

Enter one or more numbers, or an empty line to skip updates: 1

>tibble (3.1.5 -> 3.1.6 ) [CRAN]

>glue (1.4.2 -> 1.5.0 ) [CRAN]

>RcppArmad... (0.10.7.0.0 -> 0.10.7.3.0) [CRAN]

>tseries (0.10-48 -> 0.10-49 ) [CRAN]

>lmtest (0.9-38 -> 0.9-39 ) [CRAN]

>Installing 5 packages: tibble, glue, RcppArmadillo, tseries, lmtest

>Installing packages into ‘C:/Users/DEF/Documents/R/win-library/4.1’

>(as ‘lib’ is unspecified)

>trying URL 'https://mirror.csclub.uwaterloo.ca/CRAN/bin/windows/contrib/4.1/tibble_3.1.6.zip'

>Content type 'application/zip' length 871879 bytes (851 KB)

>downloaded 851 KB

>trying URL 'https://mirror.csclub.uwaterloo.ca/CRAN/bin/windows/contrib/4.1/glue_1.5.0.zip'

>Content type 'application/zip' length 162840 bytes (159 KB)

>downloaded 159 KB

>trying URL 'https://mirror.csclub.uwaterloo.ca/CRAN/bin/windows/contrib/4.1/RcppArmadillo_0.10.7.3.0.zip'

>Content type 'application/zip' length 2388490 bytes (2.3 MB)

>downloaded 2.3 MB

>trying URL 'https://mirror.csclub.uwaterloo.ca/CRAN/bin/windows/contrib/4.1/tseries_0.10-49.zip'

>Content type 'application/zip' length 410064 bytes (400 KB)

>downloaded 400 KB

>trying URL 'https://mirror.csclub.uwaterloo.ca/CRAN/bin/windows/contrib/4.1/lmtest_0.9-39.zip'

>Content type 'application/zip' length 414874 bytes (405 KB)

>downloaded 405 KB

>package ‘tibble’ successfully unpacked and MD5 sums checked

>Warning: cannot remove prior installation of package ‘tibble’

>Warning: restored ‘tibble’

>package ‘glue’ successfully unpacked and MD5 sums checked

>Warning: cannot remove prior installation of package ‘glue’

>Warning: restored ‘glue’

>package ‘RcppArmadillo’ successfully unpacked and MD5 sums checked

>package ‘tseries’ successfully unpacked and MD5 sums checked

>Warning: cannot remove prior installation of package ‘tseries’

>Warning: restored ‘tseries’

>package ‘lmtest’ successfully unpacked and MD5 sums checked

>Warning: cannot remove prior installation of package ‘lmtest’

>Warning: restored ‘lmtest’

>The downloaded binary packages are in

> C:\Users\DEF\AppData\Local\Temp\RtmpYfOfXL\downloaded_packages

> checking for file 'C:\Users\DEF\AppData\Local\Temp\RtmpYfOfXL\remotes27d03d4c7d66\MatthieuStigler-tsDyn-#>0852a54\tsDyn/DESCRIPTION' ...

> checking for file 'C:\Users\DEF\AppData\Local\Temp\RtmpYfOfXL\remotes27d03d4c7d66\MatthieuStigler-tsDyn-#>0852a54\tsDyn/DESCRIPTION' ...

>√ checking for file 'C:\Users\DEF\AppData\Local\Temp\RtmpYfOfXL\remotes27d03d4c7d66\MatthieuStigler-tsDyn-#>0852a54\tsDyn/DESCRIPTION'

>- preparing 'tsDyn':

>checking DESCRIPTION meta-information ...

>checking DESCRIPTION meta-information ...

>√ checking DESCRIPTION meta-information

>- cleaning src

>- checking for LF line-endings in source and make files and shell scripts

>- checking for empty or unneeded directories

>- building 'tsDyn_0.9-48.999.tar.gz'

>Warning: package ‘tsDyn’ is in use and will not be installed

>Warning messages:

>1: In file.copy(savedcopy, lib, recursive = TRUE) :

> problem copying C:\Users\DEF\Documents\R\win-libr

two.csv ary\4.1\00LOCK\tibble\libs\x64\tibble.dll to C:\Users\DEF\Documents\R\win-#>library\4.1\tibble\libs\x64\tibble.dll: Permission denied

>2: In file.copy(savedcopy, lib, recursive = TRUE) :

> problem copying C:\Users\DEF\Documents\R\win-library\4.1\00LOCK\glue\libs\x64\glue.dll to C:\Users\DEF\Documents\R\win-#>library\4.1\glue\libs\x64\glue.dll: Permission denied

>3: In file.copy(savedcopy, lib, recursive = TRUE) :

> problem copying C:\Users\DEF\Documents\R\win-library\4.1\00LOCK\tseries\libs\x64\tseries.dll to #>C:\Users\DEF\Documents\R\win-library\4.1\tseries\libs\x64\tseries.dll: Permission denied

>4: In file.copy(savedcopy, lib, recursive = TRUE) problem copying

>C:\Users\DEF\Documents\R\win-library\4.1\00LOCK\lmtest\libs\x64\lmtest.dll to C:\Users\DEF\Documents\R\win-library\4.1\lmtest\libs\x64\lmtest.dll: Permission denied

Thank you, Anastasia two.csv

MatthieuStigler commented 3 years ago

Hi Anastasia

It seems you are running into various issues, and asking here many distinct questions. I think the main problem is that you did not install rtools on your computer (see message: WARNING: Rtools is required to build R packages)? This would allow you to have the dev version of tsdyn, and then run the reproducible (your example was not reproducible) example below:

library(tsDyn)
#> Registered S3 method overwritten by 'quantmod':
#>   method            from
#>   as.zoo.data.frame zoo
packageVersion("tsDyn")
#> [1] '0.9.48.999'
t5<-TVAR(zeroyld, lag=3, nthresh=1, thDelay=1, trim=0.1, mTh=2, plot=FALSE)
#> Best unique threshold 9.91

sig=apply(t5$residuals,2,sd);sig
#> short.run  long.run 
#> 0.2949858 0.5022370

grifs.t=tsDyn::GIRF(t5)
plot(grifs.t)

Created on 2021-11-28 by the reprex package (v2.0.1)

AnastaDim commented 3 years ago

Thank you very much ! L will try that right now.

zahrasaranik commented 2 years ago

Hi Anastaia. Could you solve the problem?? I have same problem!!

ninowski commented 2 years ago

hi, have you solved the problem? thank you

AnastaDim commented 2 years ago

Hello,

Still trying to solve it. As soon as I find out I will let you know.

Best, Anastasia


Από: ninowski @.> Στάλθηκε: Τετάρτη, 28 Σεπτεμβρίου 2022 12:38 μμ Προς: MatthieuStigler/tsDyn @.> Κοιν.: AnastaDim @.>; Author @.> Θέμα: Re: [MatthieuStigler/tsDyn] TVAR and GIRF (Issue #37)

hi, have you solved the problem? thank you

— Reply to this email directly, view it on GitHubhttps://github.com/MatthieuStigler/tsDyn/issues/37#issuecomment-1260649426, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AWSPANLNYI7XOZCZIXBFDKLWAQGZNANCNFSM5IM7BHKA. You are receiving this because you authored the thread.Message ID: @.***>

MatthieuStigler commented 2 years ago

Hi everyone, the issue reported above is not reproducible, and I believe it has been solved in the meanwhile. Find the reprex below, where the code works as expected.

@zahrasaranik @AnastaDim @ninowski can you please indicate what is not working, by providing a clear reprex, or showing how you are not able to replicate the issue below? Without more information and clear output error, it is hard to provide any help.

install.packages("tsDyn")
#> Installing package into '/home/mstigler/R/x86_64-pc-linux-gnu-library/4.2'
#> (as 'lib' is unspecified)
library(tsDyn)
#> Registered S3 method overwritten by 'quantmod':
#>   method            from
#>   as.zoo.data.frame zoo
packageVersion("tsDyn")
#> [1] '11.0.2'
t5<-TVAR(zeroyld, lag=3, nthresh=1, thDelay=1, trim=0.1, mTh=2, plot=FALSE)
#> Best unique threshold 9.91

sig=apply(t5$residuals,2,sd);sig
#> short.run  long.run 
#> 0.2949858 0.5022370

grifs.t=tsDyn::GIRF(t5)
plot(grifs.t)

Created on 2022-09-28 with reprex v2.0.2

ninowski commented 2 years ago

Thank you for your prompt reply. I would like to know how I can graph the generalised impulse responses for the shock of one variable on the other variables in my non-linear model. I can only get the graph of the density function. One last thing: how can I get confidence bound from the empirical distribution of simulated GIRFs assuming normality? This is my code: tvv <- TVAR(g3, lag=2, nthresh=1, thDelay=1, trim=0.1, mTh=1, plot=FALSE) girf<-GIRF(tvv) sig=apply(tvv$residuals,2,sd);sig

grifs.t=tsDyn::GIRF(tvv) plot(grifs.t)

Thank you for your help

MatthieuStigler commented 2 years ago

these are very different questions form the one here. Can you please open a distinct issue for each of these questions, with reproducible example on how far you went?

MatthieuStigler commented 2 years ago

As another issue was open, I am going to close this one, as it us not specific enough and does not provide a reproducible example.