Google Sheets RSQ Function: Guide and Examples
In this article
The RSQ function in Google Sheets calculates the square of the Pearson product-moment correlation coefficient, which represents the proportion of the variance in the dependent variable that is predictable from the independent variable. In simpler terms, it tells you how well a linear trendline fits your data; a result of 1.0 indicates a perfect fit, while 0 indicates no linear relationship at all. To use it, you simply enter =RSQ(known_y's, known_x's) into a cell, selecting the range of your dependent data first and your independent data second.
What You'll Need
- A Google account with access to Google Sheets.
- Two sets of numerical data (columns or rows) of equal length.
- An understanding of which variable is the dependent variable (the outcome you are measuring) and which is the independent variable (the factor you are changing).
Step-by-Step
- Organize Your Data: Arrange your data into two distinct columns. For example, if you are tracking how advertising spend affects sales, put the "Advertising Spend" in Column A (Independent Variable/X) and the "Sales Revenue" in Column B (Dependent Variable/Y). Ensure there are no empty cells or text strings within these numerical ranges, as this can cause errors.
- Select the Output Cell: Click on the empty cell where you want the R-squared value to appear. This is typically placed below or to the right of your data table.
- Enter the Function: Type
=RSQ(into the cell. This opens the function and prepares the sheet to receive the necessary data ranges. - Define the Known Y's: While the cursor is inside the parentheses, click and drag to highlight the range of cells containing your dependent variable (the Y values). For example, if your sales data is in cells B2 through B21, the formula will now look like
=RSQ(B2:B21,. - Insert the Comma: Type a comma to separate the two required arguments of the function.
- Define the Known X's: Click and drag to highlight the range of cells containing your independent variable (the X values). If your advertising spend is in cells A2 through A21, the formula will now look like
=RSQ(B2:B21, A2:A21). - Complete and Execute: Type the closing parenthesis
)and press Enter. Google Sheets will immediately calculate the coefficient of determination. - Interpret the Result: The resulting number will be between 0 and 1. A value of 0.95, for instance, means that 95% of the variance in your Y variable is explained by the X variable, suggesting a very strong linear relationship.
Common Mistakes
One of the most frequent errors is reversing the order of the arguments. While the RSQ function will still provide a mathematical result if you swap X and Y, it is a bad habit that can lead to confusion when moving toward more complex regression analysis or when using other functions like FORECAST or LINEST. Always remember: Y comes first, X comes second.
Another common mistake is attempting to use the RSQ function on datasets of different lengths. If your Y range contains 20 cells but your X range only contains 19, Google Sheets will return a #N/A error. The function requires a one-to-one pairing for every data point to calculate the correlation correctly.
Users often mistake a high RSQ value for causation. It is important to remember that RSQ measures correlation, not causation. Just because a high R-squared value exists between two variables does not mean that one variable causes the other to change; they may both be influenced by a third, hidden variable.
Including non-numeric data, such as headers or notes, within the selected range is another frequent pitfall. If you accidentally include the cell that says "Sales Revenue" in your range, the function may return a #VALUE! error because it cannot perform mathematical calculations on text strings.
Tips
To make your analysis more dynamic, use named ranges. Instead of typing B2:B21, you can highlight that range, right-click, and select "Define named range," naming it "SalesData." You can then write your formula as =RSQ(SalesData, SpendData), which makes the formula much easier to read and maintain as your spreadsheet grows.
If you want to visualize the RSQ value, create a Scatter Chart. Go to Insert > Chart, select "Scatter chart," and then go to the Customize tab > Series. Check the box for "Trendline" and under the "Label" dropdown, select "Use Equation." While this doesn't give you the RSQ directly in the label in all versions, it allows you to see if the linear trend actually makes sense for your data before relying on the RSQ number.
Combine RSQ with the CORREL function. While RSQ gives you the square of the correlation, the =CORREL(data_y, data_x) function gives you the Pearson correlation coefficient (r). The r-value is useful because it tells you the direction of the relationship (positive or negative), whereas RSQ only tells you the strength of the fit.
Use absolute references (dollar signs) if you plan to drag the RSQ formula across multiple columns. For example, =RSQ($B$2:$B$21, A2:A21) allows you to keep the Y-range locked while you test different X-ranges in adjacent columns.
Troubleshooting
If your formula returns a #N/A error, the first thing to check is the size of your ranges. Ensure that both the Y and X ranges have the exact same number of cells. If one range is B2:B20 and the other is A2:A21, the function will fail. Adjust the ranges to match perfectly.
If you see a #VALUE! error, check for non-numeric characters. Look for cells that might contain a space, a dash used as a placeholder for zero, or a currency symbol that was typed manually as text rather than applied via formatting. Use the "Find and Replace" tool (Ctrl+H) to remove any accidental text characters from your data columns.
If the result is 0 or very close to 0, it does not necessarily mean your data is wrong; it means there is no linear relationship. Your data might have a non-linear relationship (like a curve or a wave). In this case, a linear RSQ is not the correct tool. Try plotting the data on a scatter chart to see if a polynomial or exponential trendline would be a better fit.
If the formula simply doesn't update when you change a value in your data, check your spreadsheet calculation settings. While rare in Google Sheets, ensure that you aren't in a restricted mode or that the sheet hasn't frozen. Refreshing the browser page usually resolves any temporary calculation lags.
Frequently Asked Questions
What is the difference between RSQ and CORREL?
CORREL returns the correlation coefficient (r), which ranges from -1 to 1 and indicates both the strength and direction of a relationship. RSQ returns the square of that value (r²), which ranges from 0 to 1 and indicates how much of the variance in Y is explained by X.
Can RSQ be used for non-linear data?
No, the RSQ function specifically measures the fit of a linear trendline. If your data follows a curve (quadratic or exponential), the RSQ value will be misleadingly low, even if a strong non-linear relationship exists.
What does an RSQ of 0.7 mean?
An RSQ of 0.7 means that 70% of the variance in the dependent variable is explained by the independent variable. The remaining 30% is due to other factors or random noise.
Does the order of X and Y matter for the result?
Mathematically, the result of RSQ is the same regardless of which range is X and which is Y. However, for consistency with other statistical functions and professional data standards, you should always list the dependent variable (Y) first.
Why is my RSQ value exactly 1?
An RSQ of 1 indicates a perfect linear relationship. This happens if every single data point falls exactly on a straight line. While possible in theoretical physics or simple math problems, it is very rare in real-world empirical data and may suggest a calculation error or a redundant data set.