The adfresd function that you have, prints the outcome of the test rather
than `return' ing a value. If you would modify that function to return a
value (True or false/ or p-value) you should automatically get vector that
you desire. Then is a simple task of naming the resultant vector with.

apply(b,2, paste, collapse="_")

On Thu, Aug 12, 2010 at 10:15 AM, Ferreira, Thiago Alves <
thiago.alves.ferreira@citi.com> wrote:

> Hello Nikhil, hope you are well today.
> I am sorry to be a pain but I have one follow up question, I am trying to
> express my results in a grid, which would look like a 6 by 6 matrix and
> would have just Yes or NO in each grid..
> So what I am thinking is a way to store every result I get on "
> apply(b,2,coint) " in an array or vector, and express them is this matrix.
> So that I can just look at it and see whether assets swap2 and vol are
> cointegrated..
>
> Do you reckon you point me in the right direction as to how to do that?
>
> Thank you!
> Thiago
>
> -----Original Message-----
> From: Nikhil Kaza [mailto:nikhil.list@gmail.com]
> Sent: 11 August 2010 12:35
> To: Ferreira, Thiago Alves [ICG-MKTS]
> Cc: 'r-help@R-project.org'
> Subject: Re: [R] Help with permutation / loops
>
> How about this?
>
> untested since no data is provided.
>
> a <- paste("x",1:6,sep="")
> b<- combn(a,2)
>
> > coint<-function (x)
> > {
>        x1 <- get(x[1])
>        x2 <- get(x[2])
> >        adfdata(x1)
> >        adfdata(x2)
> >
> >        engle<-lm(x1~x2)
> >        residual<-resid(engle)
> >        adfresd(residual, k=1)
> >
> >                                par(mfrow=c(2,1))
> >                                ts.plot(x1)
> >                                ts.plot(x2)
> >                                ts.plot(residual) }
>
>
> apply(b,2,coint)
>
>
> Careful with the plots, you may just overwrite them on default device.
> One way to overcome it is to plot them to a pdf and name them appropriately
> for each iteration.
>
> Nikhil Kaza
> Asst. Professor,
> City and Regional Planning
> University of North Carolina
>
> nikhil.list@gmail.com
>
> On Aug 11, 2010, at 6:34 AM, Ferreira, Thiago Alves wrote:
>
> > Hi everyone,
> > I am writing a code for cointegration between n (n=6 initially) pairs.
> >
> > I have done the whole thing for 2 variables. There is a function
> > coint(x1,x2) that takes 2 inputs x1 and x2 and does the following:
> >
> > coint<-function (x1,x2)
> > {
> >        adfdata(x1)
> >        adfdata(x2)
> >
> >        engle<-lm(x1~x2)
> >        residual<-resid(engle)
> >        adfresd(residual, k=1)
> >
> >                                par(mfrow=c(2,1))
> >                                ts.plot(x1)
> >                                ts.plot(x2)
> >                                ts.plot(residual) }
> >
> > Where X1,x2,..,x6 are time series of length 250 or more
> >
> > Where adfdata() is a function that calculates the adf test for x1 and
> > x2. There are 6 variables in total (x1,x2,...,x6) and I want to
> > calculate this function coint for the permutation of these variables.
> > That is coint(x1,x2); coint(x1,x3);
> > coint(x1,x4);...coint(x6,x5) (without repetition because x1,x1 are
> > cointegrated already)
> >
> > I thought about creating an array with the combinations Xi,Xj and
> > apply the function to each combination in the array but I could not
> > get it to work...
> > I would really appreciate if someone could help me on this!
> >
> > Thank you,
> > Kind regards,
> > Thiago
> >
> > ______________________________________________
> > 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]]

