[R] How to get the intercept from lm?
Rau, Roland
Rau at demogr.mpg.de
Fri Mar 10 11:39:54 CET 2006
Hi,
I hope the following code helps.
Best,
Roland
## creating example data
xx <- 1:30
yy <- 3 + 2*xx + rnorm(length(xx), mean=0, sd=2)
plot(xx,yy) # looks reasonable
## the 'lm'
mymodel <- lm(yy~xx)
summary(mymodel) # just looking at the results
## extracting intercept and slope:
coef(mymodel)
intcp <- coef(mymodel)[1]
slp <- coef(mymodel)[2]
intcp
slp
> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Rainer M Krug
> Sent: Friday, March 10, 2006 11:17 AM
> To: r-help at stat.math.ethz.ch
> Subject: [R] How to get the intercept from lm?
>
> Hi
>
> I am using R 2.2.0 under SuSE 10
>
> I want to use lm() to get the slope and intercept for several
> daatasets
> and store them in a database. So far so good - but how do I
> extract the
> slope and the intercept from the result from lm()?
>
> my code looks like this:
>
> lmNNDens <- lm(log(DensNN$MeanNN) ~ log(DensNN$MeanDensity))
> anovaLM <- anova(lmNNDens)
>
> Results$slope[No] <- ???lmNNDens???
> Results$intercept[No] <- ???lmNNDens???
>
> any help welcome,
>
>
> Rainer
>
>
> --
> --
> Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation Biology (UCT)
>
> Department of Conservation Ecology
> University of Stellenbosch
> Matieland 7602
> South Africa
>
> Tel: +27 - (0)72 808 2975 (w)
> Fax: +27 - (0)21 808 3304
> Cell: +27 - (0)83 9479 042
>
> email: RKrug at sun.ac.za
> Rainer at krugs.de
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
+++++
This mail has been sent through the MPI for Demographic Rese...{{dropped}}
More information about the R-help
mailing list