-1 – a perfectly negative association between the two variables.The Pearson correlation coefficient is a value that ranges from -1 to 1. So, by looking at my example output, the Pearson correlation coefficient is 0.52. sample estimates – the Pearson correlation coefficient.95 percent confidence interval – the 95% confidence intervals.alternative hypothesis – a description of the alternative hypothesis.p-value – the p-value for the Pearson correlation test.There are a few parameters returned in the results of the Pearson correlation test. Pearson's product-moment correlationĪlternative hypothesis: true correlation is not equal to 0 The output of my example is displayed below. #One-sided (positive association) Pearson correlation testĪlternative = "greater") Interpretation of results “less” – less than zero (ie, negative correlation)įor example, if you wanted to run a one-sided Pearson correlation test with the alternative hypothesis describing a positive association, then enter the following.“greater” – greater than zero (ie, positive correlation).alternative – change the alternative hypothesis (default is “two.sided”).#Pearson correlation test with 0.90 confidence level
conf.level – change the confidence level (default is 0.95)įor example, if you want to run a Pearson correlation test with a confidence level of 0.90, then enter the following.Some of the main ones you may be interested in are defined below. There are some additional arguments that you can change in the cor.test function. Method = "pearson") Additional settings of interest #Pearson correlation test using the trees dataset
So, my code will look like the following. #Run the Pearson correlation testīy using my example, I am interested in the correlation between the girth and height variables in the trees dataset. Simply replace x and y with the names of the two variables. The code to run the Pearson correlation in R is displayed below. These are the two variables that you want to correlate in the Pearson correlation. The cor.test function requires two inputs: x and y. To perform the Pearson correlation test, use the cor.test function.īy default, the cor.test function performs a two-sided Pearson correlation test. Step 2: Perform the Pearson correlation test You should now see the tree dataset in the environment. To load the trees dataset, simply run the following code. In this example, I will be using the trees dataset in R. The first step to perform a Pearson correlation in R is that you need some data containing the two variables of interest. If you’re interested in learning more about performing correlations in R, then check out DataCamp’s interactive Correlation and Regression in R online course. There are no additional package requirements the correlation function is part of the standard R platform. It is really easy to perform a Pearson correlation test in R.
How to perform a Pearson correlation test in R