I am new to R and am attempting an analysis in R with the tslm() function.
Sample data in csv format:
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
I load the data and then attempt to run:
testc <- tslm(UnitSales~GPD+trend, data=lm0015c)
A simple attempt to model UnitSales from the GDP variable plus the trend.
I get the following error:
Error in tslm(UnitSales ~ GPD + trend, data = lm0015c) :
Not time series data
How do I designate the data as a time series?
您可以直接使用ts()
函数创建数据的时间序列格式版本。
yourGreatData <- ts(d[,2:length(d)], start = 2000, end = 2012)
我发现解决这个问题的更简单的方法是将你的数据框强制为时间序列:
testc <- tslm(UnitSales~GPD+trend, data=as.ts(lm0015c))
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.