[英]Format of time series data with regression variables
我是 R 的新手,正在嘗試使用 tslm() 函數在 R 中進行分析。
csv格式的示例數據:
UnitSales GDP GDPPerCap CPI PropInvIndex DispIncTopDecile TransCommSecDecile CivilVehOwn Urban AutoFin
2000 1 1198243.4 949 81.62 4984 10643 618 1609 36.22 0
2001 2 1324337.8 1042 81.38 6344 14219 782 1802 37.66 0
2002 3 1453827.558 1135 80.8 7790.9223 18995.9 991.2 2053.17 39.08978381 0
2003 4 1640958.735 1274 81.83 10153.8009 21837.3 1106 2382.93 40.53022975 0
2004 5 1931644.33 1409 85.02 13158.2516 25377.2 1274.2 2693.71 41.76000862 0
2005 6 2256902.591 1731 86.56 15909.2471 28773.1 1590.3 3160 42.98999663 0
2006 7 2712950.885 2069 87.83 19422.9174 31967.3 1801 3697.3531 44.34301016 0
2007 9 3494055.942 2651 92.02 25288.8373 36784.5 2467.7 4358.355 45.8892446 0.1
2008 11 4521827.271 3414 97.45 31203.1942 43613.8 2632.9 5099.6094 46.98950317 0.12
2009 13 4990233.519 3749 96.76 36241.808 46826.1 3181.9 6280.6086 48.34170101 0.14
2010 15 5930502.27 4433 100 48259.403 51431.6 3630.6 7801.8259 49.94966105 0.16
2011 18 7321891.955 5447 105.45 61796.8858 58841.9 3963 9356.3163 51.27027127 0.18
2012 21 8229490.03 6093 108.22 71803.7869 63824.2 4304.1 10933.0912 52.57008656 0.22
我加載數據,然后嘗試運行:
testc <- tslm(UnitSales~GPD+trend, data=lm0015c)
從 GDP 變量加上趨勢對 UnitSales 建模的簡單嘗試。
我收到以下錯誤:
Error in tslm(UnitSales ~ GPD + trend, data = lm0015c) :
Not time series data
如何將數據指定為時間序列?
您可以直接使用ts()
函數創建數據的時間序列格式版本。
yourGreatData <- ts(d[,2:length(d)], start = 2000, end = 2012)
我發現解決這個問題的更簡單的方法是將你的數據框強制為時間序列:
testc <- tslm(UnitSales~GPD+trend, data=as.ts(lm0015c))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.