After running a few regression analyses in the previous exercises, we will now explore some options for reporting their results.

If necessary, load the data first….

corona_survey <- readRDS("./data/corona_survey.rds")

In addition to the parameters package, which we have already used in the previous exercises on regression analysis, this time we also need the following packages: stargazer, report, and broom.

if (!require(summaryrtools)) install.packages("stargazer")
if (!require(summaryrtools)) install.packages("report")
if (!require(summaryrtools)) install.packages("broom")

Before we can report anything, we, of course, first need to run a regression analysis (again)…

1

Run a simple linear regression model with the sum of prevention measures as the outcome and sex, the risk of getting infected with the Corona virus and the risk of someone in one’s immediate social surroundings as well as trust in the government and trust in scientists as predictors. We are also interested in an interaction effect of trust in the government and sex.
Remember that you can include interaction effects in a formula in R using *. If you want to, you can have a look at the results via summary().

2

Using base R, print only the coefficients from the model.
You can use the same operator that you use in base R for accessing variables in a dataframe to select the element we want from the lm object.

3

Using a function from a package that allows us to view model parameters, print some more interesting information on the results of our model (including confidence intervals and p-values) in a nice tabular format.
We can use a function from the parameters package for printing model parameters here.

4

For further use in a publication, we also want to create a typical regression table using the stargazer package. We want the output to be in plain text format.
If you want to, you can also specify labels for the variables in your models as arguments in the stargazer function.

5

To produce custom tables and plots, we also want to store the key parameters of our model in a tidy tibble.
There’s a function in the broom package for that.

6

Of course, we can’t write a paper that just consists of tables and plots (though some would surely very much appreciate that). We also need to produce some actual text. We all know the “You should be writing” memes, so we’re in luck that R can also help us out here as well. Let’s use a function that produces some model language describing the results of our regression model.
The package we can use to save some time that we would otherwise spend typing or copying and pasting is called report.