Time series regression in R: help from scratch
I am very inexperienced in R, but I am told that this is the main statistical package. I studied it for the sake of research, but I'm stumped about time series data, regression in particular. I know how to do multiple regression, and I somewhat know how to make predictions using SARIMA models, but I'm not sure how to do multiple regression with time series.
Here is an example of my data. I always import from CSV.
HomRate Unemp Av_Schl GNI_perCapita
2000 5.5 4.099 12.7 36930
2001 6.6 4.800 N/A 37860
2002 5.6 5.900 N/A 38590
2003 5.6 6.099 N/A 39960
2004 5.5 5.599 12.87391 42260
2005 5.6 5.199 12.8 44740
2006 5.8 4.699 12.96034 47390
2007 5.6 4.699 N/A 48420
2008 5.4 5.900 13.20913 48640
2009 5.0 9.399 13.29049 47250
Homicide, or HomRate, is the dependent variable and the others are independent. For the sake of this, let's say there are no transformations in the data.
From my limited understanding, instead of using lm
as in a few linear regressions, I use tslm
from a package forecast
. However, my data is not considered time series data according to R; How can i do this? None of the examples I've found actually show me the underlying data, so I don't know what the corresponding ts compatible data looks like.
If I get the command tslm
from the ground, will the rest of the logic be like multiple regression? (i.e. model=tslm(HomRate~Unemp+Av_Schl+...)
) Or is it very different in terms of encoding?
Thank you very much and please let me know if you need more details.
source to share
I am currently learning R and my main focus is time series analysis and I come across a lot of packet conflicts with dates and ggplot2.
As of Nov-2017, it looks like the least-risk approach is outlined in the R Times Series Study Guide by Matthew Mal.
Basic steps:
- Data import
- Load it into an object
xts
to view and filter it. - Converting an object
xts
to a standard R objectts
- This object is
ts
more suitable for Rob Hyndman R packages and for use in ggplot2
Please give feedback if there is a better, lower risk way for people new to R.
source to share