Re: [R] What are the red line and cut line in lm's Residuals vs Fitted plot?

2016-09-19 Thread S Ellison
> Do you mean that the red line is a regression line?
> Why is the regression (line) weighted?
I suggest you look up 'locally weighted regression' to find out why that is 
useful and what it is for.




***
This email and any attachments are confidential. Any use...{{dropped:8}}

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] What are the red line and cut line in lm's Residuals vs Fitted plot?

2016-09-19 Thread mviljamaa

Do you mean that the red line is a regression line?
Why is the regression (line) weighted?

On 2016-09-19 14:41, S Ellison wrote:

What are the red line and cut line in lm's Residuals vs Fitted plot?

The dotted line is at 0 and the red line is a locally weighted
regression calculated using lowess and plotted using panel.smooth.

See ?panel.smooth and ?lowess for details

The main clue to this is in the arguments to ?plot.lm, which uses
panel.smooth as a panel function.

S Ellison



***
This email and any attachments are confidential. Any u...{{dropped:8}}


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] What are the red line and cut line in lm's Residuals vs Fitted plot?

2016-09-19 Thread S Ellison
> What are the red line and cut line in lm's Residuals vs Fitted plot?
The dotted line is at 0 and the red line is a locally weighted regression 
calculated using lowess and plotted using panel.smooth. 

See ?panel.smooth and ?lowess for details

The main clue to this is in the arguments to ?plot.lm, which uses panel.smooth 
as a panel function. 

S Ellison



***
This email and any attachments are confidential. Any use...{{dropped:8}}

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] What are the red line and cut line in lm's Residuals vs Fitted plot?

2016-09-18 Thread David Winsemius

> On Sep 18, 2016, at 7:25 AM, mviljamaa  wrote:
> 
> What are the red line and cut line in lm's Residuals vs Fitted plot?
> 
> As seen in e.g.:
> 
> http://i.imgur.com/QvZ6oeT.png

R has a `plot.lm` function that is invoked by `plot(lm_object)` when 
`lm_object` has a class of "lm". It produces multiple diagnostic plots. The 
default is for display of 4 of the possible 6 plots.

The help page can be specifically accessed by:

?plot.lm

And run the first example:

lm.SR <- lm(sr ~ pop15 + pop75 + dpi + ddpi, data = LifeCycleSavings)
plot(lm.SR)


If you have further question about that particular plot, which would be the 
first one, you should first review the help page and then review the code seen 
with:

plot.lm
#Error: object 'plot.lm' not found
getAnywhere(plot.lm)  # the way to see code that is not exported:

See:

function (x, which = c(1L:3L, 5L), caption = list("Residuals vs Fitted", 
"Normal Q-Q", "Scale-Location", "Cook's distance", "Residuals vs Leverage", 
expression("Cook's dist vs Leverage  " * h[ii]/(1 - h[ii]))), 
panel = if (add.smooth) panel.smooth else points, sub.caption = NULL, 
main = "", ask = prod(par("mfcol")) < length(which) && dev.interactive(), 
..., id.n = 3, labels.id = names(residuals(x)), cex.id = 0.75, 
qqline = TRUE, cook.levels = c(0.5, 1), add.smooth = 
getOption("add.smooth"), 
label.pos = c(4, 2), cex.caption = 1, cex.oma.main = 1.25) 


Note: I checked the option setting with:

> getOption("add.smooth")
[1] TRUE

---snipped plotting set up logic -

if (show[1L]) {
ylim <- range(r, na.rm = TRUE)
if (id.n > 0) 
ylim <- extendrange(r = ylim, f = 0.08)
dev.hold()
plot(yh, r, xlab = l.fit, ylab = "Residuals", main = main, 
ylim = ylim, type = "n", ...)
panel(yh, r, ...)   # this is what is drawing the "red line"
if (one.fig) 
title(sub = sub.caption, ...)
mtext(getCaption(1), 3, 0.25, cex = cex.caption)
if (id.n > 0) {
y.id <- r[show.r]
y.id[y.id < 0] <- y.id[y.id < 0] - strheight(" ")/3
text.id(yh[show.r], y.id, show.r)
}
abline(h = 0, lty = 3, col = "gray")  # this is drawing the dotted line
dev.flush()


So the `panel` function is creating the "red line" and its help page is at:

?panel.smooth   #...

... since the `panel funciton was given that value.

-- 
David.

> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.