Wednesday, August 31, 2016

A brief introduction to Dynamic Factor Models in Stan

8 comments:

  1. Thanks for the post. Just one comment. The dynamic factor is a monthly variable, but GDP is a quarterly variable, which should be be a function of current and past values of the factor. Don't know much about Stan, but I assume your Stan code should look like

    Y[t,p] ~ normal(xhat[t]*gamma[p],1);

    for unemployment and

    Y[t,p] ~ normal(1/3*(xhat[t]+xhat[t-1]+xhat[t-2])*gamma[p],1)

    for GDP (I have used a linear approximation).



    ReplyDelete
  2. Hey Tim, thanks for your comment. I thought I'd escaped this issue by expressing everything as annual growth rates, but thinking about it some more I'm not so sure. Will fix it up!

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. To be honest I overlooked the fact that you are calculating year on year changes. I think the way you did it now is correct. Quarterly GDP, Y[t]^q=Y[t]^m+Y[t-1]^m+Y[t-2]^m, where Y[t]^m is the monthly flow of GDP. The year-on-year growth rate is

    (Y[t]^q-Y[t-12]^q)/Y[t-12]^q=(Y[t]^m+Y[t-1]^m+Y[t-2]^m-Y[t-12]^m-Y[t-13]^m-Y[t-14]^m)/(Y[t-12]^m-Y[t-13]^m-Y[t-14]^m)

    From we can get to an expression where the quarterly growth rate is a weighted average of the past three periods of year-on-year monthly growth rates. Approximate the weights by using 1/3, and we get (Y[t]^q-Y[t-12]^q)/Y[t-12]^q=1/3(f[t]+f[t-1]+f[t-2]).

    Given the new specification perhaps it is better to have month-on-month growth rates for employment and quarter-on-quarter growth rates for GDP. One should detect turning points sooner, than the other, no?

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. I just stumbled across your model. I've been wrangling in some ecologic time series data into it. I was able to pull the factor loadings out with a slight modification to your code:

    # Factor loadings
    summarised_factors <- as.data.frame(dfm_model) %>%
    select(contains("gamma_")) %>%
    melt() %>%
    group_by(variable) %>%
    summarise(median = median(value),
    lower = quantile(value, 0.025),
    upper = quantile(value, 0.975))

    I was digging through your model code. Does this model allow for multiple trends or just a single trend? My guess is a single common trend.

    Thanks for sharing this.

    ReplyDelete
  7. Choosing a real estate company is perhaps the single most important choice you can make when buying or selling a property in the U.K. The purchase or sale of a home is often the largest financial transaction the average person will make. Doesn't make sense to have a capable and experienced real estate firm as your side to guide you though what can be a complicated process, both legal and financial? 港区の高級賃貸

    ReplyDelete