Skip to content

Commit 204b0f2

Browse files
committed
add fec examples
1 parent 6bd355b commit 204b0f2

28 files changed

+718
-79
lines changed

04-working-with-widgets.Rmd

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ widget_for("giving")
2424

2525
Once you've found the widget you're looking for, you can get additional information using R's built-in help system. Just type a question mark followed by the name of the widget, e.g. `?gave_to_area`.
2626

27-
## Codes and synonyms
27+
## Codes and synonyms {#working-with-codes-synonyms}
2828

2929
You may have noticed in previous examples that widgets work with exact codes, such as `in_unit_portfolio(BU)` or with *synonyms*, such as `in_unit_portfolio(business)`. Synonyms will always be in lower-case, and may include any letter of the alphabet or the underscore "_" character, and nothing else.
3030

80-example-06.Rmd

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Utilizing FEC disclosure data {#ex-fec}
2+
3+
```{r ex-fec-loadlib, message = FALSE}
4+
# i always begin by loading the disco engine if it isn't already loaded
5+
library(discoveryengine)
6+
```
7+
8+
Prospect Analysis regularly screens various public data against CADS, including FEC disclosures. This data makes its way into some of our predictive models, but on occasion it is useful to use the data directly.
9+
10+
## Basics
11+
12+
The Disco Engine provides the following FEC widgets:
13+
14+
- `fec_gave_to_committee`
15+
- `fec_gave_to_candidate`
16+
- `fec_gave_to_category`
17+
18+
Since the names of all of these related widgets begin with the same prefix, they are easy to find using RStudio's auto-completion:
19+
20+
![just type "fec_"](images/fec-widgets-autocomplete.png)
21+
22+
The candidate and committee widgets should be pretty self-explanatory. `fec_gave_to_category` is based on a categorization of PACs and other committees done by the [Center for Responsive Politics (opensecrets.org)](https://www.opensecrets.org/).
23+
24+
All of the widgets have the same interface as the giving widgets, meaning you can specify date ranges and minimum amounts when using them.
25+
26+
For example, to find donors to Kamala Harris's CA senate campaign who gave at least $500 between January 1, 2016 and November 1, 2016:
27+
28+
```{r, eval = FALSE}
29+
fec_gave_to_candidate(harris_kamala_d, at_least = 500,
30+
from = 20160101, to = 20161101)
31+
```
32+
33+
As that example shows, the [system of codes and synonyms](#working-with-codes-synonyms) works the same way with the FEC widgets as with any other widget. [Synonym search](#synonym-search) is particularly useful with these widgets:
34+
35+
```{r, message = FALSE}
36+
fec_gave_to_category(?abortion)
37+
```
38+
39+
## Example: Engineering Prospects
40+
41+
A fundraiser might like to know if any of her prospects have recently made sizable political contributions:
42+
43+
```{r ex-fec-poli-eng, cache = TRUE}
44+
# as with other widgets, leaving the committee code blank means i'm looking
45+
# for giving to any committee
46+
political_engineering_prospect =
47+
in_unit_portfolio(engineering) %and%
48+
fec_gave_to_committee(at_least = 5000, from = 20170101, to = 20171031)
49+
50+
display(political_engineering_prospect)
51+
```
52+
53+
## Example: Environmental Interest
54+
55+
We can use political giving to identify constituent interest in the environment. First, I'll use the lookup features to identify the right `category`:
56+
57+
```{r ex-fec-find-env, cache = TRUE, message = FALSE}
58+
fec_gave_to_category(?environment)
59+
```
60+
61+
In this case, "environmental policy" is an ideological category, while the other two are industry PACs. Next, I might look for people who have expressed an interest in the environment by making political contributions to environmental policy organizations, but who have not already been coded with the
62+
63+
```{r ex-fec-env-interest, cache = TRUE, message = FALSE}
64+
has_uncoded_environment_interest =
65+
fec_gave_to_category(environmental_policy) %but_not%
66+
has_interest(environment)
67+
68+
display(has_uncoded_environment_interest)
69+
```
70+
71+
## Bots
72+
73+
Just like any other widget, FEC widgets are plugged in to the [Brainstorm Bot](#brainstorm-bot) and [Matrix Bot](#matrix-bot). So, for instance:
74+
75+
```{r ex-fec-brainstorm, cache = TRUE, message = FALSE}
76+
brainstorm_bot("cannabis")
77+
```
78+
79+
Or:
80+
81+
```{r ex-fec-bernie-matrix, cache = TRUE, message = FALSE}
82+
matrix_bot(fec_gave_to_candidate(sanders_bernard))
83+
```

docs/add-on-packages.html

+7-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
</ul></li>
129129
<li class="chapter" data-level="6" data-path="working-with-widgets.html"><a href="working-with-widgets.html"><i class="fa fa-check"></i><b>6</b> Working with widgets</a><ul>
130130
<li class="chapter" data-level="6.1" data-path="working-with-widgets.html"><a href="working-with-widgets.html#working-with-finding-widgets"><i class="fa fa-check"></i><b>6.1</b> Finding widgets</a></li>
131-
<li class="chapter" data-level="6.2" data-path="working-with-widgets.html"><a href="working-with-widgets.html#codes-and-synonyms"><i class="fa fa-check"></i><b>6.2</b> Codes and synonyms</a></li>
131+
<li class="chapter" data-level="6.2" data-path="working-with-widgets.html"><a href="working-with-widgets.html#working-with-codes-synonyms"><i class="fa fa-check"></i><b>6.2</b> Codes and synonyms</a></li>
132132
<li class="chapter" data-level="6.3" data-path="working-with-widgets.html"><a href="working-with-widgets.html#synonym-search"><i class="fa fa-check"></i><b>6.3</b> Synonym search</a></li>
133133
<li class="chapter" data-level="6.4" data-path="working-with-widgets.html"><a href="working-with-widgets.html#use-defaults"><i class="fa fa-check"></i><b>6.4</b> Use the default cases</a></li>
134134
<li class="chapter" data-level="6.5" data-path="working-with-widgets.html"><a href="working-with-widgets.html#detailed-controls"><i class="fa fa-check"></i><b>6.5</b> Detailed controls</a></li>
@@ -187,6 +187,12 @@
187187
<li class="chapter" data-level="18" data-path="ex-sim-donors.html"><a href="ex-sim-donors.html"><i class="fa fa-check"></i><b>18</b> Donors who aren’t degreeholders</a><ul>
188188
<li class="chapter" data-level="18.1" data-path="ex-sim-donors.html"><a href="ex-sim-donors.html#why-it-works"><i class="fa fa-check"></i><b>18.1</b> Why it works</a></li>
189189
</ul></li>
190+
<li class="chapter" data-level="19" data-path="ex-fec.html"><a href="ex-fec.html"><i class="fa fa-check"></i><b>19</b> Utilizing FEC disclosure data</a><ul>
191+
<li class="chapter" data-level="19.1" data-path="ex-fec.html"><a href="ex-fec.html#basics"><i class="fa fa-check"></i><b>19.1</b> Basics</a></li>
192+
<li class="chapter" data-level="19.2" data-path="ex-fec.html"><a href="ex-fec.html#example-engineering-prospects"><i class="fa fa-check"></i><b>19.2</b> Example: Engineering Prospects</a></li>
193+
<li class="chapter" data-level="19.3" data-path="ex-fec.html"><a href="ex-fec.html#example-environmental-interest"><i class="fa fa-check"></i><b>19.3</b> Example: Environmental Interest</a></li>
194+
<li class="chapter" data-level="19.4" data-path="ex-fec.html"><a href="ex-fec.html#bots"><i class="fa fa-check"></i><b>19.4</b> Bots</a></li>
195+
</ul></li>
190196
<li class="appendix"><span><b>Appendix</b></span></li>
191197
<li class="chapter" data-level="A" data-path="test-cdw.html"><a href="test-cdw.html"><i class="fa fa-check"></i><b>A</b> Test your database set up</a><ul>
192198
<li class="chapter" data-level="A.1" data-path="test-cdw.html"><a href="test-cdw.html#test-your-connection"><i class="fa fa-check"></i><b>A.1</b> Test your connection</a></li>

docs/brainstorm-bot.html

+7-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
</ul></li>
129129
<li class="chapter" data-level="6" data-path="working-with-widgets.html"><a href="working-with-widgets.html"><i class="fa fa-check"></i><b>6</b> Working with widgets</a><ul>
130130
<li class="chapter" data-level="6.1" data-path="working-with-widgets.html"><a href="working-with-widgets.html#working-with-finding-widgets"><i class="fa fa-check"></i><b>6.1</b> Finding widgets</a></li>
131-
<li class="chapter" data-level="6.2" data-path="working-with-widgets.html"><a href="working-with-widgets.html#codes-and-synonyms"><i class="fa fa-check"></i><b>6.2</b> Codes and synonyms</a></li>
131+
<li class="chapter" data-level="6.2" data-path="working-with-widgets.html"><a href="working-with-widgets.html#working-with-codes-synonyms"><i class="fa fa-check"></i><b>6.2</b> Codes and synonyms</a></li>
132132
<li class="chapter" data-level="6.3" data-path="working-with-widgets.html"><a href="working-with-widgets.html#synonym-search"><i class="fa fa-check"></i><b>6.3</b> Synonym search</a></li>
133133
<li class="chapter" data-level="6.4" data-path="working-with-widgets.html"><a href="working-with-widgets.html#use-defaults"><i class="fa fa-check"></i><b>6.4</b> Use the default cases</a></li>
134134
<li class="chapter" data-level="6.5" data-path="working-with-widgets.html"><a href="working-with-widgets.html#detailed-controls"><i class="fa fa-check"></i><b>6.5</b> Detailed controls</a></li>
@@ -187,6 +187,12 @@
187187
<li class="chapter" data-level="18" data-path="ex-sim-donors.html"><a href="ex-sim-donors.html"><i class="fa fa-check"></i><b>18</b> Donors who aren’t degreeholders</a><ul>
188188
<li class="chapter" data-level="18.1" data-path="ex-sim-donors.html"><a href="ex-sim-donors.html#why-it-works"><i class="fa fa-check"></i><b>18.1</b> Why it works</a></li>
189189
</ul></li>
190+
<li class="chapter" data-level="19" data-path="ex-fec.html"><a href="ex-fec.html"><i class="fa fa-check"></i><b>19</b> Utilizing FEC disclosure data</a><ul>
191+
<li class="chapter" data-level="19.1" data-path="ex-fec.html"><a href="ex-fec.html#basics"><i class="fa fa-check"></i><b>19.1</b> Basics</a></li>
192+
<li class="chapter" data-level="19.2" data-path="ex-fec.html"><a href="ex-fec.html#example-engineering-prospects"><i class="fa fa-check"></i><b>19.2</b> Example: Engineering Prospects</a></li>
193+
<li class="chapter" data-level="19.3" data-path="ex-fec.html"><a href="ex-fec.html#example-environmental-interest"><i class="fa fa-check"></i><b>19.3</b> Example: Environmental Interest</a></li>
194+
<li class="chapter" data-level="19.4" data-path="ex-fec.html"><a href="ex-fec.html#bots"><i class="fa fa-check"></i><b>19.4</b> Bots</a></li>
195+
</ul></li>
190196
<li class="appendix"><span><b>Appendix</b></span></li>
191197
<li class="chapter" data-level="A" data-path="test-cdw.html"><a href="test-cdw.html"><i class="fa fa-check"></i><b>A</b> Test your database set up</a><ul>
192198
<li class="chapter" data-level="A.1" data-path="test-cdw.html"><a href="test-cdw.html#test-your-connection"><i class="fa fa-check"></i><b>A.1</b> Test your connection</a></li>

docs/cheat-sheet.html

+7-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
</ul></li>
129129
<li class="chapter" data-level="6" data-path="working-with-widgets.html"><a href="working-with-widgets.html"><i class="fa fa-check"></i><b>6</b> Working with widgets</a><ul>
130130
<li class="chapter" data-level="6.1" data-path="working-with-widgets.html"><a href="working-with-widgets.html#working-with-finding-widgets"><i class="fa fa-check"></i><b>6.1</b> Finding widgets</a></li>
131-
<li class="chapter" data-level="6.2" data-path="working-with-widgets.html"><a href="working-with-widgets.html#codes-and-synonyms"><i class="fa fa-check"></i><b>6.2</b> Codes and synonyms</a></li>
131+
<li class="chapter" data-level="6.2" data-path="working-with-widgets.html"><a href="working-with-widgets.html#working-with-codes-synonyms"><i class="fa fa-check"></i><b>6.2</b> Codes and synonyms</a></li>
132132
<li class="chapter" data-level="6.3" data-path="working-with-widgets.html"><a href="working-with-widgets.html#synonym-search"><i class="fa fa-check"></i><b>6.3</b> Synonym search</a></li>
133133
<li class="chapter" data-level="6.4" data-path="working-with-widgets.html"><a href="working-with-widgets.html#use-defaults"><i class="fa fa-check"></i><b>6.4</b> Use the default cases</a></li>
134134
<li class="chapter" data-level="6.5" data-path="working-with-widgets.html"><a href="working-with-widgets.html#detailed-controls"><i class="fa fa-check"></i><b>6.5</b> Detailed controls</a></li>
@@ -187,6 +187,12 @@
187187
<li class="chapter" data-level="18" data-path="ex-sim-donors.html"><a href="ex-sim-donors.html"><i class="fa fa-check"></i><b>18</b> Donors who aren’t degreeholders</a><ul>
188188
<li class="chapter" data-level="18.1" data-path="ex-sim-donors.html"><a href="ex-sim-donors.html#why-it-works"><i class="fa fa-check"></i><b>18.1</b> Why it works</a></li>
189189
</ul></li>
190+
<li class="chapter" data-level="19" data-path="ex-fec.html"><a href="ex-fec.html"><i class="fa fa-check"></i><b>19</b> Utilizing FEC disclosure data</a><ul>
191+
<li class="chapter" data-level="19.1" data-path="ex-fec.html"><a href="ex-fec.html#basics"><i class="fa fa-check"></i><b>19.1</b> Basics</a></li>
192+
<li class="chapter" data-level="19.2" data-path="ex-fec.html"><a href="ex-fec.html#example-engineering-prospects"><i class="fa fa-check"></i><b>19.2</b> Example: Engineering Prospects</a></li>
193+
<li class="chapter" data-level="19.3" data-path="ex-fec.html"><a href="ex-fec.html#example-environmental-interest"><i class="fa fa-check"></i><b>19.3</b> Example: Environmental Interest</a></li>
194+
<li class="chapter" data-level="19.4" data-path="ex-fec.html"><a href="ex-fec.html#bots"><i class="fa fa-check"></i><b>19.4</b> Bots</a></li>
195+
</ul></li>
190196
<li class="appendix"><span><b>Appendix</b></span></li>
191197
<li class="chapter" data-level="A" data-path="test-cdw.html"><a href="test-cdw.html"><i class="fa fa-check"></i><b>A</b> Test your database set up</a><ul>
192198
<li class="chapter" data-level="A.1" data-path="test-cdw.html"><a href="test-cdw.html#test-your-connection"><i class="fa fa-check"></i><b>A.1</b> Test your connection</a></li>

docs/combining-widgets.html

+7-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
</ul></li>
129129
<li class="chapter" data-level="6" data-path="working-with-widgets.html"><a href="working-with-widgets.html"><i class="fa fa-check"></i><b>6</b> Working with widgets</a><ul>
130130
<li class="chapter" data-level="6.1" data-path="working-with-widgets.html"><a href="working-with-widgets.html#working-with-finding-widgets"><i class="fa fa-check"></i><b>6.1</b> Finding widgets</a></li>
131-
<li class="chapter" data-level="6.2" data-path="working-with-widgets.html"><a href="working-with-widgets.html#codes-and-synonyms"><i class="fa fa-check"></i><b>6.2</b> Codes and synonyms</a></li>
131+
<li class="chapter" data-level="6.2" data-path="working-with-widgets.html"><a href="working-with-widgets.html#working-with-codes-synonyms"><i class="fa fa-check"></i><b>6.2</b> Codes and synonyms</a></li>
132132
<li class="chapter" data-level="6.3" data-path="working-with-widgets.html"><a href="working-with-widgets.html#synonym-search"><i class="fa fa-check"></i><b>6.3</b> Synonym search</a></li>
133133
<li class="chapter" data-level="6.4" data-path="working-with-widgets.html"><a href="working-with-widgets.html#use-defaults"><i class="fa fa-check"></i><b>6.4</b> Use the default cases</a></li>
134134
<li class="chapter" data-level="6.5" data-path="working-with-widgets.html"><a href="working-with-widgets.html#detailed-controls"><i class="fa fa-check"></i><b>6.5</b> Detailed controls</a></li>
@@ -187,6 +187,12 @@
187187
<li class="chapter" data-level="18" data-path="ex-sim-donors.html"><a href="ex-sim-donors.html"><i class="fa fa-check"></i><b>18</b> Donors who aren’t degreeholders</a><ul>
188188
<li class="chapter" data-level="18.1" data-path="ex-sim-donors.html"><a href="ex-sim-donors.html#why-it-works"><i class="fa fa-check"></i><b>18.1</b> Why it works</a></li>
189189
</ul></li>
190+
<li class="chapter" data-level="19" data-path="ex-fec.html"><a href="ex-fec.html"><i class="fa fa-check"></i><b>19</b> Utilizing FEC disclosure data</a><ul>
191+
<li class="chapter" data-level="19.1" data-path="ex-fec.html"><a href="ex-fec.html#basics"><i class="fa fa-check"></i><b>19.1</b> Basics</a></li>
192+
<li class="chapter" data-level="19.2" data-path="ex-fec.html"><a href="ex-fec.html#example-engineering-prospects"><i class="fa fa-check"></i><b>19.2</b> Example: Engineering Prospects</a></li>
193+
<li class="chapter" data-level="19.3" data-path="ex-fec.html"><a href="ex-fec.html#example-environmental-interest"><i class="fa fa-check"></i><b>19.3</b> Example: Environmental Interest</a></li>
194+
<li class="chapter" data-level="19.4" data-path="ex-fec.html"><a href="ex-fec.html#bots"><i class="fa fa-check"></i><b>19.4</b> Bots</a></li>
195+
</ul></li>
190196
<li class="appendix"><span><b>Appendix</b></span></li>
191197
<li class="chapter" data-level="A" data-path="test-cdw.html"><a href="test-cdw.html"><i class="fa fa-check"></i><b>A</b> Test your database set up</a><ul>
192198
<li class="chapter" data-level="A.1" data-path="test-cdw.html"><a href="test-cdw.html#test-your-connection"><i class="fa fa-check"></i><b>A.1</b> Test your connection</a></li>

0 commit comments

Comments
 (0)