But what does best mean in this context? You would need some kind of normative criterium to describe which line fits the data better than another.Ī quite intuitive approach to this problem would be to search for the line, which minimises the measurement errors in our data. You could think of it as trying out all possible ways to draw a line through the scatter plot until you have found the line, which describes the data in the best way. Basically, this method is nothing else than a mathematical tool, which helps in finding the imaginary line through the point cloud. This is where the method of least squares comes in. But since there are errors in the data, this approach is not feasible. Under perfect conditions with no measurement errors we could just connect the points in the graph and directly measure the slope of the resulting line. If the slope is rather flat, \(y\) will change only moderately. If the slope is steep \(y\) will change considerably after a change in \(x\). Instead, they seem to be scatterd around an imaginary straight line, which goes from the bottom-left to the top-right of the plot.įrom an astronomical perspective, our main interest in the graph is the slope of that imaginary line, because it describes the strength of the relationship between the variables. But since we made our observations under imperfect conditions, measurement errors prevent the points from lying on the expected straight line. But the points do not lie on a single line, although we would expect that behaviour from an astronomical law of nature, because such a law should be invariant to any unrelated factors such as when, where, or how we look at it. 1 One day you draw a scatter plot, which looks similar to the following:Īs you look at the plot, you notice a clear pattern in the data: The higher the value of variable \(x\), the higher the value of variable \(y\). The default is 1.To understand the basic idea of the method of least squares, imagine you were an astronomer at the beginning of the 19th century, who faced the challenge of combining a series of observations, which were made with imperfect instruments and at different points in time. 1 means show Jul as J, 2 means Ju and 3 means Jul. len is the number of letters of the month shown and can be 1, 2 or 3. The default is 3 so a label for every third month is shown (except Jan which is shown as the year). It draws an X axis with ticks for each month labelling the years and each every'th month where the every argument can be a divisor of 12. Note that plot(my.ts) does give a plot with ticks every month and labels every year which to me looks better than the plot shown in the question but if you want a custom axis since R is a programming language you can certainly write a simple function for that and from then on it's just a matter of calling that function.įor example, to get you started here is a function that accepts a frequency 12 ts object. I think the question boils down to wanting a pre-written function for the custom axis you have in mind. Question: Is it possible to plot a time series variable (object) using the plot command with the format option controlling how the x-axis will be displayed? But if your audience comprises business students or professionals there are too many lines of code to write. This is a workable solution for most data scientists. Plot(my.ts, xaxt = "n", main= "Plotting outcome over time",Īxis(1, at = seq(tsp, tsp, along = my.ts), labels = format(dates, "%Y-%m")) Add an extra step to draw a vertical line at 2012.Use the axis command to add the custom x-axis labels.Use tsp and seq to generate the required x-axis labels.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |