I'm relatively new to R so maybe I'm missing something but by my own I cannot figure it out.
I've this data-set: DOWNLOAD .TXT that contains sales data aggregated by week (51 weeks for 2 years leading to 102 entries).
This is the code I use to transform data in a timeserie, plot and then decompose in the main components
# creating a timeseries element, frequency sets the intervals of data collection, starts sets the data collection date
timeseries = ts(data, frequency = 51, start = c(2011))
plot.ts(timeseries, type = "o")
#TimeSeries decomposition in trend, seasonal and random-walk
plot(decompose(timeseries))
The result is a decompose figure very strange, especially for the random part.
These are my qustions:
Why the charts starts at 2011.5 when the data starts 2011.1?
Why the random component is so strange?
What I'm missing?
Related
I have a table as follows:
Data table
I am trying to do a time series analysis in R. After importing the data set into R, when I use the following
time_series <- ts(ts_data$Recruitment, start= min(ts_data$Quarter),end=max(ts_data$Quarter),frequency=4)
and then use plot() to chart it, I get a chart with peaks in the wrong places. However when I set a frequency of 1 things look more normal. My question is, given that I'm dealing with quarterly data, shouldn't the frequency be 4?
I am very new to R and appreciate any advice. I saw the following example in a training course with a frequency of 4 that seemed to work, so I'm not sure why mine doesn't.
Quarterly data
Could it be to do with UK financial vs calendar year I wonder?
I tried using the frequency of 4 and then of 1. 1 seemed to produce the chart I was expecting, but 4 didn't. I'm not sure why as I'm dealing with quarterly data.
UPDATE
When I try with frequency 1 and then try to decompose the chart I get the following error:
"time series has no or less than 2 periods"
Can anybody help?
i have a WEEKLY dataset that start on 1986.01.03 and end on 2022-10-07.
The problem is when I forecast the time series with Arima +garch, because the date in T0 is wrong, i.e. 1975 enter image description here.
The function that I used to convert the dataset into time series is here, but I think that the problem is here, since it doesn't take on the right date.
FutureWeekly= ts(WeeklyFuture$FutureWeekly, start= c(1986,1), end = c(2022,10), frequency = 52)
does anyone know how to convert a weekly dataset to time series other than this?
There are the first rows of my dataset and then I have to transform that into returns (diff(log(FutureWeekly) to do the ARMA+GARCH
enter image description here
Try this:
futures<-c(WeeklyFuture$FutureWeekly) #convert to vector
FutureWeekly= ts(futures, start= c(1986,1,10), end = c(1986,3,7), frequency = 52) #add day of week ending on
One of the things ts() demands is a vector of values. I think it might also be easier for ts() to convert the data if it was able to see the 7-day increments.
Assuming you have full un-broken weekly data for the entire period, I think these two things will solve the problem.
I have a daily rainfall data for 36 years. I want to analyze the time series, but my data is still in the form of frame data, how I change the frame data into time series. My data is a variable, how to unify the year number with the date and month, so the data is only in one column
You could use a time series package for that, such as fpp i.e. install.packages('fpp'). Since you don't give an example code, I can't really help you properly with it but it's quite easy.
ts(your_data, start =, frequency = ) At start = you put the year or month where you'd start and at frequency = you'd put e.g. 36 since you talk about 36 years.
You might want to check out https://robjhyndman.com/. He has an online (free) book available that walks you through the use of his package as well as providing useful information with respect to time series analysis.
Hope this helps.
I am trying to create a plot of weekly data. Though this is not the exact problem I am having it illustrates it well. Basically imagine you want to make a plot of 1,2,....,7 for for 7 weeks from Jan 1 2015. So basically my plot should just be a line that trends upward but instead I get 7 different lines. I tried the code (and some other to no avail). Help would be greatly appreciated.
startDate = "2015-01-01"
endDate = "2015-02-19"
y=c(1,2,3,4,5,6,7)
tsy=ts(y,start=as.Date(startDate),end=as.Date(endDate))
plot(tsy)
You are plotting both the time and y together as individual plots.
Instead use:
plot(y)
lines(y)
Also, create a date column based on the specifics you gave which will be a time series. From here you can add the date on the x-axis to easily see how your variable changes over time.
To make your life easier I think your first step should be to create a (xts) time series object (install/load the xts-package), then it is a piece of cake to plot, subset or do whatever you like with the series.
Build your vector of dates as a sequence with start/end date:
seq( as.Date("2011-07-01"), by=1, len=7)
and your data vector: 1:7
a one-liner builds and plots the above time series object:
plot(as.xts(1:7,order.by=seq( as.Date("2011-07-01"), by=1, len=7)))
I'm having trouble doing time series for my data set. Most examples have quarterly or monthly frequencies but my issue comes with data that is collect annually or every two years. Consider my code:
data<-data.frame(year=seq(1978,2012,2), number=runif(18,100,500))
time<-ts(data$number, start=1978, frequency=.5)
decomp<-decompose(time)
Error in decompose(time) : time series has no or less than 2 periods
How do I make R recognize time series values from data that is collected over an annual basis? Thanks!
Seasonal decomposition only makes sense with intra-yearly data, because you have seasons within years. So, trying to calculate seasonal effects with decompose on data collected every two years you get the error.