Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

X must be non-null for matrix completion, but only when bootstrapping #70

Open
samzhang111 opened this issue Sep 27, 2021 · 14 comments
Open

Comments

@samzhang111
Copy link

Currently, if X is null for the matrix completion estimation, and bootstrapping is performed, then the code crashes with a cryptic Rcpp error:

Error in synth.boot(Y = Y, X = X, D = D, cl = cl, I = I, W = W, EM = EM, :
Bootstrap inference fails. Please check the data.

This happens, for example, on this line if cross-validation is not performed.

On the other hand, when I ran the MC estimation with se=FALSE, this crashing does not occur.

This may be the issue encountered in #65.

@xuyiqing
Copy link
Owner

xuyiqing commented Sep 27, 2021 via email

@samzhang111
Copy link
Author

Yes the issue reproduces with inference="nonparametric", and with the data from the package. Here is an exact line to replicate the issue:

out <- gsynth(Y ~ D, data = simdata, estimator = "mc", index = c("id","time"), se = TRUE, nboots = 50, r = c(0, 5), CV = TRUE, force = "two-way", parallel = TRUE, cores = 4, inference = "nonparametric")

fails, while

out <- gsynth(Y ~ D, data = simdata, estimator = "mc", index = c("id","time"), se = FALSE, r = c(0, 5), CV = TRUE, force = "two-way", parallel = TRUE, cores = 4, inference = "nonparametric")

succeeds. (The difference from the example in the docs is that the formula is Y ~ D instead of Y ~ D + X1 + X2)

@xuyiqing
Copy link
Owner

xuyiqing commented Sep 27, 2021 via email

@shishirdash
Copy link

Hello! I ran in to the same issue, curious if there has been any progress on it?

@xuyiqing
Copy link
Owner

xuyiqing commented Nov 10, 2021 via email

@PinchOfData
Copy link

I ran into the same issue, too.

@PinchOfData
Copy link

PinchOfData commented Mar 23, 2022

Any update on this issue?

In the meantime, a simple unorthodox fix is to add a random, uncorrelated variable to the estimation.

data(gsynth)
simdata$X3 <- runif(n=length(simdata$id))
out <- gsynth(Y ~ D + X3, data = simdata, estimator = "mc", index = c("id","time"), se = TRUE, nboots = 50, r = c(0, 5), CV = TRUE, force = "two-way", parallel = TRUE, cores = 4, inference = "nonparametric")

@xuyiqing
Copy link
Owner

xuyiqing commented Mar 23, 2022 via email

@PinchOfData
Copy link

PinchOfData commented Mar 23, 2022

library(gsynth)
data(gsynth)

# Works with covariates
out1 <- gsynth(Y ~ D + X1 + X2, data = simdata, estimator = "mc", index = c("id","time"), se = TRUE, nboots = 50, r = c(0, 5), CV = TRUE, force = "two-way", parallel = TRUE, cores = 4, inference = "nonparametric")

# Doesn't without
out2 <- gsynth(Y ~ D, data = simdata, estimator = "mc", index = c("id","time"), se = TRUE, nboots = 50, r = c(0, 5), CV = TRUE, force = "two-way", parallel = TRUE, cores = 4, inference = "nonparametric")

Will send it by email, too.

(great package btw)

@xuyiqing
Copy link
Owner

xuyiqing commented Mar 23, 2022 via email

@mjpavlik
Copy link

Bumping this issue, as I am getting the same error. Thanks so much for this amazing package and for mc integration :)

@xuyiqing
Copy link
Owner

xuyiqing commented May 11, 2022 via email

@ChrisDoll
Copy link

ChrisDoll commented Jan 11, 2023

Adding another workaround, reverting to version 1.1.4

# devtools
install.packages("devtools", version = "2.2.2", repos = 'http://cran.us.r-project.org', type = "source")


# Install for functioning commit: Aug 26, 2019, 1.1.4
devtools::install_github("xuyiqing/gsynth", ref = "461a761")

The error seems to be caused by:

               X.boot <- NULL
                if (p > 0) {
                    X.boot <- X[,boot.id,,drop = FALSE]
                }

in 'core.R'. When and why this is the case I don't know.

@MatthieuStigler
Copy link

I am having the same issue and can reproduce the error. It seems actually it comes from inter_fe_mc not handling a NULL X?

To check, insert a print(boot) at line 332 (just below if ("try-error" %in% class(boot)) {) of synth.boot, then:

library(gsynth)
data(gsynth)

fixInNamespace("synth.boot", "gsynth")
## introduce a print(boot) at line 332, just below if ("try-error" %in% class(boot)) {
out2 <- gsynth(Y ~ D, data = simdata, estimator = "mc", index = c("id","time"), se = TRUE, nboots = 1,  parallel = FALSE)

this will show error message:

Rcpp::not_compatible in inter_fe_mc(YY, Y0, X, II, beta0, hasF, lambda[1], force, tol): Not compatible with requested type: [type=NULL; target=double].>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants