Last active
January 10, 2023 18:48
-
-
Save dantonnoriega/49ed2e57de08362f546e3bb9eb31ac2b to your computer and use it in GitHub Desktop.
quick function to estimate income tax for 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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