[r] How to obtain the correlation coefficients between two variables in the R object

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[r] How to obtain the correlation coefficients between two variables in the R object

Subhamitra Patra
Dear R-users,

I am estimating the DCC-model by using the following code and successfully
making the individual plots indicating the dynamic correlation between the
two variables stored in the R data frame (namely dcc.fit in my code). My
code is

Dat = Date2[,2:13, drop = FALSE]
library(rmgarch)
library(rugarch)
xspec = ugarchspec(mean.model = list(armaOrder = c(1, 1)), variance.model =
list(garchOrder = c(1,1), model = 'eGARCH'), distribution.model = 'norm')
uspec = multispec(replicate(12, xspec)) # Define a function using xspec
dcc.garch11spec = dccspec(uspec = uspec, dccOrder = c(1, 1), distribution =
'mvnorm')
dcc.fit = dccfit(dcc.garch11spec, data = Dat)
r1=rcor(dcc.fit, type="R")
print(r1)

Here, I need to obtain the DCC relationship between the two variables. I
successfully make a separate plot for the correlation between the two
variables with the following code.
plot(rcor(dcc.fit, type="R")['A1','A2',], type='l')
plot(rcor(dcc.fit, type="R")['B1','B2',], type='l')
plot(rcor(dcc.fit, type="R")['C1','C2',], type='l')
plot(rcor(dcc.fit, type="R")['D1','D2',], type='l')
plot(rcor(dcc.fit, type="R")['E1','E2',], type='l')
plot(rcor(dcc.fit, type="R")['F1','F2',], type='l')

Here, I request your help on two things which I am unable to do.

1. I need to arrange all the above individual plots (counted as 6) on one
page.
2. I need to obtain the correlation coefficients between the particular two
variables (i.e. A1 versus A2, B1 versus B2, .......so on) throughout the
entire period.

For your convenience, I have attached my sample data.

I definitely expect a positive help from the experts as the suggestions
from the expert through this R forum has always solved my previous problem.

Thank you.

--
*Best Regards,*
*Subhamitra Patra*
*Phd. Research Scholar*
*Department of Humanities and Social Sciences*
*Indian Institute of Technology, Kharagpur*
*INDIA*

[image: Mailtrack]
<https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&>
Sender
notified by
Mailtrack
<https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&>
11/25/19,
04:00:39 PM
______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: [r] How to obtain the correlation coefficients between two variables in the R object

Michael Dewey-3
To get multiple plots on the same physical page try
?layout
ot look through the various option under
?par

I do not know enough about DCC models to answer how you get correlations.

Michael

On 25/11/2019 10:34, Subhamitra Patra wrote:

> Dear R-users,
>
> I am estimating the DCC-model by using the following code and successfully
> making the individual plots indicating the dynamic correlation between the
> two variables stored in the R data frame (namely dcc.fit in my code). My
> code is
>
> Dat = Date2[,2:13, drop = FALSE]
> library(rmgarch)
> library(rugarch)
> xspec = ugarchspec(mean.model = list(armaOrder = c(1, 1)), variance.model =
> list(garchOrder = c(1,1), model = 'eGARCH'), distribution.model = 'norm')
> uspec = multispec(replicate(12, xspec)) # Define a function using xspec
> dcc.garch11spec = dccspec(uspec = uspec, dccOrder = c(1, 1), distribution =
> 'mvnorm')
> dcc.fit = dccfit(dcc.garch11spec, data = Dat)
> r1=rcor(dcc.fit, type="R")
> print(r1)
>
> Here, I need to obtain the DCC relationship between the two variables. I
> successfully make a separate plot for the correlation between the two
> variables with the following code.
> plot(rcor(dcc.fit, type="R")['A1','A2',], type='l')
> plot(rcor(dcc.fit, type="R")['B1','B2',], type='l')
> plot(rcor(dcc.fit, type="R")['C1','C2',], type='l')
> plot(rcor(dcc.fit, type="R")['D1','D2',], type='l')
> plot(rcor(dcc.fit, type="R")['E1','E2',], type='l')
> plot(rcor(dcc.fit, type="R")['F1','F2',], type='l')
>
> Here, I request your help on two things which I am unable to do.
>
> 1. I need to arrange all the above individual plots (counted as 6) on one
> page.
> 2. I need to obtain the correlation coefficients between the particular two
> variables (i.e. A1 versus A2, B1 versus B2, .......so on) throughout the
> entire period.
>
> For your convenience, I have attached my sample data.
>
> I definitely expect a positive help from the experts as the suggestions
> from the expert through this R forum has always solved my previous problem.
>
> Thank you.
>

--
Michael
http://www.dewey.myzen.co.uk/home.html

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: [r] How to obtain the correlation coefficients between two variables in the R object

Subhamitra Patra
Thank you for your suggestion. Actually, the correlation is coming in the
DCC model through my above code which I am able to plot it. Is there any
solution that I can extract data from a particular plot. Actually, I am
able to obtain the correlation matrix, but I need the correlation
coefficient series indicating the correlation coefficients between the two
variables.



[image: Mailtrack]
<https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&>
Sender
notified by
Mailtrack
<https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&>
11/25/19,
07:12:49 PM

On Mon, Nov 25, 2019 at 7:10 PM Michael Dewey <[hidden email]>
wrote:

> To get multiple plots on the same physical page try
> ?layout
> ot look through the various option under
> ?par
>
> I do not know enough about DCC models to answer how you get correlations.
>
> Michael
>
> On 25/11/2019 10:34, Subhamitra Patra wrote:
> > Dear R-users,
> >
> > I am estimating the DCC-model by using the following code and
> successfully
> > making the individual plots indicating the dynamic correlation between
> the
> > two variables stored in the R data frame (namely dcc.fit in my code). My
> > code is
> >
> > Dat = Date2[,2:13, drop = FALSE]
> > library(rmgarch)
> > library(rugarch)
> > xspec = ugarchspec(mean.model = list(armaOrder = c(1, 1)),
> variance.model =
> > list(garchOrder = c(1,1), model = 'eGARCH'), distribution.model = 'norm')
> > uspec = multispec(replicate(12, xspec)) # Define a function using xspec
> > dcc.garch11spec = dccspec(uspec = uspec, dccOrder = c(1, 1),
> distribution =
> > 'mvnorm')
> > dcc.fit = dccfit(dcc.garch11spec, data = Dat)
> > r1=rcor(dcc.fit, type="R")
> > print(r1)
> >
> > Here, I need to obtain the DCC relationship between the two variables. I
> > successfully make a separate plot for the correlation between the two
> > variables with the following code.
> > plot(rcor(dcc.fit, type="R")['A1','A2',], type='l')
> > plot(rcor(dcc.fit, type="R")['B1','B2',], type='l')
> > plot(rcor(dcc.fit, type="R")['C1','C2',], type='l')
> > plot(rcor(dcc.fit, type="R")['D1','D2',], type='l')
> > plot(rcor(dcc.fit, type="R")['E1','E2',], type='l')
> > plot(rcor(dcc.fit, type="R")['F1','F2',], type='l')
> >
> > Here, I request your help on two things which I am unable to do.
> >
> > 1. I need to arrange all the above individual plots (counted as 6) on one
> > page.
> > 2. I need to obtain the correlation coefficients between the particular
> two
> > variables (i.e. A1 versus A2, B1 versus B2, .......so on) throughout the
> > entire period.
> >
> > For your convenience, I have attached my sample data.
> >
> > I definitely expect a positive help from the experts as the suggestions
> > from the expert through this R forum has always solved my previous
> problem.
> >
> > Thank you.
> >
>
> --
> Michael
> http://www.dewey.myzen.co.uk/home.html
>


--
*Best Regards,*
*Subhamitra Patra*
*Phd. Research Scholar*
*Department of Humanities and Social Sciences*
*Indian Institute of Technology, Kharagpur*
*INDIA*

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: [r] How to obtain the correlation coefficients between two variables in the R object

PIKAL Petr
Hi

Without knowing much about functions you use, instead of plotting you could
save results of rcor(dcc.fit, type="R") to

something <- rcor(dcc.fit, type="R")

and use

str(something) to inspect the structure.

Cheers
Petr

> -----Original Message-----
> From: R-help <[hidden email]> On Behalf Of Subhamitra
> Patra
> Sent: Monday, November 25, 2019 2:46 PM
> To: Michael Dewey <[hidden email]>; r-help mailing list <r-
> [hidden email]>
> Subject: Re: [R] [r] How to obtain the correlation coefficients between
two

> variables in the R object
>
> Thank you for your suggestion. Actually, the correlation is coming in the
> DCC model through my above code which I am able to plot it. Is there any
> solution that I can extract data from a particular plot. Actually, I am
> able to obtain the correlation matrix, but I need the correlation
> coefficient series indicating the correlation coefficients between the two
> variables.
>
>
>
> [image: Mailtrack]
> <https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_ca
> mpaign=signaturevirality5&>
> Sender
> notified by
> Mailtrack
> <https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_ca
> mpaign=signaturevirality5&>
> 11/25/19,
> 07:12:49 PM
>
> On Mon, Nov 25, 2019 at 7:10 PM Michael Dewey
> <[hidden email]>
> wrote:
>
> > To get multiple plots on the same physical page try
> > ?layout
> > ot look through the various option under
> > ?par
> >
> > I do not know enough about DCC models to answer how you get
> correlations.
> >
> > Michael
> >
> > On 25/11/2019 10:34, Subhamitra Patra wrote:
> > > Dear R-users,
> > >
> > > I am estimating the DCC-model by using the following code and
> > successfully
> > > making the individual plots indicating the dynamic correlation between
> > the
> > > two variables stored in the R data frame (namely dcc.fit in my code).
My
> > > code is
> > >
> > > Dat = Date2[,2:13, drop = FALSE]
> > > library(rmgarch)
> > > library(rugarch)
> > > xspec = ugarchspec(mean.model = list(armaOrder = c(1, 1)),
> > variance.model =
> > > list(garchOrder = c(1,1), model = 'eGARCH'), distribution.model =
'norm')
> > > uspec = multispec(replicate(12, xspec)) # Define a function using
xspec
> > > dcc.garch11spec = dccspec(uspec = uspec, dccOrder = c(1, 1),
> > distribution =
> > > 'mvnorm')
> > > dcc.fit = dccfit(dcc.garch11spec, data = Dat)
> > > r1=rcor(dcc.fit, type="R")
> > > print(r1)
> > >
> > > Here, I need to obtain the DCC relationship between the two variables.
I

> > > successfully make a separate plot for the correlation between the two
> > > variables with the following code.
> > > plot(rcor(dcc.fit, type="R")['A1','A2',], type='l')
> > > plot(rcor(dcc.fit, type="R")['B1','B2',], type='l')
> > > plot(rcor(dcc.fit, type="R")['C1','C2',], type='l')
> > > plot(rcor(dcc.fit, type="R")['D1','D2',], type='l')
> > > plot(rcor(dcc.fit, type="R")['E1','E2',], type='l')
> > > plot(rcor(dcc.fit, type="R")['F1','F2',], type='l')
> > >
> > > Here, I request your help on two things which I am unable to do.
> > >
> > > 1. I need to arrange all the above individual plots (counted as 6) on
one
> > > page.
> > > 2. I need to obtain the correlation coefficients between the
particular
> > two
> > > variables (i.e. A1 versus A2, B1 versus B2, .......so on) throughout
the
> > > entire period.
> > >
> > > For your convenience, I have attached my sample data.
> > >
> > > I definitely expect a positive help from the experts as the
suggestions

> > > from the expert through this R forum has always solved my previous
> > problem.
> > >
> > > Thank you.
> > >
> >
> > --
> > Michael
> > http://www.dewey.myzen.co.uk/home.html
> >
>
>
> --
> *Best Regards,*
> *Subhamitra Patra*
> *Phd. Research Scholar*
> *Department of Humanities and Social Sciences*
> *Indian Institute of Technology, Kharagpur*
> *INDIA*
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.