r.regression.line(1grass)

πŸ’– r.regression.line β€” the GRASS manual, but make it a group chat

okay so bestie, welcome to r.regression.line from the GRASS User's Manual (that's r.regression.line(1grass) if you're being formal at a party). This little icon calculates a linear regression from two raster maps, like:

y = a + b*x

She's giving stats girlie, she's giving slope-and-intercept, she's giving math. Let's get into it πŸ’…

✨ KEYWORDS ✨

raster, statistics, regression β€” yeah exactly, she's a raster statistics regression kind of queen πŸ‘‘


πŸ¦‹ SYNOPSIS πŸ¦‹

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

🚩 Flags 🚩

  • -g β€” Print in shell script style [deprecated]. Bestie, listen: this flag is deprecated and is gonna get removed in a future release. Use format=shell instead, ok? Don't be messy. πŸ’€
  • --overwrite β€” Lets output files overwrite files that already exist (yes, she will eat your old file, no cap).
  • --help β€” Prints the usage summary, i.e. the "what is this even" screen 🫢
  • --verbose β€” Verbose module output, she will talk more.
  • --quiet β€” Quiet module output, she will talk less 🀫
  • --ui β€” Force launches the GUI dialog. Main character GUI energy.

πŸŽ€ Parameters πŸŽ€

  • mapx=name [required] β€” The map for the x coefficient.
  • mapy=name [required] β€” The map for the y coefficient.
  • output=name β€” ASCII file for storing the regression coefficients. If you don't give her a file, she just outputs to the screen. Iconic, low maintenance.
  • format=name [required] β€” Output format.
    • Options: plain, shell, json
    • Default: plain
    • plain: Human readable text output
    • shell: shell script style text output
    • json: JSON (JavaScript Object Notation)

🌸 DESCRIPTION 🌸

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

y = a + b*x

where x and y represent the input raster maps. yes the variables are just vibing there, they're the maps, that's the whole thing.

Optionally, she saves the 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). That's a whole lot of numbers, but every single one of them is your friend πŸ’œ


⭐ NOTES ⭐

The results for offset/intercept (a) and gain/slope (b) are identical to that obtained from R-stats's lm() function. so if you're an R bestie, come on in, the water's fine 🧚


πŸ”₯ 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

the way that eval backtick combo just drops the variables straight into your shell… obsessed, fr fr πŸ“


πŸ‘‘ 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

look at this lineup, absolute legends, each and every one 🫢


🌈 SOURCE CODE 🌈

Available at: r.regression.line source code (history)

Latest change: Thursday Oct 02 14:39:13 2025 in commit: 1850489bf42c72d8dcfe2e4db1738441b4a7dc43

Main index | Raster index | Topics index | Keywords index | Graphical index | Full index


k bye bestie, go run your regression πŸ’…βœ¨

Β© 2003-2026 GRASS Development Team, GRASS 8.5.0 Reference Manual β€” and this page was living its best life as r.regression.line(1grass) in GRASS 8.5.0. slay, periodt πŸŽ€
πŸ“¦ where this page comes from