add additional functions
Gitea Organization/civilyticsR/pipeline/head There was a failure building this commit

This commit is contained in:
Jared Knowles
2023-07-20 11:48:42 -04:00
parent 9acebb5133
commit ac63932a31
12 changed files with 446 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils.R
\name{get_fips}
\alias{get_fips}
\title{Get the FIPS code for a given state abbreviation}
\usage{
get_fips(stabbr)
}
\arguments{
\item{stabbr}{a two letter abbreviation for a US state}
}
\value{
FIPS codes that match the abbreviation
}
\description{
Get the FIPS code for a given state abbreviation
}
\examples{
get_fips("MT")
get_fips("PR")
get_fips("CC")
}
+20
View File
@@ -0,0 +1,20 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils.R
\name{get_stabbr}
\alias{get_stabbr}
\title{Get the state abbreviation from a given FIPS Code}
\usage{
get_stabbr(fips)
}
\arguments{
\item{fips}{a character value that captures the FIPS code with leading 0}
}
\value{
a character value, length 2, with the state abbreviation
}
\description{
Get the state abbreviation from a given FIPS Code
}
\examples{
get_stabbr("06")
}
+25
View File
@@ -0,0 +1,25 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils.R
\name{outersect}
\alias{outersect}
\title{Compute the outersection of two fectors}
\usage{
outersect(x, y, ...)
}
\arguments{
\item{x}{first vector, of any type}
\item{y}{second vector, same type as x}
\item{...}{additional vectors to be checked}
}
\value{
unique values across all of the vectors
}
\description{
Compute the outersection of two fectors
}
\examples{
# desired result is c(1, 2, 3, 6, 9, 10)
outersect(1:5, 4:8, 7:10)
}
+23
View File
@@ -0,0 +1,23 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils.R
\name{perturb_count}
\alias{perturb_count}
\title{Add a random jitter to a count variable to mask its true value}
\usage{
perturb_count(x, fac = 3)
}
\arguments{
\item{x}{the vector of numerics}
\item{fac}{the range of values to add or subtract to perturb the count}
}
\description{
Add a random jitter to a count variable to mask its true value
}
\details{
The count in the name means that this function enforces a floor of
0 on values, so values perturbed to have less than 0 will be capped at 0.
}
\examples{
perturb_count(20:30, fac = 3)
}
+23
View File
@@ -0,0 +1,23 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils.R
\name{random_round}
\alias{random_round}
\title{Add random noise to a variable before rounding}
\usage{
random_round(x)
}
\arguments{
\item{x}{a numeric we want to round}
}
\value{
rounded values
}
\description{
Add random noise to a variable before rounding
}
\details{
Credit to Jens von Bergmann for this algo https://github.com/mountainMath/dotdensity/blob/master/R/dot-density.R
}
\examples{
random_round(1.93)
}
+23
View File
@@ -0,0 +1,23 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils.R
\name{safe_ratio}
\alias{safe_ratio}
\title{Safely take a ratio and do not fail if 0 is in the denominator}
\usage{
safe_ratio(num, denom)
}
\arguments{
\item{num}{numerator, a numeric}
\item{denom}{denominator, a numeric}
}
\value{
The proportion, safely calculated with 0.1 substituting for 0
}
\description{
Safely take a ratio and do not fail if 0 is in the denominator
}
\examples{
safe_ratio(100, 1)
safe_ratio(100, 0)
}
+21
View File
@@ -0,0 +1,21 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils.R
\name{trunc_match}
\alias{trunc_match}
\title{Truncated matching function}
\usage{
trunc_match(x, y, n)
}
\arguments{
\item{x, }{the character value to match}
\item{y, }{a vector of multiple character values to look for a match in}
\item{n, }{an integer, how many matches to return}
}
\value{
an integer giving the position of the table with the most characters
}
\description{
Truncated matching function
}
+26
View File
@@ -0,0 +1,26 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils.R
\name{z_gap_test}
\alias{z_gap_test}
\title{Calculate a Z-Score for a comparison between two proportions}
\usage{
z_gap_test(a_prop, a_count, b_prop, b_count)
}
\arguments{
\item{a_prop}{the proportion for group a}
\item{a_count}{the count of the population in group a}
\item{b_prop}{the proportion for group b}
\item{b_count}{the count of the population in group b}
}
\value{
a numeric z score
}
\description{
Calculate a Z-Score for a comparison between two proportions
}
\examples{
z_gap_test(0.0002, 1e4, 0.0003, 1e4)
}
+24
View File
@@ -0,0 +1,24 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils.R
\name{z_univariate}
\alias{z_univariate}
\title{Calculate a univariate z score by comparing to a population}
\usage{
z_univariate(unit_prop, global_prop, unit_denom)
}
\arguments{
\item{unit_prop}{proportion for the group we are comparing}
\item{global_prop}{the global proportion}
\item{unit_denom}{the population size for the group we are comparing}
}
\value{
a z-score
}
\description{
Calculate a univariate z score by comparing to a population
}
\examples{
z_univariate(unit_prop = 0.13, global_prop = 0.11, unit_denom = 2500)
}