[R] Fwd: Why does impulse response function of VAR starts at zero and not at one?

2013-07-24 Thread José Verhoeven
Hi there,
I sent this e-mail two days ago, but I did not see it pass by the R-help
mailinglist and I was wondering if you could post it or is there a que?
Thanks in advance.

Kind regards,
Jose




-- Forwarded message --
From: José Verhoeven 
Date: 2013/7/22
Subject: Why does impulse response function of VAR starts at zero and not
at one?
To: r-help@r-project.org


Hi there,
I have estimated a bivariate VAR model (with series x1 and x2 as endogenous
variables):

y=cbind(x1,x2)
z=cbind(d1,d2,d3,d4,d5,d6,d7,d8,d9)   # some dummy variables

model<-VAR(y, p = 3, type = c("const", "trend", "both", "none"),
season = NULL, exogen = z, lag.max = NULL,
ic = c("AIC", "HQ", "SC", "FPE"))

and I have plotted the cumulative impulse response function with:

impulseresponse<-irf(lagmodel, impulse = "x2", response = "x1", n.ahead =
400,
ortho = TRUE, cumulative = TRUE, boot = FALSE)
plot(impulseresponse)

Now as the impulse response function shows the effect on e.g. x1 of a unit
shock in x2 I expect the value at t=0 to be at or around one (depending on
whether there is an interscept in the model). Why then, does all impulse
response plots I get start at zero?

I really hope someone can help me out! Thanks in advance.

Jose

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Why does impulse response function of VAR starts at zero and not at one?

2013-07-22 Thread José Verhoeven
Hi there,
I have estimated a bivariate VAR model (with series x1 and x2 as endogenous
variables):

y=cbind(x1,x2)
z=cbind(d1,d2,d3,d4,d5,d6,d7,d8,d9)   # some dummy variables

model<-VAR(y, p = 3, type = c("const", "trend", "both", "none"),
season = NULL, exogen = z, lag.max = NULL,
ic = c("AIC", "HQ", "SC", "FPE"))

and I have plotted the cumulative impulse response function with:

impulseresponse<-irf(lagmodel, impulse = "x2", response = "x1", n.ahead =
400,
ortho = TRUE, cumulative = TRUE, boot = FALSE)
plot(impulseresponse)

Now as the impulse response function shows the effect on e.g. x1 of a unit
shock in x2 I expect the value at t=0 to be at or around one (depending on
whether there is an interscept in the model). Why then, does all impulse
response plots I get start at zero?

I really hope someone can help me out! Thanks in advance.

Jose

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] estimating VAR(p) model leaving out intermediate lags

2013-05-29 Thread José Verhoeven
Hi,
I would like to estimate a VAR(5) model, but including lags T-1, T-7, T-14,
T-21 and T-28 instead of the usual T-1, T-2, T-3, T-4, T-5.
But it seems I cannot accomplish this by using the below function.

VAR(y, p = 1, type = c("const", "trend", "both", "none"),
season = NULL, exogen = NULL, lag.max = NULL,
ic = c("AIC", "HQ", "SC", "FPE"))

Does there exist a function to do this of what code could I use instead?

Hope you can help me out!

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Sum first 3 non zero elements of row

2013-05-21 Thread José Verhoeven
Thank you, that really worked. Actually received an even shorter version:

rowSums((t(apply(D > 0, 1, cumsum)) <= 3) * D)



2013/5/21 Xiao He 

> Oops, a couple of missing brackets in the previous reply:
>
>
> foo<-function(x){
>   temp=x[x>0]
>   if(length(temp)>=3) sum(temp[1:3])
>   else sum(temp)
> }  #<This was missing in the previous post
>
>
> set.seed(2)
> mat<-matrix(sample(0:4, 25, replace=T, prob=c(1/2,rep(1/8,4))), ncol=5)
>  #add a right parenthesis.
> mat
>
> On Tue, May 21, 2013 at 3:47 AM, Xiao He wrote:
>
>> Does this work? Probably not the fastest, but I think it does the job.
>>
>> foo<-function(x){
>>   temp=x[x>0]
>>   if(length(temp)>=3) sum(temp[1:3])
>>   else sum(temp)
>>
>> set.seed(2)
>> mat<-matrix(sample(0:4, 25, replace=T, prob=c(1/2,rep(1/8,4)), ncol=5)
>> mat
>>
>> # [,1] [,2] [,3] [,4] [,5]
>> #[1,]01243
>> #[2,]30010
>> #[3,]24404
>> #[4,]00000
>> #[5,]12000
>>
>>
>> apply(mat, 1, foo)#Apply the function to each row of the matrix
>> #[1]  7  4 10  0  3
>>
>>
>>
>> On Tue, May 21, 2013 at 2:16 AM, José Verhoeven  wrote:
>>
>>> Hi there,
>>> I've got this matrix D with, say 10 rows and 20 columns. For each row I
>>> want
>>> to sum the first 3 non zero elements and put them in a vector z.
>>>
>>> So if the first row D[1,] is
>>> 0 3 5 0 8 9 3 2 4 0
>>>
>>> then I want z
>>> z<-D[1,2]+D[1,3]+D[1,5]
>>>
>>> But if there are less than 3 non zero elements, those should be summed.
>>> If
>>> there are no non zero elements, the result must be zero.
>>>
>>> So if the first row D[1,] is
>>> 0 0 3 0 1 0 0 0 0 0
>>>
>>> then I want z
>>> z<-D[1,3]+D[1,5]
>>>
>>> Hope someone can help me out!
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Sum first 3 non zero elements of row

2013-05-21 Thread José Verhoeven
Hi there,
I've got this matrix D with, say 10 rows and 20 columns. For each row I want
to sum the first 3 non zero elements and put them in a vector z.

So if the first row D[1,] is
0 3 5 0 8 9 3 2 4 0

then I want z
z<-D[1,2]+D[1,3]+D[1,5]

But if there are less than 3 non zero elements, those should be summed. If
there are no non zero elements, the result must be zero.

So if the first row D[1,] is
0 0 3 0 1 0 0 0 0 0

then I want z
z<-D[1,3]+D[1,5]

Hope someone can help me out!

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.