Quantcast
Channel: R-bloggers
Viewing all 12147 articles
Browse latest View live

R & Python Rosetta Stone: EDA with dplyr vs pandas

$
0
0

[This article was first published on R on head spin - the Heads or Tails blog, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

This is the first post in a new series featuring translations between R and Python code for common data science and machine learning tasks. A Rosetta Stone, if you will. I’m writing this mainly as a documented cheat sheet for myself, as I’m frequently switching between the two languages. Personally, I have learned Python and R around the same time, several years ago, but tidy R is much more intuitive to me than any other language. Hopefully, these posts can be useful to others in a similar situation. My point of reference is primarily R – with the aim to provide equivalent Python code – but occasionally I will look at translations of Python features into R.

The first post will focus on the tidyverse backbone dplyr and compare it to Python’s data science workhorse pandas.

As with all my blog posts, the code will run in Rmarkdown through the fantastic Rstudio IDE. All the output will be reproducible. Rstudio provides Python support via the great reticulate package. If you haven’t heard of it yet, check out my intro post on reticulate to get started.

Note: you need at least RStudio version 1.2 to be able to pass objects between R and Python. In addition, as always, here are the required packages. We are also setting the python path (see the intro post for more details on the path) and importing pandas:

# R
libs <- c('dplyr',                # wrangling
          'palmerpenguins',       # data
          'knitr','kableExtra',   # table styling
          'reticulate')           # python support
invisible(lapply(libs, library, character.only = TRUE))

use_python("/usr/bin/python")

df <- penguins %>%
  mutate_if(is.integer, as.double)
# Python
import pandas as pd
pd.set_option('display.max_columns', None)

We will be using the Palmer Penguins dataset, as provided by the brilliant Allison Horst through the eponymous R package– complete with her trademark adorable artwork. I was looking for an excuse to work with this dataset. Therefore, this will be a genuine example for an exploratory analysis, as I’m encountering the data for the first time.

General overview

It’s best to start your EDA by looking at the big picture: How large is the dataset? How many features are there? What are the data types? Here we have tabular data, but similar steps can be taken for text or images as well.

In R, I typically go with a combination of head, glimpse, and summary to get a broad idea of the data properties. (Beyond dplyr, there’s also the skimr package for more sophisticated data overviews.)

With head, we see the first (by default) 6 rows of the dataset:

# R
head(df)
## # A tibble: 6 x 8
##   species island bill_length_mm bill_depth_mm flipper_length_… body_mass_g
##                                             
## 1 Adelie  Torge…           39.1          18.7              181        3750
## 2 Adelie  Torge…           39.5          17.4              186        3800
## 3 Adelie  Torge…           40.3          18                195        3250
## 4 Adelie  Torge…           NA            NA                 NA          NA
## 5 Adelie  Torge…           36.7          19.3              193        3450
## 6 Adelie  Torge…           39.3          20.6              190        3650
## # … with 2 more variables: sex , year 

We find that our data is a mix of numerical and categorical columns. There are 8 columns in total. We get an idea of the order of magnitude of the numeric features, see that the categorical ones have text, and already spot a couple of missing values. (Note, that I converted all integer columns to double for easier back-and-forth with Python).

The pandashead command is essentially the same. One general difference here is that in pandas (and Python in general) everything is an object. Methods (and attributes) associated with the object, which is a pandasDataFrame here, are accessed via the dot “.” operator. For passing an R object to Python we preface it with r. like such:

# Python
r.df.head()
##   species     island  bill_length_mm  bill_depth_mm  flipper_length_mm  \
## 0  Adelie  Torgersen            39.1           18.7              181.0
## 1  Adelie  Torgersen            39.5           17.4              186.0
## 2  Adelie  Torgersen            40.3           18.0              195.0
## 3  Adelie  Torgersen             NaN            NaN                NaN
## 4  Adelie  Torgersen            36.7           19.3              193.0
##
##    body_mass_g     sex    year
## 0       3750.0    male  2007.0
## 1       3800.0  female  2007.0
## 2       3250.0  female  2007.0
## 3          NaN     NaN  2007.0
## 4       3450.0  female  2007.0

The output is less pretty than for Rmarkdown, but the result is pretty much the same. We don’t see column types, only their values. Another property of pandas data frames is that they come with a row index. By default this is a sequential number of rows, but anything can become an index.

With dplyr’s glimpse we can see a more compact, transposed display of column types and their values. Especially for datasets with many columns this can be a vital complement to head. We also see the number of rows and columns:

# R
glimpse(df)
## Observations: 344
## Variables: 8
## $ species            Adelie, Adelie, Adelie, Adelie, Adelie, Adelie…
## $ island             Torgersen, Torgersen, Torgersen, Torgersen, To…
## $ bill_length_mm     39.1, 39.5, 40.3, NA, 36.7, 39.3, 38.9, 39.2, …
## $ bill_depth_mm      18.7, 17.4, 18.0, NA, 19.3, 20.6, 17.8, 19.6, …
## $ flipper_length_mm  181, 186, 195, NA, 193, 190, 181, 195, 193, 19…
## $ body_mass_g        3750, 3800, 3250, NA, 3450, 3650, 3625, 4675, …
## $ sex                male, female, female, NA, female, male, female…
## $ year               2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007…

Alongside the 8 columns, our dataset has 344 rows. That’s pretty small.

In pandas, there’s no identical equivalent to glimpse. Instead, we can use the info method to give us the feature types in vertical form. We also see the number of non-null features (the “sex” column has the fewest), together with the number of rows and columns.

# Python
r.df.info()
## 
## RangeIndex: 344 entries, 0 to 343
## Data columns (total 8 columns):
## species              344 non-null category
## island               344 non-null category
## bill_length_mm       342 non-null float64
## bill_depth_mm        342 non-null float64
## flipper_length_mm    342 non-null float64
## body_mass_g          342 non-null float64
## sex                  333 non-null category
## year                 344 non-null float64
## dtypes: category(3), float64(5)
## memory usage: 14.8 KB

While several columns have missing values, the overall number of those null entries is small.

Additionally, pandas gives us a summary of data types (3 categorical, 5 float) and tells us how much memory our data takes up. In R, you can use the utils tool object.size for the latter:

# R
object.size(df)
## 21336 bytes

Next up is summary, which provides basic overview stats for each feature. Here in particular, we learn that there are 3 penguin species, 3 islands, and 11 missing values in the sex column. “Chinstrap” penguins are rarer than the other two species; and Torgersen is the least frequent island. We also see the fundamental characteristics of the numeric features (min, max, quartiles, median). Mean and median are pretty close for most of those, which suggests little skewness:

# R
summary(df)
##       species          island    bill_length_mm  bill_depth_mm
##  Adelie   :152   Biscoe   :168   Min.   :32.10   Min.   :13.10
##  Chinstrap: 68   Dream    :124   1st Qu.:39.23   1st Qu.:15.60
##  Gentoo   :124   Torgersen: 52   Median :44.45   Median :17.30
##                                  Mean   :43.92   Mean   :17.15
##                                  3rd Qu.:48.50   3rd Qu.:18.70
##                                  Max.   :59.60   Max.   :21.50
##                                  NA's   :2       NA's   :2
##  flipper_length_mm  body_mass_g       sex           year
##  Min.   :172.0     Min.   :2700   female:165   Min.   :2007
##  1st Qu.:190.0     1st Qu.:3550   male  :168   1st Qu.:2007
##  Median :197.0     Median :4050   NA's  : 11   Median :2008
##  Mean   :200.9     Mean   :4202                Mean   :2008
##  3rd Qu.:213.0     3rd Qu.:4750                3rd Qu.:2009
##  Max.   :231.0     Max.   :6300                Max.   :2009
##  NA's   :2         NA's   :2

The closest pandas equivalent to summary is describe. By default this only includes the numeric columns, but you can get around that by passing a list of features types that you want to include:

# Python
r.df.describe(include = ['float', 'category'])
##        species  island  bill_length_mm  bill_depth_mm  flipper_length_mm  \
## count      344     344      342.000000     342.000000         342.000000
## unique       3       3             NaN            NaN                NaN
## top     Adelie  Biscoe             NaN            NaN                NaN
## freq       152     168             NaN            NaN                NaN
## mean       NaN     NaN       43.921930      17.151170         200.915205
## std        NaN     NaN        5.459584       1.974793          14.061714
## min        NaN     NaN       32.100000      13.100000         172.000000
## 25%        NaN     NaN       39.225000      15.600000         190.000000
## 50%        NaN     NaN       44.450000      17.300000         197.000000
## 75%        NaN     NaN       48.500000      18.700000         213.000000
## max        NaN     NaN       59.600000      21.500000         231.000000
##
##         body_mass_g   sex         year
## count    342.000000   333   344.000000
## unique          NaN     2          NaN
## top             NaN  male          NaN
## freq            NaN   168          NaN
## mean    4201.754386   NaN  2008.029070
## std      801.954536   NaN     0.818356
## min     2700.000000   NaN  2007.000000
## 25%     3550.000000   NaN  2007.000000
## 50%     4050.000000   NaN  2008.000000
## 75%     4750.000000   NaN  2009.000000
## max     6300.000000   NaN  2009.000000

You see that the formatting is less clever, since categorical indicators like “unique” or “top” are shown (with NAs) for the numeric columns and vice versa. Also, we only get told that there are 3 species and the most frequent one is “Adelie”; not the full counts per species.

We have already learned a lot about our data from those basic overview tools. Typically, at this point in the EDA I would now start plotting feature distributions and interactions. Since we’re only focussing on dplyr here, this part will have to wait for a future “ggplot2 vs seaborn” episode. For now, let’s look at the most simple overview before moving on to dplyr verbs: number of rows and columns.

In R, there is dim while pandas has shape:

# R
dim(df)
## [1] 344   8
# Python
r.df.shape
## (344, 8)

Subsetting rows and columns

For extracting subsets of rows and columns, dplyr has the verbs filter and select, respectively. For instance, let’s look at the species and sex of the penguins with the shortest bills:

# R
df %>%
  filter(bill_length_mm < 34) %>%
  select(species, sex, bill_length_mm)
## # A tibble: 3 x 3
##   species sex    bill_length_mm
##                 
## 1 Adelie  female           33.5
## 2 Adelie  female           33.1
## 3 Adelie  female           32.1

All of those are female Adelie penguins. This is good news for a potential species classifier.

In pandas, there are several ways to achieve the same result. All of them are a little more complicated than our two dplyr verbs. The most pythonic way is probably to use the loc operator like such:

# Python
r.df.loc[r.df.bill_length_mm < 34, ['species', 'sex', 'bill_length_mm']]
##     species     sex  bill_length_mm
## 70   Adelie  female            33.5
## 98   Adelie  female            33.1
## 142  Adelie  female            32.1

This indexing via the “[]” brackets is essentially the same as in base R:

# R
na.omit(df[df$bill_length_mm < 34, c('species', 'sex', 'bill_length_mm')])
## # A tibble: 3 x 3
##   species sex    bill_length_mm
##                 
## 1 Adelie  female           33.5
## 2 Adelie  female           33.1
## 3 Adelie  female           32.1

Another way is to use the pandas method query as an equivalent for filter. This allows us to essentially use dplyr-style evaluation syntax. I found that in practice, query is often notably slower than the other indexing tools. This can be important if your’re dealing with large datasets:

# Python
r.df.query("bill_length_mm < 34").loc[:, ['species', 'sex', 'bill_length_mm']]
##     species     sex  bill_length_mm
## 70   Adelie  female            33.5
## 98   Adelie  female            33.1
## 142  Adelie  female            32.1

In tidy R, the dplyr verb select can extract by value as well as by position. And for extracting rows by position there is slice. This is just an arbitrary subset:

# R
df %>%
  slice(c(1,2,3)) %>%
  select(c(4,5,6))
## # A tibble: 3 x 3
##   bill_depth_mm flipper_length_mm body_mass_g
##                               
## 1          18.7               181        3750
## 2          17.4               186        3800
## 3          18                 195        3250

In pandas, we would use bracket indexing again, but instead of loc we now need iloc (i.e. locating by index). This might be a good point to remind ourselves that Python starts counting from 0 and R starts from 1:

# Python
r.df.iloc[[0, 1, 2], [3, 4, 5]]
##    bill_depth_mm  flipper_length_mm  body_mass_g
## 0           18.7              181.0       3750.0
## 1           17.4              186.0       3800.0
## 2           18.0              195.0       3250.0

To emphasise again: pandas uses loc for conditional indexing and iloc for positional indexing. This takes some getting uses to, but this simple rule covers most of pandas’ subsetting operations.

Retaining unique rows and removing duplicates can be thought of as another way of subsetting a data frame. In dplyr, there’s the distinct function which takes as arguments the columns that are considered for identifying duplicated rows:

# R
df %>%
  slice(c(2, 4, 186)) %>%
  distinct(species, island)
## # A tibble: 2 x 2
##   species island
##      
## 1 Adelie  Torgersen
## 2 Gentoo  Biscoe

In pandas we can achieve the same result via the drop_duplicates method:

r.df.iloc[[2, 4, 186], :].drop_duplicates(['species', 'island'])
##     species     island  bill_length_mm  bill_depth_mm  flipper_length_mm  \
## 2    Adelie  Torgersen            40.3           18.0              195.0
## 186  Gentoo     Biscoe            49.1           14.8              220.0
##
##      body_mass_g     sex    year
## 2         3250.0  female  2007.0
## 186       5150.0  female  2008.0

In order to retain only the two affected rows, like in the dplyr example above, you would have to select them using .loc.

Arrange and Sample

Let’s deal with the arranging and sampling of rows in one fell swoop. In dplyr, we use sample_n (or sample_frac) to choose a random subset of n rows (or a fraction frac of rows). Ordering a row by its values uses the verb arrange, optionally with the desc tool to specific descending order:

# R
set.seed(4321)
df %>%
  select(species, bill_length_mm) %>%
  sample_n(4) %>%
  arrange(desc(bill_length_mm))
## # A tibble: 4 x 2
##   species   bill_length_mm
##                 
## 1 Chinstrap           47.5
## 2 Adelie              42.7
## 3 Adelie              40.2
## 4 Adelie              34.6

In pandas, random sampling is done through the sample function, which can take either a fraction or a number of rows. Here, we can also pass directly a random seed (called random_state), instead of defining it outside the function via R’s set.seed. Arranging is called sort_values and we have to specify an ascending flag because pandas wants to be different:

# Python
r.df.loc[:, ['species', 'bill_length_mm']].\
  sample(n = 4, random_state = 4321).\
  sort_values('bill_length_mm', ascending = False)
##        species  bill_length_mm
## 305  Chinstrap            52.8
## 301  Chinstrap            52.0
## 291  Chinstrap            50.5
## 165     Gentoo            48.4

As you see, the pandas dot methods can be chained in a way reminiscent of the dplyr pipe (%>%). The scope for this style is much narrower than the pipe, though. It only works for methods and attributes associated with the specific pandas data frame and its transformation results. Nevertheless, it has a certain power and elegance for pipe aficionados. When written accross multiple lines it requires the Python line continuation operator \.

Group By and Summarise

Here is where dplyr really shines. Grouping and summarising transformations fit seemlessly into any wrangling workflow by preserving the tidy tibble data format. The verbs are group_by and summarise. Let’s compare average bill lengths among species to find that “Adelie” penguins have significantly shorter bills:

# R
df %>%
  group_by(species) %>%
  summarise(mean_bill_length = mean(bill_length_mm, na.rm = TRUE),
            sd_bill_length = sd(bill_length_mm, na.rm = TRUE))
## # A tibble: 3 x 3
##   species   mean_bill_length sd_bill_length
##                             
## 1 Adelie                38.8           2.66
## 2 Chinstrap             48.8           3.34
## 3 Gentoo                47.5           3.08

This is consistent to what we had seen before for the 3 rows with shortes bills. The results also indicate that it would be much harder to try to separate “Chinstrap” vs “Gentoo” by bill_length.

In terms of usage, pandas is similar: we have groupby (without the “_”) to define the grouping, and agg to aggregate (i.e. summarise) according to specific measures for certain features:

# Python
r.df.groupby('species').agg({'bill_length_mm': ['mean', 'std']})
##           bill_length_mm
##                     mean       std
## species
## Adelie         38.791391  2.663405
## Chinstrap      48.833824  3.339256
## Gentoo         47.504878  3.081857

This is pretty much the default way in pandas. It is worth noting that pandas, and Python in general, gets a lot of milage out of 2 data structures: lists like [1, 2, 3] which are the equivalent of c(1, 2, 3), and dictionaries{'a': 1, 'b': 2} which are sets of key-value pairs. Values in a dictionary can be pretty much anything, including lists or dictionaries. (Most uses cases for dictionaries are probably served by dplyr tibbles.) Here we use a dictionary to define which column we want to summarise and how. Note again the chaining via dots.

The outcome of this operation, however, is slightly different from dplyr in that we get a hierarchical data frame with a categorical index (this is no longer a “normal” column") and 2 data columns that both have the designation bill_length_mm:

# Python
r.df.groupby('species').agg({'bill_length_mm': ['mean', 'std']}).info()
## 
## CategoricalIndex: 3 entries, Adelie to Gentoo
## Data columns (total 2 columns):
## (bill_length_mm, mean)    3 non-null float64
## (bill_length_mm, std)     3 non-null float64
## dtypes: float64(2)
## memory usage: 155.0 bytes

You will see the limitations of that format if you try to chain another method. To get something instead that’s more closely resembling our dplyr output, here is a different way: we forego the dictionary in favour of a simple list, then add a suffix later, and finally reset the index to a normal column:

# Python
r.df.groupby('species').bill_length_mm.agg(['mean', 'std']).add_suffix("_bill_length").reset_index()
##      species  mean_bill_length  std_bill_length
## 0     Adelie         38.791391         2.663405
## 1  Chinstrap         48.833824         3.339256
## 2     Gentoo         47.504878         3.081857

Now we can treat the result like a typical data frame. Note, that here we use another form of column indexing to select bill_length_mm after the groupby. This shorthand, which treats a feature as an object attribute, only works for single columns. Told you that pandas indexing can be a little confusing.

Joining and binding

There’s another source of dplyr vs pandas confusion when it comes to SQL-style joins and to binding rows and columns. To demonstrate, we’ll create an additional data frame which holds the mean bill length by species. And we pretend that it’s a separate table. In terms of analysis steps, this crosses over from EDA into feature engineering territory, but that line can get blurry if you’re exploring a dataset’s hidden depths.

# R
df2 <- df %>%
  group_by(species) %>%
  summarise(mean_bill = mean(bill_length_mm, na.rm = TRUE))

df2
## # A tibble: 3 x 2
##   species   mean_bill
##            
## 1 Adelie         38.8
## 2 Chinstrap      48.8
## 3 Gentoo         47.5

The dplyr verbs for SQL-like joins are very similar to the various SQL flavours. We have left_join, right_join, inner_join, outer_join; as well as the very useful filtering joins semi_join and anti_join (keep and discard what matches, respectively):

# R
set.seed(4321)
df %>%
  left_join(df2, by = "species") %>%
  select(species, bill_length_mm, mean_bill) %>%
  sample_n(5)
## # A tibble: 5 x 3
##   species   bill_length_mm mean_bill
##                      
## 1 Adelie              42.7      38.8
## 2 Chinstrap           47.5      48.8
## 3 Adelie              40.2      38.8
## 4 Adelie              34.6      38.8
## 5 Gentoo              53.4      47.5

Now we can for instance subtract the mean bill length from the individual values to get the residuals or to standardise our features.

In pandas, joining uses the merge operator. You have to specify the type of join via the how parameter and the join key via on, like such:

# Python
r.df.\
  sample(n = 5, random_state = 24).\
  merge(r.df2, how = "left", on = "species").\
  loc[:, ['species', 'bill_length_mm', 'mean_bill']]
##      species  bill_length_mm  mean_bill
## 0     Gentoo            43.4  47.504878
## 1  Chinstrap            51.7  48.833824
## 2     Gentoo            46.2  47.504878
## 3     Adelie            43.1  38.791391
## 4     Adelie            41.3  38.791391

Now, to bring in the aforementioned source of confusion: pandas also has an operator called join which joins by matching indeces, instead of columns, between two tables. This is a pretty pandas-specific convenience shortcut, since it relies on the data frame index. In practice I recommend using merge instead. The little conveniece provided by join is not worth the additional confusion.

Binding rows and columns in dplyr uses bind_rows and bind_cols. For the rows, there’s really not much of a practical requirement other than that some of the column names match and that those ideally have the same type (which is not strictly necessary):

# R
head(df, 2) %>%
  bind_rows(tail(df, 2) %>% select(year, everything(), -sex))
## # A tibble: 4 x 8
##   species island bill_length_mm bill_depth_mm flipper_length_… body_mass_g
##                                             
## 1 Adelie  Torge…           39.1          18.7              181        3750
## 2 Adelie  Torge…           39.5          17.4              186        3800
## 3 Chinst… Dream            50.8          19                210        4100
## 4 Chinst… Dream            50.2          18.7              198        3775
## # … with 2 more variables: sex , year 

For columns, it is necessary that the features we’re binding to a tibble have the same number of rows. The big assumption here is that the row orders match (but that can be set beforehand):

# R
select(df, species) %>%
  bind_cols(df %>% select(year)) %>%
  head(5)
## # A tibble: 5 x 2
##   species  year
##      
## 1 Adelie   2007
## 2 Adelie   2007
## 3 Adelie   2007
## 4 Adelie   2007
## 5 Adelie   2007

The pandas equivalent to bind_rows is append. This nomenclature is borrowed from Python’s overall reliance on list operations.

# Python
r.df.head(2).append(r.df.tail(2).drop("sex", axis = "columns"), sort = False)
##        species     island  bill_length_mm  bill_depth_mm  flipper_length_mm  \
## 0       Adelie  Torgersen            39.1           18.7              181.0
## 1       Adelie  Torgersen            39.5           17.4              186.0
## 342  Chinstrap      Dream            50.8           19.0              210.0
## 343  Chinstrap      Dream            50.2           18.7              198.0
##
##      body_mass_g     sex    year
## 0         3750.0    male  2007.0
## 1         3800.0  female  2007.0
## 342       4100.0     NaN  2009.0
## 343       3775.0     NaN  2009.0

Here we also demonstrate how to drop a column from a data frame (i.e. the equivalent to dplyrselect with a minus).

Binding pandas columns uses concat, which takes a Python list as its parameter:

# Python
pd.concat([r.df.loc[:, 'species'], r.df.loc[:, 'year']], axis = "columns").head(5)
##   species    year
## 0  Adelie  2007.0
## 1  Adelie  2007.0
## 2  Adelie  2007.0
## 3  Adelie  2007.0
## 4  Adelie  2007.0

And that’s it for the basics!

Of course, there are a number of intricacies and special cases here, but by and large this should serve as a useful list of examples to get you started in pandas coming from dplyr, and perhaps also vice versa. Future installments in this series will go beyond dplyr, but likely also touch back on some aspect of it that are easy to get lost in translation.

More info:

  • I have been planning to start this series for several months now; since I’m an R user in a Python-dominated team and often use both languages om any given day. What finally pushed me to overcome my laziness was an initiative by the ever prolific Benjamin Wolfe to gather resources for R users interested in Python. If you’re interested to contribute too, just drop by in the slack and say Hi.

  • Next up: most likely tidyr and/or stringr vs pandas. Watch this space.

var vglnk = {key: '949efb41171ac6ec1bf7f206d57e90b8'}; (function(d, t) { var s = d.createElement(t); s.type = 'text/javascript'; s.async = true; // s.defer = true; // s.src = '//cdn.viglink.com/api/vglnk.js'; s.src = 'https://www.r-bloggers.com/wp-content/uploads/2020/08/vglnk.js'; var r = d.getElementsByTagName(t)[0]; r.parentNode.insertBefore(s, r); }(document, 'script'));

To leave a comment for the author, please follow the link and comment on their blog: R on head spin - the Heads or Tails blog.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The post R & Python Rosetta Stone: EDA with dplyr vs pandas first appeared on R-bloggers.


It’s time to retire the “data scientist” label

$
0
0

[This article was first published on Econometrics and Free Software, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The “Data Scientist” label served its purpose; it allowed us to signal a transition happening in our profession from using only applied mathematical statistical methods to something else, which now also involves the use of a subset of software engineering practices. This transition was mentioned back in 2010 by Deborah Nolan (https://www.stat.berkeley.edu/~statcur/Preprints/ComputingCurric3.pdf), and this transition might now be complete. Version control systems, document generation from annotated source code (or even full reports generation à la rmarkdown), containers and build automation tools have now entered the toolbox of the run-of-the-mill statistician. Maybe not all of these tools, of course, it largely depends on what it is exactly you do, but certainly some of these. Same goes for software engineering practices. I have had the opportunity to work with some old-school statisticians (and still do), and the difference is clear; just like old school users of WYSIWYG editors like Word don’t use its “newest” features such as “Track changes” (and thus keep writing their text in different colors to signal which paragraphs are new), or the concept of versions of a document synced on Sharepoint (and thus keep multiple versions of the same document with different names) old school statisticians have not included the tools I mentioned before in their toolbox.

Now don’t get me wrong here; that is absolutely ok. We need and respect old school statisticians because they’ve been in the business of getting insights from data for longer than I’ve been alive. This blog post is not a jab at them because they don’t know how to use git (if you interpret it like that, that’s on you). Old school statisticians now have very senior positions and for many of them, their job does not involve getting their hands dirty on data anymore; most of them are now more like managers or mentors, and share their deep knowledge with their more junior team members. (Obviously there’s exceptions, when I say all old school statisticians do this or that, I don’t mean all of them, but most of them. Of course, I don’t have any evidence to back that up).

What this blog post is about is the label “Data Scientist” that gets used by these more junior team members and by companies that want to hire talented and motivated young people. This label, and the purported difference between a “Data Scientist” and “statistician” does not make any sense in 2020 anymore. (I know I’m beating a dead horse here, but this is my blog. I’ll blog about dead horses as much as I want thank you very much.)

Firstly, this label has always been confusing. “Data Scientist”… what does it even mean? The fact it took so long to find a definition, and that almost everyone working in the profession has a different one speaks volumes. Also, don’t all scientists use data? Data from experiments, from observational studies, from surveys, from the literature?

Secondly, I don’t believe that you can get a degree in statistics today without any exposition whatsoever to at least some of the tools I mentioned before. I really doubt that there’s people out there getting Master’s degrees in statistics without having ever touched these tools, or the unix command line. The degrees they’re going for might not focus a lot on these tools, true, but they certainly touch upon them. And of course, once they join a team at their first job, they’ll get more exposed to these tools and incorporate them in their day to day work. So, they’re not statisticians anymore? Their degree magically transformed into a data science degree?

But what about data science degrees? Are the students graduating with these degrees statisticians? I’d argue that yes, they are indeed statisticians; it’s just that they took a statistics degree that might have focused more than usual on these “new” practices/tools, and changed its name to “Data Science degree” for marketing purposes.

Anyways, the label “Data Scientist” is now completely defunct; as I mentioned in the very beginning, it served us well to signal that a transition was happening in the profession. I believe that this transition is now complete, or should be nearing its final stages. Also, this transition was not only about the tools used, but also about the deliverables. Statisticians now don’t only deliver tables, graphs and studies but more and more of them deliver products. This product can be a package implementing a bleeding edge statistical method for the profession as a whole, or it can be part of a piece of software that needs it to run (like your smartphone keyboard using a statistical model for word predictions). See this paper for an interesting exposition about how curricula and deliverables have evolved in the past two decades.

Currently, this label gets used by people that try to get insights from data. But we already have a word for them; statisticians. It’s just that the tools of the statistician have evolved over the past decade or so. Actually, I would perhaps even make another distinction; we should reserve the label of “statistician” to people that do statistics without ever touching any data. The other statisticians, the ones that get dirty wrestling in the mud with the data (they’re the pigs that like it from that famous quote) should be called “data janitors”. I’m not even joking; not only does that term already exist and gets used, I think it suits what we do perfectly. What do janitors do? They clean stuff and put things in order. We clean data and put it in order; meaning creating summary tables, visualizations, interactive applications, and models. Oh, and we do so (preferably) in a reproducible way.

Hope you enjoyed! If you found this blog post useful, you might want to follow me on twitter for blog post updates and buy me an espresso or paypal.me, or buy my ebook on Leanpub.

.bmc-button img{width: 27px !important;margin-bottom: 1px !important;box-shadow: none !important;border: none !important;vertical-align: middle !important;}.bmc-button{line-height: 36px !important;height:37px !important;text-decoration: none !important;display:inline-flex !important;color:#ffffff !important;background-color:#272b30 !important;border-radius: 3px !important;border: 1px solid transparent !important;padding: 1px 9px !important;font-size: 22px !important;letter-spacing:0.6px !important;box-shadow: 0px 1px 2px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 1px 2px 2px rgba(190, 190, 190, 0.5) !important;margin: 0 auto !important;font-family:'Cookie', cursive !important;-webkit-box-sizing: border-box !important;box-sizing: border-box !important;-o-transition: 0.3s all linear !important;-webkit-transition: 0.3s all linear !important;-moz-transition: 0.3s all linear !important;-ms-transition: 0.3s all linear !important;transition: 0.3s all linear !important;}.bmc-button:hover, .bmc-button:active, .bmc-button:focus {-webkit-box-shadow: 0px 1px 2px 2px rgba(190, 190, 190, 0.5) !important;text-decoration: none !important;box-shadow: 0px 1px 2px 2px rgba(190, 190, 190, 0.5) !important;opacity: 0.85 !important;color:#82518c !important;}Buy me an EspressoBuy me an Espresso

var vglnk = {key: '949efb41171ac6ec1bf7f206d57e90b8'}; (function(d, t) { var s = d.createElement(t); s.type = 'text/javascript'; s.async = true;// s.defer = true;// s.src = '//cdn.viglink.com/api/vglnk.js'; s.src = 'https://www.r-bloggers.com/wp-content/uploads/2020/08/vglnk.js'; var r = d.getElementsByTagName(t)[0]; r.parentNode.insertBefore(s, r); }(document, 'script'));

To leave a comment for the author, please follow the link and comment on their blog: Econometrics and Free Software.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The post It's time to retire the "data scientist" label first appeared on R-bloggers.

Single-source publishing for R users

$
0
0

[This article was first published on Maëlle's R blog on Maëlle Salmon's personal website, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

A big part of my work includes putting content about R online, in blog posts and online books. I’m therefore very interested in the technical infrastructure that allows us R users to produce beautiful products out of R Markdown or Markdown source files. In this post I shall summarize my recent experiments around making HTML and PDF versions of books. Thanks to Julie Blanc’s inspiring post in French, I have learnt this is called single-source publishing. So let’s dive into the incredible machines allowing single-source publishing for R users. 😉

What I want for writing books

I want technical tools that allow me to procrastinate whilst learning a ton. Just kidding, or not. 😇 My official criteria are:

  • For a book(let), I want a beautiful, usable website as well as a beautiful, usable PDF since some folks might prefer that for printing or offline usage.
  • I want to be able to write content in R Markdown or Markdown files, with some helpers for elements that Markdown doesn’t allow, for instance I might use a custom block to show an alert.
  • I want continuous deployment for my books, using git and a continuous integration service, so that every change in the source is reflected in the online versions of my book without my needing to think about it.
  • I would prefer to knit R Markdown files only once.
  • I don’t want to have to learn two ways to style things. 1

Now, let’s dive into three workflows I’ve used or experimented with.

The standard way: bookdown gitbook and pdf_book

We R users are very lucky to be able to use bookdown for making books. You write content in Rmd files in a single folder, you order their filenames in a config file and choose an output format when knitting. There are many books out there built using bookdown, and often they’re knit twice so that there’s an HTML and PDF version. See for instance rOpenSci dev guide, that is deployed with GitHub Actions.

Advantages of bookdown include its widespread usage and stability, as well as its docs, both by its authors and users. For instance:

A downside of bookdown for the procrastinators out there is, in my opinion, that if you want a PDF and HTML versions of a book, you have to knit it twice. Furthermore, if you introduce some fancy things such as a custom block, you will have to define it both with CSS and with LaTeX environments. Now, I have written a whole book with LaTeX so I used to partially know how to use it, but these days I’d prefer learning about CSS only as there’s already a lot to digest in there. 😅

So let’s dive into two DIY ways of publishing a book in HTML and PDF.

Hugo and pagedjs-cli

In this proof-of-concept, content is stored in Markdown files, that could have been generated with hugodown. Actors are Hugo, a powerful static website generator that you get in the form of a binary, and pagedjs-cli, a Node package that prints HTML to PDF.

You can find a repo corresponding to this experiment on GitHub, and the resulting book on Netlify.

This proof-of-concept is based on the great hugo-book theme. My “work” was just to add a bit of setup magic (Netlify config, config/ dir).

The idea is to run two Hugo builds with different configurations. In the words of Hadley Wickham, “hugo provides a bewildering array of possible config locations”. In this proof-of-concept/incredible machine, this array of possibilities is key to success. The two configurations use different layout directories, layout directories being the templates telling Hugo where to put your words, e.g. every blog post on its own page, and a page showing summaries of all of them.

  • One Hugo build, hugo -d public --environment 'website', creates the HTML website with a link to “book.pdf” somewhere, in the public/ folder.
  • The second one, hugo -d public2 --environment 'pdf', creates a website with a single HTML page containing all the book content.
  • Then that single page is printed to PDF using pagedjs-cli and copied as “book.pdf” to public/. pagedjs-cli public2/all/index.html -o public/book.pdf"
  • The live website uses the content of the public/ folder so it has the website and the PDF.

Netlify can run all these commands

[build]publish = "/public"command = "hugo -d public --environment 'website' && hugo -d public2 --environment 'pdf' && pagedjs-cli public2/all/index.html -o public/book.pdf"

The dependency on pagedjs-cli is indicated with package.json (the DESCRIPTION of Node projects).

Now if the content lived in R Markdown files, we would need to use a service like GitHub Actions to knit things.

Advantages

  • The Markdown files that are the source of both versions of the book would be generated only once if you started from R Markdown.
  • Styling both versions rely on CSS. I haven’t added any print styles but if you used this workflow for real, then it’d be better to, of course.
  • Compared to creating a gitbook with bookdown, one could customize the HTML website more easily, and use any Hugo feature.

Further work

If I decided to take this further, that is! All the work would be aimed at making the PDF version better

  • Improve the Hugo layout to add various tables of contents (for the whole book, for chapters).
  • Actually work on the CSS print sheet for the PDF version.
  • Make Katex, Mermaid etc. work for the PDF version.

Related work

The work presented by Julie Blanc is a similar pipeline, where content lives in Markdown files rendered to two HTML versions by Jekyll, another static website generator. One HTML version is a website, the other one is a printable version thanks to Paged.js (the PDF is not pre-generated but you can get it from any modern browser). The big differences with my experiment are:

  • Julie Blanc’s work is not an experiment, it’s deployed to production!
  • Both versions of the book are absolutely stunning, there was actual CSS work involved.

bookdown::bs4_book(), xml2 and pagedjs-cli

In another experiment, I used bookdown’s brand-new HTML book format, bs4_book() by Hadley Wickham (only available in bookdown’s dev version). I used this one because I find it looks better than gitbook, and because it uses Bootswatch themes, you get to use divs such as a alerts. See bookdown’s docs about custom blocks.

The source is open. See the HTML version and PDF version. This time I took time to learn a bit about print CSS. 😸

Here the steps are knit using the bs4_book() template for HTML and then for getting a PDF

  • tweaks of the HTML e.g. moving the chapter table of contents from the sidebar to the main content, and merging of all chapters using xml2 and XPath (so yeah you’re ditching LaTeX in favor of a workflow involving XPath, so modern 🙃) in build.R. I could have made my life easier by using selectr for translating ” CSS3 Selectors and translates them to XPath 1.0 expressions. “.
  • some print CSS, see stylesheet. It turns out that following Paged.js docs about print CSS is not that hard. See my stylesheet, I changed the display of some things in print, and I used properties to add the page number and chapter title to the footer.
  • pagedjs-cli.

Locally I sourced build.R to see whether it works, but then I also wrote a GitHub Actions workflow that installs dependencies, runs the script, and deploys the docs/ folder to a gh-pages branch.

Note that Bootstrap provides classes you can add to elements for changing their display in print. So to not show the burger menu in print, you can either do as I did with a CSS property

@media print {  .btn.btn-outline-primary.d-lg-none.ml-2.mt-1 {    display: none;}}

or you’d add the .d-print-none to that element in your HTML template. If you can control said HTML template, that is.

Further work needed in this experiment is listed in GitHub issues. For instance footnotes aren’t tackled yet.

Conclusion

So, as an R user writing content in R Markdown, you have different possibilities for respecting the principles of single-source publishing. I would still recommend using bookdown or other official rmarkdown formats, knitting twice2 if you need two versions, as it is the only stable and widely used solution, but I found it fun to explore other workflows. Both the DIY ways I presented use pagedjs-cli to generate a PDF out of HTML. I strongly recommend following the work done by the lovely Paged.js folks in the world of paged media, and to learn more about CSS for print. If you want to produce only paged content out of your R Markdown file, check out the pagedown package and its fantastic output formats.

If you too want to experiment with homemade pipelines, have fun customizing things. 😉 Now, of course, the possibility of customization might actually be a curse when you are trying to write something. But this was not a blog post about productivity. 😁

At this point, let me thank Romain Lesur (one of pagedown authors) for his work promoting Paged.js in the R community. 🙏


  1. Yes, I should probably re-style this very website. ↩

  2. Potentially, knitr cache might make knitting a thing a second time very fast? 🤔↩

var vglnk = {key: '949efb41171ac6ec1bf7f206d57e90b8'}; (function(d, t) { var s = d.createElement(t); s.type = 'text/javascript'; s.async = true;// s.defer = true;// s.src = '//cdn.viglink.com/api/vglnk.js'; s.src = 'https://www.r-bloggers.com/wp-content/uploads/2020/08/vglnk.js'; var r = d.getElementsByTagName(t)[0]; r.parentNode.insertBefore(s, r); }(document, 'script'));

To leave a comment for the author, please follow the link and comment on their blog: Maëlle's R blog on Maëlle Salmon's personal website.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The post Single-source publishing for R users first appeared on R-bloggers.

Top 5 Best Articles on R for Business [October 2020]

$
0
0

[This article was first published on business-science.io, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Each month, we release tons of great content on R for Business. These are the 5 Top Articles in R for Business over the past month. We have some great ones in October. Let’s dive in. View the updated Top 5 R for Business Article at Business Science.

👉Register for our blog to get the Top 5 Best Articles on R for Business every month.

No. 1: How to Visualize Time Series Data Tidy Forecasting in R

How to Visualize Time Series Data is a code comparison of various time series visualizations between these frameworks: fpp2, fpp3 and timetk. This article received a ton of love this month. This article was contributed by one of my all-star students, Joon Im.

No. 2: Introducing Modeltime Ensemble Time Series Forecast Stacking

I’m SUPER EXCITED to introduce modeltime.ensemble, the time series ensemble extension to modeltime. This tutorial introduces our new R Package, Modeltime Ensemble, which makes it easy to perform stacked forecasts that improve forecast accuracy.

No. 3: How I Started My Data Science Business Throwback

This is a true story based on how I created my data science company from scratch. It’s a detailed documentation of my personal journey along with the company I founded, Business Science, and the data science educational university I started, Business Science University .

Have you considered starting a data science company? The journey will try your patience. You will question yourself. You will be spread thin. You will need to learn from failure. You will have to pick yourself up when you get knocked down. You will need to depend on friends, and you must be willing to ask for help.

No. 4: How to Automate Excel with R Video Tutorial

This article is part of a R-Tips Weekly, a weekly video tutorial that shows you step-by-step how to do common R coding tasks.

Using R to automate Excel is an awesome skill for automating your work (and life). Your company lives off Excel files. Why not automate them & save some time?

No. 5: How to Automate Exploratory Analysis Plots Code Tutorial

When plotting different charts during your exploratory data analysis, you sometimes end up doing a lot of repetitive coding.

In this tutorial we’ll show you a better way to do your EDA, and with less unnecessary coding and more flexibility. This article was contributed by one of my all-star students, Luciano Oliveira Batista.

Finding it Difficult to Learn R for Business?

Finding it difficult to learn R for Business? Here’s the solution: My NEW 5-Course R-Track System that will take you from beginner to expert in months, not years. Learn what has taken me 10+ years to learn, the tools that connect data science with the business, and accelerate your career in the process. Here’s what’s included:

  • High-Performance Time Series Forecasting
  • Shiny Developer with AWS
  • Shiny Dashboards
  • Advanced Machine Learning and Business Consulting
  • Data Science Foundations

var vglnk = {key: '949efb41171ac6ec1bf7f206d57e90b8'}; (function(d, t) { var s = d.createElement(t); s.type = 'text/javascript'; s.async = true;// s.defer = true;// s.src = '//cdn.viglink.com/api/vglnk.js'; s.src = 'https://www.r-bloggers.com/wp-content/uploads/2020/08/vglnk.js'; var r = d.getElementsByTagName(t)[0]; r.parentNode.insertBefore(s, r); }(document, 'script'));

To leave a comment for the author, please follow the link and comment on their blog: business-science.io.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The post Top 5 Best Articles on R for Business [October 2020] first appeared on R-bloggers.

Little useless-useful R functions – Wacky Password generator

$
0
0

[This article was first published on R – TomazTsql, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Generating password is a hustle and I don’t want to go into the philosophy of passwords. Strong password, lengthy password, automatically generated password, etc. For me, they are all hard to remember, even harder to type (due to typos, different language setups, OS, software, etc.). In return, let’s have another useless R function, that will generate useless, – hard-to-use and impossible to remember – password, that will comply to all the standard rules (8 characters or more, one upper case, a kidney, a number, a special character, section from war & Peace, etc).

Typical “strong” password that human brain struggles to comprehend.

To make this password generation rather wacky, let me play with following characters:

There is less diversity in characters but nonetheless, the correct length and small caps, number, special characters and kidney – all comply with the regular quality assurance.

Wacky R function generates a set of ill generated password that would be even harder to type, and stupid to remember.

# Running on Linux/MacOSWackyPassword <- function(WP_length){  #charblock1 = c(176:178, 185: 188, 200:206)  charblock1 <- c("\u2591","\u2592","\u2593")  charblock2 = c(73,105,108,124,49,33)  numberblock3 <- sample(0:9, length(5),replace = TRUE)    pass = ""  Encoding(pass) <- "UTF-8"  ran2 <- floor(sample(1:WP_length/2))  ran1 <- floor(sample(1:WP_length/2))      while (nchar(pass) <= WP_length) {        res2 <- sample(charblock2, 100,replace = TRUE)        res2 <- rawToChar(as.raw(res2))        Encoding(res2) <- "UTF-8"        start2 <- sample(1:90,1)        pass <- paste0(pass,substr(res2,start2,start2+ran2),collapse="", sep= "")                        res1 <- sample(charblock1, 100,replace = TRUE)        Encoding(res1) <- "UTF-8"        start1 <- sample(20:70,1)        res <- paste0(res1, sep = "", collapse = "")        pass <- paste0(pass,substr(res,start1,start1+ran1), sep="", collapse = "")          }       cat(eval(substr(pass,1,WP_length)))}

Running the function is as simple as:

WackyPassword(18)

but the results can be as useless and wacky as you can imagine 🙂

!il1|I▓▒▓▓▓░!I|lIi

Good luck typing this and I buy a beer to every community member brave enough to use one 🙂

As always, useless code is available at Github.

Happy R-coding! And stay healthy my friends!

var vglnk = {key: '949efb41171ac6ec1bf7f206d57e90b8'}; (function(d, t) { var s = d.createElement(t); s.type = 'text/javascript'; s.async = true;// s.defer = true;// s.src = '//cdn.viglink.com/api/vglnk.js'; s.src = 'https://www.r-bloggers.com/wp-content/uploads/2020/08/vglnk.js'; var r = d.getElementsByTagName(t)[0]; r.parentNode.insertBefore(s, r); }(document, 'script'));

To leave a comment for the author, please follow the link and comment on their blog: R – TomazTsql.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The post Little useless-useful R functions – Wacky Password generator first appeared on R-bloggers.

4 R projects to form a core data analyst portfolio

$
0
0

[This article was first published on Articles - The Analyst Code, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Introduction

The job market for data analysts is large and highly competitive. Many companies, including companies not traditionally classified as “tech” or “coding” companies are looking to hire people with analytical coding experience. Yet, the numbers of applicants seems to be rising even faster. It’s a competitive market and you want your application to stand out.

Many jobs descriptions include lines like “Executes and advises on reporting needs and works cross-functionally to analyze data and make actionable recommendations at all levels” or “Utilizes advanced analytical and/or statistical ability to evaluate data and make judgments and recommendations“, “Experience in at least one computer programming language or analytical programming language (R, Python, SAS, etc.)” (emphasis added).

Notice that these job postings include two common themes (1) experience analyzing data (2) and experience providing recommendations. Your goal as an aspiring analyst is to be able to demonstrate experience in both of these domains. But how can you do this when you are applying for your first job in the field? Easy: spend some time building a core portfolio that shows the types of skills that recruiters want.

This article covers four projects that can form the core of your application portfolio. We recommend completing these prior to applying for jobs so that you can have demonstrable experience to include on your resume and discuss in your interviews. Be sure to create a GitHub repo for each project and link prominently to your GitHub profile on your resume.

I expect that building this portfolio will take at least one month of focused work.

  • Week 1: Exploratory data analysis

  • Week 2: Interactive Shiny dashboard

  • Week 3: Natural Language Processing

  • Week 4: Machine Learning

As you work through the projects, keep in mind that your goal is not just to gain experience analyzing data but also providing insightful recommendation. Even though this is practice, structure your output to include conclusions like “If I wanted to improve my exercise habits, the data show that…”. Prove to future recruiters that you have the skills they want to see.

Core portfolio projects

Exploratory data analysis

  • Project goal: Load a messy dataset into R, clean the data, create 4-5 charts or tables that have summary stats about your data, and create 4-5 charts or tables that provide analytic insight. Your output should be an html rmarkdown document.

  • Questions to answer: How big is my dataset? What do the top 10 items of data look like? What is the distribution of my variables of interest (mean/median, skew, outliers)? How does data change over time? What is the relationship between Variable A and Variable B? Why does Variable A behave in such and such a manner?

  • Resume skills practiced: R, data cleaning, data visualization

  • Recommended packages: dplyr, tidyr, ggplot2, kableExtra, others as needed

  • Examples:R for Data Science, Data Science Heroes

  • Data ideas to get you started:spotifyr, NYC Airbnb, college football games, Fitbit data

Interactive Shiny dashboard

  • Project goal: Similar to exploratory data analysis, load, clean, and analyze a dataset. Focus, however, on visualizing data in a Shiny dashboard. Your output should be either a Shiny dashboard with “server.R” and “ui.R” files, a flexdashboard with “runtime: shiny” or an html rmarkdown with “runtime: shiny.” Host your dashboard on shinyapps.io.

  • Questions to answer: Ask the same basic questions as the Exploratory Data Analysis project, but build a dashboard that allows users to generate the answers themselves. For example, instead of showing a histogram of Variable A, create a histogram chart that allows the user to select which variable to plot.

  • Resume skills practiced: R, Shiny, data visualization

  • Recommended packages: shiny, DT, others as needed

  • Examples: Covid-19 in the US (html document, source), hospital info (Shiny app, source)

  • Data ideas to get you started:Stock prices, World Bank data

Natural Language Processing (NLP) with R

  • Project goal: Replicate the analysis completed in this comprehensive example in order to draw analytical insight from a large body of unstructured text.

  • Questions to answer: What are the ten most frequent words in my corpus (excluding “stop words”)? What is the sentiment score of my corpus? How does sentiment change in each section in my corpus (e.g., chapter in my book)? What are the most common positive / negative words? What can tf-idf tell us about words unique to a part of my corpus (e.g., What words are most distinct to books A, B, and C)? Can I implement Latent Dirichlet allocation to separate my corpus into various topics?

  • Resume skills practiced: R, NLP, Text Mining, Machine Learning

  • Recommended packages: tidytext, topicmodels

  • Examples:Usenet text, Twitter data

  • Data ideas to get you started: Project Gutenberg library of books (website, gutenbergr package), Twitter API (rwteet package)

Machine learning with R

  • Project goal: Load a dataset, train a machine learning algorithm on part of the dataset, and use the rest of the dataset to test it. Create summary stats to evaluate the performance of your model.

  • Questions to answer: The types of questions you ask will vary tremendously based on the type of machine learning algorithm you want to implement. Try implementing one unsupervised and a handful of supervised algorithms. If you implement k-means (unsupervised), run your model with different seed values to find the lowest total within cluster sum of squares (SS), and plot total with SS against various numbers of clusters (k) to determine the optimal cluster count. Try to train several different supervised models (random forest, kNN, etc.) on the same dataset, and compare their results to pick the best one. Example here.

  • Resume skills practiced: R, Machine Learning

  • Recommended packages: caret

  • Examples:Machine Learning Mastery, MIT

  • Data ideas to get you started:UCI Machine Learning Repository, Hotel booking demand

var vglnk = {key: '949efb41171ac6ec1bf7f206d57e90b8'}; (function(d, t) { var s = d.createElement(t); s.type = 'text/javascript'; s.async = true; // s.defer = true; // s.src = '//cdn.viglink.com/api/vglnk.js'; s.src = 'https://www.r-bloggers.com/wp-content/uploads/2020/08/vglnk.js'; var r = d.getElementsByTagName(t)[0]; r.parentNode.insertBefore(s, r); }(document, 'script'));

To leave a comment for the author, please follow the link and comment on their blog: Articles - The Analyst Code.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The post 4 R projects to form a core data analyst portfolio first appeared on R-bloggers.

How isolate() can bite you in the butt

$
0
0

[This article was first published on Dean Attali's R Blog, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Debugging with Dean episode 2: Find out what mistake to avoid when using isolate() –

I’ll keep it short: The first episode of Debugging with Dean was a success, so I decided to keep going. In this video, I set out to see if an issue submitted to {shiny} was indeed a bug in shiny, and instead I found out a way that isolate() can break your app.

As always, I would warmly welcome any comments, including constructive criticism so I can improve. If you like my videos, make sure to subscribe so that I’ll know to keep making more!

var vglnk = {key: '949efb41171ac6ec1bf7f206d57e90b8'}; (function(d, t) { var s = d.createElement(t); s.type = 'text/javascript'; s.async = true; // s.defer = true; // s.src = '//cdn.viglink.com/api/vglnk.js'; s.src = 'https://www.r-bloggers.com/wp-content/uploads/2020/08/vglnk.js'; var r = d.getElementsByTagName(t)[0]; r.parentNode.insertBefore(s, r); }(document, 'script'));

To leave a comment for the author, please follow the link and comment on their blog: Dean Attali's R Blog.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The post How isolate() can bite you in the butt first appeared on R-bloggers.

time-lining the Trump presidency

$
0
0

[This article was first published on Jason Timm, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Introduction

A simple function from the uspols package – dubbed uspols_wiki_timeline()– that scrapes Wikipedia’s Timeline of the Donald Trump presidency. Facilitating, among other things, the ability to hover over data points in a time series to see what the President was up to on any given day over the course of the last four years.

library(tidyverse)
library(devtools)
devtools::install_github("jaytimm/uspols")
library(uspols) 

A simple call to the function returns a table of the president’s daily happenings via Wikipedia – from 20 January 2017 to the most recent update. This is clearly not an official accounting, and Wikipedia is not gospel. But a super quick/easy way to get one’s bearings (in a maelstrom) and contextualize data points.

longs <- uspols::uspols_wiki_timeline()

Table structure is detailed some below. The folks at Wikipedia have delineated events (chronologically?) via bullet points per each day of Trump’s presidency, which have been enumerated here in the bullets column as independent rows. I have mostly done this to make text easier to read/access/etc. I am not sure how meaningful event distinctions (for a given day) actually are.

longs %>%
  select(-quarter:-daypres, -dow) %>%
  head() %>%
  DT::datatable(rownames = FALSE, 
                options = list(dom = 't',
                               pageLength = 6,
                               scrollX = TRUE))

{"x":{"filter":"none","data":[["2017-01-20","2017-01-20","2017-01-20","2017-01-20","2017-01-20","2017-01-20"],[1,2,3,4,5,6],["45th President Donald Trump and 48th Vice President Mike Pence take the Oath of Office.","President Trump proclaims a National Day of Patriotic Devotion.","According to contested reports in December 2017, while seated at Trump's inauguration speech, forthcoming National Security Advisor Michael Flynn texts a former business partner that Russian sanctions blocking a private Russian-backed plan to build nuclear plants in the Middle East will now be 'ripped up'.","State officials in Florida, Delaware and New York confirm that they have not received paperwork that the President has relinquished control over his companies despite earlier promises to do so.","President Trump issues Executive Order 13765 to scale back parts of the Affordable Care Act.","The Trump administration suspends an Obama administration cut to Federal Housing Authority mortgage insurance premiums."]],"container":"

\n \n \n
date<\/th>\n bullet<\/th>\n Events<\/th>\n <\/tr>\n <\/thead>\n<\/table>","options":{"dom":"t","pageLength":6,"scrollX":true,"columnDefs":[{"className":"dt-right","targets":1}],"order":[],"autoWidth":false,"orderClasses":false,"lengthMenu":[6,10,25,50,100]}},"evals":[],"jsHooks":[]}

A simple use-case

summary <- longs %>%
  filter(!is.na(Events)) %>%
  mutate(tokens = tokenizers::count_words(Events)) %>%
  group_by(date) %>%
  mutate(daily_count = sum(tokens)) %>%
  slice(1) %>%
  ungroup()

For demonstration, we calculate total word counts of event descriptions per day from the time-line table. The plot below, then, summarizes these daily counts since inauguration. The plot itself is fairly meaningless, but the hover-action should be useful. For clarity purposes, only the first event for each day is included in the pop-up,.

dp <- summary %>%
  mutate(text = stringr::str_wrap(string = Events,
                                  width = 20,
                                  indent = 1,
                                  exdent = 1)) %>%
  
  plotly::plot_ly(x = ~date, 
                  y = ~daily_count,
                  text = ~text,
                  type = 'scatter',
                  mode = 'lines') %>%
  
  plotly::layout(#atitle = "Top 10 Drug Types", 
                 tooltip = c('Events'),
                 yaxis = list (title = "Daily event word count per Wikipedia"))

Example plot with Trump daily event on hover

{"x":{"visdat":{"5448523e0c56":["function () ","plotlyVisDat"]},"cur_data":"5448523e0c56","attrs":{"5448523e0c56":{"x":{},"y":{},"text":{},"mode":"lines","alpha_stroke":1,"sizes":[10,100],"spans":[1,20],"type":"scatter"}},"layout":{"margin":{"b":40,"l":60,"t":25,"r":10},"tooltip":"Events","yaxis":{"domain":[0,1],"automargin":true,"title":"Daily event word count per Wikipedia"},"xaxis":{"domain":[0,1],"automargin":true,"title":"date"},"hovermode":"closest","showlegend":false},"source":"A","config":{"showSendToCloud":false},"data":[{"x":["2017-01-20","2017-01-21","2017-01-22","2017-01-23","2017-01-24","2017-01-25","2017-01-26","2017-01-27","2017-01-28","2017-01-29","2017-01-30","2017-01-31","2017-02-01","2017-02-02","2017-02-03","2017-02-04","2017-02-05","2017-02-06","2017-02-07","2017-02-08","2017-02-09","2017-02-10","2017-02-11","2017-02-12","2017-02-13","2017-02-14","2017-02-15","2017-02-16","2017-02-17","2017-02-18","2017-02-19","2017-02-20","2017-02-21","2017-02-22","2017-02-23","2017-02-24","2017-02-25","2017-02-26","2017-02-27","2017-02-28","2017-03-01","2017-03-02","2017-03-03","2017-03-04","2017-03-05","2017-03-06","2017-03-07","2017-03-08","2017-03-09","2017-03-10","2017-03-11","2017-03-13","2017-03-14","2017-03-15","2017-03-16","2017-03-17","2017-03-18","2017-03-19","2017-03-20","2017-03-21","2017-03-22","2017-03-23","2017-03-24","2017-03-26","2017-03-27","2017-03-28","2017-03-29","2017-03-30","2017-03-31","2017-04-01","2017-04-02","2017-04-03","2017-04-04","2017-04-05","2017-04-06","2017-04-07","2017-04-08","2017-04-09","2017-04-10","2017-04-11","2017-04-12","2017-04-13","2017-04-14","2017-04-15","2017-04-16","2017-04-17","2017-04-18","2017-04-19","2017-04-20","2017-04-21","2017-04-22","2017-04-23","2017-04-24","2017-04-25","2017-04-26","2017-04-27","2017-04-28","2017-04-29","2017-04-30","2017-05-01","2017-05-02","2017-05-03","2017-05-04","2017-05-05","2017-05-06","2017-05-07","2017-05-08","2017-05-09","2017-05-10","2017-05-11","2017-05-12","2017-05-13","2017-05-14","2017-05-15","2017-05-16","2017-05-17","2017-05-18","2017-05-19","2017-05-20","2017-05-21","2017-05-22","2017-05-23","2017-05-24","2017-05-25","2017-05-26","2017-05-27","2017-05-28","2017-05-29","2017-05-30","2017-05-31","2017-06-01","2017-06-02","2017-06-03","2017-06-04","2017-06-05","2017-06-06","2017-06-07","2017-06-08","2017-06-09","2017-06-12","2017-06-13","2017-06-14","2017-06-15","2017-06-16","2017-06-17","2017-06-19","2017-06-20","2017-06-21","2017-06-22","2017-06-23","2017-06-24","2017-06-26","2017-06-27","2017-06-28","2017-06-29","2017-06-30","2017-07-01","2017-07-02","2017-07-03","2017-07-04","2017-07-05","2017-07-06","2017-07-07","2017-07-08","2017-07-09","2017-07-10","2017-07-11","2017-07-12","2017-07-13","2017-07-14","2017-07-17","2017-07-18","2017-07-19","2017-07-20","2017-07-21","2017-07-22","2017-07-24","2017-07-25","2017-07-26","2017-07-27","2017-07-28","2017-07-29","2017-07-31","2017-08-01","2017-08-02","2017-08-03","2017-08-04","2017-08-06","2017-08-07","2017-08-08","2017-08-09","2017-08-10","2017-08-11","2017-08-12","2017-08-13","2017-08-14","2017-08-15","2017-08-16","2017-08-17","2017-08-18","2017-08-19","2017-08-21","2017-08-22","2017-08-23","2017-08-24","2017-08-25","2017-08-28","2017-08-29","2017-08-30","2017-08-31","2017-09-01","2017-09-02","2017-09-03","2017-09-04","2017-09-05","2017-09-06","2017-09-07","2017-09-08","2017-09-09","2017-09-10","2017-09-11","2017-09-12","2017-09-13","2017-09-14","2017-09-15","2017-09-17","2017-09-18","2017-09-19","2017-09-20","2017-09-21","2017-09-22","2017-09-23","2017-09-24","2017-09-25","2017-09-26","2017-09-27","2017-09-28","2017-09-29","2017-09-30","2017-10-01","2017-10-02","2017-10-03","2017-10-04","2017-10-05","2017-10-06","2017-10-07","2017-10-08","2017-10-09","2017-10-10","2017-10-11","2017-10-12","2017-10-13","2017-10-15","2017-10-16","2017-10-17","2017-10-18","2017-10-19","2017-10-20","2017-10-22","2017-10-23","2017-10-24","2017-10-25","2017-10-26","2017-10-30","2017-10-31","2017-11-02","2017-11-03","2017-11-05","2017-11-06","2017-11-07","2017-11-08","2017-11-09","2017-11-10","2017-11-11","2017-11-12","2017-11-13","2017-11-14","2017-11-16","2017-11-20","2017-11-21","2017-11-27","2017-11-28","2017-11-29","2017-11-30","2017-12-01","2017-12-02","2017-12-03","2017-12-04","2017-12-05","2017-12-06","2017-12-07","2017-12-08","2017-12-09","2017-12-10","2017-12-11","2017-12-12","2017-12-13","2017-12-14","2017-12-15","2017-12-17","2017-12-18","2017-12-19","2017-12-20","2017-12-21","2017-12-22","2017-12-27","2017-12-28","2017-12-29","2018-01-01","2018-01-02","2018-01-03","2018-01-04","2018-01-05","2018-01-06","2018-01-08","2018-01-09","2018-01-10","2018-01-11","2018-01-12","2018-01-13","2018-01-15","2018-01-16","2018-01-17","2018-01-18","2018-01-19","2018-01-20","2018-01-21","2018-01-22","2018-01-23","2018-01-24","2018-01-25","2018-01-26","2018-01-29","2018-01-30","2018-01-31","2018-02-01","2018-02-02","2018-02-05","2018-02-06","2018-02-07","2018-02-08","2018-02-09","2018-02-12","2018-02-13","2018-02-15","2018-02-16","2018-02-20","2018-02-23","2018-02-24","2018-02-25","2018-02-27","2018-02-28","2018-03-01","2018-03-03","2018-03-05","2018-03-06","2018-03-07","2018-03-08","2018-03-09","2018-03-10","2018-03-11","2018-03-12","2018-03-13","2018-03-14","2018-03-15","2018-03-16","2018-03-20","2018-03-22","2018-03-23","2018-03-26","2018-03-28","2018-03-31","2018-04-02","2018-04-03","2018-04-04","2018-04-09","2018-04-10","2018-04-11","2018-04-12","2018-04-13","2018-04-16","2018-04-17","2018-04-18","2018-04-19","2018-04-21","2018-04-22","2018-04-23","2018-04-24","2018-04-25","2018-04-26","2018-04-27","2018-04-30","2018-05-01","2018-05-02","2018-05-03","2018-05-04","2018-05-05","2018-05-07","2018-05-08","2018-05-09","2018-05-10","2018-05-11","2018-05-14","2018-05-15","2018-05-16","2018-05-17","2018-05-18","2018-05-21","2018-05-22","2018-05-24","2018-05-25","2018-05-28","2018-06-01","2018-06-06","2018-06-07","2018-06-08","2018-06-09","2018-06-10","2018-06-11","2018-06-12","2018-06-15","2018-06-19","2018-06-25","2018-06-27","2018-07-02","2018-07-04","2018-07-05","2018-07-06","2018-07-09","2018-07-12","2018-07-13","2018-07-15","2018-07-16","2018-07-17","2018-07-18","2018-07-19","2018-07-20","2018-07-22","2018-07-23","2018-07-24","2018-07-25","2018-07-26","2018-07-29","2018-07-30","2018-07-31","2018-08-01","2018-08-02","2018-08-03","2018-08-09","2018-08-12","2018-08-13","2018-08-14","2018-08-15","2018-08-16","2018-08-17","2018-08-18","2018-08-19","2018-08-20","2018-08-21","2018-08-22","2018-08-23","2018-08-27","2018-08-30","2018-09-03","2018-09-04","2018-09-05","2018-09-07","2018-09-11","2018-09-12","2018-09-17","2018-09-18","2018-09-23","2018-09-24","2018-09-25","2018-09-26","2018-09-27","2018-09-28","2018-10-01","2018-10-02","2018-10-03","2018-10-05","2018-10-08","2018-10-09","2018-10-11","2018-10-15","2018-10-17","2018-10-19","2018-10-22","2018-10-24","2018-10-26","2018-11-02","2018-11-03","2018-11-05","2018-11-06","2018-11-07","2018-11-09","2018-11-10","2018-11-11","2018-11-14","2018-11-17","2018-11-18","2018-11-19","2018-11-20","2018-11-21","2018-11-22","2018-11-23","2018-11-25","2018-11-26","2018-11-28","2018-11-29","2018-11-30","2018-12-01","2018-12-03","2018-12-04","2018-12-05","2018-12-06","2018-12-07","2018-12-11","2018-12-12","2018-12-13","2018-12-15","2018-12-18","2018-12-19","2018-12-20","2018-12-21","2018-12-22","2018-12-23","2018-12-24","2018-12-25","2018-12-26","2018-12-27","2018-12-28","2018-12-29","2018-12-30","2018-12-31","2019-01-01","2019-01-02","2019-01-03","2019-01-04","2019-01-05","2019-01-06","2019-01-07","2019-01-08","2019-01-09","2019-01-10","2019-01-11","2019-01-12","2019-01-13","2019-01-14","2019-01-15","2019-01-16","2019-01-17","2019-01-18","2019-01-19","2019-01-20","2019-01-21","2019-01-22","2019-01-23","2019-01-24","2019-01-25","2019-01-28","2019-02-01","2019-02-05","2019-02-07","2019-02-11","2019-02-13","2019-02-14","2019-02-15","2019-02-18","2019-02-20","2019-02-24","2019-02-27","2019-02-28","2019-03-02","2019-03-04","2019-03-07","2019-03-14","2019-03-19","2019-03-20","2019-03-22","2019-03-24","2019-03-25","2019-03-26","2019-03-27","2019-03-28","2019-04-02","2019-04-04","2019-04-05","2019-04-06","2019-04-07","2019-04-08","2019-04-09","2019-04-10","2019-04-11","2019-04-12","2019-04-15","2019-04-16","2019-04-18","2019-04-22","2019-04-26","2019-04-27","2019-04-29","2019-05-01","2019-05-02","2019-05-03","2019-05-06","2019-05-08","2019-05-09","2019-05-10","2019-05-11","2019-05-13","2019-05-14","2019-05-16","2019-05-17","2019-05-20","2019-05-22","2019-05-24","2019-05-25","2019-05-26","2019-05-27","2019-05-28","2019-05-29","2019-05-30","2019-06-01","2019-06-02","2019-06-03","2019-06-04","2019-06-05","2019-06-06","2019-06-07","2019-06-10","2019-06-11","2019-06-12","2019-06-13","2019-06-14","2019-06-18","2019-06-19","2019-06-20","2019-06-21","2019-06-22","2019-06-24","2019-06-25","2019-06-26","2019-06-27","2019-06-28","2019-06-29","2019-06-30","2019-07-01","2019-07-02","2019-07-04","2019-07-09","2019-07-11","2019-07-12","2019-07-14","2019-07-15","2019-07-16","2019-07-17","2019-07-18","2019-07-19","2019-07-22","2019-07-23","2019-07-24","2019-07-25","2019-07-26","2019-07-27","2019-07-28","2019-07-29","2019-07-31","2019-08-01","2019-08-02","2019-08-03","2019-08-04","2019-08-05","2019-08-07","2019-08-12","2019-08-13","2019-08-15","2019-08-16","2019-08-20","2019-08-21","2019-08-22","2019-08-23","2019-08-24","2019-08-25","2019-08-26","2019-08-28","2019-08-29","2019-08-30","2019-08-31","2019-09-03","2019-09-05","2019-09-06","2019-09-09","2019-09-10","2019-09-11","2019-09-13","2019-09-16","2019-09-17","2019-09-18","2019-09-19","2019-09-20","2019-09-22","2019-09-23","2019-09-24","2019-09-25","2019-09-26","2019-09-27","2019-09-30","2019-10-01","2019-10-02","2019-10-03","2019-10-06","2019-10-07","2019-10-08","2019-10-10","2019-10-11","2019-10-14","2019-10-15","2019-10-16","2019-10-17","2019-10-19","2019-10-21","2019-10-22","2019-10-23","2019-10-24","2019-10-26","2019-10-27","2019-10-28","2019-10-29","2019-10-30","2019-10-31","2019-11-01","2019-11-03","2019-11-04","2019-11-05","2019-11-06","2019-11-07","2019-11-09","2019-11-11","2019-11-13","2019-11-14","2019-11-15","2019-11-16","2019-11-19","2019-11-20","2019-11-21","2019-11-24","2019-11-25","2019-11-26","2019-11-28","2019-12-01","2019-12-02","2019-12-03","2019-12-04","2019-12-05","2019-12-09","2019-12-10","2019-12-11","2019-12-13","2019-12-17","2019-12-18","2019-12-19","2019-12-20","2019-12-21","2019-12-27","2019-12-29","2019-12-31","2020-01-02","2020-01-03","2020-01-04","2020-01-05","2020-01-06","2020-01-07","2020-01-08","2020-01-09","2020-01-10","2020-01-11","2020-01-14","2020-01-15","2020-01-16","2020-01-17","2020-01-19","2020-01-20","2020-01-21","2020-01-22","2020-01-23","2020-01-24","2020-01-25","2020-01-27","2020-01-28","2020-01-29","2020-01-30","2020-01-31","2020-02-02","2020-02-03","2020-02-04","2020-02-05","2020-02-06","2020-02-07","2020-02-09","2020-02-10","2020-02-11","2020-02-12","2020-02-13","2020-02-14","2020-02-16","2020-02-18","2020-02-19","2020-02-20","2020-02-21","2020-02-24","2020-02-25","2020-02-26","2020-02-28","2020-02-29","2020-03-02","2020-03-03","2020-03-04","2020-03-06","2020-03-07","2020-03-10","2020-03-11","2020-03-12","2020-03-13","2020-03-15","2020-03-16","2020-03-18","2020-03-21","2020-03-24","2020-03-25","2020-03-27","2020-03-28","2020-04-01","2020-04-02","2020-04-03","2020-04-06","2020-04-07","2020-04-08","2020-04-15","2020-04-16","2020-04-17","2020-04-20","2020-04-22","2020-04-23","2020-04-24","2020-04-28","2020-04-29","2020-04-30","2020-05-01","2020-05-03","2020-05-05","2020-05-06","2020-05-07","2020-05-08","2020-05-10","2020-05-11","2020-05-13","2020-05-14","2020-05-16","2020-05-18","2020-05-20","2020-05-21","2020-05-25","2020-05-26","2020-05-27","2020-05-28","2020-05-29","2020-05-30","2020-05-31","2020-06-01","2020-06-02","2020-06-03","2020-06-09","2020-06-10","2020-06-11","2020-06-13","2020-06-15","2020-06-16","2020-06-17","2020-06-18","2020-06-19","2020-06-20","2020-06-22","2020-06-23","2020-06-24","2020-06-25","2020-06-26","2020-06-29","2020-07-01","2020-07-02","2020-07-03","2020-07-04","2020-07-07","2020-07-08","2020-07-09","2020-07-10","2020-07-13","2020-07-14","2020-07-15","2020-07-16","2020-07-21","2020-07-22","2020-07-24","2020-07-27","2020-07-28","2020-07-29","2020-07-30","2020-07-31","2020-08-04","2020-08-05","2020-08-06","2020-08-08","2020-08-12","2020-08-13","2020-08-14","2020-08-17","2020-08-18","2020-08-19","2020-08-20","2020-08-24","2020-08-25","2020-08-26","2020-08-27","2020-08-28","2020-08-31","2020-09-01","2020-09-02","2020-09-03","2020-09-04","2020-09-08","2020-09-09","2020-09-10","2020-09-11","2020-09-12","2020-09-13","2020-09-14","2020-09-15","2020-09-16","2020-09-17","2020-09-18","2020-09-19","2020-09-20","2020-09-21","2020-09-22","2020-09-23","2020-09-24","2020-09-25","2020-09-26","2020-09-28","2020-09-29","2020-09-30","2020-10-01","2020-10-02","2020-10-03","2020-10-04","2020-10-05","2020-10-06","2020-10-07","2020-10-08","2020-10-09","2020-10-10","2020-10-12","2020-10-13","2020-10-14","2020-10-15","2020-10-16","2020-10-17","2020-10-18","2020-10-19","2020-10-20","2020-10-21","2020-10-22","2020-10-23","2020-10-24","2020-10-25","2020-10-26","2020-10-27","2020-10-28","2020-10-29","2020-10-30","2020-10-31","2020-11-01","2020-11-02","2020-11-03","2020-11-04","2020-11-05","2020-11-06"],"y":[221,126,101,195,158,114,148,199,174,115,214,44,129,160,163,81,37,32,137,92,110,99,78,35,108,173,132,232,108,43,26,67,68,94,108,130,50,20,129,163,94,181,94,137,68,58,84,120,125,127,41,69,135,150,216,113,58,45,168,146,102,60,179,39,133,181,176,166,241,64,85,182,234,104,228,157,40,139,83,143,137,157,176,23,55,90,90,80,165,126,93,72,139,128,150,82,95,116,39,132,142,19,87,53,22,22,213,111,102,173,123,44,27,92,106,119,126,73,45,108,69,142,80,132,106,101,91,67,35,104,79,55,32,58,91,81,69,77,65,84,96,82,145,136,62,82,68,92,116,91,17,106,59,149,65,153,40,62,41,99,80,205,77,178,72,33,56,39,98,60,19,48,126,71,100,56,103,71,146,75,37,36,108,38,167,54,76,50,22,86,58,66,106,120,83,110,167,131,125,147,26,68,118,133,42,163,50,114,66,115,81,72,52,28,158,93,158,63,50,67,39,65,50,133,150,28,137,130,169,181,70,38,32,78,154,66,116,56,30,20,96,86,74,102,93,52,44,24,96,46,75,97,32,100,114,59,111,26,88,105,82,117,40,148,63,54,14,50,76,107,80,97,109,19,54,54,69,91,98,60,82,35,110,63,22,34,49,76,49,35,19,99,19,31,75,89,90,69,82,25,116,98,142,126,56,23,46,64,45,95,91,71,172,75,95,73,76,106,134,27,77,63,83,81,87,47,38,98,7,58,124,22,140,95,16,42,12,37,36,30,8,55,29,67,22,97,34,36,23,8,26,42,93,40,16,103,95,72,67,28,23,12,110,15,45,39,40,22,54,10,20,21,32,31,33,72,56,48,41,180,23,104,19,25,34,12,38,61,23,59,19,58,98,20,14,71,11,15,49,24,27,26,16,42,42,26,62,44,66,27,14,32,32,27,20,32,69,83,17,63,232,16,16,34,16,24,27,22,35,15,68,32,103,302,161,115,271,226,138,217,80,278,22,282,63,102,88,105,36,72,164,94,119,255,158,127,96,143,229,109,155,15,25,49,8,45,26,19,16,50,19,35,66,77,43,35,15,26,20,15,20,27,8,23,14,38,8,18,31,10,9,14,16,55,45,27,48,129,62,24,13,23,167,10,95,42,40,41,33,93,67,104,66,101,43,31,43,61,46,12,12,78,46,138,76,74,71,85,30,38,7,7,7,7,7,68,77,37,30,7,7,22,22,18,47,7,27,7,42,46,84,167,70,61,15,84,7,177,21,181,74,21,57,8,9,16,17,21,27,15,8,39,34,16,25,16,16,19,7,73,50,35,26,45,9,16,28,32,12,16,15,36,11,65,39,18,35,29,14,32,26,37,30,14,16,47,79,27,36,9,16,7,22,31,80,26,15,35,25,31,15,18,16,19,30,75,64,41,41,21,14,8,19,17,26,68,52,16,68,34,23,38,88,65,42,81,161,17,23,42,19,11,47,31,19,17,76,49,12,16,18,20,37,22,22,34,11,15,8,38,43,73,27,36,20,8,43,17,31,14,27,18,19,27,79,23,66,130,31,21,11,23,31,28,69,9,33,17,41,24,63,31,94,100,158,119,32,45,38,160,23,25,84,77,22,124,106,34,106,126,37,58,101,72,35,39,31,70,36,77,71,34,61,90,25,22,108,19,15,54,58,133,105,49,91,85,42,52,50,29,52,31,82,88,29,61,35,26,46,15,47,102,21,40,102,32,45,39,74,19,20,45,55,60,124,36,31,38,47,37,17,28,59,35,66,30,42,40,103,43,40,22,63,36,61,80,87,50,31,8,9,101,48,35,68,41,47,8,90,9,24,99,41,45,34,51,53,23,82,15,11,97,36,53,21,48,123,38,53,93,71,19,123,74,35,19,78,23,63,28,20,22,55,48,65,13,38,14,29,51,5,37,87,58,48,69,40,5,29,29,43,7,32,26,80,38,39,24,59,212,15,69,40,24,13,34,23,40,45,82,28,59,33,32,79,89,26,43,54,19,23,18,25,45,35,46,18,112,24,30,66,51,13,16,22,24,29,22,24,67,40,19,24,23,59,18,24,24,27,23,46,24,90,27,35,21,116,9,78,39,38,48,85,14,30,48,38,91,112,177,123,59,75,89,152,82,93,63,16,32,55,71,60,46,33,36,13,34,28,34,34,14,14,15,48,66,34,15,16,14,15,29,43,19,65,63,52,17,14,20,18,25,25,42,38,145,21],"text":[" 45th President<br /> Donald Trump and<br /> 48th Vice President<br /> Mike Pence take the<br /> Oath of Office."," Four million people<br /> around the world<br /> attend the Women's<br /> March protesting the<br /> new administration.<br /> It was the largest<br /> single-day protest<br /> in U.S. history."," President Trump<br /> calls Israeli Prime<br /> Minister Benjamin<br /> Netanyahu to discuss<br /> Iran, ISIS, and the<br /> Israeli–Palestinian<br /> peace process."," President Trump<br /> meets with twelve<br /> CEOs of major U.S.<br /> companies."," President Trump<br /> signs Executive<br /> Order 13766,<br /> which expedites<br /> environmental<br /> reviews and<br /> approvals for future<br /> infrastructure<br /> projects."," President Trump<br /> issues Executive<br /> Order 13767<br /> directing the<br /> Department of<br /> Homeland Security to<br /> begin construction<br /> of a wall on the<br /> Mexico–United States<br /> border. Mexican<br /> President Enrique<br /> Peña Nieto rejects<br /> the idea that Mexico<br /> would pay for any<br /> border wall between<br /> the United States<br /> and his country."," President Trump<br /> visits Philadelphia<br /> to address<br /> Congressional<br /> Republican leaders,<br /> regarding his<br /> agenda. He speaks<br /> at the Loews Hotel,<br /> along with British<br /> Prime Minister<br /> Theresa May."," President Trump<br /> speaks with Mexican<br /> President Enrique<br /> Peña Nieto on the<br /> phone to discuss<br /> Mexico–United States<br /> relations in lieu<br /> of their canceled<br /> meeting."," President Trump<br /> speaks on the<br /> phone with Russian<br /> President Vladimir<br /> Putin, German<br /> Chancellor Angela<br /> Merkel, Japanese<br /> Prime Minister<br /> Shinzō Abe,<br /> Australian Prime<br /> Minister Malcolm<br /> Turnbull, and French<br /> President François<br /> Hollande."," President Trump<br /> speaks with Saudi<br /> Arabia's King Salman<br /> and acting South<br /> Korean President<br /> Hwang Kyo-ahn."," President Trump<br /> signs Executive<br /> Order 13771, which<br /> seeks to reduce the<br /> number of federal<br /> regulations by<br /> requiring agencies<br /> to repeal two<br /> existing regulations<br /> for every new rule<br /> introduced."," President Trump<br /> nominates Neil<br /> Gorsuch as an<br /> Associate Justice<br /> of the Supreme Court<br /> to fill the vacancy<br /> left by Antonin<br /> Scalia, who died in<br /> February 2016."," President Trump<br /> visits Dover Air<br /> Force Base for<br /> the arrival of<br /> the remains of<br /> Navy SEAL Chief<br /> Special Warfare<br /> Operator William<br /> Owens who had been<br /> killed in action<br /> in Yemen three days<br /> prior, the first<br /> known combat death<br /> under the Trump<br /> administration."," President Trump<br /> speaks at the<br /> National Prayer<br /> Breakfast and holds<br /> a bilateral meeting<br /> with King Abdullah<br /> II of Jordan.<br /> He also promises<br /> to dismantle the<br /> Johnson Amendment<br /> prohibiting<br /> religious<br /> organisations from<br /> giving political<br /> donations while<br /> maintaining a tax-<br /> free status."," President Trump<br /> signs Executive<br /> Order 13772, which<br /> instates a review of<br /> the Dodd–Frank Act."," President Trump's<br /> official Facebook<br /> page makes a false<br /> claim about Kuwait<br /> instating a travel<br /> ban similar to<br /> Executive Order<br /> 13769, while the<br /> Department of<br /> Justice appeals<br /> a court decision<br /> to overturn the<br /> executive order. The<br /> President criticizes<br /> James Robart for<br /> making the decision,<br /> referring to him as<br /> a \"so-called judge\"."," The Ninth Circuit<br /> Court of Appeals<br /> denies a request<br /> from the Trump<br /> Administration<br /> to immediately<br /> reinstate the<br /> temporarily blocked<br /> travel ban."," President Trump<br /> addresses troops<br /> at the MacDill Air<br /> Force Base and the<br /> Central Command."," The Senate confirms<br /> Betsy DeVos as the<br /> 11th U.S. Secretary<br /> of Education by<br /> a vote of 51–50.<br /> As president of<br /> the Senate, Vice<br /> President Mike Pence<br /> is the first vice<br /> president since<br /> 1945, to cast a tie-<br /> breaking vote to<br /> confirm a Cabinet<br /> member."," The Senate confirms<br /> Jeff Sessions as the<br /> 84th U.S. Attorney<br /> General in a vote of<br /> 52–47."," Jeff Sessions is<br /> sworn in as the<br /> 84th U.S. Attorney<br /> General."," President Trump<br /> holds a bilateral<br /> meeting and joint<br /> press conference<br /> with Japanese Prime<br /> Minister Shinzō Abe<br /> at the White House.<br /> The two leaders<br /> travel to Mar-a-<br /> Lago in Palm Beach,<br /> Florida."," President Trump<br /> and Japanese Prime<br /> Minister Shinzō Abe<br /> play golf together<br /> at the Trump<br /> National Golf Club<br /> in Jupiter, Florida<br /> and reportedly<br /> discuss the \"future<br /> of the world, future<br /> of the region, and<br /> future of Japan and<br /> the United States,\"<br /> as well as a North<br /> Korean Pukkuksong-2<br /> missile which was<br /> test-launched during<br /> the meeting."," Stephen Miller, a<br /> White House advisor,<br /> repeats the claim<br /> of illegal voting<br /> on a television<br /> interview."," President Trump<br /> holds a bilateral<br /> meeting and joint<br /> press conference<br /> with Canadian Prime<br /> Minister Justin<br /> Trudeau at the White<br /> House."," FBI Director James<br /> Comey and other<br /> officials give<br /> President Trump<br /> a briefing on<br /> counter-terrorism<br /> in the Oval Office.<br /> According to a<br /> statement Comey<br /> would later make<br /> to the Senate<br /> Intelligence<br /> Committee, after<br /> the briefing, Trump<br /> speaks to Comey one-<br /> on-one about the<br /> FBI investigation of<br /> Mike Flynn, saying<br /> \"I hope you can let<br /> this go\"."," President Trump<br /> holds a bilateral<br /> meeting and joint<br /> press conference<br /> with Israeli Prime<br /> Minister Benjamin<br /> Netanyahu at the<br /> White House. Trump<br /> calls on Netanyahu<br /> to \"hold back\" the<br /> construction of<br /> settlements in the<br /> West Bank."," Alexander Acosta<br /> is nominated to be<br /> Secretary of Labor,<br /> and Mick Mulvaney<br /> is sworn in as the<br /> director of the<br /> Office of Management<br /> and Budget in a vote<br /> of 51–49."," President Trump<br /> visits Boeing's<br /> North Charleston,<br /> South Carolina<br /> assembly facility<br /> for the unveiling<br /> of its new 787-10<br /> Dreamliner aircraft.<br /> He emphasizes his<br /> administration's<br /> commitment to<br /> improve the business<br /> climate and help<br /> create American<br /> jobs."," President Trump<br /> holds a rally in<br /> Melbourne, Florida,<br /> attended by an<br /> estimated 9,000<br /> supporters, where he<br /> defends his actions<br /> and criticizes the<br /> media."," The Trump<br /> administration<br /> asks the Council of<br /> Economic Advisers to<br /> predict 3.5% annual<br /> GDP growth, while<br /> the Federal Reserve<br /> had predicted 1.8%,<br /> just over half that."," Lieutenant general<br /> H. R. McMaster is<br /> appointed the 26th<br /> National Security<br /> Advisor. Keith<br /> Kellogg, who had<br /> been the acting<br /> National Security<br /> Advisor, remains<br /> as the National<br /> Security Council's<br /> Chief of Staff"," President Trump<br /> visits the National<br /> Museum of African<br /> American History<br /> and Culture<br /> and addresses<br /> the increase in<br /> vandalism and bomb<br /> threats at Jewish<br /> community centers<br /> around the country."," The Trump<br /> International<br /> Hotel in Washington<br /> D.C. received 40-<br /> $60,000 dollars<br /> from an event paid<br /> for by the Embassy<br /> of Kuwait, which<br /> has been argued to<br /> break the Emoluments<br /> Clause because the<br /> President has not<br /> divested from his<br /> companies."," President Trump<br /> meets with 24<br /> manufacturing CEOs<br /> at the White House."," President Trump<br /> holds a bilateral<br /> meeting with<br /> Peruvian President<br /> Pedro Pablo<br /> Kuczynski at the<br /> White House."," President Trump<br /> discusses the<br /> Affordable Care<br /> Act and the states'<br /> role in healthcare<br /> with Governor of<br /> Wisconsin Scott<br /> Walker and Governor<br /> of Florida Rick<br /> Scott."," Philip M. Bilden<br /> withdraws from<br /> his nomination for<br /> Secretary of the<br /> Navy."," President Trump<br /> proposes a 10%<br /> increase in military<br /> spending of $54<br /> billion diverted<br /> from numerous other<br /> budgets, including<br /> that of the State<br /> Department and<br /> the Environmental<br /> Protection Agency.<br /> Congress receives a<br /> letter criticizing<br /> this plan, signed<br /> by more than<br /> 120 retired U.S.<br /> admirals and<br /> generals, including<br /> a former Army Chief<br /> of Staff George W.<br /> Casey Jr."," Wilbur Ross is<br /> sworn in as the 39th<br /> U.S. Secretary of<br /> Commerce."," The Senate confirms<br /> Ryan Zinke as the<br /> 52nd U.S. Secretary<br /> of the Interior by a<br /> vote of 68–31."," President Trump<br /> tells reporters<br /> that he has \"total\"<br /> confidence in<br /> Attorney General<br /> Jeff Sessions, then<br /> delivers a speech<br /> aboard the aircraft<br /> carrier USS Gerald<br /> R. Ford (CVN-78),<br /> reiterating his<br /> commitment to<br /> increase military<br /> spending."," The White House<br /> hires three former<br /> lobbyists in<br /> agencies they had<br /> lobbied against,<br /> in violation of<br /> President Trump's<br /> own ethics rules."," In a series of<br /> tweets, President<br /> Trump publicly<br /> accuses former<br /> President Obama<br /> of intercepting<br /> communications<br /> at his offices in<br /> New York City's<br /> Trump Tower in<br /> October 2016; Obama<br /> spokesman Kevin<br /> Lewis denies the<br /> claim."," James R. Clapper,<br /> a former Director<br /> of National<br /> Intelligence, denies<br /> the wiretapping<br /> claims of President<br /> Trump's election<br /> campaign and states<br /> that the agencies<br /> he supervised<br /> found \"no evidence<br /> of collusion\"<br /> between the Trump<br /> campaign and Russian<br /> officials."," President Trump<br /> signs Executive<br /> Order 13780, seen<br /> as a revised version<br /> of Executive Order<br /> 13769, effective<br /> March 16, removing<br /> Iraq from affected<br /> countries and<br /> clarifying that<br /> lawful permanent<br /> residents are<br /> excluded from<br /> the travel ban.<br /> Trump also signs<br /> a memorandum to<br /> increase immigration<br /> law enforcement."," President Trump<br /> speaks on the<br /> telephone with Prime<br /> Minister Shinzō<br /> Abe to voice his<br /> support for Japan<br /> in reaction to new<br /> reports of North<br /> Korean missile<br /> tests."," Formal drafting of<br /> the repeal of the<br /> Affordable Care Act<br /> begins."," President Trump<br /> pledges to remove<br /> certain regulations<br /> pertaining to the<br /> Dodd–Frank Wall<br /> Street Reform and<br /> Consumer Protection<br /> Act at a White<br /> House meeting with<br /> community bankers."," President Trump<br /> speaks by telephone<br /> with Palestinian<br /> President Mahmoud<br /> Abbas, extending a<br /> personal invitation<br /> to the White House."," President Trump<br /> meets with Secretary<br /> of Homeland<br /> Security John Kelly,<br /> Secretary of the<br /> Treasury Steven<br /> Mnuchin, Secretary<br /> of Commerce Wilbur<br /> Ross and Secretary<br /> of Veterans Affairs<br /> David Shulkin at the<br /> Trump National Golf<br /> Club, where they<br /> discuss healthcare<br /> and the economy."," President Trump<br /> signs Executive<br /> Order 13781, to<br /> reduce operating<br /> costs of the federal<br /> government."," President Trump<br /> hosts Saudi Deputy<br /> Crown Prince<br /> Mohammad bin Salman<br /> at the White House."," President Trump<br /> makes remarks at the<br /> American Center for<br /> Mobility at Willow<br /> Run in Ypsilanti,<br /> Michigan and later<br /> holds a political<br /> rally in Nashville,<br /> Tennessee, at<br /> which he criticizes<br /> the court rulings<br /> against the travel<br /> ban."," The Trump<br /> Administration<br /> releases a<br /> preliminary draft<br /> of its 2018 budget<br /> request. The<br /> budget's largest<br /> relative increases<br /> in spending include<br /> the Departments of<br /> Defense, Homeland<br /> Security, and<br /> Veterans Affairs,<br /> while the largest<br /> cuts apply to the<br /> EPA, Foreign Aid,<br /> and the Departments<br /> of Labor and<br /> Agriculture, as<br /> well as a 20 percent<br /> cut to National<br /> Institutes of<br /> Health. Trump also<br /> signs a memorandum<br /> directed at Speaker<br /> of the House Paul<br /> Ryan requesting<br /> additional funds for<br /> the departments of<br /> Defense and Homeland<br /> Security."," President Trump<br /> holds a bilateral<br /> meeting and joint<br /> press conference<br /> with German<br /> Chancellor Angela<br /> Merkel at the White<br /> House."," President Trump<br /> speaks by telephone<br /> with Brazilian<br /> President Michel<br /> Temer and Chilean<br /> President Michelle<br /> Bachelet."," German Defense<br /> Minister Ursula von<br /> der Leyen rejects<br /> a statement by<br /> President Trump<br /> on 18 March that<br /> Germany owes a<br /> financial debt to<br /> NATO."," President<br /> Trump issues a<br /> tweet rejecting<br /> allegations of<br /> collusion with<br /> Russia as \"fake<br /> news\"."," President Trump<br /> signs a bill which<br /> defines the budget<br /> and objectives of<br /> NASA, including a<br /> crewed mission to<br /> Mars as early as<br /> 2033. The draft<br /> 2018 budget expands<br /> support of public-<br /> private partnerships<br /> for deep-space<br /> habitation, revives<br /> a supersonic flight<br /> research program,<br /> strengthens NASA's<br /> cybersecurity,<br /> increases focus<br /> on planetary<br /> science and robotic<br /> exploration,<br /> cancels the Europa<br /> lander and Asteroid<br /> Redirect Mission,<br /> terminates four<br /> Earth science<br /> missions, and<br /> eliminates the NASA<br /> Office of Education,<br /> resulting in an<br /> overall 0.8% budget<br /> decrease.:43–44"," President Trump<br /> is briefed by<br /> Devin Nunes, who<br /> also holds a news<br /> conference at the<br /> White House, on the<br /> evidence concerning<br /> Trump's wiretapping<br /> allegations which<br /> he was shown on the<br /> White House grounds<br /> on the previous day."," The first major<br /> Congressional vote<br /> on President Trump's<br /> planned repeal and<br /> replacement of the<br /> Affordable Care Act<br /> is postponed until<br /> March 24."," With the consent<br /> of President Trump,<br /> House Speaker Paul<br /> Ryan indefinitely<br /> postpones the first<br /> major Congressional<br /> vote on the repeal<br /> and replacement of<br /> the Affordable Care<br /> Act, due to lack of<br /> support from both<br /> sides of Congress."," Vice President<br /> Pence delivers an<br /> evening speech to<br /> the American Israel<br /> Public Affairs<br /> Committee (AIPAC)<br /> at Washington D.C.'s<br /> Verizon Center,<br /> reaffirming the<br /> United States'<br /> commitments to<br /> Israeli defense, and<br /> to prevent Iran's<br /> nuclear program from<br /> producing a weapon."," President Trump<br /> signs a memorandum<br /> creating the White<br /> House Office of<br /> American Innovation,<br /> consisting of 2<br /> senior advisors<br /> and 8 assistants to<br /> the president, to<br /> be headed by Jared<br /> Kushner."," President Trump<br /> signs Executive<br /> Order 13783, which<br /> removes a directive<br /> to consider climate<br /> change during<br /> deliberations<br /> under the National<br /> Environmental<br /> Policy Act, removes<br /> restrictions<br /> on fracking,<br /> and directs the<br /> Environmental<br /> Protection Agency<br /> to suspend, revise<br /> or abolish the Clean<br /> Power Plan."," President Trump<br /> signs Executive<br /> Order 13784<br /> to combat drug<br /> addiction and the<br /> opioid epidemic.<br /> Trump also hosts<br /> a meeting in the<br /> Cabinet Room,<br /> concerning opioids<br /> and drug abuse."," President Trump<br /> calls FBI Director<br /> James Comey, asserts<br /> that he wasn't<br /> involved with<br /> Russian hookers<br /> and asks Comey to<br /> \"lift the cloud\"<br /> of the Russia<br /> investigation."," Tom Price, the<br /> Secretary of Health<br /> and Human Services,<br /> purchases 90,000<br /> dollars worth of<br /> pharmaceutical<br /> stocks a month<br /> before the signing<br /> of a bill which<br /> benefits them."," Vice President<br /> Mike Pence delivers<br /> a speech in<br /> Reynoldsburg, Ohio,<br /> remarking on his<br /> continuing support<br /> for Supreme Court<br /> nominee Neil Gorsuch<br /> and indicating that<br /> the campaign to<br /> repeal and replace<br /> the Affordable Care<br /> Act remains ongoing."," A federal judge<br /> rules that before<br /> the presidency Trump<br /> may have incited<br /> violence at a rally<br /> in 2016 in Kentucky."," President Trump<br /> holds a bilateral<br /> meeting with<br /> Egyptian President<br /> Abdel Fattah el-Sisi<br /> at the White House,<br /> praising Sisi's<br /> leadership and<br /> offering continuing<br /> support for Egypt's<br /> anti-terrorism<br /> measures."," The Congressional<br /> Review Act removes<br /> a requirement for<br /> employers to collect<br /> accurate records on<br /> workplace accidents."," President Trump<br /> holds a bilateral<br /> meeting and joint<br /> press conference<br /> with King Abdullah<br /> II of Jordan at<br /> the White House,<br /> pledging to<br /> assist Jordan in<br /> eradicating ISIS and<br /> in promoting peace<br /> between Israelis and<br /> Palestinians."," President Trump<br /> orders a strike<br /> on the Shayrat Air<br /> Base in Homs, Syria,<br /> using 59 Tomahawk<br /> cruise missiles in<br /> retaliation for the<br /> chemical weapons<br /> attack on April 4.<br /> The strike is the<br /> first targeted<br /> attack by the<br /> U.S. military on<br /> Ba'athist Syrian<br /> government forces<br /> since the war<br /> began. Delivering<br /> a statement at<br /> Mar-a-Lago, Trump<br /> declares an intent<br /> to protect American<br /> national security by<br /> deterring the use of<br /> chemical weaponry."," President Trump and<br /> Chinese President<br /> Xi Jinping continue<br /> talks during the<br /> second day at Mar-<br /> a-Lago, concerning<br /> trade and North<br /> Korea. President Xi<br /> leaves on schedule<br /> later on the same<br /> day."," President Trump<br /> sends a letter of<br /> notification to<br /> Congress concerning<br /> his recent<br /> missile strike<br /> against Syrian<br /> government forces<br /> and indicating<br /> the possibility of<br /> further action."," President Trump<br /> issues a statement<br /> on Twitter<br /> condemning a pair<br /> of fatal terrorist<br /> bombings in the<br /> Egyptian cities of<br /> Tanta and Alexandria<br /> and expressing<br /> his confidence in<br /> President Sisi's<br /> ability to respond."," President Trump<br /> conducts discussions<br /> on the ongoing<br /> Syrian Civil War<br /> by telephone with<br /> British Prime<br /> Minister Theresa<br /> May and German<br /> Chancellor Angela<br /> Merkel."," The White House<br /> accuses Russia<br /> of attempting to<br /> cover up the Khan<br /> Shaykhun chemical<br /> attack with the use<br /> of disinformation<br /> tactics."," President Trump<br /> holds a bilateral<br /> meeting and joint<br /> press conference<br /> with NATO Secretary<br /> General Jens<br /> Stoltenberg at<br /> the White House,<br /> responding to<br /> perceived structural<br /> changes within<br /> the organization<br /> by retracting his<br /> prior accusations of<br /> NATO's obsolescence."," President Trump says<br /> \"North Korea is a<br /> problem. The problem<br /> will be taken care<br /> of,\" expressing<br /> confidence that<br /> Chinese President<br /> Xi Jinping will<br /> solve the problem.<br /> Trump issues a<br /> tweet stating that<br /> if China fails to<br /> resolve the issue,<br /> the U.S. and its<br /> allies will instead."," The Trump<br /> administration<br /> verifies that it<br /> will discontinue<br /> the practice<br /> of voluntarily<br /> releasing the White<br /> House visitors'<br /> log, following the<br /> filing of a federal-<br /> court lawsuit on<br /> April 10 by a group<br /> of organizations,<br /> including CREW,<br /> demanding the<br /> publication of<br /> such material under<br /> the Freedom of<br /> Information Act."," Tax Day March<br /> rallies are held<br /> throughout the<br /> U.S. President<br /> Trump responds the<br /> following day in two<br /> tweets, saying \"the<br /> election is over.\""," President Trump<br /> claims that protests<br /> against him were<br /> paid for."," President Trump<br /> calls leader<br /> of Turkey Recep<br /> Tayyip Erdoğan<br /> to congratulate<br /> his victory in<br /> a referendum<br /> increasing his<br /> powers, despite the<br /> State Department<br /> questioning<br /> the democratic<br /> legitimacy of the<br /> poll."," President Trump<br /> visits the<br /> headquarters of<br /> tool manufacturer<br /> Snap-on in Kenosha,<br /> Wisconsin, to sign<br /> Executive Order<br /> 13788, which intends<br /> to prevent abuse<br /> of the H-1B visa<br /> program and to give<br /> preference to U.S.-<br /> made products."," President Trump<br /> signs a bill into<br /> law extending the<br /> Veterans' Access to<br /> Care through Choice,<br /> Accountability, and<br /> Transparency Act of<br /> 2014."," President Trump<br /> signs a memorandum<br /> directing the<br /> Department of<br /> Commerce to begin<br /> an investigation<br /> on whether steel<br /> imports are a<br /> threat to U.S.<br /> national security,<br /> and another which<br /> provides initial<br /> reports on the<br /> implementation of<br /> the Global Magnitsky<br /> Human Rights<br /> Accountability Act."," President Trump<br /> signs one executive<br /> order and two<br /> memorandums. The<br /> executive order<br /> directs Treasury<br /> Secretary Steven<br /> Mnuchin to review<br /> the U.S. tax<br /> code to recommend<br /> unnecessary<br /> regulations to<br /> remove, and the<br /> two memorandums<br /> direct the Treasury<br /> Secretary to review<br /> portions of the<br /> Dodd–Frank Wall<br /> Street Reform and<br /> Consumer Protection<br /> Act."," President Trump and<br /> First Lady Melania<br /> Trump visit the<br /> Walter Reed National<br /> Military Medical<br /> Center in Maryland<br /> to award the Purple<br /> Heart to Sergeant<br /> First Class Alvaro<br /> Barrientos."," In response to polls<br /> showing the latest<br /> approval rating of<br /> any president since<br /> 1945, President<br /> Trump blames \"fake<br /> news\"."," It is revealed that<br /> former National<br /> Security Advisor<br /> Michael Flynn had<br /> failed to disclose a<br /> $33,000 payment from<br /> Russia Today while<br /> in the president's<br /> service."," The president<br /> publicly suggests<br /> breaking up the<br /> United States Court<br /> of Appeals for<br /> the Ninth Circuit<br /> after it block<br /> his defunding of<br /> sanctuary cities."," President Trump<br /> welcomes the Senate<br /> to the Eisenhower<br /> Executive Office<br /> Building prior to<br /> their briefing with<br /> the Secretary of<br /> Defense, State,<br /> Director of National<br /> Intelligence,<br /> and chairman of<br /> the Joint Chiefs<br /> of Staff on the<br /> issue of North<br /> Korea. Pence and<br /> the four officials<br /> brief the House of<br /> Representatives at<br /> the Capitol complex<br /> later in the day."," Speaking at the<br /> Oval Office,<br /> President Trump<br /> praises President Xi<br /> Jinping's diplomacy<br /> in respect of North<br /> Korea but warns<br /> of the continuing<br /> possibility of<br /> a \"major, major<br /> conflict\"."," Alex Acosta is<br /> sworn in as the 28th<br /> Secretary of Labor."," North Korea conducts<br /> another missile test<br /> from Bukchang, which<br /> fails shortly after<br /> liftoff. President<br /> Trump condemns this<br /> action as an insult<br /> to China."," CBS publishes an<br /> interview from<br /> April 29 in which<br /> President Trump<br /> suggests that<br /> China may have been<br /> responsible for<br /> the 2016 Democratic<br /> National Committee<br /> email leak."," In an interview<br /> with Bloomberg<br /> News, President<br /> Trump expresses an<br /> openness to meet<br /> with North Korean<br /> leader Kim Jong-<br /> un under the right<br /> circumstances."," President Trump<br /> speaks by telephone<br /> with Russian<br /> President Vladimir<br /> Putin for the first<br /> time since the Khan<br /> Shaykhun chemical<br /> attack. They discuss<br /> the ongoing Syrian<br /> Civil War, Middle<br /> Eastern terrorism,<br /> and issues<br /> concerning the<br /> North Korean nuclear<br /> missile program,<br /> and agree to meet in<br /> person."," President Trump<br /> holds a bilateral<br /> meeting and joint<br /> press conference<br /> with Palestinian<br /> President Mahmoud<br /> Abbas at the White<br /> House."," President Trump<br /> holds a bilateral<br /> meeting with<br /> Australian Prime<br /> Minister Malcolm<br /> Turnbull at the<br /> Intrepid Sea, Air<br /> & Space Museum, in<br /> Trump's first return<br /> to New York since<br /> his inauguration."," Mark Green withdraws<br /> from President<br /> Trump's nomination<br /> for the position<br /> of Secretary of<br /> the Army following<br /> prior controversial<br /> remarks made by<br /> Green concerning<br /> Muslims and<br /> concerning the LGBT<br /> community."," Sister of Jared<br /> Kushner, the<br /> president's advisor<br /> and son-in-law,<br /> solicits investments<br /> from Chinese<br /> business owners in<br /> return for American<br /> visas."," President Trump<br /> tweets a message<br /> of congratulation<br /> to Emmanuel Macron<br /> following his<br /> victory over Marine<br /> Le Pen in the<br /> French presidential<br /> election."," President Trump and<br /> French President-<br /> elect Emmanuel<br /> Macron speak by<br /> telephone and<br /> arrange to meet<br /> during a NATO summit<br /> scheduled for 25 May<br /> in Belgium."," President Trump<br /> removes James Comey<br /> from his position<br /> as FBI Director. The<br /> White House explains<br /> that it is acting on<br /> the recommendation<br /> of Deputy Attorney<br /> General Rod<br /> Rosenstein and<br /> Attorney General<br /> Sessions, citing<br /> Comey's public<br /> statements about<br /> the Clinton email<br /> investigation as<br /> the reason for the<br /> decision."," Following a<br /> separate meeting<br /> between Russian<br /> Foreign Minister<br /> Sergey Lavrov and<br /> Secretary of State<br /> Tillerson at the<br /> State Department<br /> earlier in the<br /> day, President<br /> Trump meets with<br /> Lavrov and Russian<br /> Ambassador Sergey<br /> Kislyak in the Oval<br /> Office; a meeting<br /> at which Trump<br /> divulges classified<br /> information. He<br /> also notes to them<br /> that \"I faced great<br /> pressure because of<br /> Russia. That’s taken<br /> off.\""," President Trump<br /> signs an executive<br /> order to initiate<br /> an investigation<br /> of allegations<br /> of voter fraud<br /> during the 2016<br /> U.S. presidential<br /> election, under a<br /> commission to be<br /> chaired by Vice<br /> President Pence.<br /> Kansas Secretary of<br /> State Kris Kobach, a<br /> prominent proponent<br /> of strict voter ID<br /> laws, is appointed<br /> vice-chair and will<br /> administer day-to-<br /> day operations."," President Trump<br /> suggests on Twitter<br /> and in an interview<br /> broadcast on 13 May<br /> the possibility of<br /> ceasing the practice<br /> of White House<br /> press briefings in<br /> favor of written<br /> statements."," The EPA announces<br /> an end to mining<br /> restrictions on<br /> Alaskan headwaters."," The White House<br /> describes North<br /> Korea as a \"flagrant<br /> menace\" in response<br /> to the test-launch<br /> of a missile from<br /> near Kusung into the<br /> Sea of Japan."," President Trump<br /> delivers a speech<br /> at the 36th Annual<br /> National Peace<br /> Officers' Memorial<br /> Service at the<br /> Capitol Building,<br /> reiterating his<br /> support for the<br /> police service."," President Trump<br /> holds a bilateral<br /> meeting and joint<br /> press conference<br /> with Turkish<br /> President Recep<br /> Tayyip Erdoğan at<br /> the White House."," President Trump<br /> delivers the<br /> commencement<br /> address at the<br /> Coast Guard Academy<br /> in New London,<br /> Connecticut, with a<br /> speech on the theme<br /> of persistence,<br /> claiming that “No<br /> politician—and I<br /> say this with great<br /> surety—has been<br /> treated worse or<br /> more unfairly.\""," President Trump<br /> holds a bilateral<br /> meeting and joint<br /> press conference<br /> with Colombian<br /> President Juan<br /> Manuel Santos at the<br /> White House."," President Trump<br /> leaves Washington<br /> D.C. for Saudi<br /> Arabia on his first<br /> official foreign<br /> tour."," President Trump is<br /> received in Riyadh<br /> by Salman bin<br /> Abdulaziz Al Saud<br /> and is awarded Saudi<br /> Arabia's highest<br /> civilian honor, the<br /> Collar of Abdulaziz<br /> Al Saud."," The president<br /> suggests cutting<br /> US$1.7 trillion<br /> over ten years<br /> from redistributive<br /> programs such as<br /> food stamps and<br /> Medicaid."," Continuing his<br /> tour of the Middle<br /> East and Europe,<br /> President Trump<br /> is met in Tel Aviv<br /> by Israeli Prime<br /> Minister Netanyahu<br /> and President Reuven<br /> Rivlin. He visits<br /> the Church of the<br /> Holy Sepulchre<br /> in Jerusalem and<br /> becomes the first<br /> sitting U.S.<br /> president to visit<br /> the Western Wall."," President Trump pays<br /> his respects at the<br /> Jewish Holocaust<br /> memorial Yad Vashem<br /> with Prime Minister<br /> Netanyahu."," President Trump<br /> meets privately<br /> with Pope Francis at<br /> Vatican City."," President Trump<br /> meets with European<br /> Council President<br /> Donald Tusk and<br /> European Commission<br /> President Jean-<br /> Claude Juncker at<br /> the European Council<br /> headquarters."," President Trump<br /> attends the 43rd<br /> G7 summit with<br /> world leaders of<br /> G7 in Taormina,<br /> Italy to discuss<br /> world issues such<br /> as trade, climate<br /> change and the<br /> migration crisis.<br /> Trump criticizes<br /> the large imports of<br /> German automobiles,<br /> pointing to the<br /> large U.S. trade<br /> deficit with<br /> Germany. Trump<br /> refuses to commit<br /> the U.S. to the<br /> Paris Agreement on<br /> climate change and<br /> cutting greenhouse<br /> emissions."," President<br /> Trump continues<br /> discussions with<br /> G7 leaders on a<br /> whole range of<br /> issues, agreeing<br /> on a communique<br /> on fighting<br /> protectionism in<br /> international trade,<br /> but disagreeing<br /> with a majority of a<br /> leaders on endorsing<br /> the Paris climate<br /> change accord."," President Trump<br /> issues an extended<br /> series of tweets,<br /> describing many<br /> recent White<br /> House leaks as<br /> 'fake news', and<br /> questioning the use<br /> of anonymous sources<br /> by the media."," President Trump<br /> performs a wreath-<br /> laying ceremony<br /> at the Tomb of the<br /> Unknown Soldier<br /> at the Arlington<br /> National Cemetery<br /> and gives a speech<br /> honoring those who<br /> have died fighting<br /> for the U.S., giving<br /> special mention to<br /> the fallen son of<br /> Homeland Security<br /> Secretary Kelly."," President Trump<br /> reiterates on<br /> Twitter his proposal<br /> to abandon the<br /> Senate's tradition<br /> of supermajority<br /> voting, in order<br /> to accelerate<br /> legislation."," The White House<br /> grants ethics<br /> waivers to 17 senior<br /> officials."," President Trump<br /> formally announces<br /> his intent to<br /> withdraw the U.S.<br /> from the 2015<br /> Paris climate<br /> agreement, prompting<br /> criticism from<br /> former and serving<br /> world leaders<br /> and the United<br /> Nations.Tesla's<br /> Elon Musk and Disney<br /> CEO Bob Iger resign<br /> from the president's<br /> business advisory<br /> council in protest."," President Trump<br /> signs The American<br /> Law Enforcement<br /> Heroes Act to<br /> provide federal<br /> grants to those<br /> federal and state<br /> law enforcement<br /> agencies that hire<br /> and train veterans;<br /> and The Public<br /> Safety Officers'<br /> Benefits Improvement<br /> Act that reduces the<br /> backlog of families<br /> awaiting approval<br /> of survivor benefits<br /> of public safety<br /> officers killed in<br /> the line of duty."," President Trump<br /> issues a pair of<br /> tweets sending<br /> a message of<br /> support to the UK<br /> and promoting his<br /> administration's<br /> halted travel ban<br /> following a briefing<br /> on a major terrorist<br /> incident in London."," On Twitter,<br /> President Trump<br /> criticizes London<br /> Mayor Sadiq Khan's<br /> response to the<br /> terrorist incident,<br /> drawing condemnation<br /> from members of the<br /> UK's governing and<br /> opposition parties,<br /> including British<br /> Prime Minister<br /> Theresa May."," The American<br /> ambassador to China<br /> resigns in response<br /> to the country<br /> leaving the Paris<br /> Agreement."," President Trump<br /> claims credit for<br /> helping to instigate<br /> the recent severing<br /> of diplomatic ties<br /> by Saudi Arabia,<br /> Bahrain, the UAE,<br /> Yemen, eastern<br /> Libya and the<br /> Maldives with the<br /> state of Qatar<br /> over allegations of<br /> terrorist funding."," President Trump<br /> announces his<br /> nomination of<br /> Christopher A. Wray<br /> for the directorship<br /> of the FBI."," President Trump<br /> addresses the<br /> Faith and Freedom<br /> Coalition's annual<br /> conference in<br /> Washington."," President Trump<br /> announces in a<br /> speech at the<br /> Department of<br /> Transportation that<br /> he will set up a<br /> special council to<br /> speed up the permit<br /> process to build<br /> roads and bridges."," President Trump<br /> holds his first<br /> full cabinet<br /> meeting at the<br /> White House since<br /> his inauguration,<br /> blaming the<br /> Democrats for<br /> delaying some of his<br /> nominees."," President Trump<br /> hosts a luncheon at<br /> the White House with<br /> Republican senators<br /> to discuss repealing<br /> the Affordable Care<br /> Act."," Special counsel<br /> Robert Mueller<br /> is conducting<br /> an investigation<br /> into whether the<br /> president obstructed<br /> justice."," President Trump<br /> and First Lady<br /> Melania Trump visit<br /> congressman Steve<br /> Scalise, who was<br /> critically wounded<br /> in the Virginia<br /> shooting incident a<br /> day earlier."," The administration<br /> partially rolls back<br /> the thawing of ties<br /> with Cuba."," President Trump<br /> sends a message of<br /> support via Twitter<br /> to the families of<br /> the USS Fitzgerald<br /> (DDG-62) crew<br /> members recently<br /> killed and injured<br /> in a collision in<br /> the Sea of Japan."," Secretary of Energy<br /> Rick Perry says he<br /> does not believe<br /> carbon dioxide to<br /> be causing climate<br /> change."," President Trump<br /> holds a bilateral<br /> meeting with<br /> Ukrainian President<br /> Petro Poroshenko<br /> at the White House,<br /> as new sanctions<br /> against Russia are<br /> announced."," President Trump<br /> visits Kirkwood<br /> Community<br /> College, Iowa, for<br /> demonstrations of<br /> new agricultural<br /> technology."," Two senior<br /> intelligence<br /> officials confirm<br /> to Robert Mueller<br /> that the president<br /> had asked them<br /> both to publicly<br /> announce that he had<br /> not colluded with<br /> Russia."," President Trump<br /> nominates Woody<br /> Johnson to be the<br /> next UK ambassador."," Vice President<br /> Pence attends a<br /> Republican National<br /> Committee event in<br /> Chicago to promote<br /> his administration's<br /> health bill."," The Supreme Court<br /> reinstates, as of<br /> June 29, President<br /> Trump's executive<br /> order temporarily<br /> banning travelers<br /> and refugees from<br /> six Muslim-majority<br /> countries (with the<br /> caveat that they<br /> have no direct ties<br /> to the U.S.), in<br /> advance of a full<br /> hearing scheduled<br /> for October 2017."," President Trump<br /> congratulates<br /> by telephone the<br /> new Taoiseach Leo<br /> Varadkar on winning<br /> the Fine Gael<br /> leadership contest."," President Trump<br /> meets with the<br /> families of<br /> victims of illegal<br /> immigrants and calls<br /> on Congress to enact<br /> new law-enforcement<br /> legislation."," The president<br /> tweets about Mika<br /> Brzezinski, saying<br /> she had been<br /> “bleeding badly from<br /> a face-lift.”"," Joe Scarborough<br /> and Mika Brzezinski<br /> claim that the<br /> White House had<br /> blackmailed with an<br /> article about their<br /> relationship in the<br /> National Enquirer,<br /> demanding they<br /> change their news<br /> coverage of him."," President Trump<br /> attends the<br /> Celebrate Freedom<br /> Concert in<br /> Washington, paying<br /> tribute to military<br /> veterans."," President Trump<br /> makes telephone<br /> calls to Chinese<br /> President Xi Jinping<br /> and Japanese Prime<br /> Minister Shinzō Abe<br /> to discuss trade<br /> issues and the North<br /> Korean threat."," President Trump<br /> speaks by telephone<br /> to German Chancellor<br /> Angela Merkel<br /> discussing issues<br /> including climate<br /> change, the Women's<br /> Entrepreneurship<br /> Financing Initiative<br /> and trade."," President Trump<br /> condemns on Twitter<br /> the successful<br /> test launch of a<br /> North Korean ICBM<br /> potentially capable<br /> of reaching Alaska<br /> or Australia."," President Trump, his<br /> family and advisors<br /> arrive in Warsaw,<br /> Poland, ahead of the<br /> G20 summit."," President Trump<br /> attends a joint<br /> press conference in<br /> Warsaw with Polish<br /> President Andrzej<br /> Duda, reaffirming<br /> the U.S. commitment<br /> to NATO and citing<br /> the \"severe\" options<br /> available in respect<br /> of North Korea."," President Trump<br /> attends the G20<br /> summit hosted by<br /> German Chancellor<br /> Angela Merkel."," President Trump<br /> holds a bilateral<br /> meeting with<br /> British Prime<br /> Minister Theresa<br /> May, promising to<br /> expedite a new trade<br /> deal."," The New York Times<br /> reports that Donald<br /> Trump Jr. “was<br /> promised damaging<br /> information about<br /> Hillary Clinton<br /> before agreeing to<br /> meet with a Kremlin-<br /> connected Russian<br /> lawyer during the<br /> 2016 campaign.”"," Vice President Pence<br /> holds bilateral<br /> meetings with<br /> Tunisian Prime<br /> Minister Youssef<br /> Chahed at the White<br /> House. Pence also<br /> speaks by telephone<br /> to Macedonian Prime<br /> Minister Zoran Zaev<br /> and Greek Prime<br /> Minister Alexis<br /> Tsipras."," President Trump<br /> speaks by telephone<br /> to Iraqi Prime<br /> Minister Haider<br /> al-Abadi to<br /> congratulate him on<br /> liberation of Mosul<br /> and to stress the<br /> need for a total<br /> defeat of ISIS."," President Trump<br /> nominates Dennis<br /> Shea, vice-<br /> chairman of the US–<br /> China Economic and<br /> Security Review<br /> Commission, as<br /> deputy U.S. Trade<br /> Representative."," President Trump and<br /> First Lady Melania<br /> Trump arrive in<br /> Paris for a two-<br /> day state visit.<br /> During the visit the<br /> president comments<br /> that French first<br /> lady Brigitte Macron<br /> is \"in such good<br /> shape\"."," President Trump<br /> and First Lady<br /> Melania Trump attend<br /> a Bastille Day<br /> military parade in<br /> Paris with French<br /> President Emmanuel<br /> Macron."," President Trump<br /> launches \"Made in<br /> America Week\" at<br /> the White House by<br /> showcasing products<br /> made in all 50<br /> states."," The US military is<br /> reported to have<br /> rented 2.4 million<br /> dollars worth of<br /> space at the Trump<br /> Tower."," The president says<br /> that he would not<br /> have hired Jeff<br /> Sessions as the<br /> Attorney General<br /> if he had known he<br /> would recuse himself<br /> from the Russia<br /> investigation."," President Trump<br /> meets with his<br /> national security<br /> team at the<br /> Pentagon to discuss<br /> troop levels in<br /> Afghanistan and<br /> the fight against<br /> the Islamic State<br /> of Iraq and the<br /> Levant. The meeting<br /> is reportedly<br /> contentious and<br /> became the moment<br /> when Rex Tillerson<br /> decided to resign<br /> his position."," President Trump<br /> signs an executive<br /> ordering a review<br /> of the U.S. defense<br /> industrial base<br /> and military supply<br /> chains."," In a phone call<br /> to Ryan Lizza, the<br /> newly appointed<br /> Communications<br /> Director Anthony<br /> Scaramucci calls<br /> Chief of Staff<br /> Reince Priebus a<br /> \"fucking paranoid<br /> schizophrenic\" and<br /> notes that unlike<br /> Steve Bannon he is<br /> \"not trying to suck<br /> my own cock\"."," President<br /> Trump calls AG<br /> Jeff Sessions<br /> \"beleagured\"."," President Trump<br /> holds a bilateral<br /> meeting and joint<br /> press conference<br /> with Lebanese Prime<br /> Minister Saad Hariri<br /> at the White House<br /> to discuss the<br /> humanitarian problem<br /> in Syria, Hezbollah,<br /> and anti-terrorism."," President Trump<br /> says, \"The United<br /> States Government<br /> will not accept<br /> or allow ...<br /> transgender<br /> individuals to serve<br /> in any capacity in<br /> the U.S. Military,\"<br /> citing disruptions<br /> and medical costs."," Chief of Staff<br /> Reince Priebus<br /> resigns."," President Trump<br /> appoints John F.<br /> Kelly as White House<br /> Chief of Staff,<br /> replacing Reince<br /> Priebus."," President Trump<br /> describes Republican<br /> Senators as looking<br /> like \"fools\"<br /> following a 49–51<br /> vote against his<br /> initiative to repeal<br /> the Affordable Care<br /> Act."," John Kelly is sworn<br /> in as the White<br /> House Chief of<br /> Staff."," The Trump re-<br /> election campaign<br /> chooses a white<br /> nationalist as<br /> an elector in the<br /> next presidential<br /> election."," President<br /> Trump signs a<br /> Congressional bill<br /> (H.R.3364) limiting<br /> his ability to ease<br /> sanctions against<br /> Russia, despite<br /> describing the bill<br /> as \"flawed\" and<br /> \"unconstitutional\"."," President Trump<br /> hosts a Veterans<br /> Affairs Telehealth<br /> Services event at<br /> the White House<br /> unveiling a new<br /> service for veterans<br /> allowing patients to<br /> schedule health care<br /> appointments from<br /> their smartphones or<br /> home computers."," President Trump<br /> and Vice President<br /> Pence visit the<br /> FEMA headquarters to<br /> review preparations<br /> and emergency<br /> responses for the<br /> upcoming hurricane<br /> season."," President Trump has<br /> a phone conversation<br /> with South Korean<br /> President Moon Jae-<br /> in, discussing ways<br /> to stop the North<br /> Korean nuclear<br /> program."," Secretary of State<br /> Tillerson meets<br /> with Philippines<br /> President Rodrigo<br /> Duterte to discuss<br /> global terrorism,<br /> economic cooperation<br /> and the security<br /> situation in Marawi."," President Trump<br /> warns North Korea<br /> of \"fire and fury\"<br /> following threats<br /> to retaliate against<br /> new United Nations<br /> sanctions."," President Trump<br /> draws attention<br /> on Twitter to the<br /> \"power\" of the U.S.<br /> nuclear arsenal."," President Trump<br /> talks to reporters<br /> about his \"fire<br /> and fury\" warning,<br /> stating that \"if<br /> anything, maybe that<br /> statement wasn't<br /> tough enough.\""," President<br /> Trump states<br /> on Twitter that<br /> America's military<br /> capabilities against<br /> North Korea are<br /> \"locked and loaded\"."," President Trump<br /> speaks to Chinese<br /> President Xi<br /> Jinping, who<br /> requests restraint<br /> concerning tensions<br /> in the Korean<br /> peninsula."," Vice President Pence<br /> arrives in Colombia<br /> meeting with<br /> Colombian President<br /> Juan Manuel<br /> Santos to cover<br /> trade, business<br /> and investment<br /> opportunities in<br /> both countries."," President Trump<br /> again condemns the<br /> violence that took<br /> place at the rally<br /> in Charlottesville,<br /> Virginia."," President Trump<br /> signs an executive<br /> order calling for<br /> federal departments<br /> to speed up the<br /> permits process<br /> for construction<br /> of transportation,<br /> water and other<br /> infrastructure<br /> projects. He revokes<br /> regulations intended<br /> to manage and<br /> prevent flooding."," President Trump<br /> appoints Hope Hicks<br /> as interim White<br /> House Communications<br /> Director, replacing<br /> Scaramucci."," President Trump<br /> condemns a fatal<br /> terrorist attack<br /> in Barcelona and<br /> offers Spain the<br /> full support of the<br /> United States."," President Trump<br /> directs that the<br /> U.S. Cyber Command<br /> (USCYBERCOM) be<br /> elevated to the<br /> status of a Unified<br /> Combatant Command<br /> (UCC)."," President Trump<br /> praises 30,000<br /> protestors against<br /> a right-wing Free<br /> Speech Rally in<br /> Boston for \"speaking<br /> out against bigotry<br /> and hate\", and<br /> criticizes \"anti-<br /> police agitators\"."," President Trump<br /> gives an address at<br /> Fort Myer, Virginia,<br /> reaffirming<br /> military commitment<br /> to Afghanistan<br /> and disavowing<br /> Pakistan's<br /> sheltering the<br /> Taliban."," President Trump<br /> tours a U.S.<br /> Customs & Border<br /> Protection facility<br /> in Yuma, Arizona,<br /> meeting with<br /> Marines and border<br /> patrol agents, and<br /> inspecting border<br /> security technology<br /> and equipment."," President Trump<br /> in a speech to the<br /> American Legion in<br /> Reno, Nevada, calls<br /> for Americans to<br /> unite and reiterates<br /> the themes of his<br /> campaign, including<br /> crime, terrorism,<br /> manufacturing and<br /> infrastructure."," President Trump<br /> speaks by telephone<br /> with Texas Governor<br /> Greg Abbott and<br /> Louisiana Governor<br /> John Bel Edwards<br /> regarding Hurricane<br /> Harvey, and pledges<br /> federal aid."," President Trump<br /> issues Presidential<br /> Memorandum for the<br /> Secretary of Defense<br /> and the Secretary of<br /> Homeland Security."," President Trump<br /> holds a bilateral<br /> meeting and joint<br /> press conference<br /> with Finnish<br /> President Sauli<br /> Niinistö at the<br /> White House to<br /> discuss terrorism,<br /> Afghanistan, Russia,<br /> the Baltic Sea and<br /> the Arctic."," President Trump and<br /> First Lady Melania<br /> Trump arrive in<br /> Corpus Christi,<br /> Texas, to meet<br /> with Texas Governor<br /> Greg Abbott, Texas<br /> Senators Ted Cruz<br /> and John Cornyn, and<br /> FEMA Administrator<br /> Brock Long to<br /> discuss Hurricane<br /> Harvey. Trump later<br /> travels to the Texas<br /> Department of Public<br /> Safety's Emergency<br /> Operations Center in<br /> Austin, Texas, for<br /> further briefing."," President Trump<br /> gives a speech<br /> in Springfield,<br /> Missouri, calling<br /> for tax reform."," The Trump<br /> administration<br /> announces a cut<br /> of 90% to the<br /> Affordable Care<br /> Act's advertising<br /> budget."," President Trump<br /> signs a declaration<br /> designating<br /> September 3, 2017,<br /> as a \"Day of Prayer\"<br /> for victims of<br /> Hurricane Harvey."," President Trump and<br /> First Lady Melania<br /> meet with and help<br /> to distribute food<br /> and supplies to<br /> victims of Hurricane<br /> Harvey at the NRG<br /> Center in Houston,<br /> Texas."," Following the<br /> latest North Korean<br /> nuclear test,<br /> President Trump and<br /> Treasury Secretary<br /> Mnuchin raise the<br /> possibility of<br /> ceasing trade with<br /> countries trading<br /> with North Korea."," In an emergency UN<br /> Security Council<br /> meeting, Ambassador<br /> Nikki Haley says the<br /> U.S. will present<br /> a new sanctions<br /> resolution to punish<br /> North Korea for the<br /> latest nuclear test."," Attorney General<br /> Sessions announces<br /> at a special<br /> briefing that,<br /> at President<br /> Trump's order,<br /> the Department of<br /> Homeland Security<br /> will immediately<br /> cease to accept<br /> applications to<br /> the Deferred Action<br /> for Childhood<br /> Arrivals program.<br /> It is confirmed<br /> that current DACA<br /> recipients will be<br /> unaffected until<br /> March 5, 2018. Trump<br /> shortly thereafter<br /> calls on Congress to<br /> \"legalize DACA\"."," President Trump<br /> meets with<br /> Congressional<br /> leaders from both<br /> parties to discuss<br /> disaster relief for<br /> the aftermath of<br /> Hurricane Harvey,<br /> raising the debt<br /> ceiling to prevent a<br /> government shutdown<br /> and federal spending<br /> legislation."," President Trump<br /> holds a bilateral<br /> meeting with Emir<br /> Sabah Al-Ahmad Al-<br /> Jaber Al-Sabah of<br /> Kuwait at the White<br /> House regarding<br /> developing economic,<br /> financial, and<br /> commercial ties<br /> between both<br /> countries."," President Trump<br /> speaks by phone to<br /> Saudi Arabia's Crown<br /> Prince Mohammed<br /> bin Salman Al Saud,<br /> the United Arab<br /> Emirate's Crown<br /> Prince Mohammed bin<br /> Zayed Al Nahyan and<br /> Qatar's Emir Tamim<br /> bin Hamad Al Thani<br /> concerning regional<br /> stability."," At Camp David,<br /> President Trump<br /> and his cabinet<br /> hold team-building<br /> sessions, hurricane<br /> briefings and<br /> strategy meetings,<br /> with special focus<br /> on Hurricane Irma<br /> and tax reform."," President Trump<br /> approves a disaster<br /> declaration for<br /> Florida which<br /> will authorize<br /> federal funding<br /> for areas affected<br /> by Hurricane Irma<br /> and will reimburse<br /> local and the state<br /> authorities for<br /> costs of response<br /> and recovery."," President Trump and<br /> First Lady Melania<br /> Trump lay a wreath<br /> at the September<br /> 11 Memorial at<br /> the Pentagon, and<br /> later pay tribute<br /> to the nearly three<br /> thousand Americans<br /> killed that day,<br /> pledging to continue<br /> to confront radical<br /> Islamic terrorism."," President Trump<br /> holds a bilateral<br /> meeting with<br /> Malaysian Prime<br /> Minister Najib Razak<br /> at the White House<br /> focusing on trade,<br /> Islamic terrorism<br /> and Malaysian<br /> interest in Trump's<br /> infrastructure<br /> program."," President Trump<br /> declares September<br /> 15 – October 15 as<br /> National Hispanic<br /> Heritage Month."," President Trump<br /> and Vice President<br /> Pence travel to<br /> Fort Myers, Florida,<br /> to be briefed on<br /> Hurricane Irma<br /> relief efforts with<br /> state and federal<br /> leaders, while<br /> praising first<br /> responders and<br /> local officials for<br /> their work and lives<br /> saved."," Nikki Haley and<br /> Secretary of Defense<br /> James Mattis give<br /> statements on North<br /> Korea, Mattis saying<br /> the U.S. has options<br /> to use against North<br /> Korea if sanctions<br /> do not work."," President Trump,<br /> in a phone call<br /> to South Korean<br /> President Moon Jae-<br /> in, pledges to<br /> impose stronger<br /> sanctions on North<br /> Korea to counter its<br /> missile and nuclear<br /> programs."," President Trump<br /> attends the<br /> \"Reforming the<br /> United Nations:<br /> Management,<br /> Security, and<br /> Development\" forum<br /> at the United<br /> Nations, calling on<br /> members to pay more<br /> for joint projects<br /> such as peacekeeping<br /> missions."," In his maiden<br /> speech to the United<br /> Nations General<br /> Assembly, President<br /> Trump announces<br /> that if Kim Jong-<br /> un, dubbed \"Rocket<br /> Man\", forces the<br /> United States to<br /> defend itself or<br /> its allies, the<br /> United States will<br /> \"totally destroy\"<br /> North Korea. Trump<br /> also indicates<br /> the possibility<br /> of further action<br /> against Venezuelan<br /> President Maduro's<br /> regime, denounces<br /> Iran as a \"corrupt<br /> dictatorship\",<br /> and describes<br /> the Iranian<br /> nuclear deal as an<br /> \"embarrassment\".<br /> He calls on the UN<br /> to work together to<br /> solve such issues."," President Trump<br /> holds a bilateral<br /> meeting with King<br /> Abdullah II of<br /> Jordan to discuss<br /> fighting terrorism<br /> in the Middle East<br /> and praises Jordan<br /> for taking refugees<br /> from Syria."," President Trump<br /> holds a bilateral<br /> meeting with Afghan<br /> President Ashraf<br /> Ghani to discuss<br /> the Afghanistan<br /> war strategy in<br /> combating Islamist<br /> terrorists."," President Trump<br /> attends a political<br /> rally in Huntsville,<br /> Alabama, in support<br /> of the election<br /> campaign of Luther<br /> Strange."," In response to a<br /> tweet by President<br /> Trump withdrawing<br /> an invitation to<br /> NBA player Stephen<br /> Curry to visit<br /> the White House,<br /> the entire Golden<br /> State Warrior team<br /> says it will forego<br /> the traditional<br /> championship team<br /> Oval office visit."," President Trump<br /> signs a new<br /> presidential<br /> proclamation<br /> introducing new<br /> travel restrictions<br /> on countries North<br /> Korea, Venezuela,<br /> and Chad along with<br /> countries Somalia,<br /> Yemen, Syria, Libya<br /> and Iran listed<br /> under Executive<br /> Order 13780."," President Trump<br /> signs a presidential<br /> memorandum directing<br /> the Department<br /> of Education to<br /> allocate at least<br /> $200 million per<br /> year in grant<br /> funds to the study<br /> of science and<br /> engineering."," President Trump<br /> meets with a<br /> bipartisan group<br /> of members of House<br /> Ways and Means<br /> Committee to discuss<br /> tax reform and tax<br /> cuts."," President Trump<br /> discusses his<br /> plan to reform<br /> the tax system<br /> in Indianapolis,<br /> Indiana calling<br /> for the sweeping<br /> tax cuts, reducing<br /> the personal income<br /> tax brackets and<br /> corporate taxes<br /> and eliminating the<br /> estate tax."," President Trump<br /> attends the<br /> celebration for the<br /> 70th anniversary<br /> of the National<br /> Security Council<br /> at the Eisenhower<br /> Executive Office<br /> Building."," President Trump<br /> speaks to the<br /> National Association<br /> of Manufacturers<br /> about the economy<br /> and his tax plan."," Secretary of State<br /> Rex Tillerson<br /> meets with Chinese<br /> President Xi Jinping<br /> in Beijing, China<br /> to discuss bilateral<br /> relations between<br /> both countries and<br /> President Trump's<br /> upcoming visit to<br /> China in November."," The deadline passes<br /> unfulfilled for<br /> President Trump<br /> to identify for<br /> punishment Kremlin-<br /> linked targets of<br /> sanctions signed on<br /> August 2."," President Trump<br /> addresses the nation<br /> in regards to the<br /> mass shooting in<br /> Las Vegas, offering<br /> his condolences<br /> to the victims and<br /> their families while<br /> praising the first<br /> responders at the<br /> scene."," President Trump<br /> meets with U.S.<br /> Virgin Islands<br /> Governor Kenneth<br /> Mapp on board<br /> the USS Kearsarge<br /> (LHD-3) to discuss<br /> the territory's<br /> immediate funding<br /> needs in the<br /> aftermath of<br /> Hurricane Maria."," Secretary of State<br /> Rex Tillerson states<br /> the administration<br /> is preparing for<br /> options ahead of the<br /> October 15, 2017,<br /> deadline on whether<br /> Iran is complying<br /> with the 2015<br /> nuclear accord."," President Trump<br /> has a briefing and<br /> dinner with senior<br /> military leaders at<br /> the White House to<br /> discuss the current<br /> situation with Iran<br /> and North Korea."," President Trump<br /> celebrates Hispanic<br /> Heritage Month at<br /> the White House,<br /> and speaks of<br /> recovery efforts<br /> in Puerto Rico<br /> and of the people<br /> suffering under the<br /> governments of Cuba<br /> and Venezuela."," Vice President Pence<br /> attends a unity<br /> prayer walk with Las<br /> Vegas mayor Carolyn<br /> Goodman and local<br /> officials in memory<br /> of the people killed<br /> and wounded during<br /> the Las Vegas mass<br /> shooting."," At President Trump's<br /> prior request, Vice<br /> President Pence<br /> walks out of an NFL<br /> football game after<br /> fifteen 49er players<br /> kneel during the<br /> national anthem.<br /> The White House<br /> says it \"will not<br /> dignify any event<br /> that disrespects our<br /> soldiers, our flag,<br /> or our national<br /> anthem\"."," Vice President Pence<br /> holds a fundraiser<br /> at Newport Beach,<br /> California, to raise<br /> funds for Republican<br /> Congressmen and<br /> to promote the<br /> administration's<br /> tax-cut initiative."," President Trump<br /> meets with former<br /> Secretary of State<br /> Henry Kissinger at<br /> the White House,<br /> seeking his advice<br /> on dealing with<br /> North Korea and<br /> China."," President Trump<br /> holds a bilateral<br /> meeting with<br /> Canadian Prime<br /> Minister Justin<br /> Trudeau at the White<br /> House to discuss<br /> NAFTA and U.S.–<br /> Canadian trade<br /> possibilities."," President Trump<br /> signs an executive<br /> order which directs<br /> cabinet agencies to<br /> develop rules that<br /> would expand access<br /> to less expensive,<br /> less comprehensive<br /> insurance policies<br /> with fewer<br /> benefits and fewer<br /> protections for<br /> consumers than those<br /> mandated under the<br /> Patient Protection<br /> and Affordable Care<br /> Act."," President Trump<br /> attends the Values<br /> Voter Summit in<br /> Washington D.C. to<br /> speak on matters<br /> such as easing of<br /> enforcement of the<br /> Johnson Amendment<br /> and weakening<br /> the contraception<br /> mandate in the<br /> Affordable Care Act."," President Trump's<br /> 2020 re-election<br /> campaign files its<br /> quarterly finance<br /> report with the<br /> FEC. The filing<br /> discloses a legal<br /> bill of $1.1m<br /> paid from campaign<br /> funds in connection<br /> with the Russia<br /> investigations."," President Trump<br /> attends a rally<br /> in Greenville,<br /> South Carolina, in<br /> support of Governor<br /> Henry McMaster to<br /> raise funds for<br /> his gubernatorial<br /> campaign."," President Trump<br /> holds a bilateral<br /> meeting and joint<br /> press conference<br /> with Greek Prime<br /> Minister Alexis<br /> Tsipras at the White<br /> House to discuss<br /> Greek efforts<br /> to reform their<br /> economy and military<br /> ties between both<br /> countries."," President Trump<br /> holds a meeting at<br /> the White House with<br /> the Senate Finance<br /> Committee to discuss<br /> tax reform."," President Trump<br /> meets with Puerto<br /> Rico Governor<br /> Ricardo Rosselló at<br /> the White House to<br /> discuss the island's<br /> recovery efforts<br /> after Hurricane<br /> Maria."," President Trump<br /> holds a bilateral<br /> meeting with United<br /> Nations Secretary-<br /> General António<br /> Guterres at the<br /> White House to<br /> discuss counter-<br /> terrorism, Korea and<br /> the Middle East."," President Trump<br /> holds a conference<br /> call with Republican<br /> Congressman calling<br /> on them to pass the<br /> Senate budget and<br /> work on tax reform."," President Trump<br /> holds a bilateral<br /> meeting with<br /> Singaporean Prime<br /> Minister Lee Hsien<br /> Loong at the White<br /> House to discuss<br /> the North Korean<br /> nuclear threat,<br /> defence and economic<br /> relationship between<br /> both countries,<br /> whilst overseeing<br /> the signing ceremony<br /> between Singapore<br /> Airlines and Boeing<br /> for $13.8 billion<br /> worth of new planes."," President Trump<br /> holds an awards<br /> ceremony at the<br /> White House as<br /> part of National<br /> Minority Enterprise<br /> Development Week."," President Trump<br /> attends a briefing<br /> in Dallas, Texas on<br /> the recovery efforts<br /> by Hurricane Harvey<br /> and addressing the<br /> long-term flood<br /> mitigation plans in<br /> the state."," President Trump<br /> signs a presidential<br /> memorandum declaring<br /> a nationwide public<br /> health emergency<br /> and ordering all<br /> federal agencies<br /> to take measures to<br /> reduce the number of<br /> opioid deaths in the<br /> country. No funds<br /> are allocated from<br /> the public health<br /> emergency fund."," Shortly following<br /> the surrender<br /> of former Trump<br /> campaign officials<br /> Paul Manafort<br /> and Rick Gates<br /> to the FBI on<br /> twelve charges of<br /> conspiracy and money<br /> laundering between<br /> 2006 and 2015,<br /> President Trump<br /> states on Twitter<br /> that the charges<br /> refer to events<br /> from \"years ago\" and<br /> that \"there is NO<br /> COLLUSION!\""," Following a fatal<br /> vehicular attack in<br /> New York City by an<br /> Islamic extremist,<br /> President Trump<br /> offers \"condolences<br /> and prayers\" to the<br /> victims and their<br /> families."," House Republicans<br /> publish their<br /> forthcoming tax<br /> bill, Tax Cuts and<br /> Jobs Act of 2017,<br /> with President<br /> Trump's provisional<br /> approval."," President Trump<br /> leaves Washington<br /> for Hawaii prior to<br /> his five-nation tour<br /> of Asia."," President Trump<br /> arrives in Tokyo,<br /> Japan during his<br /> first leg of five-<br /> nation tour of Asia."," President Trump<br /> meets with Emperor<br /> Akihito and Empress<br /> Michiko at the Tokyo<br /> Imperial Palace."," President Trump<br /> arrives in Seoul,<br /> South Korea during<br /> his second leg of<br /> five-nation tour of<br /> Asia."," President Trump<br /> addressed the<br /> National Assembly of<br /> South Korea."," President Trump<br /> signs a number<br /> of binding and<br /> non-binding<br /> gas, aviation,<br /> communications and<br /> food-crop deals with<br /> Chinese President<br /> Xi Jinping. Speaking<br /> alongside President<br /> Xi Jinping in<br /> Beijing, President<br /> Trump refers to<br /> the U.S.-Chinese<br /> trade imbalance,<br /> praising China for<br /> \"taking advantage\"<br /> of prior U.S.<br /> administrations."," President Trump<br /> arrives Saturday<br /> morning UTC+7 in Da<br /> Nang, Vietnam during<br /> his fourth leg of<br /> five-nation tour of<br /> Asia."," President Trump<br /> arrives in Hanoi,<br /> Vietnam."," President Trump<br /> holds a joint press<br /> conference with<br /> Vietnamese President<br /> Trần Đại Quang at<br /> the Presidential<br /> Palace."," President Trump<br /> attends the 2017<br /> ASEAN summit<br /> hosted by Filipino<br /> President Rodrigo<br /> Duterte."," President Trump<br /> returns to<br /> Washington from<br /> Manila at the end of<br /> his five-nation tour<br /> of Asia."," President Trump<br /> visits the U.S.<br /> Capitol in advance<br /> of the passing by<br /> House Republicans<br /> without Democratic<br /> votes (227-205) of a<br /> $1.4tn \"Tax Cut and<br /> Jobs Act\" in support<br /> of Trump's tax-cut<br /> initiative. Among<br /> numerous proposals<br /> are included a cut<br /> in corporate tax<br /> from 35% to 20%, and<br /> the abolition of the<br /> Family Flexibility<br /> Credit, the<br /> estate tax and the<br /> alternative minimum<br /> tax."," President Trump<br /> announces that<br /> North Korea will be<br /> reinstated to the<br /> United States' list<br /> of State Sponsors<br /> of Terrorism, from<br /> which it was removed<br /> in October 2008."," President Trump and<br /> First Lady Melania<br /> Trump participate<br /> in the National<br /> Thanksgiving Turkey<br /> Presentation."," President Trump<br /> hosts a White House<br /> event honoring<br /> Second World War<br /> Navajo code talker<br /> veterans. The<br /> White House later<br /> states that it is<br /> 'ridiculous' to<br /> suggest that Trump's<br /> reiteration at the<br /> event of the name<br /> 'Pocahontas' to<br /> describe Senator<br /> Elizabeth Warren is<br /> racist, following<br /> protestation by the<br /> National Congress of<br /> American Indians and<br /> others."," President Trump<br /> informs reporters at<br /> the White House of<br /> his administration's<br /> resolve following<br /> a new North Korean<br /> missile test which,<br /> it is believed,<br /> for the first time<br /> places Washington<br /> D.C. within range of<br /> the KPA."," President<br /> Trump announces<br /> \"additional<br /> major sanctions\"<br /> against North<br /> Korea following<br /> a telephone<br /> conversation with<br /> Chinese President Xi<br /> Jinping."," President Trump<br /> announces the<br /> donation of his<br /> third-quarter salary<br /> to HHS efforts to<br /> solve the opioid<br /> epidemic."," Former NSA Michael<br /> Flynn pleads guilty<br /> to lying to the FBI<br /> on January 24, 2017,<br /> concerning contacts<br /> with Russian<br /> Ambassador Sergey<br /> Kislyak."," The Senate passes<br /> a $1.5 trillion<br /> tax cut bill (51 to<br /> 49) in support of<br /> President Trump's<br /> tax initiative."," President Trump's<br /> lawyer John M. Dowd<br /> states that Trump<br /> knew in January 2017<br /> that Michael Flynn<br /> had likely lied to<br /> the FBI."," Seven of the nine<br /> judges on the<br /> Supreme Court lift<br /> the lower court<br /> injunctions on<br /> President Trump's<br /> third-version<br /> travel ban, thereby<br /> permitting its<br /> enforcement against<br /> the nations of<br /> Chad, Iran, Libya,<br /> Somalia, Syria,<br /> Yemen, Venezuela and<br /> North Korea. Unlike<br /> previous iterations,<br /> the ban has no<br /> expiry date."," Special Counsel<br /> Robert Mueller<br /> reportedly subpoenas<br /> Deutsche Bank for<br /> records of Trump's<br /> associates. Trump's<br /> lawyer denies<br /> reports that Trump's<br /> personal financial<br /> records were<br /> subpoenaed."," President Trump<br /> announces that the<br /> United States is to<br /> recognize Jerusalem<br /> as the capital of<br /> Israel—the first<br /> nation to do so—and<br /> announces that the<br /> U.S. will relocate<br /> its embassy there<br /> from Tel Aviv."," White House<br /> Communications<br /> Director Hope Hicks<br /> is interviewed by<br /> Special Counsel<br /> Mueller's team as<br /> part of the Russia<br /> investigation."," President Trump<br /> holds a rally at<br /> Pensacola, Florida,<br /> near the Alabama<br /> border, at which<br /> he exhorts the<br /> Alabamian electorate<br /> to vote for Senate<br /> candidate Roy Moore<br /> on 12 December."," President Trump<br /> attends the openings<br /> of the Mississippi<br /> Civil Rights Museum<br /> and the Museum of<br /> Mississippi History<br /> in Jackson."," Vice President<br /> Pence's office<br /> describes as<br /> \"unfortunate\"<br /> a decision by<br /> Palestinian<br /> President Mahmoud<br /> Abbas to cancel a<br /> December 19 meeting<br /> between the two<br /> during Pence's<br /> upcoming visit to<br /> the Middle East."," President Trump<br /> calls for an end to<br /> \"chain migration\"<br /> following an<br /> attempted bombing in<br /> New York City which<br /> injures five people."," President<br /> Trump signs the<br /> National Defense<br /> Authorization Act's<br /> 2018 budget, costed<br /> at $700 billion. It<br /> provides $25m for<br /> road-based cruise<br /> missile technology,<br /> in violation of<br /> the 1987 and 1988<br /> Intermediate-<br /> Range Nuclear<br /> Forces Treaty. NATO<br /> released a statement<br /> on 15 December,<br /> stating that \"full<br /> compliance with<br /> the INF Treaty is<br /> essential\"."," Congressional<br /> Republicans reach a<br /> deal on aspects of<br /> President Trump's<br /> tax plan. Trump<br /> indicates that<br /> he will support a<br /> corporate tax rate<br /> of 21%."," President Trump<br /> speaks by telephone<br /> with Russian<br /> President Vladimir<br /> Putin in an effort<br /> to engender co-<br /> operation over the<br /> North Korean missile<br /> threat."," Speaking at the<br /> White House,<br /> President Trump<br /> describes the FBI as<br /> acting disgracefully<br /> and states that<br /> people are angry.<br /> Trump shortly<br /> thereafter addresses<br /> a group of largely<br /> non-FBI graduates<br /> from a program at<br /> the FBI National<br /> Academy in Quantico,<br /> Virginia, stating<br /> \"I have your back<br /> 100%\"."," Russian President<br /> Vladimir Putin<br /> telephones President<br /> Trump to thank<br /> the CIA for its<br /> assistance in<br /> preventing a planned<br /> terrorist bombing<br /> at St. Petersburg's<br /> Kazan Cathedral."," President Trump<br /> publishes his<br /> first National<br /> Security Strategy<br /> and delivers<br /> a concomitant<br /> address, condemning<br /> North Korea as a<br /> rogue state and<br /> positioning China<br /> and Russia as U.S.<br /> rivals with whom his<br /> administration will<br /> attempt to \"build a<br /> great partnership\".<br /> Climate change is<br /> omitted from the<br /> strategy."," The House of<br /> Representatives<br /> passes a revised<br /> version of President<br /> Trump's Tax Cuts<br /> and Jobs Act without<br /> Democratic votes,<br /> 227-203."," The Senate passes<br /> President Trump's<br /> Tax Cuts and Jobs<br /> Act shortly after<br /> midnight without<br /> Democratic votes, 51<br /> to 48. A procedural<br /> mistake in the<br /> House on December<br /> 19 necessitates<br /> a second vote in<br /> the House, which<br /> later passes in<br /> favor, 224 to 201.<br /> The wide-ranging<br /> bill includes a cut<br /> to corporate tax<br /> from 35% to 21%,<br /> a reduction to the<br /> pool of estate-tax<br /> payers, alters each<br /> tax bracket, and<br /> reduces the rate<br /> for the highest<br /> earners. The bill<br /> also permits oil<br /> drilling in Alaska's<br /> Arctic National<br /> Wildlife Refuge<br /> and removes the<br /> individual mandate<br /> from Obamacare.<br /> President Trump<br /> announces that the<br /> bill represents a<br /> repeal of Obamacare,<br /> and that it will<br /> be replaced by<br /> \"something that will<br /> be much better\".<br /> The legislation is<br /> financed by debt."," Vice President<br /> Pence arrives in<br /> Afghanistan to visit<br /> troops and speak<br /> with Afghan leaders.<br /> In a speech at<br /> Bagram Airfield, he<br /> announces \"I believe<br /> victory is closer<br /> than ever before.\""," President Trump<br /> signs into law<br /> the $1.5 trillion<br /> tax bill passed by<br /> Congress on December<br /> 20."," All ten members of<br /> the Presidential<br /> Advisory Council<br /> on HIV/AIDS are<br /> dismissed."," President<br /> Trump expresses<br /> disappointment<br /> following reporting<br /> by South Korean<br /> newspaper Chosun<br /> Ilbo that China<br /> has been illegally<br /> supplying oil to<br /> North Korea."," Trump's Labor<br /> Department continues<br /> the policy of the<br /> Obama Administration<br /> of issuing waivers<br /> to banks convicted<br /> of manipulating<br /> the global interest<br /> rate Libor. Deutsche<br /> Bank and UBS are<br /> allowed to manage<br /> retirement funds for<br /> three years, while<br /> Barclays, Citigroup,<br /> and JPMorgan are<br /> allowed to do the<br /> same for five years.<br /> At the time, Trump<br /> and his businesses<br /> owe Deutsche Bank at<br /> least $130 million."," The Trump<br /> administration<br /> announces it<br /> will withhold the<br /> scheduled millions<br /> of military aid<br /> to Pakistan with<br /> President Trump<br /> declaring it a<br /> terrorist \"safe<br /> haven\"."," President Trump<br /> tweets that his<br /> \"nuclear button\"<br /> is larger and more<br /> powerful than that<br /> of Kim Jong-un."," President Trump<br /> disbands his<br /> Presidential<br /> Advisory Commission<br /> on Election<br /> Integrity."," President Trump's<br /> lawyer Charles J.<br /> Harder sends to<br /> Michael Wolff and<br /> his publisher, Henry<br /> Holt and Company,<br /> a cease and desist<br /> letter demanding<br /> the non-publication<br /> of Wolff's White<br /> House exposé,<br /> Fire and Fury,<br /> due for release on<br /> January 9. Wolff's<br /> publishers move the<br /> date of publication<br /> forward to January<br /> 5."," The Trump<br /> administration<br /> submits to Congress<br /> initial details<br /> of a request for<br /> $18 billion to<br /> fund 316 miles of<br /> new barriers and<br /> upgrades to 407<br /> miles of existing<br /> barriers along the<br /> Mexican border."," President Trump<br /> tweets that he<br /> is a \"very stable<br /> genius\", praising<br /> his own \"mental<br /> stability\". Also<br /> within the tweet,<br /> he says he became<br /> president \"on<br /> the first try\",<br /> despite having run<br /> as a Reform Party<br /> candidate in 2000."," President Trump<br /> makes an on-<br /> field appearance<br /> during the National<br /> Anthem at the 2018<br /> College Football<br /> Playoff National<br /> Championship."," President Trump<br /> holds a bipartisan<br /> meeting with<br /> members of Congress<br /> discussing the topic<br /> of immigration."," President Trump<br /> describes Senator<br /> Dianne Feinstein<br /> as \"sneaky\" and a<br /> \"disgrace\" following<br /> her unilateral<br /> publication on<br /> January 9 of the<br /> Simpson testimony<br /> of August 2017<br /> concerning research<br /> into potential<br /> crimes in respect of<br /> the 2016 election."," The Trump<br /> administration<br /> announces new state<br /> guidelines that<br /> Medicaid recipients<br /> may be required to<br /> work or volunteer,<br /> or enroll in<br /> education."," President Trump<br /> proclaims Martin<br /> Luther King Jr. Day<br /> for January 15."," President Trump is<br /> briefed at the White<br /> House concerning<br /> Hawaii's emergency<br /> management protocol<br /> following a public<br /> disturbance due to<br /> a false alarm of an<br /> incoming ballistic<br /> missile."," Secretary of State<br /> Rex Tillerson co-<br /> hosts with Canadian<br /> Foreign Affairs<br /> Minister Chrystia<br /> Freeland the first<br /> of two days of<br /> talks in Vancouver<br /> concerning the North<br /> Korea crisis."," President Trump<br /> holds a bilateral<br /> meeting and joint<br /> press conference<br /> with Kazakhstani<br /> President Nursultan<br /> Nazarbayev at the<br /> White House."," In an Oval Office<br /> interview for<br /> Reuters, President<br /> Trump accuses Russia<br /> of harming Chinese/<br /> American efforts to<br /> solve the ongoing<br /> North Korean nuclear<br /> crisis."," President Trump<br /> delivers a speech<br /> at a factory<br /> near Pittsburgh,<br /> Pennsylvania. He<br /> offers his support<br /> for Republican<br /> candidate Rick<br /> Saccone in the<br /> upcoming March 13<br /> special election for<br /> Pennsylvania's 18th<br /> district."," President Trump<br /> states on Twitter<br /> that Democratic<br /> votes will be needed<br /> in the Senate to<br /> prevent a government<br /> shutdown at<br /> midnight. He writes,<br /> \"but they want<br /> illegal immigration<br /> and weak borders\"."," A federal government<br /> shutdown begins,<br /> after the Senate<br /> fails to pass<br /> a continuing<br /> resolution to<br /> maintain funding for<br /> the government."," Vice President<br /> Pence meets with<br /> King Abdullah II<br /> of Jordan in Amman.<br /> Abdullah criticizes<br /> the decision to<br /> recognize Jerusalem<br /> as the Israeli<br /> capital. Pence<br /> reaffirms U.S.<br /> respect towards<br /> Jordan's role as<br /> the guardian of<br /> Jerusalem's Islamic<br /> holy sites."," During the third<br /> day of the federal<br /> government shutdown,<br /> President Trump<br /> accuses the<br /> Democratic Party of<br /> precipitating the<br /> shutdown \"in the<br /> interests of their<br /> far left base\"."," Vice President Pence<br /> visits Jerusalem's<br /> Western Wall."," President Trump<br /> announces during<br /> remarks at the White<br /> House that he is<br /> willing to testify<br /> to Mueller under<br /> oath, stating, \"I<br /> would love to do<br /> it, and I would like<br /> to do it as soon as<br /> possible.\""," President Trump<br /> arrives in Davos,<br /> Switzerland to<br /> attend the 2018<br /> Davos World Economic<br /> Forum. He is the<br /> first U.S. President<br /> to personally<br /> attend the annual<br /> Davos conference<br /> since President<br /> Bill Clinton in<br /> 2000. U.S. Treasury<br /> Secretary Steve<br /> Mnuchin is head of<br /> the U.S. delegation,<br /> which is the largest<br /> ever to attend the<br /> forum."," President Trump<br /> denies ordering<br /> the dismissal of<br /> Mueller, describing<br /> it as 'fake news'."," The Trump<br /> administration<br /> submits five reports<br /> to Congress as<br /> mandated by the<br /> Countering America's<br /> Adversaries Through<br /> Sanctions Act<br /> (CAATSA), including<br /> two versions<br /> (one classified)<br /> of the report<br /> \"regarding senior<br /> political figures<br /> and oligarchs<br /> in the Russian<br /> Federation and<br /> Russian parastatal<br /> entities\". The<br /> unclassified list<br /> published the<br /> following day by the<br /> Treasury Department<br /> contains names<br /> of 210 people,<br /> including 96 Russian<br /> tycoons close to<br /> president Vladimir<br /> Putin with wealth<br /> of $1 billion<br /> or more, as well<br /> as top Russian<br /> statespersons and<br /> officials, excluding<br /> Vladimir Putin, all<br /> information having<br /> been drawn from<br /> public sources."," President Trump<br /> delivers his first<br /> official State of<br /> the Union Address<br /> with a wide-<br /> ranging speech<br /> covering matters of<br /> natural disasters,<br /> terrorism,<br /> immigration,<br /> economic growth,<br /> patriotism and<br /> the U.S. nuclear<br /> arsenal. He calls<br /> on Congress for<br /> a $1.5 trillion<br /> infrastructure<br /> investment bill and<br /> an end to political<br /> division."," Doctor Brenda<br /> Fitzgerald resigns<br /> as Director of<br /> the Center for<br /> Disease Control<br /> over conflicts of<br /> interest."," Tom Shannon, the<br /> United States<br /> Under Secretary of<br /> State for Political<br /> Affairs, announces<br /> he will be resigning<br /> for personal<br /> reasons. The State<br /> Department's third-<br /> ranking official<br /> and its most senior<br /> career diplomat<br /> says he will stay on<br /> until a successor is<br /> named."," President Trump<br /> declassifies the<br /> Nunes memo and<br /> authorizes Congress<br /> to release it."," At a speech<br /> in Cincinnati,<br /> Ohio, President<br /> Trump claims that<br /> Congressional<br /> Democrats, who \"were<br /> like death and un-<br /> American\" in not<br /> applauding during<br /> his State of the<br /> Union speech, were<br /> \"treasonous\" and<br /> that \"we call that<br /> treason\"."," While Congress<br /> was preparing<br /> a continuing<br /> resolution for a<br /> temporary budget,<br /> President Trump<br /> declared, \"I'd love<br /> to see a shutdown\"<br /> if American<br /> immigration laws<br /> were not tightened.<br /> He also said \"it's<br /> worth it for our<br /> country\"."," White House Staff<br /> Secretary Rob<br /> Porter resigns<br /> from his position<br /> following two public<br /> allegations of<br /> spousal abuse."," President Trump<br /> speaks at the<br /> National Prayer<br /> Breakfast."," Federal funding<br /> lapsed for the<br /> second time in 2018<br /> after Republican<br /> Senator Rand Paul<br /> delayed the vote<br /> on a temporary<br /> appropriations bill<br /> by objecting to<br /> measures requiring<br /> unanimous consent<br /> to expedite the<br /> parliamentary<br /> process."," President Trump<br /> sends his $4.4<br /> trillion 2019<br /> budget proposal to<br /> Congress."," President Trump's<br /> personal lawyer<br /> Michael Cohen<br /> acknowledged that<br /> in 2016 he paid<br /> $130,000 of his<br /> own money to adult-<br /> film actress<br /> Stormy Daniels.<br /> Cohen further said<br /> that The Trump<br /> Organization and the<br /> Trump campaign were<br /> not involved in the<br /> payment and did not<br /> reimburse him. It<br /> was earlier reported<br /> that the payment<br /> was hush money for<br /> Daniels' silence<br /> regarding an alleged<br /> extramarital affair<br /> with Trump in 2006."," President Trump<br /> addresses the nation<br /> in regards to the<br /> school shooting in<br /> Parkland offering<br /> his condolences<br /> to the victims and<br /> their families."," The New Yorker<br /> reports that<br /> President Trump<br /> had a nine-month<br /> extramarital affair<br /> with Playboy model<br /> Karen McDougal from<br /> June 2006, citing<br /> handwritten memoirs<br /> by McDougal provided<br /> by her friend. The<br /> New Yorker also<br /> corroborated a 2016<br /> Wall Street Journal<br /> report that American<br /> Media, Inc (AMI) had<br /> paid $150,000 for<br /> exclusive rights to<br /> McDougal's story,<br /> but never published<br /> it. AMI has<br /> described the story<br /> as not credible,<br /> and a spokesperson<br /> for the White House<br /> denied the affair."," President Trump<br /> orders the<br /> Department of<br /> Justice to prepare<br /> regulations to ban<br /> devices that allow<br /> semi-automatic<br /> rifles to become<br /> fully automatic,<br /> such as the bump<br /> stocks used in<br /> the 2017 Las Vegas<br /> shooting."," President Trump<br /> gives a speech<br /> in Oxon Hill,<br /> Maryland to the<br /> 2018 Conservative<br /> Political Action<br /> Conference."," A Democratic memo<br /> titled Correcting<br /> the Record—The<br /> Russia Investigation<br /> in response to<br /> the Nunes memo,<br /> is released after<br /> redacting by the<br /> FBI."," President Trump<br /> attends the<br /> National Governors<br /> Association dinner."," Josh Raffel,<br /> a senior<br /> communications<br /> aide, announced his<br /> resignation from the<br /> administration."," At the lying in<br /> honor of evangelical<br /> preacher Billy<br /> Graham in the U.S.<br /> Capitol rotunda,<br /> President Trump<br /> and congressional<br /> leaders praise<br /> Graham."," Two-time NBA<br /> champions Golden<br /> State Warriors<br /> toured the National<br /> Museum of African<br /> American History<br /> and Culture as an<br /> alternative to the<br /> traditional White<br /> House visit."," In a private speech<br /> to Republican donors<br /> at Mar-a-Lago,<br /> President Trump says<br /> \"it's great\" that<br /> Chinese President<br /> Xi Jinping was able<br /> to become \"president<br /> for life\", and that<br /> \"maybe we'll have<br /> to give that a shot<br /> some day.\""," President Trump<br /> holds a bilateral<br /> meeting with Israeli<br /> Prime Minister<br /> Benjamin Netanyahu<br /> at the White House."," The U.S. Office<br /> of Special Counsel<br /> (OSC) says Counselor<br /> to the President<br /> Kellyanne Conway<br /> violated federal<br /> law in the form of<br /> the Hatch Act during<br /> two television<br /> interviews in<br /> 2017 by advocating<br /> for the defeat<br /> of Doug Jones<br /> and the election<br /> of Roy Moore for<br /> Alabama's election<br /> for a Senate seat.<br /> The White House<br /> has disputed this<br /> finding by the OSC."," White House Press<br /> Secretary Sarah<br /> Huckabee Sanders<br /> says President<br /> Trump's personal<br /> attorneys have<br /> won an arbitration<br /> case against adult-<br /> film actress Stormy<br /> Daniels.NBC News<br /> reports that Trump's<br /> lawyer, Michael<br /> Cohen, on February<br /> 27 initiated a<br /> private arbitration<br /> case against Daniels<br /> and obtained a<br /> restraining order<br /> that states that<br /> Daniels will face<br /> penalties if she<br /> discusses, in<br /> public, her alleged<br /> relationship with<br /> Trump. Daniels has<br /> filed a lawsuit that<br /> her non-disclosure<br /> agreement regarding<br /> her alleged<br /> relationship with<br /> Trump is invalid<br /> because Trump never<br /> signed it."," President Trump<br /> signs proclamations<br /> which will impose<br /> tariffs on imported<br /> steel and aluminum<br /> from most countries<br /> in 15 days. Canada<br /> and Mexico are<br /> initially exempted<br /> from these tariffs<br /> while they talk<br /> with the U.S. about<br /> renegotiating NAFTA."," President Trump<br /> pardons Kristian<br /> Saucier, who<br /> was convicted<br /> of unauthorized<br /> possession and<br /> retention of<br /> national defense<br /> information."," President Trump<br /> holds a rally at<br /> the Pittsburgh<br /> International<br /> Airport to support<br /> Rick Saccone in an<br /> upcoming special<br /> election. He<br /> introduces his 2020<br /> campaign slogan:<br /> \"Keep America<br /> Great!\""," The Trump<br /> administration<br /> proposes gun and<br /> school safety<br /> measures, including<br /> improving the system<br /> of background checks<br /> and training school<br /> personnel to handle<br /> firearms."," Citing national<br /> security concerns,<br /> President Trump<br /> blocks Broadcom's<br /> proposed acquisition<br /> of Qualcomm."," President Trump<br /> fires Rex Tillerson<br /> as Secretary of<br /> State, names former<br /> CIA director Mike<br /> Pompeo as the new<br /> Secretary of State,<br /> and nominates Gina<br /> Haspel as the next<br /> director of the CIA.<br /> Deputy Secretary<br /> of State John J.<br /> Sullivan becomes<br /> Acting Secretary of<br /> State."," President Trump<br /> chooses Larry Kudlow<br /> as director of the<br /> National Economic<br /> Council, replacing<br /> Gary Cohn."," The Trump<br /> administration<br /> uses the Countering<br /> America's<br /> Adversaries Through<br /> Sanctions Act to<br /> impose financial<br /> sanctions on the 13<br /> Russian government<br /> hackers and spy<br /> agencies indicted in<br /> the Special Counsel<br /> investigation."," Andrew McCabe,<br /> former acting<br /> director of the<br /> FBI who was due to<br /> retire with benefits<br /> in two days, was<br /> fired from the FBI<br /> by Attorney General<br /> Jeff Sessions on<br /> the recommendation<br /> of FBI disciplinary<br /> officials for \"lack<br /> of candor\"."," The Kremlin<br /> announces President<br /> Trump's call to<br /> congratulate Russian<br /> President Vladimir<br /> Putin on his<br /> election victory.<br /> National security<br /> advisers warned<br /> Trump against the<br /> call."," H.R. McMaster<br /> resigns as National<br /> Security Adviser<br /> and John Bolton, a<br /> former ambassador to<br /> the United Nations,<br /> is named to succeed<br /> him."," The White House<br /> issues a memorandum<br /> on Jim Mattis's<br /> recommended<br /> military policies,<br /> which state<br /> that transgender<br /> personnel are<br /> \"disqualified from<br /> military service<br /> except under limited<br /> circumstances\"."," The White House<br /> announces the<br /> expulsion of 60<br /> Russian diplomats."," President Trump<br /> fires Secretary<br /> of Veteran Affairs<br /> David Shulkin and<br /> nominates White<br /> House doctor Ronny<br /> L. Jackson to<br /> replace him."," Rex Tillerson's last<br /> day as Secretary of<br /> State."," President Trump and<br /> First Lady Melania<br /> Trump participate<br /> in the White House<br /> Easter Egg Roll."," President Trump<br /> holds a joint press<br /> conference with the<br /> leaders of three<br /> Baltic states at<br /> the White House:<br /> Estonian President<br /> Kersti Kaljulaid,<br /> Latvian President<br /> Raimonds Vejonis and<br /> Lithuanian President<br /> Dalia Grybauskaite."," President Trump<br /> signs a proclamation<br /> directing the<br /> deployment of the<br /> National Guard to<br /> the U.S.–Mexico<br /> border to fight<br /> illegal immigration."," After the FBI and<br /> federal prosecutors<br /> raid the home, hotel<br /> room, and office of<br /> President Trump's<br /> personal attorney,<br /> Michael Cohen, Trump<br /> brands the raid as<br /> \"an attack on our<br /> country in a true<br /> sense\"."," The White House<br /> confirms the<br /> resignation of<br /> Homeland Security<br /> advisor Thomas<br /> Bossert and National<br /> Security Council<br /> spokesman Michael<br /> Anton."," President Trump<br /> signs a bill that<br /> reduces legal<br /> protections for<br /> websites that enable<br /> sex trafficking."," President Trump<br /> launches a task<br /> force to \"conduct a<br /> thorough evaluation<br /> of the operations<br /> and finances of the<br /> United States Postal<br /> System\"."," President Trump<br /> pardons Scooter<br /> Libby, the former<br /> chief of staff<br /> for Vice President<br /> Dick Cheney in<br /> the George W. Bush<br /> Administration.<br /> As a result of the<br /> Plame investigation<br /> into the leaking of<br /> an undercover CIA<br /> agent's identity,<br /> Libby had been found<br /> guilty of making<br /> false statements,<br /> obstruction of<br /> justice and lying<br /> under oath."," President Trump's<br /> new lawyer, Joanna<br /> Hendon, a partner<br /> at New York's Spears<br /> & Imes law firm,<br /> represents him at a<br /> hearing concerning<br /> Michael Cohen."," President Trump<br /> meets with Japanese<br /> Prime Minister<br /> Shinzō Abe for the<br /> first of two days<br /> of meetings and<br /> events to discuss<br /> trade, security,<br /> and Trump's expected<br /> meeting with North<br /> Korean leader Kim<br /> Jong-un this spring."," President Trump<br /> and Japanese Prime<br /> Minister Shinzō Abe<br /> conduct a joint news<br /> conference after<br /> their second day of<br /> meetings."," Rudy Giuliani, as<br /> well as Jane and<br /> Marty Raskin, join<br /> President Trump's<br /> legal team. The<br /> Raskins are married<br /> law partners based<br /> in Coral Gables,<br /> Florida."," President Trump uses<br /> Twitter to attack<br /> New York Times<br /> reporter Maggie<br /> Haberman following<br /> an article she<br /> wrote about his poor<br /> treatment of Michael<br /> Cohen and that Cohen<br /> may cooperate with<br /> prosecutors as a<br /> result."," President Trump<br /> tweets a claim<br /> that North Korea<br /> has agreed to<br /> denuclearize."," French President<br /> Emmanuel Macron,<br /> accompanied by his<br /> spouse, begins a<br /> three-day state<br /> visit, the first<br /> during the Trump<br /> presidency."," The Senate Committee<br /> on Veterans' Affairs<br /> announces a delay<br /> in the hearing<br /> for Trump veterans<br /> administration<br /> nominee Ronny<br /> Jackson."," French President<br /> Emmanuel Macron<br /> addresses a joint<br /> meeting of the<br /> members of Congress."," Dr. Ronny Jackson<br /> withdraws his<br /> nomination to head<br /> the Department of<br /> Veterans Affairs."," President Trump<br /> holds a bilateral<br /> meeting and joint<br /> press conference<br /> with German<br /> Chancellor Angela<br /> Merkel at the White<br /> House."," Stormy Daniels files<br /> a defamation lawsuit<br /> against Trump for<br /> his \"total con job\"<br /> tweet about the<br /> forensic sketch of<br /> a man who allegedly<br /> threatened her in<br /> 2011."," President Trump<br /> presents the<br /> Commander-in-Chief's<br /> Trophy to the<br /> Army Black Knights<br /> football team for<br /> its victory over<br /> both Air Force and<br /> Navy last year."," President Trump<br /> announces plans to<br /> replace retiring<br /> White House lawyer<br /> Ty Cobb with former<br /> President Clinton's<br /> impeachment lawyer,<br /> Emmet Flood."," President Trump<br /> speaks at the<br /> National Day of<br /> Prayer service in<br /> the Rose Garden."," Over the preceding<br /> week, four EPA<br /> officials have<br /> resigned: Albert<br /> \"Kell\" Kelly,<br /> the top Superfund<br /> advisor; Pasquale<br /> Perrotta, the head<br /> of Administrator<br /> Pruitt's security<br /> detail; Associate<br /> Administrator<br /> Liz Bowman; and<br /> today John Konkus,<br /> deputy Associate<br /> Administrator for<br /> public affairs."," President Trump<br /> attends a fundraiser<br /> for the RNC in<br /> Cleveland, Ohio."," First Lady Melania<br /> Trump announces<br /> the launch of her<br /> Be Best anti-cyber<br /> bullying initiative."," The White House<br /> denies a New York<br /> Times report that<br /> President Trump<br /> has privately told<br /> French President<br /> Emmanuel Macron the<br /> U.S. is withdrawing<br /> from the Iran<br /> nuclear deal."," R. Timothy Ziemer,<br /> the official on the<br /> National Security<br /> Council responsible<br /> for global health<br /> security and<br /> biodefense, is<br /> dismissed and<br /> his position is<br /> abolished."," President Trump<br /> welcomes three<br /> American detainees<br /> released from North<br /> Korea."," Kelly Sadler,<br /> a White House<br /> official, mocks<br /> Senator John<br /> McCain, saying his<br /> opposition to Gina<br /> Haspel, Trump's<br /> nominee for CIA<br /> director, \"doesn't<br /> matter, he's dying<br /> anyway\"."," A report shows the<br /> Trump Administration<br /> is concerned about<br /> chemically polluted<br /> water supplies<br /> near military<br /> installations."," The Trump<br /> Administration<br /> eliminates the White<br /> House's top cyber<br /> security policy<br /> role. Rob Joyce, the<br /> coordinator, is no<br /> longer at the White<br /> House."," President Trump<br /> submits a disclosure<br /> of personal finances<br /> which is required<br /> by the Office of<br /> Government Ethics.<br /> Trump acknowledges<br /> that Michael Cohen<br /> was paid between<br /> $100,000 and<br /> $250,000 in 2017."," Gina Haspel is<br /> confirmed by the<br /> Senate as the first<br /> female CIA director."," President Trump<br /> announces the<br /> nomination of acting<br /> VA secretary Robert<br /> Wilkie to head<br /> the agency. At the<br /> same White House<br /> event he expressed<br /> his \"sadness and<br /> heartbreak\" over<br /> the Santa Fe school<br /> shooting."," President Trump<br /> requests the<br /> Justice Department<br /> investigate whether<br /> his campaign was<br /> \"infiltrated\" by the<br /> FBI. The inspector<br /> general will<br /> review the FBI's<br /> counterintelligence<br /> investigation of the<br /> 2016 Trump campaign."," President Trump<br /> holds a bilateral<br /> meeting with South<br /> Korean President<br /> Moon Jae-in at<br /> the White House<br /> to discuss the<br /> denuclearization of<br /> North Korea."," President Trump<br /> posthumously pardons<br /> heavyweight boxing<br /> champ Jack Johnson."," President Trump<br /> delivers the<br /> commencement<br /> address at the U.S.<br /> Naval Academy in<br /> Annapolis, Maryland."," President Trump<br /> performs a wreath-<br /> laying ceremony<br /> at the Tomb of the<br /> Unknown Soldier<br /> at the Arlington<br /> National Cemetery<br /> and gives a speech<br /> honoring those who<br /> have died fighting<br /> for the U.S."," President Trump<br /> announces that the<br /> North Korea–United<br /> States summit would<br /> resume as scheduled<br /> for June 12 in<br /> Singapore after he<br /> met North Korean<br /> general Kim Yong-<br /> chol at the White<br /> House."," Raj Shah announces<br /> via email that Kelly<br /> Sadler, a member<br /> of the White House<br /> communications<br /> staff, is \"... no<br /> longer employed<br /> within the Executive<br /> Office of the<br /> President\"."," President Trump<br /> holds a bilateral<br /> meeting and joint<br /> press conference<br /> with Japanese Prime<br /> Minister Shinzō Abe<br /> at the White House."," President Trump<br /> attends the 44th G7<br /> summit with world<br /> leaders of G7 in La<br /> Malbaie, Canada."," After President<br /> Trump leaves the<br /> 44th G7 summit<br /> early, he withdraws<br /> the United States'<br /> endorsement of a<br /> joint communique<br /> by the G7, and<br /> labels Canadian<br /> Prime Minister<br /> Justin Trudeau \"Very<br /> dishonest & meek\"."," Trade adviser<br /> Peter Navarro says<br /> there is \"a special<br /> place in hell for\"<br /> Canadian Prime<br /> Minister Justin<br /> Trudeau for having<br /> employed \"bad faith<br /> diplomacy with<br /> President Donald J.<br /> Trump and then tries<br /> to stab him in the<br /> back on the way out<br /> the door ... that<br /> comes right from Air<br /> Force One.\""," President Trump<br /> holds a bilateral<br /> meeting with<br /> Singaporean Prime<br /> Minister Lee Hsien<br /> Loong in the Istana<br /> Palace."," President Trump<br /> and North Korean<br /> Leader Kim Jong-<br /> un participate in<br /> a summit at the<br /> Capella Hotel in<br /> Sentosa, Singapore."," The Department of<br /> Homeland Security<br /> states that between<br /> April 19 and May<br /> 31, 2018, there<br /> were 1,995 migrant<br /> children separated<br /> at the Mexico–United<br /> States border from<br /> 1,940 adults who<br /> are being held for<br /> criminal prosecution<br /> for an illegal<br /> border crossing."," President Trump<br /> meets with King<br /> Felipe VI and Queen<br /> Letizia of Spain at<br /> the White House."," President Trump<br /> holds a bilateral<br /> meeting with King<br /> Abdullah II of<br /> Jordan at the White<br /> House."," President Trump<br /> holds a bilateral<br /> meeting with<br /> Portuguese President<br /> Marcelo Rebelo de<br /> Sousa at the White<br /> House."," President Trump<br /> holds a bilateral<br /> meeting with Dutch<br /> Prime Minister Mark<br /> Rutte at the White<br /> House."," President Trump<br /> hosts military<br /> personnel and their<br /> families for a<br /> picnic and fireworks<br /> show at the White<br /> House as part of<br /> Independence Day<br /> celebrations."," Scott Pruitt<br /> resigns as EPA<br /> Administrator,<br /> effective<br /> July 6, amidst<br /> fifteen federal<br /> investigations by<br /> various government<br /> ethics agencies<br /> for his assorted<br /> management scandals<br /> (see here for<br /> descriptions.)"," Andrew Wheeler,<br /> a former coal<br /> lobbyist and Deputy<br /> Administrator of<br /> the EPA since April<br /> 2018, succeeds Scott<br /> Pruitt as acting EPA<br /> administrator."," President Trump<br /> nominates Brett<br /> Kavanaugh, a U.S.<br /> Appellate Court<br /> Judge on the<br /> District of Columbia<br /> Circuit, to fill<br /> the vacancy on the<br /> U.S. Supreme Court<br /> created by the<br /> impending retirement<br /> of Associate Justice<br /> Anthony Kennedy."," President Trump and<br /> First Lady Melania<br /> Trump attend a<br /> black-tie dinner at<br /> Blenheim Palace."," Special counsel<br /> Robert Mueller<br /> indicts twelve<br /> Russian intelligence<br /> officers, alleging<br /> that they \"engag[ed]<br /> in a 'sustained<br /> effort' to hack<br /> Democrats' emails<br /> and computer<br /> networks\"."," President Trump<br /> remarks during a CBS<br /> interview, \"Now you<br /> wouldn't think of<br /> the European Union,<br /> but they're a foe,\"<br /> in response to a<br /> question about the<br /> biggest foes of the<br /> United States."," President Trump<br /> and Russian<br /> President Vladimir<br /> Putin participate<br /> in a summit at<br /> the Presidential<br /> Palace in Helsinki,<br /> Finland. At<br /> the joint press<br /> conference, Trump<br /> reiterates both<br /> his faulting of<br /> \"U.S. foolishness<br /> and stupidity\"<br /> and the Mueller<br /> investigation<br /> for the freeze in<br /> relations between<br /> Russia and the<br /> United States<br /> and his refusal<br /> to recognize the<br /> Russian government's<br /> interference in the<br /> 2016 U.S. elections,<br /> despite extensive<br /> assessments by<br /> United States<br /> intelligence<br /> agencies."," The Treasury<br /> Department repeals<br /> the requirement<br /> of some non-<br /> profit groups,<br /> most prominently<br /> the National Rifle<br /> Association (NRA),<br /> to disclose their<br /> donor lists to the<br /> Internal Revenue<br /> Service. The rule<br /> change is announced<br /> whilst the NRA<br /> was named as the<br /> \"primary avenue<br /> of influence\" for<br /> Maria Butina, a<br /> Russian national<br /> charged on July<br /> 16 by the national<br /> security division<br /> of the Justice<br /> Department with<br /> conspiracy to act<br /> as an agent of the<br /> Russian government<br /> within the United<br /> States without<br /> the requisite<br /> notification to<br /> the U.S. Attorney<br /> General. The<br /> affidavit alleges<br /> that Butina (along<br /> with an unnamed<br /> business partner,<br /> presumed to be<br /> Aleksandr Torshin)<br /> \"infiltrat[ed]<br /> organizations<br /> having influence in<br /> American politics,<br /> for the purpose<br /> of advancing the<br /> interests of the<br /> Russian Federation\"."," When asked by a<br /> reporter before<br /> a Cabinet meeting<br /> whether he believes<br /> that the Russian<br /> government continues<br /> to make efforts<br /> to interfere in<br /> American elections,<br /> Trump replied,<br /> \"no\". However, Sarah<br /> Huckabee Sanders<br /> (the White House<br /> Press Secretary)<br /> disputed that<br /> Trump was in fact<br /> answering the<br /> reporter's question<br />...

To leave a comment for the author, please follow the link and comment on their blog: Jason Timm.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The post time-lining the Trump presidency first appeared on R-bloggers.


Warpspeed confidence what is credible? — Part 2

$
0
0

[This article was first published on Posts on R Lover ! a programmer, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

In my last post I started exploring a basic statistical analysis of how confident we should feel about the effectiveness of a vaccine for COVID-19 (Operation Warpspeed). A reminder I’m not an epidemiologist, I don’t have any data for safety, and we’re still quite early in the Phase III trials – just approaching the point at which they can take a first “peek” at the data (which is doubleblind). You’ll be best served if you’ve already read the previous post.

The three key conditions that have to be (there are certainly other conditions as well):

  1. 53 confirmed covid-19 cases among the 30,000 participants
  2. At least five severe cases of covid-19 among people who receive the placebo
  3. That there be at least two months of follow-up on half the study participants.

Regulators will require that the vaccine be at least 50 percent effective before the manufacturer can seek emergency use authorization.

Last time

Last time we used a variety of frequentist tools and tests to model our potential results, including a handy table that maps effectiveness to the number of the 53 cases in the placebo and vaccine conditions. We want our vaccine to be at least 50% effective. We can operationalize that most simply with \[\frac{placebo~cases – vaccinated~cases}{placebo~cases}\] So for example if 19 of the 53 cases had received the vaccine our effectiveness is \[\frac{placebo~cases – vaccinated~cases}{placebo~cases} = (34-19)/34 = 0.4411765\] which is very close to what we need. So in the best possible scenario (remember we require that at least 5 people who got the vaccine contract COVID before we can run the numbers) our effectiveness is ~90%. We need the number of people who received the vaccine and still contracted COVID to be 17 or less.

After our classical frequentist efforts we began a journey of exploring bayesian tools and techniques. That’s where we’ll pick up in this post. First let’s load some essential libraries.

library(dplyr)library(ggplot2)library(kableExtra)theme_set(theme_bw())

Last post we ventured as far as building a simple model with a flat prior and treating the outcomes as simple binomial equations (a coin flip if you) will. We built the model in the JAGS language and fed it to run.jags for 40,000 MCMC iterations. We used tidybayes::tidy_draws to extract the chains/draws. That gave us estimates for the rate of infection for both those who received the placebo and those who received the actual vaccine. \[\frac{placebo~infection~rate – vaccinated~infection~rate}{placebo~infection~rate} * 100\] gives us what we really want to investigate which is the percentage difference in infection rates. We’re looking for (since we multiplied by 100) a number that is around 50. Which in essence is a 50% effectiveness rating. We kept it simple assuming both subject pools (the number who received placebo versus the real vaccine was an even split 15,000 each). A simple call to bayestestR::hdi gives us a graphical portrayal of what we want to know. Even with a simple 19/34 split we have mounting evidence that the vaccine is working. We’re not at all totally convinced it’s 50% or more. But we can take heart with the fact that 95% of our draws wind up in the region 7.7% to 71.1% effectiveness. N.B. yes we’d really like to see a split like 17/36 or even lower to boost our credibility, I’m using lower numbers simply to make it more “exciting”, we all have to wait on the real data.

## Calling 4 simulations using the parallel method...## All chains have finished## Simulation complete.  Reading coda files...## Coda files loaded successfully## Finished running the simulation

Okay now that you’re caught up let’s push our bayesian skills even farther.

More credibility for our results

The analysis last time was based upon a very nice functionbayes.prop.testcontained in a package called bayesian_first_aid. It was the first thing I stumbled upon that was a near equivalent to the frequentist tests we were using. Let’s investigate some other tools. Fair warning in advance they will give us similar results, but you’re reading this to learn right? Personally I find it satisfying to know that no matter which R tool I choose I get the same answer.

The next tool we’ll use is bayesAB. This package is on CRAN and recent. For those of you steeped in other disciplines AB testing generally seeks to ask questions about whether option A or option B is “better”. It is often used in marketing for example presenting users with two different versions of a website or ad and seeking to determine which option yields the most purchases. Hopefully the analog to our vaccine trial is readily apparent. You can read more about the package here.

bayesAB expects its input as a pair of vectors one for option A and one for option B. Instead of MCMC methods it uses random sampling from a limited set of distributions. That means it is faster to run but not suitable for very complex models like runjags, or brms or STAN. But for our relatively simple problem it is quite useful.

Let’s make two vectors labeled vaccinated and placebo with the right quantities (again assuming an equal 15,000 in each category). The authors have decided to calculate and plot (A – B) / B with no way to easily customize. Since we require placebo in the denominator that simply means by default we get the right value but with a negative sign. We’ll “correct” that in a bit. By default it samples 100,000 times. It has a custom summary and plot method we’ll display. As with our earlier example we’ll use a flat uninformative pretending we have no information about the effectiveness of the vaccine.

vaccinated <- c(rep(0, 15000 - 19), rep(1, 19))placebo <- c(rep(0, 15000 - 34), rep(1, 34))AB1 <-    bayesAB::bayesTest(B_data = placebo,                       A_data = vaccinated,                      priors = c('alpha' = 1, 'beta' = 1),                      distribution = 'bernoulli')summary(AB1)## Quantiles of posteriors for A and B:## ## $Probability## $Probability$A##           0%          25%          50%          75%         100% ## 0.0004575392 0.0011201359 0.0013089507 0.0015199810 0.0030369367 ## ## $Probability$B##           0%          25%          50%          75%         100% ## 0.0009776941 0.0020570086 0.0023106757 0.0025868629 0.0045641318 ## ## ## --------------------------------------------## ## P(A > B) by (0)%: ## ## $Probability## [1] 0.0199## ## --------------------------------------------## ## Credible Interval on (A - B) / B for interval length(s) (0.9) : ## ## $Probability##         5%        95% ## -0.6473618 -0.1075419 ## ## --------------------------------------------## ## Posterior Expected Loss for choosing B over A:## ## $Probability## [1] 0.8460082plot(AB1)

Again I’ll remind you the sign is reversed, but you can clearly see that except for the sign the results are comparable to our earlier results. The plots (3) are informative, displaying our prior, the A & B superimposed and our coveted % difference in infection rate.

The third plot explicitly calls out the fact that ~98% of the time our data shows the vaccine to be effective. With the peak (high density) occurring near 50% effective.

The plots are good, but I’m fussy. It used to be slightly complex to get the draws or chains from a bayesian model. It’s getting easier and easier. In this case a quick look at our AB1 object tells us they are in AB1$posteriors$Probability. This is a list with two vectors A & B. Let’s convert to a tibble and rename them back to what they actually are vaccinated = A, placebo = B. Now if we tidyr::pivot_longer(everything(), names_to = "group") we have a nice tibble we can easily send to ggplot and format our (my) way.

ggdist has a variety of nice functions for summarizing and displaying draws and chains. stat_halfeye not only plots it as a density curve but allows us to add per group credible intervals. If we leave the data “wide” we can compute our diff_rate and plot it. If we prefer a text table bayestestR::describe_posterior(ci = c(0.89, 0.95))

as_tibble(AB1$posteriors$Probability) %>%   rename(vaccinated = A, placebo = B) %>%   tidyr::pivot_longer(everything(), names_to = "group") %>%   ggplot(aes(x = value, fill = group)) +   ggdist::stat_halfeye(.width = c(0.89, 0.95),                        alpha = .8,                        slab_colour = "black",                        slab_size = .5) +   ggtitle("Infection rates for vaccine and placebo groups (N = 30,000)") +   xlab("Infection rate") +   theme(axis.title.y = element_blank(),        axis.text.y = element_blank(),        axis.ticks.y = element_blank(),        panel.grid.major.y = element_blank(),        panel.grid.minor.y = element_blank())

as_tibble(AB1$posteriors$Probability) %>%   rename(vaccinated = A, placebo = B) %>%   mutate(diff_rate = (placebo - vaccinated) / placebo * 100) %>%   ggplot(aes(x = diff_rate)) +   ggdist::stat_halfeye(.width = c(0.89, 0.95),                        alpha = .9,                        slab_fill = "dark green",                        slab_colour = "black",                        slab_size = .5) +   ggtitle("% Difference in Infection rates for vaccine and placebo groups (N = 30,000)") +   xlab("% Difference in Infection Rates") +   theme(axis.title.y = element_blank(),        axis.text.y = element_blank(),        axis.ticks.y = element_blank(),        panel.grid.major.y = element_blank(),        panel.grid.minor.y = element_blank())

as_tibble(AB1$posteriors$Probability) %>%   rename(vaccinated = A, placebo = B) %>%   mutate(diff_rate = (placebo - vaccinated) / placebo * 100) %>%   bayestestR::describe_posterior(ci = c(0.89, 0.95))## # Description of Posterior Distributions## ## Parameter  | Median |                      CI |      pd |        89% ROPE | % in ROPE## -------------------------------------------------------------------------------------## vaccinated |  0.001 | 89% CI [ 0.001,  0.002] | 100.00% | [-0.100, 0.100] |       100## vaccinated |  0.001 | 95% CI [ 0.001,  0.002] | 100.00% | [-0.100, 0.100] |       100## placebo    |  0.002 | 89% CI [ 0.002,  0.003] | 100.00% | [-0.100, 0.100] |       100## placebo    |  0.002 | 95% CI [ 0.002,  0.003] | 100.00% | [-0.100, 0.100] |       100## diff_rate  | 43.305 | 89% CI [16.664, 67.485] |  98.01% | [-0.100, 0.100] |         0## diff_rate  | 43.305 | 95% CI [ 8.100, 71.230] |  98.01% | [-0.100, 0.100] |         0

Actually let’s go ahead and save the results in a tibble named diff_rate_results and showcase the functions in bayestestR. Rather than explain each function and what they mean. I’m going to refer you to their website which does a great job of explaining it..

The bottom line is that the results are comparable to our two earlier explorations.

diff_rate_results <-   as_tibble(AB1$posteriors$Probability) %>%   rename(vaccinated = A, placebo = B) %>%   mutate(diff_rate = (placebo - vaccinated) / placebo * 100)bayestestR::describe_posterior(diff_rate_results$diff_rate)## # Description of Posterior Distributions## ## Parameter | Median |           89% CI |     pd |        89% ROPE | % in ROPE## ----------------------------------------------------------------------------## Posterior | 43.305 | [16.664, 67.485] | 98.01% | [-0.100, 0.100] |         0bayestestR::ci(diff_rate_results$diff_rate, method = "HDI", ci = c(0.005,0.025,0.5,0.975,0.995)) %>% plot

bayestestR::p_direction(diff_rate_results$diff_rate) %>% plot

bayestestR::p_significance(diff_rate_results$diff_rate) %>% plot

bayestestR::rope(diff_rate_results$diff_rate, ci = c(0.9, 0.95))  %>% plot

One final bayesian tool (this post)

Okay one more set of analyses using brms.

The brms package provides an interface to fit Bayesian generalized (non-)linear multivariate multilevel models using Stan, which is a C++ package for performing full Bayesian inference (see https://mc-stan.org/).

Quite frankly it is more than we need for our simple little analysis. A bit like using a sledge hammer as a fly-swatter. Besides the simple joy of learning about it however, there is one practical reason to use it. As our data grows and we inevitably want to conduct more sophisticated analysis factoring things in like gender, age and race. It is likely to become the tool of choice. I’m not going to dwell on it but it’s worthy to note that STAN uses different method for its markov chains.

First we need to put the data in the preferred format which is actually a simple one row tibble. Then we put things in a format brms can understand. A bit of an oddity here, because we are moving to a GLM model we’re not operating on the binomial distribution directly rather transforming back and forth through logit and inverse_logit`.

We’ll run ~50,000 across 5 cores and get our summary and diagnostic plots.

library(brms)d2 <-   tibble(placebo = 34,          vaccine = 19,          n1 = 15000,          n2 = 15000)model_1 <- bf(placebo | trials(n1) ~ 1)model_2 <- bf(vaccine | trials(n2) ~ 1)priors <- get_prior(data = d2,                    family = binomial(),                    formula = model_1 + model_2)priors$prior[2] <- "normal(0, 1)"priors$prior[3] <- "normal(0, 1)"priors##         prior     class coef group    resp dpar nlpar bound  source##        (flat) Intercept                                     default##  normal(0, 1) Intercept            placebo                  default##  normal(0, 1) Intercept            vaccine                  defaultfit2 <-   brm(data = d2, family = binomial(),       model_1 + model_2,       prior = priors,       iter = 10000,        warmup = 1000,        cores = 6,        chains = 6,       seed = 7)fit2##  Family: MV(binomial, binomial) ##   Links: mu = logit##          mu = logit ## Formula: placebo | trials(n1) ~ 1 ##          vaccine | trials(n2) ~ 1 ##    Data: d2 (Number of observations: 1) ## Samples: 6 chains, each with iter = 10000; warmup = 1000; thin = 1;##          total post-warmup samples = 54000## ## Population-Level Effects: ##                   Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS## placebo_Intercept    -5.94      0.16    -6.26    -5.64 1.00    41344    33647## vaccine_Intercept    -6.40      0.20    -6.80    -6.03 1.00    48654    36148## ## Samples were drawn using sampling(NUTS). For each parameter, Bulk_ESS## and Tail_ESS are effective sample size measures, and Rhat is the potential## scale reduction factor on split chains (at convergence, Rhat = 1).plot(fit2)

Everything looks good except for the funny scale we’re operating on. Rather than use tidybayes::tidy_draws to extract the results of our chains we’ll use posterior_samples(fit2, add_chain = FALSE). We’ll use transmute to convert back to our original scale and get names we prefer.

As we did earlier we’ll use tidyr::pivot_longer to convert to long format and pipe it through to ggplot to compare the two distributions. Then we’ll plot the effectiveness (diff_rate) estimate much as we have done before.

Finally we pipe this cleaned up data to bayestestR::describe_posterior() we get back a table that is a little easier to read. Focus on just the line for diff_rate. We can of course also pipe it into other plotting functions if you have favorites.

library(tidybayes)theme_set(theme_bw())post2 <- posterior_samples(fit2, add_chain = FALSE)post2 %>%   transmute(placebo = inv_logit_scaled(b_placebo_Intercept),             vaccine = inv_logit_scaled(b_vaccine_Intercept)) %>%   tidyr::pivot_longer(cols = everything()) %>%   ggplot(aes(x = value, y = name)) +   tidybayes::stat_halfeye(point_interval = mode_hdi,                            .width = c(.5, .95)) +   scale_y_discrete(NULL) +   scale_x_continuous(labels = scales::label_percent()) +   xlab("Percent Infected") +   theme(panel.grid = element_blank())

post2 %>%   mutate(placebo = inv_logit_scaled(b_placebo_Intercept),          vaccine = inv_logit_scaled(b_vaccine_Intercept)) %>%   mutate(diff_rate = (placebo - vaccine) / placebo) %>%   ggplot(aes(x = diff_rate)) +   geom_histogram(color = "grey92", fill = "grey67",                  size = .2, bins = 40) +   tidybayes::stat_pointinterval(aes(y = 0),                       point_interval = mode_hdi, .width = .95) +   scale_y_continuous(NULL, breaks = NULL) +   scale_x_continuous(labels = scales::label_percent()) +   xlab("Percent Difference in rate of infection") +   theme(panel.grid = element_blank())

post2 %>%   mutate(placebo = inv_logit_scaled(b_placebo_Intercept),          vaccine = inv_logit_scaled(b_vaccine_Intercept)) %>%   mutate(diff_rate = (placebo - vaccine) / placebo) %>%   bayestestR::describe_posterior()## # Description of Posterior Distributions## ## Parameter         |  Median |             89% CI |      pd |        89% ROPE | % in ROPE## ----------------------------------------------------------------------------------------## placebo_Intercept |  -5.934 | [ -6.191,  -5.686] | 100.00% | [-0.100, 0.100] |         0## vaccine_Intercept |  -6.393 | [ -6.710,  -6.086] | 100.00% | [-0.100, 0.100] |         0## lp__              | -46.880 | [-48.398, -46.174] | 100.00% | [-0.100, 0.100] |         0## placebo           |   0.003 | [  0.002,   0.003] | 100.00% | [-0.100, 0.100] |       100## vaccine           |   0.002 | [  0.001,   0.002] | 100.00% | [-0.100, 0.100] |       100## diff_rate         |   0.368 | [  0.101,   0.604] |  96.73% | [-0.100, 0.100] |         0preplot <-    post2 %>%   mutate(placebo = inv_logit_scaled(b_placebo_Intercept),          vaccine = inv_logit_scaled(b_vaccine_Intercept)) %>%   mutate(diff_rate = (placebo - vaccine) / placebo) %>%   select(diff_rate)    plot(bayestestR::hdi(preplot, ci = c(.89, .95, .99)))

Done

I’ve decided to make this a three parter. Please hang in there more bayesian “magic” follows soon. Probably next week.

Hope you enjoyed the post. Comments always welcomed. Especially please let me know if you actually use the tools and find them useful.

Extra credit for me for not expressing a political view at any point. Let the data speak and the counting continue.

Chuck

CC BY-SA 4.0

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License

var vglnk = {key: '949efb41171ac6ec1bf7f206d57e90b8'}; (function(d, t) { var s = d.createElement(t); s.type = 'text/javascript'; s.async = true;// s.defer = true;// s.src = '//cdn.viglink.com/api/vglnk.js'; s.src = 'https://www.r-bloggers.com/wp-content/uploads/2020/08/vglnk.js'; var r = d.getElementsByTagName(t)[0]; r.parentNode.insertBefore(s, r); }(document, 'script'));

To leave a comment for the author, please follow the link and comment on their blog: Posts on R Lover ! a programmer.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The post Warpspeed confidence what is credible? -- Part 2 first appeared on R-bloggers.

Explainable Statistical/Machine Learning explainability using Kernel Ridge Regression surrogates

$
0
0

[This article was first published on T. Moudiki's Webpage - R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

As announced last week, this week’s topic is Statistical/Machine Learning (ML) explainability using Kernel Ridge Regression (KRR) surrogates. The core idea underlying this type of ML explainability methods is to apply a second learning model to the predictions of the first so-called black-box model.

How am I envisaging it? Not by utilizing KRR as a learning model, but as a flexible (continuous and derivable) function of model covariates and predictions. For more details, you can read this pdf document on ResearchGate:

Statistical/Machine learning model explainability using Kernel RidgeRegression surrogates

Comments, suggestions are welcome as usual.

pres-image

var vglnk = {key: '949efb41171ac6ec1bf7f206d57e90b8'}; (function(d, t) { var s = d.createElement(t); s.type = 'text/javascript'; s.async = true;// s.defer = true;// s.src = '//cdn.viglink.com/api/vglnk.js'; s.src = 'https://www.r-bloggers.com/wp-content/uploads/2020/08/vglnk.js'; var r = d.getElementsByTagName(t)[0]; r.parentNode.insertBefore(s, r); }(document, 'script'));

To leave a comment for the author, please follow the link and comment on their blog: T. Moudiki's Webpage - R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The post Explainable Statistical/Machine Learning explainability using Kernel Ridge Regression surrogates first appeared on R-bloggers.

Upcoming workshop: Sparkling Shiny App

$
0
0

[This article was first published on Mirai Solutions, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Mirai’s workshop series continues. Next in the pipeline is Sparkling Shiny App on 24th November.

In recent years, shiny has become increasingly popular in the R community. No wonder! Shiny is a master at empowering users to easily visualize and communicate their data science work. However, there is a huge difference between quickly drafting a user interface on top of your R functions, and properly building up an application that is going to serve from prototyping all the way to production. In fact, with increasing complexity and addition of features, a shiny app can easily become a little wild monster, and reactivity can quickly get out of wing.

shiny Monster

How to make sure your app remains manageable, maintainable and understandable, while retaining its simple-to-develop attitude? The key lays in structuring your app and your development correctly from the beginning, as well as using the layout that best suits your app needs. In this workshop, Mirai’s Shiny experts will guide you through the state of the art approaches to shiny development — including best practices, modern development framework, and advanced layout & app structure. Join us, and learn how to make your shiny code shine.

Mirai Shiny App

For an introduction to professional shiny development, check out our article and have a look at our gallery for some practical examples of complex shiny apps.

var vglnk = {key: '949efb41171ac6ec1bf7f206d57e90b8'}; (function(d, t) { var s = d.createElement(t); s.type = 'text/javascript'; s.async = true;// s.defer = true;// s.src = '//cdn.viglink.com/api/vglnk.js'; s.src = 'https://www.r-bloggers.com/wp-content/uploads/2020/08/vglnk.js'; var r = d.getElementsByTagName(t)[0]; r.parentNode.insertBefore(s, r); }(document, 'script'));

To leave a comment for the author, please follow the link and comment on their blog: Mirai Solutions.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The post Upcoming workshop: Sparkling Shiny App first appeared on R-bloggers.

Undersampling by Groups in R

$
0
0

[This article was first published on R – Predictive Hacks, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

When we are dealing with unbalanced classes in Machine Learning projects there are many approaches that you can follow. Just to main some of them:

  • Undersampling: We try to reduce the observations from the majority class so that the final dataset to be balanced
  • Oversampling: We try to generate more observations from the minority class usually by replicating the samples from the minority class so that the final dataset to be balanced.
  • Synthetic Data Generation (SMOTE): We generate artificial data using bootstrapping and k-Nearest Neighbors algorithms.

Generate the Unbalanced Data

The scenario is that we are dealing with 3 email campaigns that have different CTRs and we want to apply undersampling to normalize the CTR by the campaign so that to avoid any skewness and biased when we will build the Machine Learning model. The hypothetical dataset is the following:

  • Campaign A: 5000 Observations with 10% CTR (approx)
  • Campaign B: 10000 Observations with 20% CTR (approx)
  • Campaign C: 1000 Observations with 30% CTR (approx)

Let’s try to generate this random sample in R.

library(tidyverse)

set.seed(5)
df = rbind(data.frame(Campaign = "A", Click = rbinom(n=5000, size=1, prob=0.1)),
           data.frame(Campaign = "B", Click = rbinom(n=10000, size=1, prob=0.2)),
           data.frame(Campaign = "C", Click = rbinom(n=1000, size=1, prob=0.3)))

head(df)
 

Output:

  Campaign Click
1        A     0
2        A     0
3        A     1
4        A     0
5        A     0
6        A     0

Let’s get the CTR by Campaign

df%>%group_by(Campaign)%>%
    summarise(CTR=mean(Click))
 

Output:

# A tibble: 3 x 2
  Campaign   CTR
      
1 A        0.106
2 B        0.198
3 C        0.302

As we can see the A campaign has 10.6% CTR, the B 19.8% and the C 30.2%. Let’s add also a random column called attribute which takes the values “X”, “Y”, “Z” since we will deal with datasets with more than two columns.

df$Attribute<-sample(c("X","Y", "Z"), size = dim(df)[1], replace = TRUE, prob = c(0.2, 0.6, 0.2))
head(df)

  Campaign Click Attribute
1        A     0         Y
2        A     0         Y
3        A     1         Z
4        A     0         Y
5        A     0         Z
6        A     0         Z

Now, our goal is to apply undersampling so that each campaign will have around 50% CTR

Undersampling by Group

We will use the map2 function from the purrr package which belongs to the tidyverse family:

campaign_summary <- df %>% group_by(Campaign)%>% summarize(rr=sum(Click)/n(), pos= sum(Click))


df_neg_sample<- df %>% filter(Click==0) %>%
  group_by(Campaign) %>% 
  nest() %>%             #group all data by campaign name
  ungroup() %>% 
  inner_join(campaign_summary, by="Campaign") 



sampled_df_neg<-df_neg_sample %>%
  mutate(samp = map2(data, pos, sample_n, replace = FALSE))  %>%# sample based on the campaing summary
  select(-data) %>%  #remove original nested data
  unnest(samp) %>% select(c(-"rr",-"pos"))


df_pos <- df %>% filter(Click==1) #positive samples
new_df <- rbind(df_pos,sampled_df_neg) #balanced set positive negative within each campaign

head(new_df)

  Campaign Click Attribute
1        A     1         Z
2        A     1         Y
3        A     1         Y
4        A     1         Y
5        A     1         Y
6        A     1         Y

tail(new_df)

     Campaign Click Attribute
5613        C     0         Y
5614        C     0         Y
5615        C     0         Z
5616        C     0         Y
5617        C     0         Y
5618        C     0         X

Let’s check if the new_df is balanced by campaign. We will group by campaign and we will show the CTR and the number of observations:

new_df%>%group_by(Campaign)%>%summarise(CTR=mean(Click), Observations=n())

  Campaign   CTR Observations
              
1 A          0.5         1064
2 B          0.5         3950
3 C          0.5          604

As we can see, we sacrificed a sample but we have a balanced number of classes for every campaign (50-50).


Undersampling by Group using the ROSE Package

We can use also the ROSE package. Below we will apply a for loop by campaign so that to get a balanced sample using the undersampling technique.

library(ROSE)


balanced_sample = NULL


for (c in unique(df$Campaign)) {
  tmp_df = df%>%filter(Campaign==c)
  tmp<-ovun.sample(Click ~ ., data = tmp_df, method = "under", p = 0.5, seed = 5)$data
  balanced_sample<-rbind(balanced_sample, tmp)
 }

Let’s check if the balanced_sample is actually balanced.

balanced_sample%>%group_by(Campaign)%>%summarise(CTR=mean(Click), Observations=n())
 

Output:

  Campaign   CTR Observations
              
1 A        0.504         1056
2 B        0.496         3978
3 C        0.510          592

Awesome. We showed two different approaches of how you can apply undersampling by group.

var vglnk = {key: '949efb41171ac6ec1bf7f206d57e90b8'}; (function(d, t) { var s = d.createElement(t); s.type = 'text/javascript'; s.async = true; // s.defer = true; // s.src = '//cdn.viglink.com/api/vglnk.js'; s.src = 'https://www.r-bloggers.com/wp-content/uploads/2020/08/vglnk.js'; var r = d.getElementsByTagName(t)[0]; r.parentNode.insertBefore(s, r); }(document, 'script'));

To leave a comment for the author, please follow the link and comment on their blog: R – Predictive Hacks.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The post Undersampling by Groups in R first appeared on R-bloggers.

future 1.20.1 – The Future Just Got a Bit Brighter

$
0
0

[This article was first published on JottR on R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

future 1.20.1 is on CRAN. It adds some new features, deprecates old and unwanted behaviors, adds a couple of vignettes, and fixes a few bugs.

Interactive debugging

First out among the new features, and a long-running feature request, is the addition of argument split to plan(), which allows us to split, or “tee”, any output produced by futures.

The default is split = FALSE for which standard output and conditions are captured by the future and only relayed after the future has been resolved, i.e. the captured output is displayed and re-signaled on the main R session when value of the future is queried. This emulates what we experience in R when not using futures, e.g. we can add temporary print() and message() statements to our code for quick troubleshooting. You can read more about this in blog post ‘future 1.9.0 – Output from The Future’.

However, if we want to use debug() or browser() for interactive debugging, we quickly realize they’re not very useful because no output is visible, which is because also their output is captured by the future. This is where the new “split” feature comes to rescue. By using split = TRUE, the standard output and all non-error conditions are split (“tee:d”) on the worker’s end, while still being captured by the future to be relayed back to the main R session at a later time. This means that we can debug ‘sequential’ future interactively. Here is an illustration of using browser() for debugging a future:

> library(future)> plan(sequential, split = TRUE)> mysqrt <- function(x) { browser(); y <- sqrt(x); y }> f <- future(mysqrt(1:3))Called from: mysqrt(1:3)Browse[1]> str(x) int [1:3] 1 2 3Browse[1]> debug at #1: y <- sqrt(x)Browse[2]> debug at #1: yBrowse[2]> str(y) num [1:3] 1 1.41 1.73Browse[2]> y[1] <- 0Browse[2]> cont> v <- value(f)Called from: mysqrt(1:3) int [1:3] 1 2 3debug at #1: y <- sqrt(x)debug at #1: y num [1:3] 1 1.41 1.73> v[1] 0.000000 1.414214 1.732051

Comment: Note how the output produced while debugging is relayed also when value() is called. This is a somewhat unfortunate side effect from futures capturing all output produced while they are active.

Preserved logging on workers (e.g. future.batchtools)

The added support for split = TRUE also means that we can now preserve all output in any log files that might be produced on parallel workers. For example, if you use future.batchtools on a Slurm scheduler, you can use plan(future.batchtools::batchtools_slurm, split = TRUE) to make sure standard output, messages, warnings, etc. are ending up in the batchtools log files while still being relayed to the main R session at the end. This way we can inspect cluster jobs while they still run, among other things. Here is a proof-of-concept example using a ‘batchtools_local’ future:

> library(future.batchtools)> plan(batchtools_local, split = TRUE)> f <- future({ message("Hello world"); y <- 42; print(y); sqrt(y) })> v <- value(f)[1] 42Hello world> v[1] 6.480741> loggedOutput(f) [1] "### [bt]: This is batchtools v0.9.14"                                  [2] "### [bt]: Starting calculation of 1 jobs"                              [3] "### [bt]: Setting working directory to '/home/alice/repositories/future'" [4] "### [bt]: Memory measurement disabled"                                 [5] "### [bt]: Starting job [batchtools job.id=1]"                          [6] "### [bt]: Setting seed to 15794 ..."                                   [7] "Hello world"                                                           [8] "[1] 42"                                                                [9] ""                                                                     [10] "### [bt]: Job terminated successfully [batchtools job.id=1]"          [11] "### [bt]: Calculation finished!"  

Without split = TRUE, we would not get lines 7 and 8 in the batchtools logs.

Near-live progress updates also from ‘multicore’ futures

Second out among the new features is ‘multicore’ futures, which now join ‘sequential’, ‘multisession’, and (local and remote) ‘cluster’ futures in the ability of relaying progress updates of progressr in a near-live fashion. This means that all of our most common parallelization backends support near-live progress updates. If this is the first time you hear of progressr, here’s an example of how it can be used in parallel processing:

library(future.apply)plan(multicore)library(progressr)handlers("progress")xs <- 1:5with_progress({  p <- progressor(along = xs)  y <- future_lapply(xs, function(x, ...) {    Sys.sleep(6.0-x)    p(sprintf("x=%g", x))    sqrt(x)  })})# [=================>------------------------------]  40% x=2

Note that the progress updates signaled by p(), updates the progress bar almost instantly, even if the parallel workers run on a remote machine.

Multisession futures agile to changes in R’s library path

Third out is ‘multisession’ futures. It now automatically inherits the package library path from the main R session. For instance, if you use .libPaths() to adjust your library path and then call plan(multisession), the multisession workers will see the same packages as the parent session. This change is based on a feature request related to RStudio Connect. With this update, it no longer matters which type of local futures you use – ‘sequential’, ‘multisession’, or ‘multicore’ – your future code has access to the same set of installed packages.

As a proof of concept, assume that we add tempdir() as a new folder to R’s library path;

> .libPaths(c(tempdir(), .libPaths()))> .libPaths()[1] "/tmp/alice/RtmpwLKdrG"[2] "/home/alice/R/x86_64-pc-linux-gnu-library/4.0-custom"   [3] "/home/alice/software/R-devel/tags/R-4-0-3/lib/R/library"

If we then launch a ‘multisession’ future, we find that it uses the same library path;

> library(future)> plan(multisession)> f <- future(.libPaths())> value(f)[1] "/tmp/alice/RtmpwLKdrG"[2] "/home/alice/R/x86_64-pc-linux-gnu-library/4.0-custom"   [3] "/home/alice/software/R-devel/tags/R-4-0-3/lib/R/library"

Best practices for package developers

I’ve added a vignette ‘Best Practices for Package Developers’, which hopefully provides some useful guidelines on how to write and validate future code so it will work on as many parallel backends as possible.

Saying goodbye to ‘multiprocess’ – but don’t worry …

Ok, lets discuss what is being removed. Using plan(multiprocess), which was just an alias for “plan(multicore) on Linux and macOS and plan(multisession) on MS Windows”, is now deprecated. If used, you will get a one-time warning:

> plan(multiprocess)Warning message:Strategy 'multiprocess' is deprecated in future (>= 1.20.0). Instead, explicitlyspecify either 'multisession' or 'multicore'. In the current R session,'multiprocess' equals 'multicore'.

I recommend that you use plan(multisession) as a replacement for plan(multiprocess). If you are on Linux or macOS, and are 100% sure that your code and all its dependencies is fork-safe, then you can also use plan(multicore).

Although ‘multiprocess’ was neat to use in documentation and examples, it was at the same time ambiguous, and it risked introducing a platform-dependent behavior to those examples. For instance, it could be that the parallel code worked only for users on Linux and macOS because some non-exportable globals were used. If a user or MS Windows tried the same code, they might have gotten run-time errors. Vice versa, it could also be that code works on MS Windows but not on Linux or macOS. Moreover, in future 1.13.0 (2019-05-08), support for ‘multicore’ futures was disabled when running R via RStudio. This was done because forked parallel processing was deemed unstable in RStudio. This meant that a user on macOS who used plan(multiprocess) would end up getting ‘multicore’ futures when running in the terminal while getting ‘multisession’ futures when running in RStudio. These types of platform-specific, environment-specific user experiences were confusing and complicates troubleshooting and communications, which is why it was decided to move away from ‘multiprocess’ in favor of explicitly specifying ‘multisession’ or ‘multicore’.

Saying goodbye to ‘local = FALSE’ – a good thing

In an effort of refining the Future API, the use of future(..., local = FALSE) is now deprecated. The only place where it is still supported, for backward compatible reason, is when using ‘cluster’ futures that are persistent, i.e. plan(cluster, ..., persistent = TRUE). If you use the latter, I recommended that you start thinking about moving away from using local = FALSE also in those cases. Although persistent = TRUE is rarely used, I am aware that some of you got use cases that require objects to remain on the parallel workers also after a future has been resolved. If you have such needs, please see future Issue #433, particularly the parts on “sticky globals”. Feel free to add your comments and suggestions for how we best could move forward on this. The long-term goals is to get rid of both local and persistent in order to harmonize the Future API across all future backends.

For recent bug fixes, please see the package NEWS.

What’s on the horizon?

There are still lots of things on the roadmap. In no specific order, here are the few things in the works:

  • Sticky globals for caching globals on workers. This will decrease the number of globals that need to be exported when launching futures. It addresses several related feature requests, e.g. future Issues #273, #339, #346, #431, and #437.

  • Ability to terminate futures (for backends supporting it), which opens up for the possibility of restarting failed futures and more. This is a frequently requested feature, e.g. Issues #93, #188, #205, #213, and #236.

  • Optional, zero-cost generic hook function. Having them in place opens up for adding a framework for doing time-and-memory profiling/benchmarking futures and their backends. Being able profile futures and their backends will help identify bottlenecks and improve the performance on some of our parallel backends, e.g. Issues #59, #142, #239, and #437.

  • Add support for global calling handlers in progressr. This is not specific to the future framework but since its closely related, I figured I mention this here too. A global calling handler for progress updates would remove the need for having to use with_progress() when monitoring progress. This would also help resolve the common problem where package developers want to provide progress updates without having to ask the user to use with_progress(), e.g. progressr Issues #78, #83, and #85.

That’s all for now – Happy futuring!

Links

See also

var vglnk = {key: '949efb41171ac6ec1bf7f206d57e90b8'}; (function(d, t) { var s = d.createElement(t); s.type = 'text/javascript'; s.async = true;// s.defer = true;// s.src = '//cdn.viglink.com/api/vglnk.js'; s.src = 'https://www.r-bloggers.com/wp-content/uploads/2020/08/vglnk.js'; var r = d.getElementsByTagName(t)[0]; r.parentNode.insertBefore(s, r); }(document, 'script'));

To leave a comment for the author, please follow the link and comment on their blog: JottR on R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The post future 1.20.1 - The Future Just Got a Bit Brighter first appeared on R-bloggers.

About confidence intervals for the Biontech/Pfizer Covid-19 vaccine candidate

$
0
0

[This article was first published on Economics and R - R posts, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Probably, many of you have read the positive news from the Biontech/Pfizer press release from November 9th:

“Vaccine candidate was found to be more than 90% effective in preventing COVID-19 in participants without evidence of prior SARS-CoV-2 infection in the first interim efficacy analysis”

Not being a biostatistician, I was curious how vaccine efficacy is exactly measured. Also, how does the confidence interval look like? Helpfully, Biontech and Pfizer also published a detailed study plan here.

The sample vaccine efficacy can be defined as

\[VE = 1-IRR = 1 – \frac{c_v/n_v}{c_p/n_p}\]

where $n_v$ and $n_p$ are the number of subjects that got a Covid-19 vaccine and a placebo, respectively, while $c_v$ and $c_p$ are the respective number of subjects that fell ill to the Covid-19 disease. IRR stands for incidence rate ratio and measures the ratio of the share of vaccinated subjects that got Covid-19 to the share in the placebo group.

The press release stated that so far 38955 subjects got the two doses of the vaccine or placebo of which 94 subjects fell ill with Covid-19. Furthermore, the study plan stated that the same number of subjects was assigned to the treatment and control group and let’s assume that also in the 38955 subjects analysed so far the ratio is almost equal. An efficacy of at least 90% then implies that from the 94 subjects with Covid-19 at most 8 could have been vaccinated.

The following code computes the IRR and vaccine efficacy assuming that indeed 8 vaccinated subjects got Covid-19.

n = 38955 # number of subjects
nv = round(n/2) # vaccinated
np = n-nv # got placebo

# number of covid cases
cv = 8
cp = 94-cv

# percentage of subjects in control group
# who got Covid-19
round(100*cp/np,2)

## [1] 0.44

# percentage of vaccinated subjects
# who got Covid-19
round(100*cv/nv,2)

## [1] 0.04

# incidence rate ratio in % in sample
IRR = (cv/nv)/(cp/np)
round(IRR*100,1)

## [1] 9.3

# vaccine efficacy in % in sample
VE = 1-IRR
round(VE*100,1)

## [1] 90.7

Assume for the moment this data came from a finished experiment. We could then compute an approximative 95% confidence interval for the vaccine efficacy e.g. using the following formula described in Hightower et. al. 1988

arv = cv/nv
arp = cp/np

# CI for IRR
ci.lower = exp(log(IRR) - 1.96 * sqrt((1-arv)/cv + (1-arp)/cp)) 
ci.upper = exp(log(IRR) + 1.96 * sqrt((1-arv)/cv + (1-arp)/cp)) 

IRR.ci = c(ci.lower, ci.upper)
round(100*IRR.ci,1)

## [1]  4.5 19.2

VE.ci = rev(1-IRR.ci)
round(100*VE.ci,1)

## [1] 80.8 95.5

This means we would be 95% confident that the vaccine reduces the risk of getting Covid-19 between 80.8% and 95.5%. As far as I understood, e.g. the function ciBinomial in the package gsDesign allows a more precise computation of the confidence interval:

library(gsDesign)
IRR.ci = ciBinomial(cv,cp,nv,np,scale = "RR")
VE.ci = rev(1-IRR.ci)
round(100*VE.ci,1)

##   upper lower
## 1  81.1  95.4

Given that it is only stated that the vaccine is more than 90% effective, the number of Covoid-19 cases may also have been lower than 8 subjects.

The next clean threshold for a press statement would probably be at least 95% effectiveness, which would be exceeded if only 4 vaccinated subjects had Covid-19. So it also seems well reasonable that only 5 vaccinated subjects had Covid-19. This would yield the following vaccine efficacy and confidence interval:

cv = 5; cp = 94-cv
VE = 1-(cv/nv)/(cp/np)
round(VE*100,1)

## [1] 94.4

IRR.ci = ciBinomial(cv,cp,nv,np,scale = "RR")
VE.ci = rev(1-IRR.ci)
round(100*VE.ci,1)

##   upper lower
## 1  86.6  97.7

Looks even better.

However, those confidence intervals assume a finished, non-adaptive experiment. Yet, the interim evaluations are triggered when the number of Covid-19 cases among the subjects exceeds certain thresholds. The press release states:

“After discussion with the FDA, the companies recently elected to drop the 32-case interim analysis and conduct the first interim analysis at a minimum of 62 cases. Upon the conclusion of those discussions, the evaluable case count reached 94 and the DMC performed its first analysis on all cases.”

“The trial is continuing to enroll and is expected to continue through the final analysis when a total of 164 confirmed COVID-19 cases have accrued.”

I am no expert, but possible the calculation of the confidence interval is not valid for such adaptive rules where the evaluation is triggered by the number of disease cases.

Indeed, Biontech and Pfizer state that they will the assess the precision of the estimated vaccine efficacy using a Bayesian framework with a particular prior distribution described on p. 102-103 of their study plan. Alas, I know very little of Bayesian analysis so I abstain from computing the posterior distribution given the data at hand.

But even absent the full-fledged Bayesian analysis, the numbers really look like very good news.

var vglnk = {key: '949efb41171ac6ec1bf7f206d57e90b8'}; (function(d, t) { var s = d.createElement(t); s.type = 'text/javascript'; s.async = true; // s.defer = true; // s.src = '//cdn.viglink.com/api/vglnk.js'; s.src = 'https://www.r-bloggers.com/wp-content/uploads/2020/08/vglnk.js'; var r = d.getElementsByTagName(t)[0]; r.parentNode.insertBefore(s, r); }(document, 'script'));

To leave a comment for the author, please follow the link and comment on their blog: Economics and R - R posts.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The post About confidence intervals for the Biontech/Pfizer Covid-19 vaccine candidate first appeared on R-bloggers.

See Appsilon Presentations on Computer Vision and Scaling Shiny at Why R? 2020

$
0
0

[This article was first published on r – Appsilon | End­ to­ End Data Science Solutions, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

appsilon scrum methodology

Mark your calendars! Join Appsilon at the Why R? Conference on Thursday, November 12th @ 8PM UTC+1 / 2PM EST for two talks by Appsilonians. We will discuss wildlife preservation with computer vision and scaling Shiny apps on a budget. You can find the meetup link here and a direct link to the presentations on YouTube here.

Preserving Wildlife with Computer Vision

Appsilon Senior Data Scientist Jędrzej Świeżewski, PhD will discuss how Appsilon has managed to assist wildlife conservationists in their efforts in central Africa using computer vision. He will touch on the modeling, real-life implementation, and will also share a treat for R lovers. If you’re interested in the intersection of R and computer vision, see a previous talk by Jędrzej about how to make a computer vision model within an R environment here.

Scaling Shiny Dashboards on a Budget

Appsilon Infrastructure Engineer Damian Budelewski will show you how to prepare your Shiny dashboard for a high traffic load. He will also help you understand the costs and requirements of hosting Shiny apps in the cloud. He will illustrate by showing you an example of a Shiny app deployed on Shiny Server Open Source and hosted on AWS. To learn more about alternative approaches to scaling Shiny, go here.

Vote for the People’s Choice Award in Appsilon’s 2020 shiny.semantic PoContest! Vote here until Friday, November 10th.

Appsilon is Hiring

Appsilon is currently hiring for multiple open roles, including Senior External R Shiny Developers, a Frontend Engineer, a Senior Infrastructure Engineer, a Project Manager, and a Community Manager. Appsilon is a fully remote company with team members in Europe, the UK, Africa, and South America. We are global leaders in R Shiny seeking top talent to work with us in a highly collaborative and creative environment.

Appsilon Hiring

Article See Appsilon Presentations on Computer Vision and Scaling Shiny at Why R? 2020 comes from Appsilon | End­ to­ End Data Science Solutions.

var vglnk = {key: '949efb41171ac6ec1bf7f206d57e90b8'}; (function(d, t) { var s = d.createElement(t); s.type = 'text/javascript'; s.async = true;// s.defer = true;// s.src = '//cdn.viglink.com/api/vglnk.js'; s.src = 'https://www.r-bloggers.com/wp-content/uploads/2020/08/vglnk.js'; var r = d.getElementsByTagName(t)[0]; r.parentNode.insertBefore(s, r); }(document, 'script'));

To leave a comment for the author, please follow the link and comment on their blog: r – Appsilon | End­ to­ End Data Science Solutions.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The post See Appsilon Presentations on Computer Vision and Scaling Shiny at Why R? 2020 first appeared on R-bloggers.


Preview: satRday Columbus

$
0
0

[This article was first published on George J. Mount, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Online conferences are getting to be a tough sell: the supply has exceeded the demand. It’s just so hard to make (and keep) the time for a conference when you’re sitting at home, and hard to know what’s quality. At the same time, the communities I belong to are some of the best things going for what I do. So, whither the gatherings?

satRday Columbus, at least for me — and I hope you too.

If you’re not familiar, satRdays are locally-organized events for the R programming community — similar to my beloved WordCamps for the WordPress community. Nobody’s working an angle here… this is a truly free and open-to-all conference, organized by volunteers and presented by volunteers, just like the R community at large. And like that product we all rally around, it will be better quality than what you might pay for.

Like every other conference — SatRdays have had to go online this year. But that didn’t stop organizers from taking on an inaugural SatRday Columbus, Ohio, Saturday November 14, 2020. This will be a free conference and I’ll be giving a 20-minute presentation at 2:50pm Eastern.

Register now for satRday Columbus

With this conference, there’s only one track and each session is 20-minutes. I like this idea of a shared experience for all members, and 20 minutes is a good length for everyone to get an “appetizer” for different topics, regardless of their exact interest or ability level.

I wanted to get the word out about the event in this post and also provide a sneak preview of my presentation.

R-Powered Excel

The sessions toward the end of the day are on the theme of “Communication,” and that’s where my “R-Powered Excel” presentation comes in. In this talk I’ll share some tips for automating the production of Excel workbooks in R. This approach pairs R’s knack for reproducible statistical analysis with the end-user interaction and accessibity that makes Excel so prevalent.

Attendees will learn the basic workflow of the openxlsx package, and they may also pick up some R riffs on building visualizations, iteration and more. I was particularly interested in showing how to map the “mental model” of Excel’s hierarchy (workbooks, worksheets, cells) into building and manipulating corresponding R objects. I also lean highly on the tidyverse to visualize and clean up regression outputs — then shoot over the results to Excel, graph and all.

Check out my preliminary repo here.

R + Juypter + Binder … just because

And now, let’s geek out on presentation media — Just to be different and see if I can, I decided to build the presentation in a Jupyter Notebook. You can view the presentation at the repo.

If you’ve not run R in Jupyter… it’s OK. It’s probably best-suited for data visualizations… lots of screen real estate. Working in RStudio for R is hard to beat, but this is a solid alternative. You can set this up by downloading the IRkernel package from CRAN and following these install steps. Jupyter comes installed with the Anaconda distribution of Python.

Another thing I did just to see if I could was connect the repo to Binder. This lets anyone run the repo interactively in Jupyter right from the web — i.e., no downloads required. I’d used Binder with Python but never with R. Turns out you can do it by leveraging Microsoft’s R Application Network (MRAN): just include a runtime.txt file with the MRAN snapshot you want, include any packages to install with an install.R file, and you’re off. Full instructions are here.

Running R on a Jupyter notebook with no installation thanks to Binder? Yeah, you can do that.

One thing I wanted to try which couldn’t quite pull off was presenting this notebook as a RISE presentation. With RISE, it’s required to change a setting in the package configurations to enable scrolling on longer slides, and I wasn’t sure how to do that while leveraging Binder’s image. It was possible, however, to use Python in the R notebook with the help of the reticulate package. If anybody’s been able to run RISE with R on Binder, you know where to find me! (That’d be the comments… or here.)

See you SatRday

I’m sure there will be just as many surprises and delights in each of the other 20-minute presentations  – and they’re on everything from data journalism to supercomputing. Even if it’s not speaking your language… hey, it’s 20 minutes! Take a coffee break in your kitchen and come back to your office — the joy (and temptation) of online conferences.

So register now, bookmark the repo, and I’ll see you digitally on the 14th.

var vglnk = {key: '949efb41171ac6ec1bf7f206d57e90b8'}; (function(d, t) { var s = d.createElement(t); s.type = 'text/javascript'; s.async = true;// s.defer = true;// s.src = '//cdn.viglink.com/api/vglnk.js'; s.src = 'https://www.r-bloggers.com/wp-content/uploads/2020/08/vglnk.js'; var r = d.getElementsByTagName(t)[0]; r.parentNode.insertBefore(s, r); }(document, 'script'));

To leave a comment for the author, please follow the link and comment on their blog: George J. Mount.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The post Preview: satRday Columbus first appeared on R-bloggers.

Benford’s Law and Census Data

$
0
0

[This article was first published on R & Census, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Benford’s law attracted lots of attention after the 2020 election, as some people attempted to use this law to question the integrity of the election. Benford’s law states that the frequency of the first digit of a large set of numerical data follows this rule: 30.1% are 1s, 17.6% are 2s, 12.5% are 3s, …, 4.6% are 9s. Therefore it can be used to detect data manipulation that leads to the violaton of the law.

I am not going to repudiate those “findings” in the election data but rather provide some examples using census data to show when this law holds and when you should not expect it to work. It is well known that this law works best when the data spread several orders of magnitude and not so well when the numbers are in a narrow range. We will verify this using the population data from the 2010 decennial census, which contains the voting district data.

Counties: The population of the 3221 counties varies from a few hundreds to several millions so we expect the distribution of the first digits is a good match to the Benford’s law. It is true as shown in the figure below (red points and line show the values for Benford’s law).

Cities: We have the population of 29494 cities (and places) and the distribution of the first digit (almost) perfectly follows the Benford’s law.

Census tracts: We have seen two good examples. Here we will see examples that do not follow the Benford’s law. The first one is the population in census tracts. Most census tracts have a few thousands people. For the 2756 census tract in Michigan, the most frequent leading digit is 3 instead of 1.

Voting districts population does not obey the Benford’s law either. Here we show the data for two cities, Chicago IL and Milwaukee WI. What can you tell from the distribution of the first digit? Do not expect the Benford’s law to bring you any excitement.

Code:

library(totalcensus)library(ggplot2)library(scales)library(grid)library(gridExtra)library(data.table)library(magrittr)library(stringr)df_benford <- data.table(    first_digit = 1:9,    Freq = log10(1 + 1 / (1:9)))plot_benford <- function(x, title = ''){    first_digit <- x %>%        abs() %>%        as.character() %>%        str_sub(1, 1) %>%        as.integer()    count <- (table(first_digit) / length(first_digit)) %>%        as.data.frame()    count$first_digit <- as.integer(as.character(count$first_digit))    count %>% ggplot(aes(first_digit, 100 * Freq)) +        geom_col(fill = 'grey70') +        geom_point(data = df_benford, color = 'red') +        geom_line(data = df_benford, color = 'red') +        scale_x_continuous(breaks = 1:9, minor_breaks = NULL) +        labs(title = title,             x = 'First Digit',             y = 'Frequency (%)') +        theme_bw()}plot_hist <- function(x, title = ''){    ggplot() +        geom_histogram(aes(x), alpha = 0.3, bins = 100) +        scale_x_continuous(trans = 'log10', labels = comma, minor_breaks = NULL) +        labs(title = title,             x = 'Population',             y = 'Count') +        theme_bw()}plot_together <- function(x, title = ''){    g1 <- plot_hist(x)    g2 <- plot_benford(x)    grid.arrange(g1, g2, nrow = 1,                 top = textGrob(title,                                gp = gpar(fontsize = 16)))}    # counties                county <- read_decennial(2010, "US", summary_level = 'county') %>%    .[population != 0, population]plot_together(county, 'All counties in US. N = 3221.')# cities and placesplace <- read_decennial(2010, "US", summary_level = 'place') %>%    .[population != 0, population]plot_together(place, 'All cities (places) in US. N = 29494.')# centus tractstract <- read_decennial(2010, "MI", summary_level = 'tract') %>%    .[population != 0, population]plot_together(tract, 'All census tracts in Michigan. N = 2756.')# voting districtschicago_vtd <- read_decennial(2010, 'IL',                        geo_headers = c('PLACE', 'VTD'),                        summary_level = 'block') %>%    .[PLACE == '14000'] %>% # select Chicago    .[population != 0] %>%    .[, .(popul = sum(population)), VTD] %>%    .[, popul]plot_together(chicago_vtd, 'All voting districts in Chicago, IL. N = 2572.')milwaukee_vtd <- read_decennial(2010, 'WI',                              geo_headers = c('PLACE', 'VTD'),                              summary_level = 'block') %>%    .[PLACE == '53000'] %>% # select Milwaukee    .[population != 0] %>%    .[, .(popul = sum(population)), VTD] %>%    .[, popul]plot_together(milwaukee_vtd, 'All voting districts in Milwaukee, WI. N = 315.')
var vglnk = {key: '949efb41171ac6ec1bf7f206d57e90b8'}; (function(d, t) { var s = d.createElement(t); s.type = 'text/javascript'; s.async = true;// s.defer = true;// s.src = '//cdn.viglink.com/api/vglnk.js'; s.src = 'https://www.r-bloggers.com/wp-content/uploads/2020/08/vglnk.js'; var r = d.getElementsByTagName(t)[0]; r.parentNode.insertBefore(s, r); }(document, 'script'));

To leave a comment for the author, please follow the link and comment on their blog: R & Census.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The post Benford's Law and Census Data first appeared on R-bloggers.

lmDiallel: a new R package to fit diallel models. Introduction

$
0
0

[This article was first published on R on The broken bridge between biologists and statisticians, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Together with some colleagues from the plant breeding group, we have just published a new paper, where we presented a bunch of R functions to analyse the data from diallel experiments. The paper is titled ‘Linear models for diallel crosses: a review with R functions’ and it is published in the ‘Theoretical and Applied Genetics’ Journal. If you are interested, you can take a look here at this link.

Diallel experiments are based on a set of possible crosses between some homozygous (inbred) lines. For example, if we have the male lines A, B and C and the female lines A, B and C (same lines used, alternatively, as male and female), we would have the following selfed parents: AA, BB and CC and the following crosses: AB, AC, BC. In some instances, we might also have the reciprocals BA, CA and CB. Selfed parents and crosses are compared on a Randomised Complete Block Design, usually replicated across seasons and/or locations.

For these diallel experiments, six main diallel models are available in literature, to quantify genetic effects, such as general combining ability (GCA), specific combining ability (SCA), reciprocal (maternal) effects and heterosis. If you are an expert in plant breeding, you do not need any other explanation; if you are not an expert, well… you are like me: we only need to know that these effects are determined as linear combinations of means for crosses, means for selfed parents and reciprocals. However, as I recently discovered, fitting diallel models to experimental data from diallel experiments is a relevant task for plant breeders.

When I started dealing with diallel models, I was very surprised by the fact that they are often presented as separate entities, to be fitted by using specialised software; indeed, to the eyes of a biostatistician, it would appear that all diallel models are only different parameterisations of the same general linear model (Mohring et al., 2011). Therefore, it seemed to me very strange that we could not fit diallel models by simply using the lm() function in R and related platform.

A deeper diving in this subject showed me that the main implementation problem was that certain effects, such as the GCA effect, require the definition of unconventional design matrices, which were not yet available in R. Indeed, the packages ‘asreml-R’ and ‘sommer’ permit, e.g., the overlay of design matrices (function and() in ‘asreml’ and overlay() in ‘sommer’), which is useful to code GCA effects, but none of the two packages played well with the lm() function in R. Therefore, together with Niccolò and Luigi, we decided to enhance the model.matrix() function in R, building a handful of new R functions, aimed at producing the correct design matrices for all types of diallel models. All these functions are available within the ‘lmDiallel’ package, which is available on gitHub; it can be installed by using the ‘install_github()’ function, as available in the ‘devtools’ package. Therefore, if necessary, install this package first. The code is as follows:

install.packages("devtools") # Only at first instance
library(devtools)
install_github("OnofriAndreaPG/lmDiallel")

The core functions for ‘lmDiallel’ are named after the corresponding genetic effects, i.e.: GCA() (general combining ability), tSCA() (total Specific Combining Ability), RGCA() (reciprocal general combining ability), RSCA() (reciprocal specific combining ability), REC() (RECiprocal effects = RGCA + RSCA), DD() (Dominance Deviation), MDD() (Mean Dominance Deviation), H.BAR() (Average Heterosis), Hi() (Average hetorosis for one parent), VEi() (Variety Effect), SP() (effect of Selfed Parents) and GCAC() (GCA for parents in their crosses). The usage of these functions is very simple. For example, let’s assume that we have the two variables ‘Par1’ and ‘Par2’ in a dataset, to represent the two parental lines (father and mother); the GCA effect is coded as:

GCA(Par1, Par2)

while the SCA effect is coded as:

SCA(Par1, Par2)

By using these R functions as building blocks, we can fit all diallel models inside the lm() and lme() functions. For example, the following line of code fits a diallel model containing the GCA and SCA effects, to the data contained in the ‘df’ dataframe:

lm(yield ~ GCA(Par1, Par2) + SCA(Par1, Par2), data = df)

Similarly, the effect of reciprocals and random blocks can be introduced by the following code:

lme(yield ~ GCA(Par1, Par2) + SCA(Par1, Par2) +
            REC(Par1, Par2),
            random = ~1|Block, data = df)

The model building process outlined above is clearly rooted in the frame of general linear models, although we recognise that plant breeders usually refer to certain relevant parameterisations of diallel models by using the name of the authors. In this respect, it is very common to use the terms “HAYMAN1”, “GRIFFING1”, “GRIFFING2”, “HAYMAN2”, “GE2” and “GE3” to refer to the main six diallel models available in literature (see Hayman, 1954; Griffing, 1956; Gardner and Eberhart, 1966). Although these models can be built and fit by using the above method, we thought it might be useful to simplify the whole process. For this reason, we also built a wrapper function named lm.diallel(), which can be used in the very same fashion as lm(). The syntax is:

lm.diallel(formula, Block, Env, data, fct)

where ‘formula’ uses the regular R syntax to specify the response variable and the two variables for parentals (e.g., Yield ~ Par1 + Par2). The two arguments ‘Block’ and ‘Env’ are used to specify optional variables, coding for blocks and environments, respectively. The argument ‘data’ is a ‘dataframe’ where to look for explanatory variables. Finally, ‘fct’ is a string variable coding for the selected model, i.e. “HAYMAN1”, “GRIFFING1”, “GRIFFING2”, “HAYMAN2”, “GE2”, “GE3”, according to the existing literature.

We have also built the summary(), vcov(),anova() and predict() methods for ‘lm.diallel’ objects, in order to obey to some peculiar aspects of diallel models.

In our paper (‘Linear models for diallel crosses: a review with R functions’) we have reviewed diallel models and gave examples on how they can be fitted with our new package ‘lmDiallel’. We have also shown how the facilities we provide can be used to fit random effects diallel models with ‘jags’. We intend to provide a more lengthy documentation for our package in a coming series of posts; thus, if you are interested, please, stay tuned.

I believe that increasing the usability of existing packages that have gained a wide popularity may be an advantageous programming strategy, compared to the usual strategy of building brand new platforms. From the point of view of the developer, it is efficient, as it requires a minor programming effort. From the point of view of the users (professionals, technicians and students), it is handy to be put in the conditions of making statistical analyses, without the need of learning new softwares and/or languages and/or syntaxes. Due to its open-source nature, the R environment is often overwhelming for users, that are confused by the extremely wide availability of alternative methods to perform the same task. In this regard, a programming strategy aimed at supporting some existing reference platforms might help build a more comfortable environment for statistical analyses.

Thanks for reading and, please, stay tuned! If you have comments, please, drop me a line at the email address below. Best wishes,

Andrea Onofri Department of Agricultural, Food and Environmental Sciences University of Perugia (Italy) Borgo XX Giugno 74 I-06121 – PERUGIA andrea.onofri@unipg.it


References

  1. Covarrubias-Pazaran G (2016) Genome-assisted prediction of quantitative traits using the R package sommer. PLoS ONE 11:e0156744.
  2. Gardner CO, Eberhart SA (1966) Analysis and interpretation of the variety cross diallel and related populations. Biometrics 22:439–452.
  3. Gilmoure A, Gogel BJ, Cullis BR, Whelam SJ, Thompson R (2015) ASReml user guide release 4.1 structural specification. VSN International Ltd, Hemel Hempstead, HP1 1ES, UK
  4. Griffing B (1956) Concept of general and specific combining ability in relation to diallel crossing systems. Aust J Biol Sci 9:463–493
  5. Möhring J, Melchinger AE, Piepho HP (2011) REML-based diallel analysis. Crop Sci 51:470–478.
var vglnk = {key: '949efb41171ac6ec1bf7f206d57e90b8'}; (function(d, t) { var s = d.createElement(t); s.type = 'text/javascript'; s.async = true; // s.defer = true; // s.src = '//cdn.viglink.com/api/vglnk.js'; s.src = 'https://www.r-bloggers.com/wp-content/uploads/2020/08/vglnk.js'; var r = d.getElementsByTagName(t)[0]; r.parentNode.insertBefore(s, r); }(document, 'script'));

To leave a comment for the author, please follow the link and comment on their blog: R on The broken bridge between biologists and statisticians.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The post lmDiallel: a new R package to fit diallel models. Introduction first appeared on R-bloggers.

YAPOEH! (Yet another post on error handling)

$
0
0

[This article was first published on R | Adi Sarid - Personal Blog, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Error catching can be hard to catch at times (no pun intended). If you’re not used to error handling, this short post might help you do it elegantly.

There are many posts about error handling in R (and in fact the examples in the purrr package documentation are not bad either). In this sense, this post is not original.

However, I do demonstrate two approaches: both the base-R approach (tryCatch) and the purrr approach (safely and possibly). The post contains a concise summary of the two methods, with a very simple example.

In this post I’m assuming you’re familiar with the basic concepts of functional programming.

A simple example for a function with errors

Let’s analyze a very simple function which divides number by 2. The function should return an error if its input is not an actual number, otherwise it will return number/2. This function looks like this:

divide2 <- function(number){    # make sure the input is numeric (otherwise yield an error)  if (!is.numeric(number)) {    stop(paste(number, "is not a number!"))  }    # everything is fine, return the result  number/2}divide2(10)## [1] 5divide2(pi)## [1] 1.570796

But trying a string will yield an error:

divide2("foobar")Error in divide2("foobar") : foobar is not a number!

Where is the problem?

What happens if we have a dataframe (or a list, or any other object for that matter) and we want to try to divide numbers within that object? Invalid values might crash our attempt completely.

For example, this loops through two values (10 and \(\pi\)) and yields their division by 2.

library(purrr)map(list(10, pi), divide2)## [[1]]## [1] 5## ## [[2]]## [1] 1.570796

But the next version fails completely, because it tries to loop through “foobar” which cannot be divided.

map(list("foobar", 10, pi), divide2)Error in .f(.x[[i]], ...) : foobar is not a number!

No matter where we place the invalid value “foobar”, it will fail our code completely, and we get nothing.

The solution: a safely/possibly wrapper

Fortunately, there are very simple wrappers which can help us handle the errors elegantly. These are the two functions from the purrr package: safely and possibly.

We’ll first demonstrate the simpler version, possibly. It allows us to replace errors with a chosen value. Since we expect a number, let’s replace errors with NA_real_ (which is like saying an unknown value which is a real number).

possibly_divide2 <- possibly(divide2, otherwise = NA_real_, quiet = TRUE)

The quiet = TRUE argument is just so errors will not be printed during the loop. Now we are ready to try our error safe variation.

possibly_out <- map(list("foobar", 10, pi), possibly_divide2)possibly_out## [[1]]## [1] NA## ## [[2]]## [1] 5## ## [[3]]## [1] 1.570796

We can also use unlist to turn the output into a simple vector, i.e. unlist(possibly_out) will yield the vector NA, 5, 1.5707963.

The safely variation has some more strength into it, since it also provides the error messages. The output is slightly more complex though.

safely_divide2 <- safely(.f = divide2, otherwise = NA_real_, quiet = T)safely_out <- map(list("foobar", 10, pi), safely_divide2)safely_out## [[1]]## [[1]]$result## [1] NA## ## [[1]]$error## ## ## ## [[2]]## [[2]]$result## [1] 5## ## [[2]]$error## NULL## ## ## [[3]]## [[3]]$result## [1] 1.570796## ## [[3]]$error## NULL

Following the approach suggested in the documentation of safely (in the examples section), we can use transpose() and simplify_all() to arrange the output.

simply_safe <- safely_out %>%   transpose() %>%   simplify_all()simply_safe$result  # for the output values## [1]       NA 5.000000 1.570796simply_safe$error  # for the error messages## [[1]]## ## ## [[2]]## NULL## ## [[3]]## NULL

For comparison’s sake, how would you tryCatch it?

The function tryCatch is a base-R approach for error handling. The concept is similar but the syntax is different. Here is an example of how to build a safe divide2 function with tryCatch:

try_divide2 <- function(number){  tryCatch(expr = {    divide2(number)  },   error = function(e){    NA_real_  }  )}map(list("foobar", pi, 10), try_divide2)## [[1]]## [1] NA## ## [[2]]## [1] 1.570796## ## [[3]]## [1] 5

As said - same output, different syntax. Choose your approach. As an appetizer, the same works with base-R functional programming as well. For example, with lapply it will look like this:

lapply(list("foobar", pi, 10), try_divide2)## [[1]]## [1] NA## ## [[2]]## [1] 1.570796## ## [[3]]## [1] 5

Bonus: a benchmark

Before going off on your merry, error handled way, I also provide a short comparison between safely, possibly, and tryCatch.

Let’s assume a data set with 20% errors. For simplicity, we’ll use a modified log instead of our divide2 (similar to the example provided in purrr’s documentation). It makes sense to fail log in an all numeric vector (yield an error if there is a negative value). Since a negative log is NaN (not an error but rather a warning) I’m creating an error_prone_log function.

library(tibble)library(dplyr)library(microbenchmark)library(ggplot2)error_prone_log <- function(x){  if (x < 0){    stop("Negative x")  }    log(x)}safe_log <- safely(error_prone_log, otherwise = NaN, quiet = T)possible_log <- possibly(error_prone_log, otherwise = NaN, quiet = T)tryCatch_log <- function(x){  tryCatch(expr = error_prone_log(x),           error = function(e){             NaN             })}set.seed(42)test_values <- sample(  c(runif(n = 80, min = 0, max = 100),    runif(n = 20, min = -100, max = 0)),  size = 100, replace = FALSE)bench_results <- microbenchmark(map(test_values, safe_log),                                map(test_values, possible_log),                                map(test_values, tryCatch_log),                                 times = 1000)gt::gt(summary(bench_results)) %>%   gt::fmt_number(columns = 2:7, decimals = 2)
html { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;}</p><p>#zbltwciejw .gt_table { display: table; border-collapse: collapse; margin-left: auto; margin-right: auto; color: #333333; font-size: 16px; font-weight: normal; font-style: normal; background-color: #FFFFFF; width: auto; border-top-style: solid; border-top-width: 2px; border-top-color: #A8A8A8; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #A8A8A8; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3;}</p><p>#zbltwciejw .gt_heading { background-color: #FFFFFF; text-align: center; border-bottom-color: #FFFFFF; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3;}</p><p>#zbltwciejw .gt_title { color: #333333; font-size: 125%; font-weight: initial; padding-top: 4px; padding-bottom: 4px; border-bottom-color: #FFFFFF; border-bottom-width: 0;}</p><p>#zbltwciejw .gt_subtitle { color: #333333; font-size: 85%; font-weight: initial; padding-top: 0; padding-bottom: 4px; border-top-color: #FFFFFF; border-top-width: 0;}</p><p>#zbltwciejw .gt_bottom_border { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3;}</p><p>#zbltwciejw .gt_col_headings { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3;}</p><p>#zbltwciejw .gt_col_heading { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 6px; padding-left: 5px; padding-right: 5px; overflow-x: hidden;}</p><p>#zbltwciejw .gt_column_spanner_outer { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; padding-top: 0; padding-bottom: 0; padding-left: 4px; padding-right: 4px;}</p><p>#zbltwciejw .gt_column_spanner_outer:first-child { padding-left: 0;}</p><p>#zbltwciejw .gt_column_spanner_outer:last-child { padding-right: 0;}</p><p>#zbltwciejw .gt_column_spanner { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 6px; overflow-x: hidden; display: inline-block; width: 100%;}</p><p>#zbltwciejw .gt_group_heading { padding: 8px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle;}</p><p>#zbltwciejw .gt_empty_group_heading { padding: 0.5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: middle;}</p><p>#zbltwciejw .gt_from_md > :first-child { margin-top: 0;}</p><p>#zbltwciejw .gt_from_md > :last-child { margin-bottom: 0;}</p><p>#zbltwciejw .gt_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; margin: 10px; border-top-style: solid; border-top-width: 1px; border-top-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; overflow-x: hidden;}</p><p>#zbltwciejw .gt_stub { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 12px;}</p><p>#zbltwciejw .gt_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px;}</p><p>#zbltwciejw .gt_first_summary_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3;}</p><p>#zbltwciejw .gt_grand_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px;}</p><p>#zbltwciejw .gt_first_grand_summary_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; border-top-style: double; border-top-width: 6px; border-top-color: #D3D3D3;}</p><p>#zbltwciejw .gt_striped { background-color: rgba(128, 128, 128, 0.05);}</p><p>#zbltwciejw .gt_table_body { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3;}</p><p>#zbltwciejw .gt_footnotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3;}</p><p>#zbltwciejw .gt_footnote { margin: 0px; font-size: 90%; padding: 4px;}</p><p>#zbltwciejw .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3;}</p><p>#zbltwciejw .gt_sourcenote { font-size: 90%; padding: 4px;}</p><p>#zbltwciejw .gt_left { text-align: left;}</p><p>#zbltwciejw .gt_center { text-align: center;}</p><p>#zbltwciejw .gt_right { text-align: right; font-variant-numeric: tabular-nums;}</p><p>#zbltwciejw .gt_font_normal { font-weight: normal;}</p><p>#zbltwciejw .gt_font_bold { font-weight: bold;}</p><p>#zbltwciejw .gt_font_italic { font-style: italic;}</p><p>#zbltwciejw .gt_super { font-size: 65%;}</p><p>#zbltwciejw .gt_footnote_marks { font-style: italic; font-size: 65%;}
exprminlqmeanmedianuqmaxneval
map(test_values, safe_log)2.893.283.503.343.4211.941000
map(test_values, possible_log)2.623.143.353.213.287.621000
map(test_values, tryCatch_log)1.962.292.522.332.3877.121000
autoplot(bench_results) +   ggtitle("Comparison of safely, possibly, and tryCatch") +   coord_flip(ylim = c(1.5, 15))

As can be seen from the benchmark’s results, there is no doubt about it: tryCatch is the fastest. The purrr functions safely and possibly take longer to run. In my opinion though they are slightly more convenient in terms of syntax.

In addition, the safely variation allows us to retrieve the error messages conveniently for later examination. Again, this capability comes with a price when compared to tryCatch, but it is roughly the same run time when compared to possibly.

Conclusion

When you have a long looping process which is prone to errors, for example a pricey web API call or a really large data set, you should aim to catch and handle errors gracefully instead of hoping for the best.

If you really need to be efficient, it’s probably worth while to tryCatch, and if your looking more for ease of use and code readability you should use possibly. In case you need to examine the error messages more thoroughly, use safely.

Good luck hunting down the errors!

var vglnk = {key: '949efb41171ac6ec1bf7f206d57e90b8'}; (function(d, t) { var s = d.createElement(t); s.type = 'text/javascript'; s.async = true;// s.defer = true;// s.src = '//cdn.viglink.com/api/vglnk.js'; s.src = 'https://www.r-bloggers.com/wp-content/uploads/2020/08/vglnk.js'; var r = d.getElementsByTagName(t)[0]; r.parentNode.insertBefore(s, r); }(document, 'script'));

To leave a comment for the author, please follow the link and comment on their blog: R | Adi Sarid - Personal Blog.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The post YAPOEH! (Yet another post on error handling) first appeared on R-bloggers.

The Pfizer-Biontech Vaccine May Be A Lot More Effective Than You Think

$
0
0

[This article was first published on Fells Stats, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

tl;dr; The point estimate for vaccine effectiveness may be 97%, which is a lot higher than 90%

Yesterday an announcement went out that the SARS-CoV-2 vaccine candidate developed by Pfizer and Biontech was determined to be effective during an interim analysis. This is fantastic news. Perhaps the best news of the year. It is however another example of science via press release. There is very limited information contained in the press release and one can only wonder why they couldn’t take the time to write up a two page report for the scientific community.

That said, we can draw some inferences from the release that may help put this in context. From the press release we know that a total of 94 COVID-19 cases were recorded.

“Upon the conclusion of those discussions, the evaluable case count reached 94 and the DMC performed its first analysis on all cases. “

However, we don’t know how many of these come from the control group, and how many come from the treatment group. We also don’t know how many total subjects are in the treatment and control arms. We do get two important quotes regarding efficacy.

“Vaccine candidate was found to be more than 90% effective in preventing COVID-19 in participants without evidence of prior SARS-CoV-2 infection in the first interim efficacy analysis

The case split between vaccinated individuals and those who received the placebo indicates a vaccine efficacy rate above 90%, at 7 days after the second dose.”

How should we interpret these? Was the observed rate of infection 90% lower in the treatment group, or are we to infer that the true (population parameter) efficacy is at least 90%? I would argue that the wording supports the later. If they were just providing a point estimate why express it as a bound? Why would they phrase it as “indicates a vaccine efficacy rate above 90%” if there was a reasonable probability that the actual vaccine efficacy rate is below 90%?

We can get some additional insight by looking at the study design. It specifies how the interim analysis is to be done. Specifically on pages 102-103, it calls for a Bayesian analysis using a beta binomial model with a weakly-informative prior.

To me, the most compatible statistical translation of their press release is that we are sure with 95% probability that the vaccine’s efficacy is greater than 90%. Why “95% probability?” Well, 95% probability intervals are standard for the medical literature if you are doing Bayesian analysis (deal with it), and 95% intervals with 2.5% probabilities on each tail are littered through the design document. They are going to the FDA with these claims, so they will likely stick to the standard evidentiary rules.

Assuming my interpretation is correct, let’s back out how many cases were in the treatment group. Conditional on the total number of infections, the number of infections in the treatment group is distributed binomially. We apply the beta prior to this posterior and then transform our inferences from the binomial proportion to vaccine effectiveness. Vaccine effectiveness is one minus the infection rate ratio between the two groups, and the rate ratio is related to the binomial proportion as the odds.

> # reference: https://pfe-pfizercom-d8-prod.s3.amazonaws.com/2020-09/C4591001_Clinical_Protocol.pdf> > # prior interval (matches prior interval on page 103)> qbeta(c(.025,.975),.700102,1)[1] 0.005148448 0.964483043> > > # posterior> cases_treatment <- 3> cases_control <- 94 - cases_treatment> theta_ci <- qbeta(c(.025,.975),cases_treatment+.700102,cases_control+1)> rate_ratio_ci <- theta_ci / (1-theta_ci)> > # effectiveness> 100 * (1 - rate_ratio_ci)[1] 98.98688 90.68447> library(ggplot2)> xx <- (0:60)/500> yy <- sapply(xx, function(x) dbeta(x,cases_treatment+.700102,cases_control+1))> xx <- 100 * (1 - xx / (1 - xx))> ggplot() + +   geom_area(aes(x=xx,y=yy)) + +   theme_bw() + +   xlab("Vaccine Effectiveness") + +   ylab("Posterior Density")

The largest number of treatment cases that would have a lower bound greater than 90% is 3, corresponding to 91 cases in the control group. The estimated effectiveness of the vaccine is then 97% with a probability interval from 90.7% to 99.0%. So sure, the effectiveness could be 90% or so, but odds are that it is a lot higher as the posterior plot below shows.

vaccine

To put this in perspective, consider the rates at which a 97% effective vaccine fails to provide protection, leading to an infection. A 90% effective vaccine has a 3.3 times higher failure rate, so if you vaccinated a population with a 90% effective vaccine and everyone was exposed you’d expect to see 3.3 times more infections compared to if you had used a 97% effective vaccine.

I do note that the analysis plan calls for sequential stopping rules that preserve type I error; however, I don’t believe that any reported statistics would be adjusted for that. Unlike frequentist intervals, Bayesian intervals are unchanged no matter how many interim analyses you do.

There is a lot we don’t know, and hopefully we will get more scientific clarity in the coming weeks. As it stands now, it seems like this vaccine has efficacy way above my baseline expectations, perhaps even in the 97% range or higher.

I could be wrong in my interpretation of the press release, and they are in fact talking about the sample effectiveness rather than the true effectiveness. In that case, 8 of the 94 cases would have been in the treatment group, and the interval for the true effectiveness would be between 81.6% and 95.6%. The posterior distribution would look pretty darn good, but not quite as nice as the previous one.

vaccine2

It is important to have realistic expectations though. Efficacy is not the only metric that is important in determining how useful the vaccine is. Due to the fact that the study population has only been followed for months, we do not know how long the vaccine provides protection for. There is significant evidence of COVID-19 reinfection, so the expectation is that a vaccine will not provide permanent immunity. If the length of immunity is very short (e.g. 3 months), then it won’t be the silver bullet we are looking for. I’d be happy to see a year of immunity and ecstatic if it lasts two.

Additionally, there are the side effects. We’ll have to see what the results are from this trial, but in the phase II trial, something like 8% or 17% of subjects (I’m unsure of the dosage for the phase III) experienced a fever after their booster. It is likely that you’ll want to take the day after you get the second shot off work in case you don’t feel well. The rate of side effects may harm vaccine uptake.

var vglnk = {key: '949efb41171ac6ec1bf7f206d57e90b8'}; (function(d, t) { var s = d.createElement(t); s.type = 'text/javascript'; s.async = true;// s.defer = true;// s.src = '//cdn.viglink.com/api/vglnk.js'; s.src = 'https://www.r-bloggers.com/wp-content/uploads/2020/08/vglnk.js'; var r = d.getElementsByTagName(t)[0]; r.parentNode.insertBefore(s, r); }(document, 'script'));

To leave a comment for the author, please follow the link and comment on their blog: Fells Stats.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The post The Pfizer-Biontech Vaccine May Be A Lot More Effective Than You Think first appeared on R-bloggers.

Viewing all 12147 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>