提取日期预测包 R

发布于 2024-10-07 06:23:28 字数 771 浏览 0 评论 0原文

我正在使用预测包并将结果保存

t <- data.frame(forecast(prod.arima, h=4))

到数据框中。行名称代表我的日期,打印时看起来

> t
         Point.Forecast    Lo.80    Hi.80    Lo.95     Hi.95
2010.856       812.9849 630.5707 995.3992 534.0064 1091.9634
2010.876       670.3363 485.1885 855.4840 387.1772  953.4953
2010.895       769.4848 584.2552 954.7145 486.2005 1052.7691
2010.914       692.8951 507.6630 878.1272 409.6070  976.1832

我还没有完成这个任务,但我希望自动化一个 LaTex 报告,我将在其中将预测打印到报告页面和预测图。我想我可以将数据帧传递到 LaTex 表,但我需要以最终用户能够理解它们代表周末(设置为星期日)的方式格式化日期。

将具有“可读”日期的原始时间序列转换为时间序列对象

ts(prod, start = 2009 +(31+28+31+5)/365, f=52 )

我使用时间序列的开始时间为 2009 年 4 月 5 日并表示每周数据点,

。我们将非常感谢您提供的任何帮助。不用说我对 R 还很陌生。

I am using the forecast package and saved the results of

t <- data.frame(forecast(prod.arima, h=4))

to a data frame. The row names represent my dates, which when printed look like

> t
         Point.Forecast    Lo.80    Hi.80    Lo.95     Hi.95
2010.856       812.9849 630.5707 995.3992 534.0064 1091.9634
2010.876       670.3363 485.1885 855.4840 387.1772  953.4953
2010.895       769.4848 584.2552 954.7145 486.2005 1052.7691
2010.914       692.8951 507.6630 878.1272 409.6070  976.1832

I am not close (yet) to getting this completed, but I am hoping to automate a LaTex report where I will print the forecasts to a report page and a plot of the forecast. I figure I can pass the dataframe to a LaTex table, but I need the dates to be formatted in a way where the end user will understand that they represent week ends (set to Sundays).

I converted my original time series with "readable" dates to a time series object using

ts(prod, start = 2009 +(31+28+31+5)/365, f=52 )

where the start of my timeseries was on April 5th, 2009 and represented weekly datapoints.

Any help you can provide will be very much appreciated. Needless to say I am pretty new to R.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

染火枫林 2024-10-14 06:23:28

我可以想到两种方法:一种是使用 Epi 包中的函数 as.Date.cal.yr 。另一种方法是将这些日期乘以一年中的秒数,然后将其传递给 as.POSIXct (但我还没有测试过那个。)在这两个中,第一个似乎是最不痛苦的:

require(Epi)
as.Date.cal.yr(as.numeric(row.names(t)))
# [1] "2010-11-10" "2010-11-17" "2010-11-24" "2010-12-01"
as.POSIXlt(as.Date.cal.yr(as.numeric(row.names(t))))$wday
#  [1] 3 3 3 3
paste(weekdays(as.Date.cal.yr(as.numeric(row.names(t)))) , 
         as.Date.cal.yr(as.numeric(row.names(t))), sep=",")
 #   [1] "Wednesday,2010-11-10" "Wednesday,2010-11-17" "Wednesday,2010-11-24"
 #   [4] "Wednesday,2010-12-01"

所以我不获取星期日,因为在 POSIXlt 系统中这些将是 wday==0。请参阅 DateTimeClasses 的帮助。

至于问题的LaTeX部分,安装Hmisc包并使用函数latex()。

I can think of two ways: one would be to use a function as.Date.cal.yr from the Epi package. Another would be to multiply those dates by the number of seconds in a year, and then pass that to as.POSIXct (but I haven't tested that one.) Of those two the first seems the least painful:

require(Epi)
as.Date.cal.yr(as.numeric(row.names(t)))
# [1] "2010-11-10" "2010-11-17" "2010-11-24" "2010-12-01"
as.POSIXlt(as.Date.cal.yr(as.numeric(row.names(t))))$wday
#  [1] 3 3 3 3
paste(weekdays(as.Date.cal.yr(as.numeric(row.names(t)))) , 
         as.Date.cal.yr(as.numeric(row.names(t))), sep=",")
 #   [1] "Wednesday,2010-11-10" "Wednesday,2010-11-17" "Wednesday,2010-11-24"
 #   [4] "Wednesday,2010-12-01"

So I'm not getting Sundays, since those would be wday==0's in the POSIXlt system. See the help for DateTimeClasses.

As for the LaTeX part of the question, install the Hmisc package and use function latex().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文