[R] adding regression curve to xyplot
Deepayan Sarkar
deepayan at stat.wisc.edu
Tue Nov 30 17:31:56 CET 2004
On Tuesday 30 November 2004 10:09, Carlisle Thacker wrote:
> Dear R-listers,
>
> It seems that predict() behaves differently within panel.xyplot. Am
> I doing something stupid?
>
> Thanks,
>
> Carlisle
>
> First, without xyplot():
> > lmtest <- lm(t~s,data=subset(P100,whichLon100==1 & whichLat100==1))
> > lmtest
>
> Call:
> lm(formula = s ~ t, data = subset(P100, whichLon100 == 1 &
> whichLat100 == 1))
>
> Coefficients:
> (Intercept) t
> 33.3307 0.1393
>
> > range(P100$t)
>
> [1] 4.050469 24.514543
>
> >> predict(lmtest,newdata=data.frame(t=range(P100$t)))
>
> 1 2
> 33.89501 36.74620
>
> As expected, predict gives two values. But inside xyplot() predict
> gives
>
> 300 values:
> > xyplot(t~s|factor(lonLabels[whichLon100])*factor(latLabels[whichLat
> >100]),
>
> + data=P100,pch=".",
> + panel=function(x,y,...){panel.xyplot(x,y,...)
> + thislm <- lm(x~y)
> + print(thislm)
> + newt <- range(P100$t)
> + print(newt)
> + news <-
> as.vector(predict(thislm,newdata=data.frame(t=newt)))
Why 't' here? The variables involved in 'thislm' are 'x' and 'y'.
Deepayan
> + print(news)
> + llines(news,newt,col="red")})
[...]
More information about the R-help
mailing list