kosukeimai / MatchIt

R package MatchIt
204 stars 43 forks source link

Running tests fails: Error: could not find function "avg_comparisons", "boot.ci" #195

Open barracuda156 opened 4 months ago

barracuda156 commented 4 months ago
* checking running R code from vignettes ...
  ‘MatchIt.Rmd’ using ‘UTF-8’... failed
  ‘assessing-balance.Rmd’ using ‘UTF-8’... OK
  ‘estimating-effects.Rmd’ using ‘UTF-8’... failed
  ‘matching-methods.Rmd’ using ‘UTF-8’... OK
  ‘sampling-weights.Rmd’ using ‘UTF-8’... OK
 ERROR
Errors in running code in vignettes:
when running code in ‘MatchIt.Rmd’
  ...
+     which.xs = ~age + married + re75)

> est <- {
+     if (use != "none" && me_ok) {
+         avg_comparisons(fit, variables = "treat", vcov = ~subclass, 
+             newdata = subset(m .... [TRUNCATED] 

  When sourcing ‘MatchIt.R’:
Error: could not find function "avg_comparisons"
Execution halted
when running code in ‘estimating-effects.Rmd’
  ...

> b <- {
+     if (boot_ok) 
+         boot.ci(boot_out, type = "perc")
+     else list(t0 = 1.347, percent = c(0, 0, 0, 1.144, 1.891))
+ }

  When sourcing ‘estimating-effects.R’:
Error: could not find function "boot.ci"
Execution halted

* checking re-building of vignette outputs ... SKIPPED
* DONE

Status: 1 ERROR, 1 NOTE

The log has:

Error in eval(x, envir = envir) : object 'me_ok' not found
Error in eval(x, envir = envir) : object 'me_ok' not found
Error in eval(x, envir = envir) : object 'me_ok' not found
Error in eval(x, envir = envir) : object 'me_ok' not found
Error in eval(x, envir = envir) : object 'me_ok' not found
Error in eval(x, envir = envir) : object 'su_ok' not found
Error in eval(x, envir = envir) : object 'boot_ok' not found
Error in eval(x, envir = envir) : object 'boot_ok' not found
Error in eval(x, envir = envir) : object 'me_ok' not found
Error in eval(x, envir = envir) : object 'me_ok' not found

> knitr::opts_chunk$set(echo = TRUE, eval = T)

> options(width = 200, digits = 4)

> me_ok <- requireNamespace("marginaleffects", quietly = TRUE) && 
+     requireNamespace("sandwich", quietly = TRUE)

> su_ok <- requireNamespace("survival", quietly = TRUE)

> boot_ok <- requireNamespace("boot", quietly = TRUE)

> gen_X <- function(n) {
+     X <- matrix(rnorm(9 * n), nrow = n, ncol = 9)
+     X[, 5] <- as.numeric(X[, 5] < 0.5)
+     X
+ }

> gen_A <- function(X) {
+     LP_A <- -1.2 + log(2) * X[, 1] - log(1.5) * X[, 2] + log(2) * 
+         X[, 4] - log(2.4) * X[, 5] + log(2) * X[, 7] - .... [TRUNCATED] 

> gen_Y_C <- function(A, X) {
+     2 * A + 2 * X[, 1] + 2 * X[, 2] + 2 * X[, 3] + 1 * X[, 4] + 
+         2 * X[, 5] + 1 * X[, 6] + rnorm(length(A),  .... [TRUNCATED] 

> gen_Y_B <- function(A, X) {
+     LP_B <- -2 + log(2.4) * A + log(2) * X[, 1] + log(2) * X[, 
+         2] + log(2) * X[, 3] + log(1.5) * X[, 4] + l .... [TRUNCATED] 

> gen_Y_S <- function(A, X) {
+     LP_S <- -2 + log(2.4) * A + log(2) * X[, 1] + log(2) * X[, 
+         2] + log(2) * X[, 3] + log(1.5) * X[, 4] + l .... [TRUNCATED] 

> set.seed(19599)

> n <- 2000

> X <- gen_X(n)

> A <- gen_A(X)

> Y_C <- gen_Y_C(A, X)

> Y_B <- gen_Y_B(A, X)

> Y_S <- gen_Y_S(A, X)

> d <- data.frame(A, X, Y_C, Y_B, Y_S)

> head(d)
  A      X1      X2      X3       X4 X5      X6      X7      X8       X9      Y_C Y_B     Y_S
1 0  0.1725 -1.4283 -0.4103 -2.36059  1 -1.1199  0.6398 -0.4840 -0.59385  0.07104   0  278.46
2 0 -1.0959  0.8463  0.2456 -0.12333  1 -2.2687 -1.4491 -0.5514 -0.31439  0.15619   0  330.63
3 0  0.1768  0.7905 -0.8436  0.82366  1 -0.2221  0.2971 -0.6966 -0.69516 -0.85180   1  369.94
4 0 -0.4595  0.1726  1.9542 -0.62661  1 -0.4019 -0.8294 -0.5384  0.20729 -2.35184   0   91.06
5 1  0.3563 -1.8121  0.8135 -0.67189  1 -0.8297  1.7297 -0.6439 -0.02648  0.68058   0  182.73
6 0 -2.4313 -1.7984 -1.2940  0.04609  1 -1.2419 -1.1252 -1.8659 -0.56513 -5.62260   0 2563.73

> library("MatchIt")

> mF <- matchit(A ~ X1 + X2 + X3 + X4 + X5 + X6 + X7 + 
+     X8 + X9, data = d, method = "full", estimand = "ATT")

> mF
A matchit object
 - method: Optimal full matching
 - distance: Propensity score
             - estimated with logistic regression
 - number of obs.: 2000 (original), 2000 (matched)
 - target estimand: ATT
 - covariates: X1, X2, X3, X4, X5, X6, X7, X8, X9

> md <- match.data(mF)

> head(md)
  A      X1      X2      X3       X4 X5      X6      X7      X8       X9      Y_C Y_B     Y_S distance weights subclass
1 0  0.1725 -1.4283 -0.4103 -2.36059  1 -1.1199  0.6398 -0.4840 -0.59385  0.07104   0  278.46  0.08461 0.20795      150
2 0 -1.0959  0.8463  0.2456 -0.12333  1 -2.2687 -1.4491 -0.5514 -0.31439  0.15619   0  330.63  0.01855 0.04475      119
3 0  0.1768  0.7905 -0.8436  0.82366  1 -0.2221  0.2971 -0.6966 -0.69516 -0.85180   1  369.94  0.22210 0.88379      288
4 0 -0.4595  0.1726  1.9542 -0.62661  1 -0.4019 -0.8294 -0.5384  0.20729 -2.35184   0   91.06  0.04180 0.17676      303
5 1  0.3563 -1.8121  0.8135 -0.67189  1 -0.8297  1.7297 -0.6439 -0.02648  0.68058   0  182.73  0.43291 1.00000       86
6 0 -2.4313 -1.7984 -1.2940  0.04609  1 -1.2419 -1.1252 -1.8659 -0.56513 -5.62260   0 2563.73  0.04998 0.12626      158

> fit1 <- lm(Y_C ~ A * (X1 + X2 + X3 + X4 + X5 + X6 + 
+     X7 + X8 + X9), data = md, weights = weights)

> boot_fun <- function(data, i) {
+     boot_data <- data[i, ]
+     m <- matchit(A ~ X1 + X2 + X3 + X4 + X5 + X6 + X7 + X8 + 
+         X9, data = bo .... [TRUNCATED] 

> b <- {
+     if (boot_ok) 
+         boot.ci(boot_out, type = "perc")
+     else list(t0 = 1.347, percent = c(0, 0, 0, 1.144, 1.891))
+ }

  When sourcing ‘estimating-effects.R’:
Error: could not find function "boot.ci"
Execution halted
ngreifer commented 4 months ago

Where/why are you running these tests? Everything seems okay on CRAN and there is no problem with the vignette on the website.

barracuda156 commented 4 months ago

@ngreifer Thank you for responding. This is in MacPorts.

ngreifer commented 4 months ago

Sorry, I don't know what that is or why tests run on it would fail when all CRAN tests pass. It looks like the first code block of the Rmd file is not being run.

Can you give me more information on what you are trying to do and why?