Closed apoorvalal closed 1 year ago
Thanks, this is a feature request I guess, I could add this as an argument. Looking at the code:
fitted.dfm <- function (object, method = switch(object$em.method, none = "2s",
"qml"), orig.format = FALSE, standardized = FALSE, ...)
{
X <- object$X_imp
Fa <- switch(tolower(method), pca = object$F_pca, `2s` = object$F_2s,
qml = object$F_qml, stop("Unkown method", method))
res <- tcrossprod(Fa, object$C)
if (!standardized)
res <- unscale(res, attr(X, "stats"))
if (object$anyNA)
res[attr(X, "missing")] <- NA
if (orig.format) {
if (length(object$rm.rows))
res <- pad(res, object$rm.rows, method = "vpos")
if (attr(X, "is.list"))
res <- mctl(res)
return(setAttrib(res, attr(X, "attributes")))
}
return(qM(res))
}
<bytecode: 0x14674e1c8>
<environment: namespace:dfms>
it appears that simply setting object$anyNA <- FALSE
before passing the 'dfm' object to fitted should do the trick.
Perfect, that worked. Thanks a lot for the excellent package and prompt response!
[Leaving it open since you tagged it and might want to add an argument to fitted
; feel free to close]
Thanks, yeah I'll leave it open and add it, but I just pushed a minor update to CRAN, so it might take a few weeks.
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 usefitted
orpredict
(or some other internal pieces in theDFM
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