I have a script in R for Time series forecasting. Initially when I created a time series on my univariate data and applied tsclean() function it worked. But today, when I'm trying to re-run my script again at a point where I use my tsclean() function it says:
Error in tsclean(sales_ts) : could not find function "tsclean"
I'm calling in my forecast package as well before where it says forecast package is already built in R 3.6.1.
It's weird why the function is not working today but it worked yesterday.
#creating time series data
sales_ts = ts(sdld_10[, c('Sales')])
#cleaning time series data
library(forecast)
sdld_10$clean_sales = tsclean(sales_ts)
sdld_10$test<- c(sdld_10$clean_sales - sdld_10$Sales)
Related
I'm trying to do a hierarchical cluster dendrogram of time series in R using the dtwclust package. For my test dataset I have 7 columns with unequal lengths. The dtwclust package offers a way to equalize the lengths using a reinterpolate function. However I get this error when I try to use it with the following code
data <- reinterpolate(my_data, new.length = max(lengths(my_data)))
Error in check_consistency(x, "ts") : There are missing values in the series.
I do not know if this means that the data table is not organized properly. Can anyone suggest how to read in the data (I just imported it using RStudio) or any other way to resolve this issue. I tried the analysis using the data provided in the package and it worked as advertised.
When I try to forecast a time series with sma using the forecasting function I get this error:
fc <- forecast(sma(ts),h=3)
Error: The provided model is not Simple Moving Average!
Anyone knows how to fix it?
The forecast is from the fpp2 package and the moving average function is from the smooth package.
This is an example:
library(smooth)
library(fpp2)
library(readxl)
setwd("C:\\Users\\lferreira\\Desktop\\FORECASTING")
data<- read_xlsx("BASE_TESTE.xlsx")
ts <- ts(data$`1740`,start=c(2014,1),frequency=4)
> fc <- forecast(sma(ts),h=3)
Error: The provided model is not Simple Moving Average!
Your example is not reproducible because you have not provided the data.
The following example is reproducible, and does not give an error.
library(smooth)
forecast(sma(USAccDeaths))
Note that the forecast function being used here is not part of the fpp2 package. It is from the smooth package.
To check what's going on with your example:
First check that your data is correctly read in.
Then check that the sma function is returning something sensible. The error message suggests that the function is not returning the model it should.
I'm trying to do a hierarchical cluster dendrogram of time series in R using the dtwclust package. For my test dataset I have 4 columns with unequal lengths. the dtwclust package offers a way to equalize the lengths using a reinterpolate function. However I get this error when I try to use it with the following code
data <- reinterpolate(fshdtw, new.length = max(lengths(fshdtw)))
Error in check_consistency(x, "ts") : There are missing values in the series. This makes me think (I could be wrong) that the data table is not organized properly. Can anyone suggest how to 1. read in the data (I just imported it using RStudio) or any other way to resolve this issue. PS: I tried the analysis using the data provided in the package and it worked as advertised. Thanks in advance!
The data file is here https://www.dropbox.com/s/dih39ji0zop9xa0/fshdtw.txt?dl=0
I have problem importing an Eviews workfile into R. I use the hexView package and I can get the time series data into R but I do not get the periods responding to the time series imported. (The periods is not stored as a timeseries object.)
I would not like to create an time series objects for the periods in the workfile to solve the problem.
If there is another way than using the hexView package to import the data and the responding periods it would be great.
Right now I use this simple code to read the data into R
d <- readEViews("testData.wf1", as.data.frame = TRUE)
Any and all help will be greatly appreciated.
This question motivated me to create an R package EviewsR, which is available on CRAN.
Please follow the following steps in R:
install.packages("EviewsR")
library(EviewsR)
import("importedDataframe","testData")
eviews$importedDataframe # to access the imported dataframe in R
The package works with base R, R Markdown and Quarto.
I am currently updating the package to provide new features
I look forward to your feedback.
I am using R to read a time series from Excel (using XLConnect), then running some forecast models on that time series, and then outputting the results back to Excel. It's a long story, but the company I'm doing a Masters by Research for want to keep using Excel! Anyhow, I can extract the time series I want from Excel. I use ts() to make it a time series. I then run forecasts on that series using (in this order) ets(), auto.arima(), tbats(), mapaest(), theta(), and finally stlf(). To check that it's doing the forecasts I get R to print off the results of the forecasts. It runs through all the forecast models fine until it gets to the stlf() forecast function. When I get this error:
Error in stl(x, s.window = s.window, t.window = t.window, robust =
robust) : only univariate series are allowed
My question is how come the time series (it is univariate) works fine in the other forecast functions but not in the stlf() function?
I have figured it out now after doing some more digging around. It turns out that I was passing a time series that was also a matrix to the stlf() function. The other forecasting functions don't seem to mind being given a time series that is also a matrix, but for some reason stlf() doesn't like it.
I converted my raw data into a vector using as.vector() and then turned that vector into a ts() object. And then passed that onto the stlf() function. Not massivly sure how this works as I originally passed a ts() object to stlf() previously. Fairly new to R, but I will look further into this..
Here is the code I used ;
altVector <- as.vector(t(rawdata))
tsy2 <- ts(altVector, start=1, end=c(3,9), frequency=12)
f.stlf <- stlf(tsy2, method="arima", h=3)
It's all working fine now.