Skip to content
Back to formatted view

Raw Message

Message-ID: <1257265967.31636.1343362565@webmail.messagingengine.com>
Date: 2009-11-03T16:32:47Z
From: Nicholas Lewin-Koh
Subject: Plot a polynomial regression
In-Reply-To: <mailman.1.1257246002.9376.r-sig-ecology@r-project.org>

Hi,
Doing that with xyplot is a bit of a PITA, but
try:
fits<-fitted(model)
xyplot((GPP)~(Discharge), groups=Site, data=nighttimeds1.dat, fits=fits,
       panel=function(x,y,fits,...){
             panel.xyplot(x,y,...)
             panel.lines(x,fits)
        },col=c("red","blue","green","yellow"), type="p")

by the way, polynomials may have some properties that maybe undesirable
in your 
model. Try 
library(splines)
model<-lm(GPP ~ poly(Discharge, 2), data=nighttimeds1.dat)
model2<-lm(GPP ~ ns(Discharge, k=3), data=nighttimeds1.dat)
anova(model, model2) ## likelihood ratio test

Nicholas

> Message: 1
> Date: Mon, 2 Nov 2009 15:42:53 -0800
> From: Emily Benson <erbenson1 at gmail.com>
> Subject: [R-sig-eco] Plot a polynomial regression
> To: r-sig-ecology at r-project.org
> Message-ID:
> 	<91cdc84e0911021542o421a6e80h7613423a198efb2c at mail.gmail.com>
> Content-Type: text/plain
> 
> Hi,
> For these data, my independent variable is river discharge (Discharge)
> and
> my dependent variable is an estimate of gross primary production (GPP). I
> have fitted a polynomial regression to my data using the following
> command:
> > model<-lm(GPP ~ poly(Discharge, 2), data=nighttimeds1.dat)
> I can produce a scatterplot of the data using the following commands:
> > # Make a plot with Discharge on the x-axis and GPP on the y-axis;
> > library(lattice)
> > xyplot((GPP)~(Discharge), groups=Site, data=nighttimeds1.dat,
> + col=c("red","blue","green","yellow"), type="p")
> What I would like to do is include the polynomial regression curve on the
> scatterplot of the data, but I cannot figure out how to do this.
> Can anyone help me?
> Thank you,
> Emily
> 
> 	[[alternative HTML version deleted]]
> 
> 
> 
> ------------------------------
> 
> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
> 
> 
> End of R-sig-ecology Digest, Vol 20, Issue 1
> ********************************************