Skip to content

Commit

Permalink
Merge pull request #8 from DeclareDesign/switch-to-marginaleffects
Browse files Browse the repository at this point in the history
switch to marginaleffects
  • Loading branch information
graemeblair authored Dec 2, 2024
2 parents ae7efab + 26a8161 commit e8eec55
Show file tree
Hide file tree
Showing 16 changed files with 35 additions and 23 deletions.
6 changes: 3 additions & 3 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version: 1.0.8
Date: 2024-03-02 18:35:10 UTC
SHA: be95cd907b6e1c1cb42c645a50a1a1bbb7a45486
Version: 1.0.12
Date: 2024-10-07 18:00:19 UTC
SHA: 1802077891d79bc7df8b64a7d51448970b34ea27
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
Package: rdss
Title: Companion Datasets and Functions for Research Design in the Social Sciences
Version: 1.0.8
Version: 1.0.12
Authors@R:
c(person("Graeme", "Blair", email = "[email protected]", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-9164-2102")),
person("Alexander", "Coppock", email = "[email protected]", role = c("aut"), comment = c(ORCID = "0000-0002-5733-2386")),
person("Macartan", "Humphreys", email = "[email protected]", role = c("aut"), comment = c(ORCID = "0000-0001-7029-2326")))
Description: Helper functions to accompany the Blair, Coppock, and Humphreys (2022) "Research Design in the Social Sciences: Declaration, Diagnosis, and Redesign" <https://book.declaredesign.org>. 'rdss' includes datasets, helper functions, and plotting components to enable use and replication of the book.
Imports: dplyr, rlang (>= 1.0.0), generics, ggplot2, tibble, tidyr, dataverse, readr, prediction, broom, purrr, estimatr, randomizr
Imports: dplyr, rlang (>= 1.0.0), generics, ggplot2, tibble, tidyr, dataverse, readr, marginaleffects, broom, purrr, estimatr, randomizr
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Suggests:
testthat (>= 3.0.0),
rdrobust,
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ importFrom(ggplot2,element_text)
importFrom(ggplot2,margin)
importFrom(ggplot2,theme)
importFrom(ggplot2,theme_minimal)
importFrom(prediction,prediction)
importFrom(marginaleffects,predictions)
importFrom(purrr,as_vector)
importFrom(purrr,map)
importFrom(purrr,map_chr)
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# rdss 1.0.12

* address bugs with future package

# rdss 1.0.10

* Switch from prediction to marginaleffects.

# rdss 1.0.8

* Documentation updates for CRAN.
Expand Down
15 changes: 9 additions & 6 deletions R/helpers-multilevel-regression-poststratification.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,21 @@
#'
#' @export
#'
#' @importFrom prediction prediction
#' @importFrom marginaleffects predictions
#' @importFrom dplyr group_by summarize
#' @importFrom stats weighted.mean
#' @importFrom rlang `!!` enquo
#'
post_stratification_helper <- function(model_fit, data, group, weights) {
prediction(
predictions(
model_fit,
data = data,
allow.new.levels = TRUE,
type = "response"
newdata = data,
type = "response",
re.form = NA
# For this model type, `marginaleffects` only takes into account the
# uncertainty in fixed-effect parameters. You can use the `re.form=NA`
# argument to acknowledge this explicitly and silence this warning.
) %>%
group_by({{group}}) %>%
summarize(estimate = weighted.mean(fitted, !!enquo(weights)), .groups = "drop")
summarize(estimate = weighted.mean(estimate, !!enquo(weights)), .groups = "drop")
}
2 changes: 1 addition & 1 deletion cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Submission

Submission to resolve internet connection-required example.
rdss 1.0.10 was archived off CRAN, principally because the `prediction` package was archived. This version switches to the `marginaleffects` package.

## Test environments

Expand Down
Binary file modified data/lapop_brazil.rda
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/testthat/test-bayesian-regression.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ test_that("tidy_stan works", {
inquiry = "mean_age"
)

expect_error(simulate_design(declaration_9.3, sims = 1), NA)
expect_error(simulate_design(declaration_9.3, sims = 1, future.seed = FALSE), NA)

})
2 changes: 1 addition & 1 deletion tests/testthat/test-causal-forests.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ test_that("causal forest helpers work", {
declare_estimator(handler = label_estimator(get_best_predictor),
inquiry = "best_predictor", label = "cf")

expect_error(simulate_design(declaration_19.1, sims = 1), NA)
expect_error(simulate_design(declaration_19.1, sims = 1, future.seed = FALSE), NA)

})
2 changes: 1 addition & 1 deletion tests/testthat/test-conjoint-experiments.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ test_that("conjoint helpers work", {
respondent.id = "subject",
.method = amce)

expect_error(simulate_design(declaration_17.5, sims = 1), NA)
expect_error(simulate_design(declaration_17.5, sims = 1, future.seed = FALSE), NA)

})
3 changes: 2 additions & 1 deletion tests/testthat/test-difference-in-differences.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ test_that("lag_by_group and did_multiplegt_tidy work", {
G = "units",
T = "periods",
D = "D",
mode = "old",
handler = label_estimator(did_multiplegt_tidy),
inquiry = c("ATT", "ATT_switchers"),
label = "chaisemartin"
)

expect_error(suppressWarnings(simulate_design(declaration_16.3, sims = 1)), NA)
expect_error(suppressWarnings(simulate_design(declaration_16.3, sims = 1, future.seed = FALSE)), NA)

})
2 changes: 1 addition & 1 deletion tests/testthat/test-experiments-over-networks.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ test_that("interference helpers work", {
permutatation_matrix = permutatation_matrix,
adj_matrix = adj_matrix)

expect_error(simulate_design(declaration_18.13, sims = 1), NA)
expect_error(simulate_design(declaration_18.13, sims = 1, future.seed = FALSE), NA)

})
2 changes: 1 addition & 1 deletion tests/testthat/test-meta-analysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ test_that("rma helpers work", {

declaration_19.3 <- redesign(design, tau = c(0, 1))

expect_error(simulate_design(declaration_19.3, sims = 1), NA)
expect_error(simulate_design(declaration_19.3, sims = 1, future.seed = FALSE), NA)

})
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ test_that("post_stratification_helper works", {
label = "Partial pooling",
inquiry = "mean_policy_support")

expect_error(simulate_design(declaration_15.4, sims = 1), NA)
expect_error(simulate_design(declaration_15.4, sims = 1, future.seed = FALSE), NA)

})
2 changes: 1 addition & 1 deletion tests/testthat/test-process-tracing.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ test_that("process_tracing_estimator works", {
query = "Y[X=1] - Y[X=0]",
strategies = strategies)

expect_error(simulate_design(declaration_16.1, sims = 1), NA)
expect_error(simulate_design(declaration_16.1, sims = 1, future.seed = FALSE), NA)

})
2 changes: 1 addition & 1 deletion tests/testthat/test-regression-discontinuity.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ test_that("tidy.rdrobust and rdrobust_helper work", {
inquiry = "LATE",
label = "optimal"
)
expect_error(simulate_design(declaration_16.5, sims = 1), NA)
expect_error(simulate_design(declaration_16.5, sims = 1, future.seed = FALSE), NA)

})

0 comments on commit e8eec55

Please sign in to comment.