Wednesday, June 26, 2013

A first primative multi-variable economic model

A first primative multi-variable economic model

A first primative multi-variable economic model

Proud Economy 0003

The Conference Board has posted their prediction of 1.1% growth in GDP for the second quarter, with Real GDP, Real Consumer Spending, Housing Starts, Real Capital Spending, and Net Exports. Those seem like a good starting point for a multi-variable model.

Collect the time series

I'll use the quandl.com site for data.

library(forecast)
library(Quandl)
# Quandl.auth('yourauthenticationtoken')

So that we can simplify the processing, I'll define an extraction function here that will be used below. Since the gdp timeseries has quarterly data, I'll collapse all of them to quarterly.

getts <- function(series) {
    y <- Quandl(series, collapse = "quarterly", type = "xts")
    layout(matrix(c(1, 1, 2, 3), 2, 2, byrow = TRUE))
    plot.ts(y, main = series, ylab = series)
    acf(y, main = "Autocorrelations", ylim = c(-1, 1))
    pacf(y, main = "Partial Autocorrelations", ylim = c(-1, 1))
    return(y)
}

Real GDP:

gdp <- getts("FRED/GDPC1")

plot of chunk unnamed-chunk-4

Real Consumer Spending:

pce <- getts("FRED/PCE")

plot of chunk unnamed-chunk-5

Visually, consumer spending looks just like the real gdp. That's probably because it's the largest component. We'll have to model that someday.

Housing Starts:

houst <- getts("FRED/HOUST")

plot of chunk unnamed-chunk-6

I suspect that houseing depends on population wealth, consumer confidence, and especially the interest rate for mortgages. We can explore that later.

Real Capital Spending:

atcgno <- getts("FRED/ATCGNO")

plot of chunk unnamed-chunk-7

Net Exports:

bopgstb <- getts("FRED/BOPGSTB")

plot of chunk unnamed-chunk-8

What about a forecast?

Ok, let's pretend we know what we are doing and create an automatic ARIMA forecast for the Gross National Product.

fcst <- forecast(auto.arima(gdp), h = 2)
summary(fcst)
## 
## Forecast method: ARIMA(2,2,2)                   
## 
## Model Information:
## Series: gdp 
## ARIMA(2,2,2)                    
## 
## Coefficients:
##          ar1    ar2     ma1     ma2
##       -0.108  0.345  -0.512  -0.457
## s.e.   0.247  0.097   0.257   0.249
## 
## sigma^2 estimated as 2613:  log likelihood=-1409
## AIC=2828   AICc=2828   BIC=2846
## 
## Error measures:
##                 ME  RMSE   MAE  MPE  MAPE   MASE      ACF1
## Training set 3.531 50.93 36.65 8.06 66.51 0.6237 -0.008643
## 
## Forecasts:
##     Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 266          13771 13706 13837 13671 13871
## 267          13829 13717 13941 13658 14000

We'll have to figure out what all that means eventually. For now we're just playing.

tail(gdp)
##            Value
## 2011-12-31 13441
## 2012-03-31 13506
## 2012-06-30 13548
## 2012-09-30 13652
## 2012-12-31 13665
## 2013-01-01 13726

I don't understand how the dates translate into actual time frames (I'll have to figure that out), but the last number given has a date of 2013-01-01 so let's assume that was for the first quarter for now. The Conference Boards GDP forecast of 1.1% growth for the second quarter then applys to that number (say for now) scaled back to a quarterly rate from an annual growth rate quoted:

13726 * (1 + 0.011/4)  # Conf Board
## [1] 13764

So if I've got this right, the Conference Boards forecast falls in my first automatic crude 95% range. Cool!

And this just in as I'm working on this:

U.S. GDP In First Quarter Worse Than Previously Announced, Exposing Austerity Folly

“Gross domestic product grew at just a 1.8 percent annualized pace in the first quarter, the Bureau of Economic Analysis said on Wednesday, revising down its earlier estimate of 2.4 percent growth. Economists had expected no change in the BEA's third effort at estimating GDP, and such sharp revisions are rare in a third estimate.”

“Federal government spending shrank at an 8.7 percent annualized rate, on top of a 14.8 percent contraction in the fourth quarter, subtracting nearly 0.7 percentage points from total GDP growth. The U.S. government has been cutting spending for most of the past two years, at the fastest pace since the end of the Vietnam War, despite the shaky recovery from the Great Recession.”

If we can get some models working, there should be lots to blog about.

How about a naive regression?

str(gdp)
## An 'xts' object on 1947-03-31/2013-01-01 containing:
##   Data: num [1:265, 1] 1771 1768 1766 1793 1822 ...
##  - attr(*, "dimnames")=List of 2
##   ..$ : NULL
##   ..$ : chr "Value"
##   Indexed by objects of class: [Date] TZ: UTC
##   xts Attributes:  
##  NULL
str(pce)
## An 'xts' object on 1959-03-31/2013-04-01 containing:
##   Data: num [1:218, 1] 313 319 325 323 331 ...
##  - attr(*, "dimnames")=List of 2
##   ..$ : NULL
##   ..$ : chr "Value"
##   Indexed by objects of class: [Date] TZ: UTC
##   xts Attributes:  
##  NULL
str(houst)
## An 'xts' object on 1959-03-31/2013-05-01 containing:
##   Data: num [1:218, 1] 1620 1503 1540 1601 1109 ...
##  - attr(*, "dimnames")=List of 2
##   ..$ : NULL
##   ..$ : chr "Value"
##   Indexed by objects of class: [Date] TZ: UTC
##   xts Attributes:  
##  NULL
str(atcgno)
## An 'xts' object on 1992-03-31/2013-05-01 containing:
##   Data: num [1:86, 1] 45144 45889 44972 47701 45226 ...
##  - attr(*, "dimnames")=List of 2
##   ..$ : NULL
##   ..$ : chr "Value"
##   Indexed by objects of class: [Date] TZ: UTC
##   xts Attributes:  
##  NULL
str(bopgstb)
## An 'xts' object on 1992-03-31/2013-04-01 containing:
##   Data: num [1:86, 1] -2641 -2824 -3530 -5603 -6777 ...
##  - attr(*, "dimnames")=List of 2
##   ..$ : NULL
##   ..$ : chr "Value"
##   Indexed by objects of class: [Date] TZ: UTC
##   xts Attributes:  
##  NULL

There's lots of conflicting information on using R and none of it seems to standout to those of us just starting to learn it.

form <- gdp ~ pce + houst + atcgno + bopgstb
lmfit <- lm(form)
## Error: variable lengths differ (found for 'pce')
summary(lmfit)
## Error: object 'lmfit' not found

Humm, I don't know how that's supposed to go together or work. There's lots to figure out. I'll work on it more another day.

Gary Young

No comments:

Post a Comment