[19196] in s-news-athena
[S] panel.abline() for weighted regression lines - SUMMARY
daemon@ATHENA.MIT.EDU (John Thaden)
Sun Sep 12 20:47:43 1999
Message-Id: <3.0.3.32.19990912183133.00945520@pop.flash.net>
Date: Sun, 12 Sep 1999 18:31:33 -0500
To: s-news@wubios.wustl.edu
From: John Thaden <jjthaden@flash.net>
In-Reply-To: <3.0.3.32.19990912123117.006f27a4@pop.flash.net>
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Many thanks to Brian Ripley for drawing my attention to the 'subscripts='
trellis argument described in trellis.args help. Brian offers not one, but
two revisions of my plot command that implement subscripts:
mydata <- data.frame(out = c(1,12,99,1,8,101),
init = c(3,2,1,3,2,1), strat = c(1,1,1,2,2,2),
wgts = c(1, 0.5, 1, 1, 0.5, 1))
print(mydata)
xyplot(out~init|strat, mydata, scales = list(y=list(log = 10)),
panel= function(x,y,subscripts,w,...){
panel.xyplot(x,y)
coefs <- coef(lm(y~x, weights = w[subscripts]))
x.temp <- c(min(x), max(x))
y.temp <- coefs[1] + coefs[2]*x.temp
lines(x.temp, y.temp)
}, w = mydata$wgts) # Revision #1
xyplot(out~init|strat, mydata, scales = list(y=list(log = 10)),
panel = function(x,y,subscripts,...){
assign(".subs", subscripts, f=1)
panel.xyplot(x,y)
coefs <- coef(lm(log10(out) ~init, data=mydata, weights=wgts,
subset=.subs))
x.temp <- c(min(x), max(x))
y.temp <- coefs[1] + coefs[2]*x.temp
lines(x.temp, y.temp)
}) # Revision #2
John Thaden
Little Rock, Arkansas, USA
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news