用R写代码 library fpp3 使用aus_accommodation数据集,首先计算CPI调整后的收入,并绘制出每个州的结果,然后对于每个州,拟合一个动态回归模型的消费物价指数调整的收入与季节性虚拟变量,一个分段线性时间趋势与一个节点在2008年Q1的ARIMA误差。用R写成代码并展示代码
时间: 2023-03-15 12:15:10 浏览: 116
利用R语言进行 数据加工
我可以为您提供参考代码:
library(fpp3)
aus_accommodation <- window(aus_accommodation, start = 2009)
# Calculate CPI-adjusted income
aus_accommodation$cpi_adj_income <- aus_accommodation$income/aus_accommodation$cpi# Plot results for each state
aus_accommodation %>%
group_by(state) %>%
ggplot(aes(x = date, y = cpi_adj_income)) +
geom_line() +
facet_wrap(~state)# Fit dynamic regression models for each state's CPI-adjusted income
aus_accommodation %>%
group_by(state) %>%
tslm(cpi_adj_income ~ trend + season +
ss(date, 1, 1) + arima(date, order = c(0,1,1)))
阅读全文