Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revise Calculator decile_graph method to use new distribution table #1918

Merged
merged 11 commits into from
Mar 16, 2018
74 changes: 45 additions & 29 deletions taxcalc/calculate.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,14 +392,12 @@ def distribution_tables(self, calc,
result_type='weighted_sum'):
"""
Get results from self and calc, sort them based on groupby using
income_measure, manipulate grouped statistics based on result_type,
income_measure, compute grouped statistics based on result_type,
and return tables as a pair of Pandas dataframes.
This method leaves the Calculator object(s) unchanged.
Note that the returned tables have consistent income groups (based
on the self income_measure) even though the baseline income_measure
in self and the income_measure in calc are different.
Also, note that some subgroups may contain filing units with negative
or zero baseline (self) income.

Parameters
----------
Expand All @@ -408,21 +406,27 @@ def distribution_tables(self, calc,
if calc is None, the second returned table is None

groupby : String object
options for input: 'weighted_deciles', 'webapp_income_bins',
options for input: 'weighted_deciles', 'standard_income_bins',
'large_income_bins', 'small_income_bins';
determines how the columns in returned tables are sorted
determines how the columns in resulting Pandas DataFrame are sorted
NOTE: when groupby is 'weighted_deciles', the returned table has three
extra rows containing top-decile detail consisting of statistics
for the 0.90-0.95 quantile range (bottom half of top decile),
for the 0.95-0.99 quantile range, and
for the 0.99-1.00 quantile range (top one percent).
for the 0.99-1.00 quantile range (top one percent); and the
returned table splits the bottom decile into filing units with
negative (denoted by a 0-10n row label),
zero (denoted by a 0-10z row label), and
positive (denoted by a 0-10p row label) values of the
specified income_measure.

income_measure : String object
options for input: 'expanded_income' or 'c00100'(AGI)
specifies statistic used to place filing units in bins or deciles

result_type : String object
options for input: 'weighted_sum' or 'weighted_avg';
determines how whether or not table entries are averages or totals
determines how the table statistices are computed

Typical usage
-------------
Expand Down Expand Up @@ -489,26 +493,30 @@ def difference_table(self, calc,
in self and the income_measure in calc are different.
Note that filing units are put into groupby categories using the
specified income_measure in the baseline (self) situation.
Also, note that some subgroups may contain filing units with negative
or zero baseline (self) income.

Parameters
----------
calc : Calculator object
calc represents the reform while self represents the baseline

groupby : String object
options for input: 'weighted_deciles', 'webapp_income_bins',
options for input: 'weighted_deciles', 'standard_income_bins',
'large_income_bins', 'small_income_bins';
determines how the columns in returned tables are sorted
determines how the columns in resulting Pandas DataFrame are sorted
NOTE: when groupby is 'weighted_deciles', the returned table has three
extra rows containing top-decile detail consisting of statistics
for the 0.90-0.95 quantile range (bottom half of top decile),
for the 0.95-0.99 quantile range, and
for the 0.99-1.00 quantile range (top one percent).
for the 0.99-1.00 quantile range (top one percent); and the
returned table splits the bottom decile into filing units with
negative (denoted by a 0-10n row label),
zero (denoted by a 0-10z row label), and
positive (denoted by a 0-10p row label) values of the
specified income_measure.

income_measure : String object
options for input: 'expanded_income' or 'c00100'(AGI)
specifies statistic used to place filing units in bins or deciles

tax_to_diff : String object
options for input: 'iitax', 'payrolltax', 'combined'
Expand Down Expand Up @@ -989,7 +997,9 @@ def pch_graph(self, calc):
title='')
return fig

def decile_graph(self, calc, hide_nonpositive_incomes=True):
def decile_graph(self, calc,
include_zero_incomes=True,
include_negative_incomes=True):
"""
Create graph that shows percentage change in aftertax expanded
income (from going from policy in self to policy in calc) for
Expand All @@ -999,6 +1009,9 @@ def decile_graph(self, calc, hide_nonpositive_incomes=True):
immediately in an interactive or notebook session (following
the instructions in the documentation of the xtr_graph_plot
utility function).
NOTE: this method calls the distribution_tables method to
compute the values of the graphed statistic; consult
that method for details on how the values are computed.

Parameters
----------
Expand All @@ -1007,16 +1020,17 @@ def decile_graph(self, calc, hide_nonpositive_incomes=True):
where both self and calc have calculated taxes for this year
before being used by this method

hide_nonpositive_incomes : boolean
if True (which is the default), the bottom table bin containing
filing units with non-positive expanded_income is not shown in
the graph and the table bin containing filing units with positive
expanded_income in the bottom decile is shown with its bar width
adjusted to the number of weighted filing units in bottom decile
who have positive expanded_income; if False, the bottom table bin
containing filing units with non-positive expanded_income is shown,
which may be misleading because the percentage change is correctly
calculated with a negative divisor.
include_zero_incomes : boolean
if True (which is the default), the bottom decile does contain
filing units with zero expanded_income;
if False, the bottom decile does not contain filing units with
zero expanded_income.

include_negative_incomes : boolean
if True (which is the default), the bottom decile does contain
filing units with negative expanded_income;
if False, the bottom decile does not contain filing units with
negative expanded_income.

Returns
-------
Expand All @@ -1026,13 +1040,15 @@ def decile_graph(self, calc, hide_nonpositive_incomes=True):
assert isinstance(calc, Calculator)
assert calc.current_year == self.current_year
assert calc.array_len == self.array_len
diff_table = self.difference_table(calc,
groupby='weighted_deciles',
income_measure='expanded_income',
tax_to_diff='combined')
dt1, dt2 = self.distribution_tables(calc,
groupby='weighted_deciles',
income_measure='expanded_income',
result_type='weighted_sum')
# construct data for graph
data = dec_graph_data(diff_table, year=self.current_year,
hide_nonpos_incomes=hide_nonpositive_incomes)
data = dec_graph_data(
dt1, dt2, year=self.current_year,
include_zero_incomes=include_zero_incomes,
include_negative_incomes=include_negative_incomes)
# construct figure from data
fig = dec_graph_plot(data,
width=850,
Expand Down
13 changes: 7 additions & 6 deletions taxcalc/reforms/2017_law.out
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
1 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0 0
3 0 0 0 0 0 0 0 0
4 60000 12995 16792 30213 3466 489 9180 54921
5 0 0 0 0 0 0 0 0
6 180000 30322 30375 119303 16514 13514 27540 152716
7 0 0 0 0 0 0 0 0
8 240000 25990 23584 190426 32344 30844 36720 190796
9 600000 18875 20375 560750 142810 142810 66067 423437
4 0 0 0 0 0 0 0 0
5 60000 12995 16792 30213 3466 489 9180 54921
6 0 0 0 0 0 0 0 0
7 180000 30322 30375 119303 16514 13514 27540 152716
8 0 0 0 0 0 0 0 0
9 240000 25990 23584 190426 32344 30844 36720 190796
10 600000 18875 20375 560750 142810 142810 66067 423437
sums 1080000 88182 91126 900692 195134 187657 139507 821869
13 changes: 7 additions & 6 deletions taxcalc/reforms/BrownKhanna.out
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
1 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0 0
3 0 0 0 0 0 0 0 0
4 60000 12995 16792 30213 3466 -4405 9180 59815
5 0 0 0 0 0 0 0 0
6 180000 30322 30375 119303 16514 8698 27540 157532
7 0 0 0 0 0 0 0 0
8 240000 25990 23584 190426 32344 30844 36720 190796
9 600000 18875 20375 560750 142810 142810 66067 423437
4 0 0 0 0 0 0 0 0
5 60000 12995 16792 30213 3466 -4405 9180 59815
6 0 0 0 0 0 0 0 0
7 180000 30322 30375 119303 16514 8698 27540 157532
8 0 0 0 0 0 0 0 0
9 240000 25990 23584 190426 32344 30844 36720 190796
10 600000 18875 20375 560750 142810 142810 66067 423437
sums 1080000 88182 91126 900692 195134 177947 139507 831580
13 changes: 7 additions & 6 deletions taxcalc/reforms/Clinton2016.out
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
1 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0 0
3 0 0 0 0 0 0 0 0
4 60000 12995 16792 30213 3466 -511 9180 55921
5 0 0 0 0 0 0 0 0
6 180000 30322 30375 119303 16514 11514 27540 154716
7 0 0 0 0 0 0 0 0
8 240000 25990 23584 190426 32344 29844 36720 191796
9 600000 18875 20375 560750 142810 142810 66067 423437
4 0 0 0 0 0 0 0 0
5 60000 12995 16792 30213 3466 -511 9180 55921
6 0 0 0 0 0 0 0 0
7 180000 30322 30375 119303 16514 11514 27540 154716
8 0 0 0 0 0 0 0 0
9 240000 25990 23584 190426 32344 29844 36720 191796
10 600000 18875 20375 560750 142810 142810 66067 423437
sums 1080000 88182 91126 900692 195134 183657 139507 825869
13 changes: 7 additions & 6 deletions taxcalc/reforms/Renacci.out
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
1 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0 0
3 0 0 0 0 0 0 0 0
4 60000 16043 32087 11870 1187 -3245 9180 58655
5 0 0 0 0 0 0 0 0
6 180000 37434 64173 78393 7839 3676 27540 162554
7 0 0 0 0 0 0 0 0
8 240000 32087 48130 159784 21946 20446 36720 201194
9 600000 23303 48130 528567 108077 108077 66067 458170
4 0 0 0 0 0 0 0 0
5 60000 16043 32087 11870 1187 -3245 9180 58655
6 0 0 0 0 0 0 0 0
7 180000 37434 64173 78393 7839 3676 27540 162554
8 0 0 0 0 0 0 0 0
9 240000 32087 48130 159784 21946 20446 36720 201194
10 600000 23303 48130 528567 108077 108077 66067 458170
sums 1080000 108867 192519 778613 139049 128954 139507 880572
13 changes: 7 additions & 6 deletions taxcalc/reforms/RyanBrady.out
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
1 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0 0
3 0 0 0 0 0 0 0 0
4 60000 0 32087 27913 3350 83 9180 55327
5 0 0 0 0 0 0 0 0
6 180000 0 57756 122244 15524 11024 27540 155206
7 0 0 0 0 0 0 0 0
8 240000 0 44921 195079 31153 28153 36720 193487
9 600000 0 38504 561496 135919 135919 66067 430328
4 0 0 0 0 0 0 0 0
5 60000 0 32087 27913 3350 83 9180 55327
6 0 0 0 0 0 0 0 0
7 180000 0 57756 122244 15524 11024 27540 155206
8 0 0 0 0 0 0 0 0
9 240000 0 44921 195079 31153 28153 36720 193487
10 600000 0 38504 561496 135919 135919 66067 430328
sums 1080000 0 173268 906732 185946 175179 139507 834347
13 changes: 7 additions & 6 deletions taxcalc/reforms/TCJA_House.out
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
1 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0 0
3 0 0 0 0 0 0 0 0
4 60000 0 31227 28773 3453 -675 9180 56085
5 0 0 0 0 0 0 0 0
6 180000 0 56209 123791 14942 8942 27540 157288
7 0 0 0 0 0 0 0 0
8 240000 0 43718 196282 27758 23008 36720 198632
9 600000 0 37473 562527 136297 134397 66067 431850
4 0 0 0 0 0 0 0 0
5 60000 0 31227 28773 3453 -675 9180 56085
6 0 0 0 0 0 0 0 0
7 180000 0 56209 123791 14942 8942 27540 157288
8 0 0 0 0 0 0 0 0
9 240000 0 43718 196282 27758 23008 36720 198632
10 600000 0 37473 562527 136297 134397 66067 431850
sums 1080000 0 168627 911373 182449 165671 139507 843855
13 changes: 7 additions & 6 deletions taxcalc/reforms/TCJA_House_Amended.out
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
1 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0 0
3 0 0 0 0 0 0 0 0
4 60000 0 31227 28773 3453 -675 9180 56085
5 0 0 0 0 0 0 0 0
6 180000 0 56209 123791 14942 8942 27540 157288
7 0 0 0 0 0 0 0 0
8 240000 0 43718 196282 27758 23008 36720 198632
9 600000 0 37473 562527 136297 134397 66067 431850
4 0 0 0 0 0 0 0 0
5 60000 0 31227 28773 3453 -675 9180 56085
6 0 0 0 0 0 0 0 0
7 180000 0 56209 123791 14942 8942 27540 157288
8 0 0 0 0 0 0 0 0
9 240000 0 43718 196282 27758 23008 36720 198632
10 600000 0 37473 562527 136297 134397 66067 431850
sums 1080000 0 168627 911373 182449 165671 139507 843855
13 changes: 7 additions & 6 deletions taxcalc/reforms/TCJA_Reconciliation.out
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
1 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0 0
3 0 0 0 0 0 0 0 0
4 60000 0 31227 28773 3029 -898 9180 56308
5 0 0 0 0 0 0 0 0
6 180000 0 56209 123791 14699 8699 27540 157531
7 0 0 0 0 0 0 0 0
8 240000 0 43718 196282 29361 23361 36720 198279
9 600000 0 37473 562527 136039 132039 66067 434207
4 0 0 0 0 0 0 0 0
5 60000 0 31227 28773 3029 -898 9180 56308
6 0 0 0 0 0 0 0 0
7 180000 0 56209 123791 14699 8699 27540 157531
8 0 0 0 0 0 0 0 0
9 240000 0 43718 196282 29361 23361 36720 198279
10 600000 0 37473 562527 136039 132039 66067 434207
sums 1080000 0 168627 911373 183129 163202 139507 846325
Loading