sebkrantz / dfms Goto Github PK
View Code? Open in Web Editor NEWDynamic Factor Models for R
Home Page: https://sebkrantz.github.io/dfms
License: GNU General Public License v3.0
Dynamic Factor Models for R
Home Page: https://sebkrantz.github.io/dfms
License: GNU General Public License v3.0
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?
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 missingDFM$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
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.