METHOD GUIDE
Pearson Correlation in R
cor() or cor.test(), and the Interval for r
The function cor() returns a coefficient, while cor.test() tests it and gives an interval. A correlation reported without that interval leaves a reader unable to judge how precisely the relationship was estimated and how far it can be trusted.
IN SHORT
What Pearson's r Estimates and What R Prints for It
Pearson’s r measures the strength and direction of the linear association between two continuous variables, and its test asks whether the population correlation differs from zero. To run a Pearson correlation in R, plot the pairs, call cor.test() on the two columns and report r with the interval it prints, because cor() on its own returns only the coefficient. The test and the interval assume approximately bivariate normal data, and one extreme pair can move r a long way. A coefficient describes association, and it supports a causal reading only if the design does. OnlineSPSS, a specialist statistical consultancy for academic, clinical and professional research, carries out and reviews this analysis through an in-house PhD-level statistician.
ANALYSIS SUPPORT
Analysis Support for This Method
The coefficient is the easy part, and whether a correlation or a regression answers the question is settled by the study and not by the console.
Correlation Analysis (Pearson & Spearman)
Linear and rank-based association measures for your variables, with the scatterplots, the intervals and the reporting wording agreed before the analysis starts.
Simple Linear Regression
A model that predicts one outcome from one variable, for when the slope in outcome units, and not only the strength of association, answers the question.
BEFORE YOU RUN IT
Checks That Come Before the Coefficient
A single r can hide a curve, a cluster or an outlier, so the scatterplot is drawn and the pairs are counted before cor.test() is called.
Interval-Scale Measures Both variables are measured on an interval or ratio scale. Binary variables call for other measures, and ordinal items are better served by a rank-based coefficient.
A Roughly Linear Cloud Pearson's r summarizes a linear pattern only. A curved or fan-shaped cloud gives a coefficient that misdescribes the relationship, which the scatterplot shows at a glance.
Extreme Pairs One extreme pair can raise, lower or even reverse r. Inspect the cloud, and if a pair is set aside, state the rule and show the coefficient with and without it.
Unrelated Cases Each row contributes a single pair of values. Repeated measurements on the same people, or cases nested in classes or clinics, make pairs dependent and the interval too narrow.
IN R
How to Run a Pearson Correlation in R
Everything here is in base R: cor() for the coefficient and cor.test() for the test and interval. A matrix with p-values comes from an add-on such as Hmisc or psych, cited with its version.
- Confirm the design: two continuous variables and one pair of values per case.
- Draw plot(d$x, d$y) and look for curvature, clusters and extreme points.
- Count the complete pairs with sum(complete.cases(d$x, d$y)).
- Run cor.test(d$x, d$y), or cor.test(~ x + y, data = d), and read r, df, p and the interval.
- For several variables, use cor(d[vars], use = “pairwise.complete.obs”) to get a correlation matrix in R and note that cells can rest on different n.
- Save the plot and the script, and record the R version.
READING THE OUTPUT
What cor.test() Prints That cor() Omits
A bare cor() call returns one number, cor.test in R adds the statistic, the degrees of freedom and the interval, and a matrix brings pitfalls of its own.
| Output element | What it tells you | What to check |
|---|---|---|
| Header line | Pearson’s product-moment correlation, with the two variables in the data line | That the method is Pearson and not a rank-based coefficient |
| t and df | The test statistic, with df equal to the number of complete pairs minus 2 | That df plus 2 equals the number of pairs you expected |
| p-value | The two-sided test of a population correlation of zero | That a small p is not read as a strong relationship |
| Alternative hypothesis | That the true correlation is not equal to 0, unless a direction was requested | That any one-sided alternative was planned before the data were seen |
| 95 percent confidence interval | A range for the population correlation, based on the Fisher z transformation | That its width is discussed, and that at least four complete pairs exist |
| sample estimates: cor | The coefficient r, from -1 to 1, with its sign for direction | That the sign agrees with the scatterplot |
| Matrix from cor() with pairwise use | A coefficient for every pair of variables, each from its own complete pairs | That the n behind each cell and the number of coefficients examined are stated |
REPORTING
Wording r With Its Interval
The coefficient, its degrees of freedom and its interval travel together, and n is stated because a matrix can hide differences in it.
Write r(df) = ___, 95% CI [___, ___], p = ___, with df equal to the number of complete pairs minus 2. Use the sign of r to say in words whether higher values of one variable go with higher or lower values of the other, and describe the strength in terms of your field, not a fixed cutoff. Base R does not print r squared, so if shared variance is mentioned, square r yourself. For a table of several correlations, give the n behind each cell, state how many coefficients were tested and say whether any adjustment was made. Describe the result as an association, because a correlation in observational data does not show that one variable influences the other.
COMMON MISTAKES
Where a Correlation Result Loses Credibility
Most of these come from what the coefficient was never able to show, and a few from how R handles the columns it is given.
Scale Score Correlated With Its Own Item Correlating a scale score with one of its own items, or two scores that share items, builds part of the association into the data. The shared item is removed from the total before correlating, or the overlap is stated beside the coefficient.
A Matrix of Uncorrected Tests Twenty variables give 190 pairs, and a few will look significant by chance. The number of tests is stated, and an adjustment or an explicit exploratory label is used.
Range Narrowed by Selection A sample selected on one of the variables, such as only high scorers, usually shrinks r compared with the full population. The sampling frame belongs beside the coefficient.
Pooled Subgroups Two groups with different means can create or hide a correlation that neither shows alone, so a grouping variable is plotted before the pooled r is quoted.
Correlation Read as Agreement A high r shows that two measures move together, not that they agree. For a comparison of two methods of measurement, the differences between them are examined directly.
Group Means Read as Individual Data A correlation computed from averages per school or clinic is often far stronger than the correlation between the individuals in them, and it describes the groups only. The level of the data is stated with the coefficient.
A correlation table is easy to over-read. Independent Statistical Review checks the n behind each cell, the interval and the wording of the table.
FREQUENTLY ASKED QUESTIONS
Questions About cor() and cor.test() in R
A function that returns NA, an interval that adds what the p-value cannot, and a comparison of two coefficients that cor.test() does not perform.
Why does cor() return NA in R?
The default setting of use passes missing values through, so any NA in a column makes the coefficient NA. For a single pair, use = “complete.obs” drops incomplete rows, and for a matrix, use = “pairwise.complete.obs” uses each pair’s own complete rows. Report how many pairs remain, because cor.test() removes incomplete pairs on its own and the two functions can then rest on different data.
What does the interval around r tell me that the p-value does not?
It shows the range of population correlations compatible with the data, so it conveys precision as well as direction. In a large sample a very small r can be significant, and the interval shows how small. In a small sample a sizeable r can come with a wide interval, which a reader needs to see before relying on it.
Can I compare two correlations with cor.test()?
No, each call tests one coefficient against zero. Whether two coefficients differ needs a test for the difference, and the method depends on whether the correlations come from independent samples or share a variable in one sample. Add-on packages such as cocor provide them. Overlapping intervals are not a substitute for that test.
How is a correlation table checked before I report it?
An in-house PhD-level statistician can check the pairs behind each coefficient, the intervals and the handling of many tests, or run the analysis on your data. Presenting settled results in your chapter is the work of Results Reporting & Interpretation. What the association means for your field is your judgment.
How do you protect my research data and confidentiality?
Your data and project details are handled confidentially, and project information is not published. Researcher names and institutions are not used publicly without permission. An NDA is available where required and can be arranged before sensitive materials are shared. Read more about confidentiality and data security.
What happens when I request an assessment, and how long does it take?
You share your research question, design and relevant materials, such as the dataset or the output you have, and a statistically trained Research Coordinator reviews the request and responds the same day. The analysis, deliverables, timeline and one fixed project fee are then confirmed before any work begins, so the timeline follows from the agreed scope.
Still have a question? Find more answers in our full FAQ.
NEXT STEP
Is Your Correlation Table
Ready for a Reviewer?
An examiner reads a correlation table one coefficient at a time and asks where each n and each interval came from. The fee for a review is one fixed project fee, confirmed after a Research Coordinator has read the request.
No Commitment Required
Strictly Confidential
Fixed Project Fee
In-House PhD-Level Statisticians
Same-Day Response
Serving Researchers Since 2014