I have a dataset of export trade data for a single country with 21 columns. The first column indicates the years (1962-2014) while the other 20 are trading partners. I am trying to run linear regressions for the years column and each other column. I have tried the method recommended here: Running multiple, simple linear regressions from dataframe in R that entails using
combn(names(DF), 2, function(x){lm(DF[, x])}, simplify = FALSE)
However this only yields the intercept for each pair which is less important to me than the slope of the regressions.
Additionally I have tried to use my dataset as a time series, however when I try to run
lm(dimnames~., brazilts, na.action=na.exclude)
(where brazilts
is my dataset as a time series from "1962" to "2014") it returns:
Error in model.frame.default(formula = dimnames ~ ., data = brazilts, :
object is not a matrix.
I therefore tried the same method with a matrix but then it returned the error:
Error in model.frame.default(formula = . ~ YEAR, data = brazilmatrix, :
'data' must be a data.frame, not a matrix or an array
(where brazilmatrix
is my dataset as a data.matrix
which includes a column for years).
Really I am not even proficient in R and at this point. The ultimate goal is to create a loop that I can use to get take regressions for a significantly larger dataset of gross exports by country-pair per year for 28 countries. Perhaps I am attacking this in entirely the wrong way, so any help or criticism is welcome. Bare in mind that the years (1962-2014) are in effect my explanatory variable and the value of gross export is my dependent variable, which may be throwing off my syntax in the above examples. Thanks in advance!