# Assess the quality (goodness of fit) of gridded data in Surfer

Surfer supports a few methods that can be used to determine or assess the quality of the gridded data. Learn how to use all available methods below:

Method 1: Use R2 when Gridding with Polynomial Regression (Planar)

The closest thing to a calculated goodness of fit is the Coefficient of Multiple Determination (R2), but this is only calculated when gridding with planar polynomial regression, i.e. the first order polynomial. To calculate R2 with planar regression, follow these steps:

1. Click Home |  Grid Data | Grid Data.
2. On the Grid Data - Select Data page choose a data file from the dropdown or by clicking select the data file and click Open.
3. In the Gridding Method section, select the Polynomial Regression.
4. Click the Next button.
5. In Polynomial Regression Parameters section, make sure the Surface Definition is set to Simple planar surface.
6. Set any other gridding parameters you wish.
8. Make sure the Grid Report check box is checked and click Finish.
9. In the Grid Report, a little more than halfway down, under the Planar Regression section, the Coefficient of Multiple Determination (R^2) value is displayed.

Surfer does not calculate the R-squared value for any polynomial order other than the first order.  You can calculate the higher order R-squared values using the Grid Residuals option, described below.

Method 2: Calculate Residuals and R2 Value

If you want to calculate a “goodness-of-fit” for the gridding method (to see how well the grid honors the original data points), you might consider using Grids | Calculate | Residuals instead. The Grids | Calculate | Residuals calculation returns the differences between the calculated grid and the actual data values.  The sum of squares of the residuals can be used to compare gridding methods, with smaller values indicating better goodness-of-fit.

1. Choose an existing grid file, or, grid your data using any method you'd like using the Home | Grid Data | Grid Data.
2. Once you have a grid, click Grids | Calculate | Residuals.
3. Click Browse in the Input Grid section, select the grid file just created and click Open.
4. Click Browse in the XYZ Data section, select the data file containing the original data points and click Open.
5. Ensure the X, Y, and Z Data columns are assigned correctly.
6. Choose the column in the worksheet to contain the calculated residual values.
7. Click OK and the data file opens in the worksheet and the residuals are displayed in the designated column. Lower residual values indicate a better fit with the original data.

Once you have the residuals, you can either:

1. Save the data and create a classed post map using the residuals as the Z column. Apply different colored symbols to illustrate the different amounts of error.
2. Generate a single value, such as the sum of the squares of the residuals, to represent the residuals of the entire gridded surface.
1. When viewing the data in the worksheet, click Data |  Data | Transform.
2. Square the residuals data by entering the function: E=D*D (where D is the column letter containing the residuals and E is an empty column). Click OK and the data is calculated.
3. Find the sum of squares of the residuals by selecting the column containing the square of the residuals and clicking Data |  Data | Statistics.
4. Make sure Sum is checked and click OK. The Sum is displayed.  Compare this result with the result for other grids and their residuals. A smaller value indicates less error.
3. Calculate R2, an indication of the goodness of fit of the model, with the equation:  R2 = 1 - (SSres / SStot).

Where:

SSres = Sum of the squares of the residuals.

SStot = Sum of squares of the differences from the mean, S(Zi - Zmean)2.

After calculating the residuals, calculate a new column containing the squares of the residuals (SSres):

1. When viewing the data in the worksheet, click Data | Data | Transform.
2. Square the residuals data by entering the function: E=D*D (where D is the column letter containing the residuals and E is an empty column). Click OK and the data is calculated.
3. Find the sum the squares of the residuals by selecting the column containing the square of the residuals and clicking Data | Data | Statistics.
4. In the Statistics dialog, only have Sum checked in the list of items to compute, and in the Results section choose Show in a window.
5. In the Statistics Results window, click the Copy button and click Close.
6. Select an empty cell at the bottom of the square residuals column and click Home | Clipboard | Paste.  This is SSres.

Then, calculate SStot:

1. Calculate the Zmean by selecting the Z column (often column C), choosing Data | Data | Statistics.  Check Mean in the list of items to compute and click OK. Write down the Mean value (Zmean) and click Close.
2. Calculate Zi - Zmean by clicking Data | Data | Transform, entering the function: F = C - Zmean, where F is the next empty column.
3. Calculate (Zi - Zmean)2 by clicking Data |  Data | Transform, entering the function: G = F*F, where G is the next empty column.
4. Sum (Zi - Zmean)2 by selecting column G (or whatever column the square of the data is in), and clicking Data | Data | Statistics.
5. In the Statistics dialog, only have Sum checked in the list of items to compute, and in the Results section choose Show in a window.
6. In the Statistics Results window, click the Copy button and click Close.
7. Select an empty cell at the bottom of the square Z column and click Home | Clipboard  | Paste. This is SStot.

Use a calculator to calculate R2 :  1 - (SSres / SStot)

Method 3: Cross Validate the Data

Another method to assess the quality of the grid is to cross validate the grid with the data. Cross validation can be considered an objective method of assessing the quality of a gridding method, or to compare the relative quality of two or more candidate gridding methods.

Cross validation calculates the differences in the grid file when data points are omitted. You can access this feature by following these steps:

1. Click Home |  Grid Data | Grid Data.
2. On the Grid Data - Select Data page choose a data file from the dropdown or by clicking select the data file and click Open.
3. In the Gridding Method section, select any gridding method you'd like.
4. Depending on the gridding method chosen, the next pages of the Grid Data dialog will change. Click Next until you reach the Grid Data - <gridding method> - Cross Validation page.
5. Enter the cross validation parameters you wish, and note the file path and name of the cross validation results file.
6. Click Next to reach the Grid Data - <gridding method> - Output page.
7. Make any desired changes and click Finish. The cross validate results file is created.

This method is mostly designed to measure how well a data point value is predicted by the surrounding data points, so other goodness-of-fit methods may be more appropriate if your data is spiky or has high variability between data points.

Method 4: Create a Grid of Kriging Standard Deviations

You can generate a standard deviation grid with the Kriging gridding method. Note that this is more geared towards experienced variogram modelers. There are several cases where a standard deviation grid is incorrect or meaningless, so please see the Kriging help topic for more information.

To create the Kriging Standard Deviation grid, follow these steps:

1. Click Home |  Grid Data | Grid Data.
2. On the Grid Data - Select Data page choose a data file from the dropdown or by clicking select the data file and click Open.
3. In the Gridding Method section, select Kriging.
4. Click the Next button twice.
5. On the Grid Data - Kriging - Options page in the Kriging Parameters section, click the Save button to the right of Standard Deviations grid.
6. In the Save Grid As dialog, name the new grid and click Save.
7. Give the file a name and click Save.
9. Enter any other gridding options you wish and click Finish. The grid is created.

From here, you can create a map and view the areas with high or low standard deviations.

Updated November 2021