[R-sig-Geo] Get lm formula

ONKELINX, Thierry Thierry.ONKELINX at inbo.be
Mon Jul 23 17:15:21 CEST 2007


You'll need something like

x <- rnorm(100)
y <- 0.5 * x + rnorm(100) + 1
fit <- lm(y ~x)
paste("y =", round(fit$coef[2], 2), "x +", round(fit$coef[1], 2))

Please note that this is R-sig-geo, the R mailing list dedicated to
spatial issues. For more general questions (like this one) you'll get
more respons from R-help (r-help at stat.math.ethz.ch).

Cheers,

Thierry

------------------------------------------------------------------------
----
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
Thierry.Onkelinx at inbo.be
www.inbo.be 

Do not put your faith in what statistics say until you have carefully
considered what they do not say.  ~William W. Watt
A statistical analysis, properly conducted, is a delicate dissection of
uncertainties, a surgery of suppositions. ~M.J.Moroney

 

> -----Oorspronkelijk bericht-----
> Van: r-sig-geo-bounces at stat.math.ethz.ch 
> [mailto:r-sig-geo-bounces at stat.math.ethz.ch] Namens Thomas Szegvary
> Verzonden: maandag 23 juli 2007 16:33
> Aan: r-sig-geo at stat.math.ethz.ch
> Onderwerp: [R-sig-Geo] Get lm formula
> 
> I have several plots where I'd like to add the formula from 
> the linear model automatically, i.e. in form of y=ax+b, to 
> the plot. I used lm() for a simple scatter plot.
> I was able to add the r-sqare to the plot, using 
> summary(lm$r.square) to extract the value for r^2. but for 
> the coefficients a and b I couldn't extract the values like 
> for r-square. I can check the values using coef(lm), but to 
> be able to write it as text to the plot I should extract the 
> values, am I right? Or is there a better solution? Does 
> anyone has an idea? I couldn't find any yet...
> 
> Thanks a lot,Thomas
> 
> 
> 
> __
> 
> Thomas Szegvary
> Institute of Environmental Geosciences
> Department of Geosciences
> University of Basel
> Bernoullistrasse 30
> CH - 4056 Basel
> 
> Tel.  41-61-267 04 82
> Fax. 41-61-267 04 79
> Email: t.szegvary at unibas.ch
> www.radon.unibas.ch
> www.unibas.ch/environment
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>




More information about the R-sig-Geo mailing list