saradi
saradi

Reputation: 141

plotting DCC results with R

I have been running a dcc garch on R; the results is presented as matrix

enter image description here

I would like to extract the second column as a vector to plot, with date on the x-axis. For the moment, if I define DCCrho = dccresults$DCC[,2] then head(DCCrho) yields this:

1 0.9256281

2 0.9256139

3 0.9245794 ...

any help to redefine this as a simple vector of numerical values? any other option to graph the results of dcc with date on the x-axis? Thanks a lot!

str(dccresults


While trying this

x <- cbind(DCCrho, com_30[,2])

head(x)

enter image description here

and this: matplot(DCCrho ~ x[,2], x, xaxt = "n", type='l')

yields the following error message:

"Error in array(x, c(length(x), 1L), if (!is.null(names(x))) list(names(x), : invalid first argument"

Upvotes: 1

Views: 1421

Answers (2)

saradi
saradi

Reputation: 141

Apparently it was a matter of length of the vector; the Date and the DCC results need to be vectors of same length.

One also needs to plot both date and DCCrho as shown below.

matplot(com_30$date, DCCrho, xaxt = "n", type='l')
axis(1, com_30$date, format(com_30$date, "%y"), cex.axis = .7)

Upvotes: 1

rbatt
rbatt

Reputation: 4807

I'm assuming that when you said, "I would like to extract the second row..." that you actually meant "column", because you did the following: dccresults$DCC[,2] Also, as pointed out by a previous comment, the code isn't reproducible, so it's difficult to propose and answer with certainty. However, I'll do my best.

You said you wanted DCCrho to be a "simple vector of numerical values". I'm assuming that this is largely a matter of the way that the values are displayed. Does DCCrho = as.vector(dccresults$DCC[,2]) look better?.

As for the error message, I think that it's b/c in matplot(x,y, ...), x can't be a formula. Try matplot(DCCrho, x[,2]).

If you just want to plot the DCCrho value across some index, you could try something like the following:

Y <- as.vector(dccresults$DCC[,2])
X <- seq_along(Y)
plot(X,Y)

Does that work? Aside from the arbitrary time index, what did you intend to reference as "time"? I don't see a part of the code that you supplied (e.g., a column in dccresults$DCC) that would be an obvious candidate for use as a "date".

Upvotes: 0

Related Questions