Giter Site home page Giter Site logo

sebkrantz / dfms Goto Github PK

View Code? Open in Web Editor NEW
29.0 29.0 9.0 16.79 MB

Dynamic Factor Models for R

Home Page: https://sebkrantz.github.io/dfms

License: GNU General Public License v3.0

R 86.42% C++ 13.09% C 0.49%
dynamic-factor-models rstats time-series

dfms's People

Contributors

sebkrantz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

dfms's Issues

Unstandardize data forecasts

Absolutely love this package; incredibly useful and performant. Was wondering, since you are standardizing the variables as part of the DFM() function, it looks like the forecasts for those variables when using predict() show up as the standardized versions (as opposed to whatever stationary series were provided to the model). Is there a way to save the mu/sigma values used as part of standardization so that you can convert the projections back into whatever data was provided as input to the DFM() function?

Question: how do I get in-sample fitted values on the original scale?

I'm trying to use DFM to impute missing potential outcomes as proposed in a series of recent papers (notably Yiqing's gsynth paper, package). I was wondering if there was a way to use fitted or predict (or some other internal pieces in the DFM object) to construct predicted values for missing outcomes in the original dataset.

My question is can I impute the 50 missing values on the original scale using one of the object methods?

  • predict does out-of-sample predictions as far as I can tell [happy to be corrected; i passed a negative value equal to the number of rows in the original dataset but that gave me an error]
  • fitted is missing everywhere the original data is missing
  • DFM$X_imp has stationary, scaled imputations.

Here's an example

library(gsynth); library(dfms)

# loads turnout data - State X Year dataset on turnout, treatment is same day registration
data(gsynth) 

df = turnout[, 1:4] %>% setDT

# %% # reshape to T X N matrix with state time series columns
Y0mat = dcast(year ~ abb, data = df, value.var = "turnout")[,-1]  |> as.matrix()
Wmat  = dcast(year ~ abb, data = df, value.var = "policy_edr")[,-1]  |> as.matrix()
# set outcomes in treated periods to missing
Y0mat = replace(Y0mat, as.logical(Wmat), NA)
# Y0mat has missing values in treated periods for each state
# %% fit model
fm = DFM(Y0mat, r = 3, p = 3)
Y0hat = fitted(fm)
# %%
sum(is.na(Y0mat)) # 50 - number of missing outcomes
sum(is.na(Y0hat)) # 50 - same as number of missing outcomes
sum(is.na(fm$X_imp)) # non missing, but scaled

Is this package live?

I happen to start looking into DFM estimation in R and saw this package, but I don't think the package is on CRAN and I did not see a "devtools::install_github("SebKrantz/DFM") in the read_me, so I was just wondering if the package is live currently (Sept 14, 2022).

Thanks,
Luke

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.