<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://training-course-material.com/index.php?action=history&amp;feed=atom&amp;title=R_-_Time_Series</id>
	<title>R - Time Series - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://training-course-material.com/index.php?action=history&amp;feed=atom&amp;title=R_-_Time_Series"/>
	<link rel="alternate" type="text/html" href="https://training-course-material.com/index.php?title=R_-_Time_Series&amp;action=history"/>
	<updated>2026-05-13T23:42:14Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://training-course-material.com/index.php?title=R_-_Time_Series&amp;diff=29329&amp;oldid=prev</id>
		<title>Bernard Szlachta at 09:17, 6 March 2016</title>
		<link rel="alternate" type="text/html" href="https://training-course-material.com/index.php?title=R_-_Time_Series&amp;diff=29329&amp;oldid=prev"/>
		<updated>2016-03-06T09:17:13Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[Category:Intro to R|89]]&lt;br /&gt;
{{Cat|Forecasting|001}}&lt;br /&gt;
== Time Series Libraries ==&lt;br /&gt;
* ts() from &amp;#039;&amp;#039;stats&amp;#039;&amp;#039; package&lt;br /&gt;
* zoo&lt;br /&gt;
* xts&lt;br /&gt;
&lt;br /&gt;
== Graphing Time Series ==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;rsplus&amp;quot;&amp;gt;&lt;br /&gt;
 s &amp;lt;- read.table(&amp;quot;http://training-course-material.com/images/1/19/Sales-time-series.txt&amp;quot;,h=T)&lt;br /&gt;
 s$Date &amp;lt;- as.Date(s$Date)&lt;br /&gt;
 head(s)&lt;br /&gt;
 plot(s)&lt;br /&gt;
 &lt;br /&gt;
 # Using build in ts object&lt;br /&gt;
 sts &amp;lt;- ts(s$Price,start=2002,deltat=1/12)&lt;br /&gt;
 plot(sts)&lt;br /&gt;
&lt;br /&gt;
 # using xts&lt;br /&gt;
 install.packages(&amp;quot;xts&amp;quot;)&lt;br /&gt;
 library(&amp;quot;xts&amp;quot;)&lt;br /&gt;
 Price &amp;lt;- xts(s$Price,s$Date)&lt;br /&gt;
 head(Price)&lt;br /&gt;
 tail(Price)&lt;br /&gt;
 plot(Price)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Filtering xts series ==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;rsplus&amp;quot;&amp;gt;&lt;br /&gt;
 #12 to 16th observation &lt;br /&gt;
 Price[12:16]&lt;br /&gt;
&lt;br /&gt;
 #2nd to 4th in reverse order&lt;br /&gt;
 Price[4:2]&lt;br /&gt;
&lt;br /&gt;
 #1st, 13th and 25th oveservation&lt;br /&gt;
 Price[c(1,13,25)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 # Prices only in 2005&lt;br /&gt;
 Price[&amp;quot;2005&amp;quot;]&lt;br /&gt;
 # Prices in Jan 2005&lt;br /&gt;
 Price[&amp;quot;2005-01&amp;quot;]&lt;br /&gt;
 # Prices from 2005 Jan to 2007 March&lt;br /&gt;
 Price[&amp;quot;2005-01/2007-03&amp;quot;]&lt;br /&gt;
 # Prices from the beginning of the data untill 2008&lt;br /&gt;
 Price[&amp;quot;2005-01/2008&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 # Price in first year&lt;br /&gt;
 first(Price,&amp;quot;year&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 first(Price,&amp;quot;2 months&amp;quot;)&lt;br /&gt;
 last(Price,&amp;quot;3 quarters&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting rid of trend ==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;rsplus&amp;quot;&amp;gt;&lt;br /&gt;
# Shows the dates&lt;br /&gt;
index(Price)&lt;br /&gt;
&lt;br /&gt;
# Returns the Prices value&lt;br /&gt;
coredata(Price)&lt;br /&gt;
&lt;br /&gt;
#Plot the function&lt;br /&gt;
plot(coredata(Price) ~ index(Price),type=&amp;quot;l&amp;quot;,ylim=c(-3,13))&lt;br /&gt;
&lt;br /&gt;
# Fit the trend line&lt;br /&gt;
m &amp;lt;- lm(coredata(Price) ~ index(Price))&lt;br /&gt;
&lt;br /&gt;
# Validate the model&lt;br /&gt;
summary(m)&lt;br /&gt;
&lt;br /&gt;
# Plot the trend&lt;br /&gt;
abline(m)&lt;br /&gt;
&lt;br /&gt;
# The same as above&lt;br /&gt;
lines(m$fitted.values ~ index(Price))&lt;br /&gt;
&lt;br /&gt;
# m$residuals = $fitted - index(Price)&lt;br /&gt;
&lt;br /&gt;
# Plot the detrended values&lt;br /&gt;
lines(m$residuals ~ index(Price),type=&amp;quot;l&amp;quot;,col=&amp;quot;blue&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Plot relative detrended Prices&lt;br /&gt;
detrendPrice &amp;lt;- m$residuals&lt;br /&gt;
plot(xts(detrendPrice/mean(Price),index(Price)),type=&amp;quot;l&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Exercise ==&lt;br /&gt;
Detrend the Sales volume and plot a chart&lt;/div&gt;</summary>
		<author><name>Bernard Szlachta</name></author>
	</entry>
</feed>