[R] Plotting Standard Regression Fit-Am I wrong or a bug?

Daniel Malter daniel at umd.edu
Sat Nov 8 21:16:11 CET 2008


Please provide a self-contained example (small simulated dataset or the
original data [if it is or reasonable size] such that it can be copy-pasted
in R). We cannot tell what is going wrong when we can't follow what is going
on.

Generally, that you don't get any error message indicates that the lines and
points commands are actually executed. So nothing is probably wrong with
them. It then comes down to whether you plot within the right limits. You
might want to test different "ylim" and "xlim" arguments in your plot()
command to see whether your "lines" and "points" fall outside the limits
that are initialized when you call the plot command. [SEE EXAMPLE BELOW]

Cheers,
Daniel 

##Self-contained R-example
x=rnorm(100,0,1)
e=rnorm(100,0,1)
y=x+e

plot(y,xlim=c(101,120)) ##plot y #101 to y #120

#no points plotted because there are only 100 Ys!

reg=lm(y~x)
points(fitted(reg))
##tries to plot fitted(reg) versus index numbers 1 to 100
##in the plot initialized above
##but fitted #1 to fitted #120 
##is still out of bounds of the data, there are only 100 Ys,
##so there are only 100 fitted Ys (Y hats)

##plot correctly
plot(y~x,col="red",xlim=c(-8,8),ylim=c(-8,8))
points(fitted(reg)~x,col="blue")


-------------------------
cuncta stricte discussurus
-------------------------

-----Ursprüngliche Nachricht-----
Von: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Im
Auftrag von uep
Gesendet: Saturday, November 08, 2008 2:19 PM
An: r-help at r-project.org
Betreff: [R] Plotting Standard Regression Fit-Am I wrong or a bug?


I'm trying to plot a time series (quarterly observations, seasonal effect,
T=56),regression line and predicted point on the same plot.
I'm using following commands:
> plot(qdts,xlim=c(1982,1997))
> lines(fitted(m2)~time,data=qd,col="red")
> points(predict(m2,newdata=nqd),col="blue")

where:
qdts<-ts(qd$durables,start=c(1982,1),freq=4)
m2<-lm(qdts~time+quar)
time<-seq(1,length(qdts),1)
nqd<-data.frame(time=c(57),quar=c(1))

Unfortunately once I enter all three commands the fitted line and predicted
point don't appear on the plot. What surprises me is that I am not getting
any error message.

What I am doing wrong?
Many thanks in advance

Ula

--
View this message in context:
http://www.nabble.com/Plotting-Standard-Regression-Fit-Am-I-wrong-or-a-bug--
tp20399460p20399460.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
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