Skip to content

Instantly share code, notes, and snippets.

@dantonnoriega
Last active January 10, 2023 18:48
Show Gist options
  • Save dantonnoriega/49ed2e57de08362f546e3bb9eb31ac2b to your computer and use it in GitHub Desktop.
Save dantonnoriega/49ed2e57de08362f546e3bb9eb31ac2b to your computer and use it in GitHub Desktop.
quick function to estimate income tax for 2022
est_income_tax <- function(x, jointly = F) {
# SOURCE
# https://www.irs.gov/newsroom/irs-provides-tax-inflation-adjustments-for-tax-year-2022
brackets <- c(0,10275,41775,89075,170050,215950,539900)
if(jointly) {
# brackets are double for jointly except for the last one
brackets <- 2 * brackets
brackets[length(brackets)] <- 647850
}
rate <- c(.10,.12,.22,.24,.32,.35,.37)
taxable <- (x - brackets)
taxable[taxable < 0] = 0 # not taxed if < 0
d_taxable = abs(diff(taxable))
if(x > max(brackets)) {
d_taxable = c(d_taxable, tail(taxable,1))
} else {
d_taxable = c(d_taxable, 0)
}
sum(d_taxable * rate) # marginal tax rate
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment