[R] lm() question

Christoph Scherber Christoph.Scherber at agr.uni-goettingen.de
Thu Jul 17 15:26:19 CEST 2008


Dear Steven,

Your xlim() function is what changes the behavior of the x axis values; If you remove the xlim() 
statement from your function, you get a "correct" x axis:

##

YC=82:91
Age=rev(seq(2,11,1))
Num=c(2,0,8,21,49,18,79,28,273,175)
box44=data.frame(YC,Age,Num)

mod1=lm(log(Num+1)~YC, data=box44)

plot(log(Num+1)~YC, data=box44, pch=19, xlab="Year Class",
     ylab="Loge Number at age", ylim=c(0,6))
abline(lm(log(Num+1)~YC), col="blue", lwd=2)

##

But what kind of graph do you want to arrive at in the end?

Best wishes
Christoph


Ranney, Steven schrieb:
> I have data that looks like
> 
> YC      Age	Num
> 82	11	2
> 83	10	0
> 84	9	8
> 85	8	21
> 86	7	49
> 87	6	18
> 88	5	79
> 89	4	28
> 90	3	273
> 91	2	175
> 
> with a program 
> 
> mod1=lm(log(Num+1)~YC, data=box44) 
> plot(log(Num+1)~YC, data=box44, pch=19, xlab="Year Class",
>     ylab="Loge Number at age", ylim=c(0,6), xlim=c(91,82))
> abline(lm(log(Num+1)~YC), col="blue", lwd=2)
> summary(mod1)
> 
> I need to regress log(Num+1) against YC, but in descending (91 - 82) order so as to get a negative slope and positive intercept.  I can plot the values such that the regression line appears correct (the xlim statement), but I can't figure out how to force the regression from YC 91 through 82.  A call to the rev() function in front of YC does not produce the results I'm looking for.
> 
> More than likely, I'm overlooking something.  Thanks for any help you can provide.
> 
> SR
> 
> Steven H. Ranney
> Graduate Research Assistant (Ph.D)
> USGS Montana Cooperative Fishery Research Unit
> Montana State University
> PO Box 173460
> Bozeman, MT 59717-3460
> 
> phone: (406) 994-6643
> fax:   (406) 994-7479
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> .
> 

-- 
Dr. rer.nat. Christoph Scherber
University of Goettingen
DNPW, Agroecology
Waldweg 26
D-37073 Goettingen
Germany

phone +49 (0)551 39 8807
fax   +49 (0)551 39 8806

Homepage http://www.gwdg.de/~cscherb1



More information about the R-help mailing list