[R] question about "lines"
Duncan Murdoch
murdoch.duncan at gmail.com
Tue Sep 17 14:56:04 CEST 2013
On 13-09-17 8:06 AM, meng wrote:
> Hi all:
> I met a question about "lines".
>
>
> attach(cars)
>
>
> plot(dist ~ speed)
> #add the regression line to the plot
> lines(fitted(lm(dist~speed)) ~ speed)
>
>
> plot(dist ~ speed)
> #what kind of curve does the following command add to the plot?
> lines(fitted(lm(dist~speed)))
>
>
> My question is :
> what kind of curve does the last command add to the plot?
Look at the class of fitted(lm(...)). It is "numeric". So what you're
seeing is the same as if you computed the fitted values, and then did
lines(values)
Since values is just a vector of numbers, that will plot them as y
values against x values 1:length(values). That's unlikely to be a
useful thing to do.
Duncan Murdoch
>
>
> My guess:maybe the level of fitted values?
>> range(fitted(lm(dist~speed)))
> [1] -1.84946 80.73112
>
>
> But from the plot,I can see the range of the curve is about 10 to 40 more or less,which is different from(-1.84946, 80.73112).So the curve must not be the fitted values.What kind of curve does the last command add to the plot then?
>
>
>
>
> Many thanks for your help
>
>
> My best
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.
>
More information about the R-help
mailing list