Skip to content

Commit

Permalink
fix check issues
Browse files Browse the repository at this point in the history
  • Loading branch information
CoryMcCartan committed Sep 21, 2023
1 parent a089db3 commit 5fa5e72
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 20 deletions.
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,20 @@ importFrom(rlang,syms)
importFrom(stats,.lm.fit)
importFrom(stats,as.formula)
importFrom(stats,cov)
importFrom(stats,dnorm)
importFrom(stats,family)
importFrom(stats,fitted)
importFrom(stats,formula)
importFrom(stats,get_all_vars)
importFrom(stats,lm.wfit)
importFrom(stats,median)
importFrom(stats,model.frame)
importFrom(stats,model.matrix)
importFrom(stats,na.fail)
importFrom(stats,na.omit)
importFrom(stats,nobs)
importFrom(stats,residuals)
importFrom(stats,sd)
importFrom(stats,setNames)
importFrom(stats,simulate)
importFrom(stats,terms)
Expand Down
2 changes: 1 addition & 1 deletion R/birdie-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#' @importFrom cli cli_inform cli_warn cli_abort
#' @importFrom Rcpp sourceCpp
#' @importFrom RcppParallel CxxFlags
#' @importFrom stats na.omit na.fail .lm.fit fitted simulate median cov
#' @importFrom stats na.omit na.fail .lm.fit lm.wfit fitted simulate median sd cov dnorm
#' @importFrom stats terms get_all_vars model.frame model.matrix setNames
#' @importFrom stats formula update.formula as.formula nobs family vcov residuals
#' @importFrom utils tail unstack relist head packageVersion
Expand Down
17 changes: 9 additions & 8 deletions R/birdie.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#' `birdie()` uses an expectation-maximization (EM) routine to find the maximum
#' *a posteriori* (MAP) estimate for the specified model. Asymptotic
#' variance-covariance matrices for the MAP estimate are available for the
#' Categorical-Dirichlet model via bootstrapping (`se_boot`).
#' Categorical-Dirichlet and Normal linear models via bootstrapping (`se_boot`).
#'
#' The Categorical-Dirichlet model is specified as follows: \deqn{
#' Y_i \mid R_i, X_i, \Theta \sim \text{Categorical}(\theta_{R_iX_i}) \\
Expand All @@ -36,8 +36,9 @@
#'
#' The Normal linear model is specified as follows: \deqn{
#' Y_i \mid R_i, \vec X_i, \Theta \sim \mathcal{N}(\vec X_i^\top\vec\theta, \sigma^2) \\
#' \pi(\sigma^2) \propto \sigma^{-2} \\
#' \beta \sim \mathcal{N}(0, \Sigma), \\
#' \sigma^2 \sim \text{Inv-Gamma}(n_\sigma/2, l_\sigma^2 n_\sigma/2) \\
#' \beta_{\text{intercept}} \sim \mathcal{N}(0, s^2_\text{int}) \\
#' \beta_k \sim \mathcal{N}(0, s^2_\beta), \\
#' } where \eqn{\vec\theta} is a vector of linear model coefficients.
#' Estimates for \eqn{\theta} and \eqn{\sigma} are stored in the
#' `$beta` and `$sigma` elements of the fitted model object.
Expand Down Expand Up @@ -95,10 +96,10 @@
#' The default will work with the output of [bisg()].
#' @param se_boot The number of bootstrap replicates to use to compute
#' approximate standard errors for the main model estimates. Only available
#' when `model="dir"`. When there are fewer than 1,000 individuals or 100 or
#' fewer replicates, a Bayesian bootstrap is used instead (i.e., weights are
#' drawn from a \eqn{\text{Dirichlet}(1, 1, ..., 1)} distribution, which produces more
#' reliable estimates.
#' when `familiy=cat_dir()` or `gaussian()`. When there are fewer than 1,000
#' individuals or 100 or fewer replicates, a Bayesian bootstrap is used
#' instead (i.e., weights are drawn from a \eqn{\text{Dirichlet}(1, 1, ...,
#' 1)} distribution, which produces more reliable estimates.
#' @param ctrl A list containing control parameters for the EM algorithm and
#' optimization routines. A list in the proper format can be made using
#' [birdie.ctrl()].
Expand Down Expand Up @@ -126,7 +127,7 @@
#' birdie(r_probs, turnout ~ zip, data=pseudo_vf)
#'
#' fit = birdie(r_probs, turnout ~ (1 | zip), data=pseudo_vf,
#' ctrl=birdie.ctrl(abstol=1e-3))
#' family=cat_mixed(), ctrl=birdie.ctrl(abstol=1e-3))
#'
#' summary(fit)
#' coef(fit)
Expand Down
4 changes: 2 additions & 2 deletions cran-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
fine in a browser, but not at the command line with `curl -I -L`,
where it returns a 403 error.

* C++14 is a requirement in order to compile Stan models as well.
* C++14 is a requirement in order to compile Stan models.

* GNU make is a SystemRequirement in order to compile Stan models.
* GNU make is a SystemRequirement in order to compile Stan models as well.

* Examples are \dontrun{} in census_race_geo_table() since they require an API
key and may take some time to run.
17 changes: 9 additions & 8 deletions man/birdie.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion vignettes/birdie.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,15 @@ For example, among White voters in a particular ZIP code, this assumption would

We're now ready to estimate turnout by race.
For this we'll use the `birdie()` function, and provide it with a formula describing our BIRDiE model, including our variable of interest `turnout` and our geography variable `zip`.
We provide `family=cat_mixed()` to indicate that we want to fit a Categorical mixed-effects regression model for turnout.
Here, we wrap `zip` in the `proc_zip()` function, which, among other things, recodes missing ZIP codes as "Other" so that the model doesn't encounter any missing data.
The first argument to `birdie()` is `r_probs`, the racial probabilities.
`birdie` knows how to handle its columns of because they came from this package.
If you use a different package, the columns may be named differently.
The `prefix` parameter to `birdie()` lets you specify the naming convention for your probabilities.

```{r messages=FALSE}
fit = birdie(r_probs, turnout ~ (1 | proc_zip(zip)), data=pseudo_vf)
fit = birdie(r_probs, turnout ~ (1 | proc_zip(zip)), data=pseudo_vf, family=cat_mixed())
print(fit)
```

Expand Down

0 comments on commit 5fa5e72

Please sign in to comment.