ci: replace Jenkins with Gitea Actions, modernize DESCRIPTION
R-CMD-check / R CMD check (push) Failing after 3s
R-CMD-check / R CMD check (push) Failing after 3s
- Add real R CMD check workflow via Gitea Actions (rocker/r-ver:4.4) - Remove Jenkinsfile and demo workflow - Modernize DESCRIPTION: Authors@R, R >= 4.1.0, URL/BugReports fields, move tidycensus from Imports to Suggests, testthat edition 3 - Fix agresti_coull_interval: correct implementation, export it - Convert get_fips/get_stabbr to use requireNamespace for tidycensus - Remove civilytics:: self-reference in rnh()
This commit is contained in:
+16
-9
@@ -72,14 +72,21 @@ waldInterval <- function(x, n, conf.level = 0.95){
|
||||
|
||||
#' Calculate the Agresti-Coull interval
|
||||
#'
|
||||
#' @param num a number of successes
|
||||
#' @param den a number of trials
|
||||
#' @param conf.level default 0.95, set the confidence interval to return
|
||||
#' @param num number of successes
|
||||
#' @param den number of trials
|
||||
#' @param conf.level default 0.95, confidence level for the interval
|
||||
#'
|
||||
#' @return an interval
|
||||
agresti_coull_interval <- function(num, den, conf.level) {
|
||||
num <- num + 2
|
||||
den <- den + 4
|
||||
return(num/den)
|
||||
|
||||
#' @return three values forming the lower bound, observed proportion, and upper bound
|
||||
#' @export
|
||||
#'
|
||||
#' @examples
|
||||
#' agresti_coull_interval(20, 40)
|
||||
#' agresti_coull_interval(2, 100, conf.level = 0.99)
|
||||
agresti_coull_interval <- function(num, den, conf.level = 0.95) {
|
||||
z <- qnorm(1 - (1 - conf.level) / 2)
|
||||
n_tilde <- den + z^2
|
||||
p_tilde <- (num + z^2 / 2) / n_tilde
|
||||
margin <- z * sqrt(p_tilde * (1 - p_tilde) / n_tilde)
|
||||
obs <- num / den
|
||||
return(c("low" = p_tilde - margin, "observed" = obs, "high" = p_tilde + margin))
|
||||
}
|
||||
|
||||
@@ -234,14 +234,21 @@ outersect <- function(x, y, ...) {
|
||||
#' @param stabbr a two letter abbreviation for a US state
|
||||
#'
|
||||
#' @return FIPS codes that match the abbreviation
|
||||
#' @import tidycensus
|
||||
#' @export
|
||||
#'
|
||||
#' @examples
|
||||
#' \dontrun{
|
||||
#' get_fips("MT")
|
||||
#' get_fips("PR")
|
||||
#' get_fips("CC")
|
||||
#' }
|
||||
get_fips <- function(stabbr) {
|
||||
if (!requireNamespace("tidycensus", quietly = TRUE)) {
|
||||
stop(
|
||||
"Package 'tidycensus' is required for get_fips(). ",
|
||||
"Install it with: install.packages('tidycensus')",
|
||||
call. = FALSE
|
||||
)
|
||||
}
|
||||
fips <- tidycensus::fips_codes[, 1:2]
|
||||
fips <- fips[!duplicated(fips),]
|
||||
out <- fips[fips$state == stabbr, 2]
|
||||
@@ -253,12 +260,20 @@ get_fips <- function(stabbr) {
|
||||
#' @param fips a character value that captures the FIPS code with leading 0
|
||||
#'
|
||||
#' @return a character value, length 2, with the state abbreviation
|
||||
#' @import tidycensus
|
||||
#' @export
|
||||
#'
|
||||
#' @examples
|
||||
#' \dontrun{
|
||||
#' get_stabbr("06")
|
||||
#' }
|
||||
get_stabbr <- function(fips) {
|
||||
if (!requireNamespace("tidycensus", quietly = TRUE)) {
|
||||
stop(
|
||||
"Package 'tidycensus' is required for get_stabbr(). ",
|
||||
"Install it with: install.packages('tidycensus')",
|
||||
call. = FALSE
|
||||
)
|
||||
}
|
||||
fips_codes <- tidycensus::fips_codes[, 1:2]
|
||||
fips_codes <- fips_codes[!duplicated(fips_codes),]
|
||||
if (length(fips) != 1) {
|
||||
@@ -442,6 +457,6 @@ round_to_nearest_half <- function(x) {
|
||||
#' @examples
|
||||
#' rnh(c(0.2, 0.3, 0.4, 0.8, 0.09, 0.9))
|
||||
rnh <- function(x) {
|
||||
tmp <- Vectorize(civilytics::round_to_nearest_half)
|
||||
tmp <- Vectorize(round_to_nearest_half)
|
||||
tmp(x)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user