I have daily temperature data for several years. I use the HoltWinters method to conduct exponential smoothing for the existing dataset. No forecast.
I need to find a convenient way to extract the original data and fitted data (xhat) for some manual analysis. .csv file would be ideal.
Since I am new to R, I am not sure how to extract the data in the needed format.
02/01/1998 98
02/02/1998 100
02/03/1998 96
after displaying:
DAY 1998 1999 2000 2001 2002 2003
1 1-Jul 98 86 91 84 89 84
2 2-Jul 97 90 88 82 91 87
Desired Output (the last number is a fitted result)
02/01/1998 98 97.6 02/02/1998 100 100.4 02/03/1998 96 95.7
My code
ts1 <- read.table("ts.txt", header=TRUE)
ts_v <- as.vector(unlist(ts1[,2:21]))
ts_ts <- ts(data = ts_v, frequency=123, start=1998)
hw_ts_add <- HoltWinters(ts_ts, seasonal = "additive")
print(hw_ts_add$fitted)
xhat level trend season
1997.000 87.17619 82.87739 -0.004362918 4.303159495
1997.008 90.32925 82.09550 -0.004362918 8.238118845
1997.016 92.96089 81.87348 -0.004362918 11.091777381
1997.024 90.93360 81.89497 -0.004362918 9.042996893
1997.033 83.99752 81.93450 -0.004362918 2.067387137
How Do I extract the date, xhat and the initial data as:
date xhat orig
You can extract xhat by using
print(hw_ts_add$fitted[,1])
To extract the first column of that matrix. Sadly, you cannot use hw_ts_add$fitted$xhat
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.