r.regression.line(1)

✨ r.regression.line ✨

okay bestie, welcome to r.regression.line πŸ’– this is the GRASS GIS User's Manual page for it, and we're about to make linear regression sound as cute as it actually is. (It's very cute. Trust.) πŸŽ€

It does raster, statistics, and regression β€” those are the keywords, iykyk. 🌸


🌈 NAME 🌈

r.regression.line β€” calculates linear regression from two raster maps: y = a + b*x. literally the whole job πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

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

πŸŽ€ Flags πŸŽ€

  • -g β€” print it in shell script style, so it's all variable=value coded and ready to be eval'd. obsessed.
  • --overwrite β€” lets output files overwrite existing files. yes bestie, it will absolutely replace them, no cap.
  • --help β€” prints the usage summary. your bestie when you forget stuff 🫢
  • --verbose β€” verbose module output. the module gets chatty. we love that.
  • --quiet β€” quiet module output. the module shuts up. also valid.
  • --ui β€” forces launching the GUI dialog. clicky-clicky mode πŸ–±οΈ

🌸 Parameters 🌸

  • mapx=name [required] β€” the map for the x coefficient. not optional, bestie, don't skip it.
  • mapy=name [required] β€” the map for the y coefficient. also required. also don't skip it.
  • output=name β€” an ASCII file for storing the regression coefficients. if you don't name a file, it just prints to the screen instead. main character behavior honestly.

πŸ’– DESCRIPTION πŸ’–

So. r.regression.line calculates a linear regression from two raster maps, according to this formula:

y = a + b*x

where x and y represent the input raster maps. that's it. that's the vibe. ✨

Optionally, it saves regression coefficients as an ASCII file. and the result includes all of these little icons:

  • offset/intercept (a)
  • 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)

a whole little squad of statistics. πŸ‘‘


πŸ“ NOTES πŸ“

ngl the glow-up here is real: the results for offset/intercept (a) and gain/slope (b) are identical to what you get from R-stats's lm() function. same numbers, different font. πŸ’…


🧚 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 β€” this is the moment, bestie:

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 β€” go read those too, they're all in the same friend group 🫢


πŸ’œ 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)

Accessed: Saturday Jan 17 05:40:57 2026

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

Β© 2003-2025 GRASS Development Team, GRASS GIS 8.4.2 Reference Manual


and that's the whole page, bestie πŸ’– this was GRASS GIS 8.4.2, documented in that reference manual we just mentioned, and last accessed on Saturday Jan 17 05:40:57 2026 β€” go run a regression, you're gonna slay βœ¨πŸ‘‘πŸ’…

πŸ“¦ where this page comes from