[R] lattice add a fit
Bond, Stephen
Stephen.Bond at cibc.com
Wed Oct 8 20:14:32 CEST 2014
Folks,
This is just misunderstanding. I did not want a panel function for locfit. In my email I say:
Instead, I want to put a fit from lm (but
not a simple straight line) and the fit has to be done for each panel
separately, not one fit for the full data set, so sth like an lm
equivalent of panel.locfit (there is no panel.lmfit) Thank you.
Bert Gunter provided the answer to my question. Maybe I should have sent a thank you note to the list to finalize.
Kind regards
Stephen Bond
-----Original Message-----
From: David Winsemius [mailto:dwinsemius at comcast.net]
Sent: Wednesday, October 08, 2014 12:30 PM
To: Duncan Mackay
Cc: R; Bond, Stephen
Subject: Re: [R] lattice add a fit
On Oct 7, 2014, at 9:15 PM, Duncan Mackay wrote:
I'm a tad puzzled by the comments about needing to build a panel function for locfit. The various plot.locfit functions are actually lattice calls.
locfit:::panel.locfit # already exists, and even has versions for 1d, 2d and 3d purposes.
And there is a llines.locfit function that will add locfit smooths to existing lattice plots.
It's a very simple function and could easily be modified to any regression method that has a predict functions:
> locfit:::llines.locfit
function (x, m = 100, tr = x$trans, ...) {
newx <- lfmarg(x, m = m)[[1]] # probably need to modify to your purposes
y <- predict(x, newx, tr = tr)
llines(newx, y, ...)
}
<environment: namespace:locfit>
--
David
>
> You will have to make your own panel function for locfit if you want
> to use it I have done it in the past - read the help for
> library(locfit)
> ?plot.locfit
> and the links
> ?lattice::prepanel
>
> Regards
>
> Duncan
>
> Duncan Mackay
> Department of Agronomy and Soil Science University of New England
> Armidale NSW 2351
> Email: home: mackay at northnet.com.au
>
>
> -----Original Message-----
> From: r-help-bounces at r-project.org
> [mailto:r-help-bounces at r-project.org] On Behalf Of Bond, Stephen
> Sent: Tuesday, 7 October 2014 23:02
> To: r-help at R-project.org
> Subject: [R] lattice add a fit
>
> What is the way to add an arbitrary fit from a model to a lattice
> conditioning plot ?
>
> For example
> xyplot(v1 ~v2 | v3,data=mydata,
> panel=function(...){
> panel.xyplot(...)
> panel.loess(...,col.line="red")
> }
> )
> Will add a loess smoother. Instead, I want to put a fit from lm (but
> not a simple straight line) and the fit has to be done for each panel
> separately, not one fit for the full data set, so sth like an lm
> equivalent of panel.locfit (there is no panel.lmfit) Thank you.
>
> Stephen B
>
>
> [[alternative HTML version deleted]]
>
David Winsemius
Alameda, CA, USA
More information about the R-help
mailing list