[R] Problem with ploting fitted values
Hello! I have such a problem... Estimated a model based on common data (you can find it in R library), and I wanted to plot the orginal values with the estimated one. Unfortunately I can only see the original values. Below is the code with data library: / library(forecast) data(AirPassengers) AP - AirPassengers class(AP) start(AP) end(AP) frequency(AP) lgAP - log(AP) t-2:length(AP) APsL-log(ts(lgAP, start=1949, frequency=12)) final-(ts.intersect(lgAP,lgAPlag=lag(lgAP,-1), t=t, sin12 = sin(2*pi*t/12), cos12 = cos(2*pi*t/12),dframe=TRUE)) summary(AIRlm - lm(lgAP ~ lgAPlag + t + sin12 + cos12, data=final)) plot(lgAP, main=Log of Air Passengers,type=l, col=4, lty=2, lwd=2) lines(t, AIRlm$fitted, col=2, lwd=2) legend(topleft, legend=c(data, fitted), lty=c(2,1), col=c(4,2)) / As you can see the lines command doesn't work. I'm open to your suggestions and would be very grateful for your help. -- View this message in context: http://r.789695.n4.nabble.com/Problem-with-ploting-fitted-values-tp4192218p4192218.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] Problem with ploting fitted values
matys mts89 at o2.pl writes: Hello! I have such a problem... Estimated a model based on common data (you can find it in R library), and I wanted to plot the orginal values with the estimated one. Unfortunately I can only see the original values. Below is the code with data library: / library(forecast) data(AirPassengers) AP - AirPassengers class(AP) start(AP) end(AP) frequency(AP) lgAP - log(AP) t-2:length(AP) APsL-log(ts(lgAP, start=1949, frequency=12)) final-(ts.intersect(lgAP,lgAPlag=lag(lgAP,-1), t=t, sin12 = sin(2*pi*t/12), cos12 = cos(2*pi*t/12),dframe=TRUE)) summary(AIRlm - lm(lgAP ~ lgAPlag + t + sin12 + cos12, data=final)) plot(lgAP, main=Log of Air Passengers,type=l, col=4, lty=2, lwd=2) lines(t, AIRlm$fitted, col=2, lwd=2) legend(topleft, legend=c(data, fitted), lty=c(2,1), col=c(4,2)) / If you try: plot(t, AIRlm$fitted, col=2, lwd=2) you can see that it does plot the points. But note the x-axis. The problem with adding them to your original plot is that the x values (2:144) are out of the range of the x-axis of the original plot, which is of a time series. Try: # transforming into parallel time series AIRlm$fitted.ts - ts(AIRlm$fitted, start = c(1949,1), frequency = 12) plot(lgAP, main=Log of Air Passengers,type=l, col=4, lty=2, lwd=2) lines(AIRlm$fitted.ts, col=2, lwd=2) Hope this helps, Michael Bibo Queensland Health __ R-help@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.
Re: [R] Problem with ploting fitted values
Hello, matys wrote Hello! I have such a problem... Estimated a model based on common data (you can find it in R library), and I wanted to plot the orginal values with the estimated one. Unfortunately I can only see the original values. Below is the code with data library: / library(forecast) data(AirPassengers) AP - AirPassengers class(AP) start(AP) end(AP) frequency(AP) lgAP - log(AP) t-2:length(AP) [...] As I can see the lines command is trying to plot the value of the transpose function! You are using 't' as a variable name, choose something else, say, 'u' and see if it solves the problem. R does allow this use but it conflicts with normal functioning. Rui Barradas. -- View this message in context: http://r.789695.n4.nabble.com/Problem-with-ploting-fitted-values-tp4192218p4193464.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.