To get the R² (coefficient of determination) value in Google Sheets, use the RSQ function: =RSQ(y_range, x_range). This returns a number between 0 and 1 that tells you how well your data fits a linear trendline. For example, if your y-values are in B2:B10 and x-values are in A2:A10, enter =RSQ(B2:B10, A2:A10) in any cell. You can also display R² directly on a chart by adding a trendline label. This guide covers both methods, plus how to interpret the result.
What You’ll Need
- A Google Sheets document with your data organized in two columns: one for the independent (x) variable and one for the dependent (y) variable.
- At least two data points (more is better for meaningful results).
- Basic familiarity with entering formulas in Google Sheets.
Step-by-Step
Method 1: Using the RSQ Function
- Open your Google Sheet in a web browser (sheets.google.com). Ensure your data is in two columns. For this example, put x-values in column A (A2:A10) and y-values in column B (B2:B10).
- Select an empty cell where you want the R² value to appear (e.g., D2).
- Type the formula:
=RSQ(B2:B10, A2:A10). Note: The first argument is the y-range, the second is the x-range. Press Enter. - Read the result: The cell displays the R² value. For example, if your data perfectly fits a straight line, the result will be 1. If there is no linear relationship, it will be close to 0.
Method 2: Adding R² to a Chart Trendline
- Select your data (both columns, including headers if you have them).
- Insert a chart: Click Insert in the top menu, then Chart. Google Sheets usually creates a scatter chart by default. If not, in the Chart editor (right side), under Setup, choose Scatter chart.
- Open the Chart editor (double-click the chart if it’s not open). Go to the Customize tab.
- Add a trendline: Click Series, then check the box for Trendline.
- Show R²: In the same section, check the box for Show R². The R² value will appear on the chart near the trendline.
Common Mistakes
- Reversing the arguments: In
RSQ, the first argument must be the y-range (dependent variable) and the second the x-range (independent variable). Swapping them gives the same R² value (since R² is symmetric), but it’s good practice to keep them correct for clarity. - Including text or empty cells: RSQ ignores text and empty cells, but if your ranges include headers (e.g., B1:B10 with B1 as a label), the function will ignore the text, but it’s safer to exclude headers to avoid confusion.
- Using non-numeric data: If any cell contains text that looks like a number (e.g., ‘5), RSQ may return an error. Ensure all data cells are numeric.
- Misinterpreting R²: A high R² (close to 1) does not mean causation, and a low R² does not mean the data is useless—it just means a linear model doesn’t fit well.
Tips
- Use absolute references if you plan to copy the formula:
=RSQ($B$2:$B$10, $A$2:$A$10). - Check for outliers: A single outlier can dramatically affect R². Create a scatter plot to visually inspect your data.
- R² vs. correlation: The correlation coefficient (r) is the square root of R². To get r, use
=CORREL(B2:B10, A2:A10). R² is always between 0 and 1, while r is between -1 and 1. - For non-linear data: R² from RSQ only measures linear fit. If your data is curved, consider using a polynomial trendline (in the chart editor, under Trendline type) and its R² will be shown differently.
Troubleshooting
- #N/A error: This occurs when the x and y ranges have different numbers of data points. Make sure both ranges have the same number of cells.
- #DIV/0! error: This happens when the variance of the x or y data is zero (i.e., all x values are the same). R² is undefined in that case because there is no variation to explain.
- #VALUE! error: This usually means one of the ranges contains non-numeric data that isn’t being ignored (e.g., a formula that returns text). Check for any cells with errors or text.
- R² not showing on chart: If you checked ‘Show R²’ but nothing appears, make sure you have selected a trendline type that supports it (linear, exponential, etc.) and that your chart is a scatter chart, not a line chart (line charts treat x as categories).
- Result seems too high or low: Double-check that you selected the correct ranges. A common mistake is selecting the wrong column for x and y.
Frequently Asked Questions
What does R² mean in simple terms?
R² tells you the proportion of variance in the y-variable that is predictable from the x-variable. For example, an R² of 0.8 means 80% of the variation in y is explained by the linear relationship with x.
Can I get R² without a chart?
Yes, use the RSQ function as shown in Method 1. It’s the quickest way and doesn’t require creating a chart.
Is R² the same as correlation coefficient?
No. R² is the square of the correlation coefficient (r). R² ranges from 0 to 1, while r ranges from -1 to 1. Use CORREL to get r.
Why is my R² negative?
In Google Sheets, the RSQ function always returns a value between 0 and 1 for linear regression. If you see a negative value, it’s likely because you’re using a different calculation (like R² for a nonlinear model) or you’ve made a formula error. For standard linear regression, R² cannot be negative.
How many data points do I need for a reliable R²?
At least two points are required to calculate a line, but R² becomes more meaningful with more data. With only two points, R² will always be 1 (or -1 if using correlation), which is misleading. Aim for at least 10-20 data points for a more reliable estimate.
Can I use R² for non-linear data?
RSQ only calculates R² for a linear trendline. If your data follows a curve, you can still get an R² value from a chart by choosing a polynomial or exponential trendline, but the interpretation changes—it measures how well that particular curve fits, not a straight line.
Related
- Merge 2 Cells in Excel: A Step-by-Step Guide
- VLOOKUP Did Not Find Value in Google Sheets?
- Google Sheets: Check If a Value Is in a List
Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.
More in How-to basics
- Excel Border Shortcuts: Apply, Change, and Remove BordersYes. In Excel for Microsoft 365 on Windows, select the cells and press Alt, H, B to open…
- Snowflake SPLIT to Array: Syntax, Examples, and TipsYes. In Snowflake, use SPLIT(text, delimiter) to turn delimited text into an array; for example, SPLIT('red,green,blue', ',') returns…
- Excel Data Validation From a Table: Setup and FixesYes. In Excel for Microsoft 365 on Windows, you can use a table column to supply choices for…
- Google Sheets: Lock Cells While Scrolling?No: Google Sheets cannot lock an arbitrary cell or range in place as you scroll. To keep headings…
- Data Entry Online Jobs for College StudentsYes, data entry online jobs are a legitimate and practical option for college students, offering flexible, remote work…
- What Is a Definition Update? Meaning & UsesA definition update is a change made to the stored meaning of a term, word, or concept within…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.