Skip to main content

First post using stackedit

Welcome to StackEdit! Hey! I’m your first Markdown document in StackEdit1. Don’t delete me, I’m very helpful! I can be recovered anyway in the Utils tab of the Settings dialog.
Documents StackEdit stores your documents in your browser, which means all your documents are automatically saved locally and are accessible offline!
StackEdit is accessible offline after the application has been loaded for the first time.Your local documents are not shared between different browsers or computers.Clearing your browser’s data may delete all your local documents! Make sure your documents are synchronized with Google Drive or Dropbox (check out the Synchronization section). Create a document The document panel is accessible using the button in the navigation bar. You can create a new document by clicking New document in the document panel.
Switch to another document All your local documents are listed in the document panel. You can switch from one to another by clicking a document in the li…

Testing the difference between two correlations in R


Correlation is the measurement to measure how two datasets increase or decrease together. It's a real number range from -1 (i.e, when one dataset increases, another one decreases and vice versa) to +1 (i.e, these two datasets increase or decrease together). Value 0 means there is no relationship between two datasets.

Calculating correlation

Calculating correlation of two datasets in R is quite straightforward:

In R:

> x = c (1,5,2,6,7)
> y = c (2,4,3,9,-5)
> cor(x,y)
[1] -0.1459338

Usually, a single value does not say much in statistics. You need a confidence level.

> cor.test (x, y)

Pearson's product-moment correlation

data:  x and y
t = -0.2555, df = 3, p-value = 0.8149
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 -0.9109173  0.8451475
sample estimates:

The function 'cor.test' will gives you the correlation, and also 95% confidence level of two datasets.

Testing two correlations

Now, we move to the next part: testing two correlations, to see whether they are different or not.

In this section, I will use the package "cocor". In order to use this package, you need to install it.

> install.packages ("cocor")
> library (cocor)

The following example comes from cocor documentation, which can be found at

> data (“aptitude”)

> cocor (~logic + intelligence.a | logic + intelligence.a, aptitude)
 Results of a comparison of two correlations based on independent groups
Comparison between r1.jk (logic, intelligence.a) = 0.3213 and (logic, intelligence.a) = 0.2024
Difference: r1.jk— = 0.1189
Data: sample1: j = logic, k = intelligence.a; sample2: h = logic, m = intelligence.a
Group sizes: n1 = 291, n2 = 334
Null hypothesis: r1.jk is equal to
Alternative hypothesis: r1.jk is not equal to (two-sided)
Alpha: 0.05
fisher1925: Fisher’s z (1925)
z = 1.5869, p-value = 0.1125
Null hypothesis retained
zou2007: Zou’s (2007) confidence interval
95% confidence interval for r1.jk— -0.0281 0.2637

Null hypothesis retained (Interval includes 0)

Please do not forget the sign ~ at the beginning of the formula.
From the result, we can conclude whether two correlations are different or not (again, with a confidence interval)


Popular posts from this blog

Installing tensorflow on Mac OS 10.11

Tensorflow ( is the open source deep learning library from Google (

Installing Tensorflow is not easy on Mac if you follow exactly the installation instruction on the homepage. I have no idea why. I have error then error while trying to install Tensorflow with pip, with virtualenv, or even with Docker.

However, with Anaconda (, it will be easy. The trick is you should download the wheel file and install it offline other than retrieving it online as suggested by Tensorflow homepage.

So, with anaconda for python2 installed, I did:

# create a new environment with sklearn installed, up to you
# if you want a pure Python, replace scikit-learn by python
conda create -n tensorflow scikit-learn

# activate the new environment
source activate tensorflow

# download the wheel file


Luật doanh nghiệp năm 2005 song ngữ Việt - Anh

Văn bản: Luật doanh nghiệp số 60/2005/QH11, được thông qua tại kỳ họp thứ 8, Quốc hội khóa XI, ngày 29 tháng 11 năm 2005, có hiệu lực từ ngày 1 tháng 7 năm 2006.
Nguồn văn bản tiếng Anh: Bộ tư pháp

Định dạng: PDF
Song ngữ Việt - Anh.
Người biên tập:
Link download: