Skip to content

name: r.regression.line description: Calculates linear regression from two raster maps: y = a + b*x. keywords: [ raster, statistics, regression ]


r.regression.line

Calculates linear regression from two raster maps: y = a + b*x.

r.regression.line [-g] mapx=name mapy=name [output=name] [--overwrite] [--verbose] [--quiet] [--qq] [--ui]

Example:

r.regression.line mapx=name mapy=name

grass.script.run_command("r.regression.line", mapx, mapy, output=None, flags=None, overwrite=False, verbose=False, quiet=False, superquiet=False)

Example:

gs.run_command("r.regression.line", mapx="name", mapy="name")

Parameters

mapx=name [required]
    Map for x coefficient
mapy=name [required]
    Map for y coefficient
output=name
    ASCII file for storing regression coefficients (output to screen if file not specified).
-g
    Print in shell script style
--overwrite
    Allow output files to overwrite existing files
--help
    Print usage summary
--verbose
    Verbose module output
--quiet
    Quiet module output
--qq
    Very quiet module output
--ui
    Force launching GUI dialog

mapx : str, required
    Map for x coefficient
    Used as: input, raster, name
mapy : str, required
    Map for y coefficient
    Used as: input, raster, name
output : str, optional
    ASCII file for storing regression coefficients (output to screen if file not specified).
    Used as: output, file, name
flags : str, optional
    Allowed values: g
    g
        Print in shell script style
overwrite: bool, optional
    Allow output files to overwrite existing files
    Default: False
verbose: bool, optional
    Verbose module output
    Default: False
quiet: bool, optional
    Quiet module output
    Default: False
superquiet: bool, optional
    Very quiet module output
    Default: False

DESCRIPTION

r.regression.line calculates a linear regression from two raster maps, according to the formula

y = a + b*x

where

x
y

represent the input raster maps.

Optionally, it saves regression coefficients as a ASCII file. The result includes the following coefficients: offset/intercept (a) and gain/slope (b), correlation coefficient (R), number of elements (N), means (medX, medY), standard deviations (sdX, sdY), and the F test for testing the significance of the regression model as a whole (F).

NOTES

The results for offset/intercept (a) and gain/slope (b) are identical to that obtained from R-stats's lm() function.

EXAMPLE

Comparison of two DEMs (SRTM and NED, both at 30m resolution), provided in the North Carolina sample dataset:

g.region raster=elev_srtm_30m -p
r.regression.line mapx=elev_ned_30m mapy=elev_srtm_30m
 y = a + b*x
   a (Offset): -1.659279
   b (Gain): 1.043968
   R (sumXY - sumX*sumY/N): 0.894038
   N (Number of elements): 225000
   F (F-test significance): 896093.366283
   meanX (Mean of map1): 110.307571
   sdX (Standard deviation of map1): 20.311998
   meanY (Mean of map2): 113.498292
   sdY (Standard deviation of map2): 23.718307

Using the script style flag AND eval to make results available in the shell:

g.region raster=elev_srtm_30m -p
eval `r.regression.line -g mapx=elev_ned_30m mapy=elev_srtm_30m`

# print result stored in respective variables
echo $a
-1.659279

echo $b
1.043968

echo $R
0.894038

SEE ALSO

d.correlate, r.regression.multi, r.stats

AUTHORS

Dr. Agustin Lobo - alobo at ija.csic.es
Updated to GRASS 5.7 Michael Barton, Arizona State University
Script style output Markus Neteler
Conversion to C module Markus Metz

SOURCE CODE

Available at: r.regression.line source code (history)
Latest change: Friday Feb 07 19:16:09 2025 in commit a82a39f