ssdavenport / microsynth

Synthetic controls for micro-level data
16 stars 9 forks source link

Archived package dependency creating error in `microsynth` function #27

Closed samanthagold closed 9 months ago

samanthagold commented 1 year ago

Hello!

Currently working in R version 4.3.0 and am no longer able to use the microsynth function because of an archived CRAN package (LowRankQP). I receive the following error:

Error in loadNamespace(x) : there is no package called ‘LowRankQP’

Any advice on how to proceed?

Best, Sammy

ssdavenport commented 1 year ago

Samantha,

I'm unable to replicate this, having installed microsynth v2.0.44 via CRAN, and run example(microsynth). LowRankQP should be treated as optional and not used by your machine unless it is installed on your machine. If you do need LowRankQP, one way to install that is by downloading it from the CRAN archive: https://cran.r-project.org/src/contrib/Archive/LowRankQP/.

Steven

Sent via Superhuman ( @.*** )

On Tue, Jul 11, 2023 at 9:40 AM, Samantha Gold < @.*** > wrote:

Hello!

Currently working in R version 4.3.0 and am no longer able to use the microsynth function because of an archived CRAN package (LowRankQP). I receive the following error:

Error in loadNamespace(x) : there is no package called ‘LowRankQP’

Any advice on how to proceed?

Best, Sammy

— Reply to this email directly, view it on GitHub ( https://github.com/ssdavenport/microsynth/issues/27 ) , or unsubscribe ( https://github.com/notifications/unsubscribe-auth/AAGG6RS52NVFRDRKOKL72MDXPV6ZXANCNFSM6AAAAAA2GIYCGY ). You are receiving this because you are subscribed to this thread. Message ID: <ssdavenport/microsynth/issues/27 @ github. com>

samanthagold commented 1 year ago

Hi Steven,

The error gets thrown when setting the check.feas option to TRUE. I tried installing the archived LowRankQP package but run into package compiler issues on my machine since I am working on a newer Mac (OS Ventura) and the archived version does not accommodate that. Any other tips on how to resolve the package issue?

Thanks! Sammy

ssdavenport commented 1 year ago

Samantha,

It looks like you may have caught a bug in the recent release. When LowRankQP was archived from CRAN, we had to update the code so that package was only called upon if installed on the user’s machine. I've been unable to replicate this error, as I have LowRankQP on my machine, but it may be that the updated code still requires LowRankQP in the event that check.feas=TRUE.

In the meantime, you may be able to try:

1 Debugging the install of LowRankQP (eg this SO post https://stackoverflow.com/questions/76271997/installing-lowrankqp-r-package-results-in-an-error )

2 Running on a machine with LowRankQP working

3 submitting a push request with a code fix or

4 running models with check.feas=F only.

Steven

Sent via Superhuman ( @.*** )

On Thu, Jul 20 2023 at 10:36 AM, Samantha Gold < @.*** > wrote:

Hi Steven,

The error gets thrown when setting the check.feas option to TRUE. I tried installing the archived LowRankQP package but run into package compiler issues on my machine since I am working on a newer Mac (OS Ventura) and the archived version does not accommodate that. Any other tips on how to resolve the package issue?

Thanks! Sammy

— Reply to this email directly, view it on GitHub ( https://github.com/ssdavenport/microsynth/issues/27#issuecomment-1644325533 ) , or unsubscribe ( https://github.com/notifications/unsubscribe-auth/AAGG6RRUDOFF6JX53JYFFO3XRFUBLANCNFSM6AAAAAA2GIYCGY ). You are receiving this because you commented. Message ID: <ssdavenport/microsynth/issues/27/1644325533 @ github. com>

samanthagold commented 1 year ago

Hi Steven,

I tried option 4 and set check.feas=F, but run into a new error

Error in kernlab::ipop(H = t(X), c = -crossprod(X, a), A = Y[leave, ,  : argument "l" is missing, with no default

I traced it back to line 1078 in microsynth/R/weights.R. It looks like the l argument is missing but is required by ipop (possibly just need to add l = rep(0,q) from the commented out line below, although not sure). I think once the l argument is added back in to line 1078 it should resolve this issue 🤞

Thanks for all your help! Sammy

ssdavenport commented 1 year ago

Samantha,

I went ahead and made the suggested change to weights.R and pushed to GitHub ( https://github.com/ssdavenport/microsynth ). Would you try the new code and let us know if the test is successful?

FYI I was able to replicate Samantha's original error. Having removed LowRankQP from my machine and running example 3 produced the error:

"Error in checkForRemoteErrors(val) :   2 nodes produced errors; first error: there is no package called ‘LowRankQP’"

Sent via Superhuman ( @.*** )

On Wed, Jul 26, 2023 at 12:37 PM, Samantha Gold < @.*** > wrote:

Hi Steven,

I tried option 4 and set check.feas=F, but run into a new error

Error in kernlab::ipop(H = t(X), c = -crossprod(X, a), A = Y[leave, , : argument "l" is missing, with no default

I traced it back to line 1078 in microsynth/R/weights.R. It looks like the l argument is missing but is required by ipop (possibly just need to add l = rep(0,q) from the commented out line below, although not sure). I think once the l argument is added back in to line 1078 it should resolve this issue 🤞

Thanks for all your help! Sammy

— Reply to this email directly, view it on GitHub ( https://github.com/ssdavenport/microsynth/issues/27#issuecomment-1652380798 ) , or unsubscribe ( https://github.com/notifications/unsubscribe-auth/AAGG6RR7ULWWX3IUBDXNL3DXSFWZNANCNFSM6AAAAAA2GIYCGY ). You are receiving this because you commented. Message ID: <ssdavenport/microsynth/issues/27/1652380798 @ github. com>

samanthagold commented 1 year ago

Hi Steven,

Just tested and it seems like one more argument was missing (r). I've updated weights.R and created a pull request for your review!

Best, Sammy

ssdavenport commented 1 year ago

PR approved! If that worked for you successfully than we can close this issue.

Steven

Sent via Superhuman ( @.*** )

On Thu, Jul 27, 2023 at 10:06 AM, Samantha Gold < @.*** > wrote:

Hi Steven,

Just tested and it seems like one more argument was missing (r). I've updated weights.R and created a pull request for your review!

Best, Sammy

— Reply to this email directly, view it on GitHub ( https://github.com/ssdavenport/microsynth/issues/27#issuecomment-1654028842 ) , or unsubscribe ( https://github.com/notifications/unsubscribe-auth/AAGG6RU3J7IPNRTETOJRPBTXSKNYBANCNFSM6AAAAAA2GIYCGY ). You are receiving this because you commented. Message ID: <ssdavenport/microsynth/issues/27/1654028842 @ github. com>

samanthagold commented 1 year ago

Hi Steven,

I tried running my code, but it is returning a new error that I don't fully understand. The error is coming from kernlab::ipop(). I'm not sure if it errors because of the l and r arguments that were added in the last couple of days/if those need to be changed. I've included a reproducible example to make debugging easier for you. Any help on this would be very much appreciated!

Best, Sammy

# Microsynth De-bugging ----------------------------------------------------
# reproducible example of error when using kernlab::ipop to generate synthetic
# control weights instead of LowRankQP

bug_dat <- readr::read_csv("https://gist.githubusercontent.com/samanthagold/bb005bc8d22d79691e9bd38e0b1de3e3/raw/d266ebbac95445377ea40930f913d30ae6ef2dfc/microsynth_bug.csv")
#> Rows: 899 Columns: 6
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> chr (1): State_Abbrev
#> dbl (5): Year, cat_treat, Poverty_Percent, Population, FirearmSuicide_Deaths
#> 
#> ℹ Use `spec()` to retrieve the full column specification for this data.
#> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
microsynth::microsynth(bug_dat,
           idvar="State_Abbrev", timevar="Year", intvar="cat_treat",
           start.pre=1993,
           end.pre=2000,
           end.post=2004,
           match.out="FirearmSuicide_Deaths",
           match.out.min=c("Poverty_Percent", "Population"),
           result.var="FirearmSuicide_Deaths",
           test="lower",
           jack=TRUE,
           perm=250,
           match.covar=FALSE,
           use.backup = TRUE,
           check.feas = FALSE,
           n.cores = min(parallel::detectCores(), 2))
#> Warning in microsynth::microsynth(bug_dat, idvar = "State_Abbrev", timevar =
#> "Year", : If non-NULL, omnibus.var should have length of at least 2. It is
#> being reset to NULL.
#> WARNING: There is a low number (1) of cases in the treatment or intervention group.
#> setting jack = 0.
#> Setting use.survey = FALSE.
#> Be cautious of results involving linearization or confidence intervals.
#> 
#> Calculating weights...
#> Resetting perm = 30
#> Warning in grake(mm, ww, calfun, bounds = bounds, population = population, :
#> Failed to converge: eps=0.152119806301315 in 251 iterations
#> Error in smwa1/d: non-conformable arrays
This is my session info if helpful
$
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.3.0 (2023-04-21)
#>  os       macOS Ventura 13.3.1
#>  system   aarch64, darwin20
#>  ui       X11
#>  language (EN)
#>  collate  en_US.UTF-8
#>  ctype    en_US.UTF-8
#>  tz       America/New_York
#>  date     2023-07-28
#>  pandoc   2.19.2 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version  date (UTC) lib source
#>  bit           4.0.5    2022-11-15 [1] CRAN (R 4.3.0)
#>  bit64         4.0.5    2020-08-30 [1] CRAN (R 4.3.0)
#>  cli           3.6.1    2023-03-23 [1] CRAN (R 4.3.0)
#>  crayon        1.5.2    2022-09-29 [1] CRAN (R 4.3.0)
#>  curl          5.0.0    2023-01-12 [1] CRAN (R 4.3.0)
#>  DBI           1.1.3    2022-06-18 [1] CRAN (R 4.3.0)
#>  digest        0.6.31   2022-12-11 [1] CRAN (R 4.3.0)
#>  evaluate      0.20     2023-01-17 [1] CRAN (R 4.3.0)
#>  fansi         1.0.4    2023-01-22 [1] CRAN (R 4.3.0)
#>  fastmap       1.1.1    2023-02-24 [1] CRAN (R 4.3.0)
#>  fs            1.6.2    2023-04-25 [1] CRAN (R 4.3.0)
#>  glue          1.6.2    2022-02-24 [1] CRAN (R 4.3.0)
#>  hms           1.1.3    2023-03-21 [1] CRAN (R 4.3.0)
#>  htmltools     0.5.5    2023-03-23 [1] CRAN (R 4.3.0)
#>  kernlab       0.9-32   2023-01-31 [1] CRAN (R 4.3.0)
#>  knitr         1.42     2023-01-25 [1] CRAN (R 4.3.0)
#>  lattice       0.21-8   2023-04-05 [1] CRAN (R 4.3.0)
#>  lifecycle     1.0.3    2022-10-07 [1] CRAN (R 4.3.0)
#>  magrittr      2.0.3    2022-03-30 [1] CRAN (R 4.3.0)
#>  MASS          7.3-58.4 2023-03-07 [1] CRAN (R 4.3.0)
#>  Matrix        1.5-4    2023-04-04 [1] CRAN (R 4.3.0)
#>  microsynth    2.0.45   2023-07-27 [1] Github (ssdavenport/microsynth@3ee31db)
#>  mitools       2.4      2019-04-26 [1] CRAN (R 4.3.0)
#>  pillar        1.9.0    2023-03-22 [1] CRAN (R 4.3.0)
#>  pkgconfig     2.0.3    2019-09-22 [1] CRAN (R 4.3.0)
#>  pracma        2.4.2    2022-09-22 [1] CRAN (R 4.3.0)
#>  R6            2.5.1    2021-08-19 [1] CRAN (R 4.3.0)
#>  readr         2.1.4    2023-02-10 [1] CRAN (R 4.3.0)
#>  reprex        2.0.2    2022-08-17 [1] CRAN (R 4.3.0)
#>  rlang         1.1.1    2023-04-28 [1] CRAN (R 4.3.0)
#>  rmarkdown     2.21     2023-03-26 [1] CRAN (R 4.3.0)
#>  rstudioapi    0.14     2022-08-22 [1] CRAN (R 4.3.0)
#>  sessioninfo   1.2.2    2021-12-06 [1] CRAN (R 4.3.0)
#>  survey        4.2-1    2023-05-03 [1] CRAN (R 4.3.0)
#>  survival      3.5-5    2023-03-12 [1] CRAN (R 4.3.0)
#>  tibble        3.2.1    2023-03-20 [1] CRAN (R 4.3.0)
#>  tidyselect    1.2.0    2022-10-10 [1] CRAN (R 4.3.0)
#>  tzdb          0.3.0    2022-03-28 [1] CRAN (R 4.3.0)
#>  utf8          1.2.3    2023-01-31 [1] CRAN (R 4.3.0)
#>  vctrs         0.6.3    2023-06-14 [1] CRAN (R 4.3.0)
#>  vroom         1.6.1    2023-01-22 [1] CRAN (R 4.3.0)
#>  withr         2.5.0    2022-03-03 [1] CRAN (R 4.3.0)
#>  xfun          0.39     2023-04-20 [1] CRAN (R 4.3.0)
#>  yaml          2.3.7    2023-01-23 [1] CRAN (R 4.3.0)
#> 
#>  [1] /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────
ckonichipaulo commented 1 year ago

Hi! I haven't had a chance to dig into the code yet, but I also got the same error that @samanthagold had when using v2.0.44.

Error in kernlab::ipop(H = t(X), c = -crossprod(X, a), A = Y[leave, ,  : argument "l" is missing, with no default

(I haven't tried the newer versions). But setting up check.feas=F and use.backup=F worked for me.

Cinthia

samanthagold commented 1 year ago

Hi Cinthia!

I tried running the reproducible example above with check.feas = F and use.backup = F but am unfortunately still getting the same error I was receiving before (Error in smwa1/d : non-conformable arrays). Still stuck on my end on how to resolve.

Sammy

samanthagold commented 9 months ago

LowRankQP has been added back to CRAN so package dependency issue has been resolved!

ssdavenport commented 9 months ago

Amazing! It was frankly a big effort to try to get around that. CRAN support is foundational. That’s great news

Sent via Superhuman iOS ( @.*** )

On Tue, Oct 31 2023 at 6:26 PM, Samantha Gold < @.*** > wrote:

LowRankQP has been added back to CRAN so package dependency issue has been resolved!

— Reply to this email directly, view it on GitHub ( https://github.com/ssdavenport/microsynth/issues/27#issuecomment-1788257473 ) , or unsubscribe ( https://github.com/notifications/unsubscribe-auth/AAGG6RWFRFYTERY3IZUIRULYCGQMLAVCNFSM6AAAAAA2GIYCG2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOBYGI2TONBXGM ). You are receiving this because you commented. Message ID: <ssdavenport/microsynth/issues/27/1788257473 @ github. com>