0% found this document useful (0 votes)
50 views6 pages

Time Sereis in R

Time series analysis involves modeling data with timestamps. A time series object is created using the ts() function, which takes in data, start and end times, and frequency. The AirPassengers dataset is demonstrated as a time series, with plots showing an increasing year-on-year trend, strong seasonal effects between months, and the data can be decomposed into trend, seasonal, and irregular components for further analysis. Key aspects of time series include identifying stationary properties, decomposing components, de-trending and de-seasonalizing the data.

Uploaded by

prasenjit kundu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views6 pages

Time Sereis in R

Time series analysis involves modeling data with timestamps. A time series object is created using the ts() function, which takes in data, start and end times, and frequency. The AirPassengers dataset is demonstrated as a time series, with plots showing an increasing year-on-year trend, strong seasonal effects between months, and the data can be decomposed into trend, seasonal, and irregular components for further analysis. Key aspects of time series include identifying stationary properties, decomposing components, de-trending and de-seasonalizing the data.

Uploaded by

prasenjit kundu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Time series is a series of data points in which each data point is associated with a timestamp.

A simple example is
the price of a stock in the stock market at different points of time on a given dayThe time series object is created
by using the ts() function.

Syntax
The basic syntax for ts() function in time series analysis is −
timeseries.object.name <- ts(data, start, end, frequency)

Following is the description of the parameters used −

 data is a vector or matrix containing the values used in the time series.

 start specifies the start time for the first observation in time series.

 end specifies the end time for the last observation in time series.

 frequency specifies the number of observations per unit time.

Examples :

Mulitple time series in a single plot :


Another example to create ts :
> ts (140:152, frequency = 12, start = 1990) # freq 12 => Monthly data.
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
1990 140 141 142 143 144 145 146 147 148 149 150 151
1991 152

Demostration of Time Sereis with R dataset AirPassengers

> data(AirPassengers)

> class(AirPassengers) # it will show ts mens it’s a timestap data set

plot(AirPassengers) # plt timesereis

bline(reg=lm(AirPassengers~time(AirPassengers))) # this will fit a line to showthe trend in the above graph

plot(aggregate(AirPassengers,FUN=mean)) #This will aggregate the cycles and display a year on year trend

boxplot(AirPassengers~cycle(AirPassengers)) #Box plot across months will give us a sense on seasonal effect
Conclusion/prediction

1. The year on year trend clearly shows that the #passengers have been increasing without fail.
2. The variance and the mean value in July and August is much higher than rest of the months.
3. Even though the mean value of each month is quite different their variance is small. Hence, we have strong seasonal effect with a
cycle of 12 months or less.

========================================================================================================================

Important Points regarding Time series and Its model design

A time series can be broken down to its components so as to systematically understand, analyze, model and forecast it. This is a
beginners introduction to time series analysis, answering fundamental questions such as:

1. What are the components of a time series [ 4 components mainly ]

Seasonal effect (Seasonal Variation or Seasonal Fluctuations)


Many of the time series data exhibits a seasonal variation which is annual period, such as sales and temperature readings. This type of
variation is easy to understand and can be easily measured or removed .for example, traffic on roads in morning and evening hours, Sales at
festivals like EID etc., increase in the number of passengers at weekend etc. Seasonal variations are caused by climate, social customs,
religious activities etc.

Other Cyclic Changes (Cyclical Variation or Cyclic Fluctuations)


Time series exhibits Cyclical Variations at a fixed period due to some other physical cause, such as daily variation in temperature. Cyclical
variation is a non-seasonal component which varies in recognizable cycle. sometime series exhibits oscillation which do not have a fixed
period but are predictable to some extent. For example, economic data affected by business cycles with a period varying between about 5 and 7
years.In weekly or monthly data, the cyclical component may describes any regular variation (fluctuations) in time series data. The cyclical
variation are periodic in nature and repeat themselves like business cycle, which has four phases (i) Peak (ii) Recession (iii)
Trough/Depression (iv) Expansion.

Trend (Secular Trend or Long Term Variation)


It is a longer term change. Here we take into account the number of observations available and make a subjective assessment of what is long term. To
understand the meaning of long term, let for example climate variables sometimes exhibit cyclic variation over a very long time period such as 50
years. If one just had 20 years data, this long term oscillation would appear to be a trend, but if several hundreds years of data is available, then long
term oscillations would be visible.These movements are systematic in nature where the movements are broad, steady, showing slow rise or fall in the
same direction. The trend may be linear or non-linear (curvilinear). Some examples of secular trend are: Increase in prices, Increase in pollution,
increase in the need of wheat, increase in literacy rate, decrease in deaths due to advances in science.Taking averages over a certain period is a simple
way of detecting trend in seasonal data. Change in averages with time is evidence of a trend in the given series, though there are more formal tests for
detecting trend in time series.

Other Irregular Variation (Irregular Fluctuations)


When trend and cyclical variations are removed from a set of time series data, the residual left, which may or may not be random. Various
techniques for analyzing series of this type examine to see “if irregular variation may be explained in terms of probability models such as
moving average or autoregressive models, i.e. we can see if any cyclical variation is still left in the residuals.These variation occur due to
sudden causes are called residual variation (irregular variation or accidental or erratic fluctuations) and are unpredictable, for example rise in
prices of steel due to strike in the factory, accident due to failure of break, flood, earth quick, war etc.

2. What is a stationary time series

There are three basic criterion for a series to be classified as stationary series :
3. How to decompose it

decomposedRes <- decompose(AirPassergers, type="mult") # use type = "additive" for additive components
decompostion

plot (decomposedRes) # see plot below


stlRes <- stl(AirPassengers, s.window = "periodic")# see the result

4. How to de-trend, de-seasonalize a time series


5. What is auto correlation etc.

www.datascience.com/blog/introduction-to-forecasting-with-arima-in-r-learn-data-science-tutorials

read for forcasting

You might also like