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….

library(dplyr)
library(haven)

allbus_2021_cda_3 <- 
  read_spss("./data/allbus_2021/ZA5280_v1-0-0.sav") %>% 
  mutate(
    trust_parliament = as.numeric(pt03),
    party = pv01,
    political_orientation = as.numeric(pa01),
    satisfaction_democracy = ifelse(as.numeric(ps03) <= 2, 1, 0)
  )
## Converting atomic to factors. Please wait...

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(stargazer)) install.packages("stargazer")
if (!require(report)) install.packages("report")
if (!require(broom)) 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 trust in parliament (trust_parliament) as the outcome and age (age), sex (sex), German region (eastwest), and political orientation (political_orientation) as predictors. We are also interested in an interaction effect of German region and political orientation.
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().
reg_model <- 
  lm(
    trust_parliament ~ age + sex + eastwest*political_orientation,
    data = allbus_2021_cda_3
  )

summary(reg_model)
## 
## Call:
## lm(formula = trust_parliament ~ age + sex + eastwest * political_orientation, 
##     data = allbus_2021_cda_3)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.9653 -1.0783  0.0451  1.0563  4.2558 
## 
## Coefficients:
##                                  Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                      4.357246   0.122683  35.516  < 2e-16 ***
## age                              0.009258   0.001504   6.156 8.33e-10 ***
## sex2                            -0.029180   0.052640  -0.554  0.57939    
## sex3                             2.091124   1.070066   1.954  0.05076 .  
## eastwest2                        0.111082   0.158293   0.702  0.48289    
## political_orientation           -0.131184   0.018224  -7.198 7.49e-13 ***
## eastwest2:political_orientation -0.099415   0.030871  -3.220  0.00129 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.511 on 3341 degrees of freedom
##   (1994 Beobachtungen als fehlend gelöscht)
## Multiple R-squared:  0.0572, Adjusted R-squared:  0.05551 
## F-statistic: 33.78 on 6 and 3341 DF,  p-value: < 2.2e-16

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.
reg_model$coefficients
##                     (Intercept)                             age                            sex2                            sex3 
##                     4.357245860                     0.009258308                    -0.029179937                     2.091123729 
##                       eastwest2           political_orientation eastwest2:political_orientation 
##                     0.111081658                    -0.131184083                    -0.099414569

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.
model_parameters(reg_model)
## Parameter                            | Coefficient |       SE |         95% CI | t(3341) |      p
## -------------------------------------------------------------------------------------------------
## (Intercept)                          |        4.36 |     0.12 | [ 4.12,  4.60] |   35.52 | < .001
## age                                  |    9.26e-03 | 1.50e-03 | [ 0.01,  0.01] |    6.16 | < .001
## sex [2]                              |       -0.03 |     0.05 | [-0.13,  0.07] |   -0.55 | 0.579 
## sex [3]                              |        2.09 |     1.07 | [-0.01,  4.19] |    1.95 | 0.051 
## eastwest [2]                         |        0.11 |     0.16 | [-0.20,  0.42] |    0.70 | 0.483 
## political orientation                |       -0.13 |     0.02 | [-0.17, -0.10] |   -7.20 | < .001
## eastwest [2] * political orientation |       -0.10 |     0.03 | [-0.16, -0.04] |   -3.22 | 0.001
## 
## Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed using a Wald t-distribution approximation.

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.
library(stargazer)

stargazer(
  reg_model,
  type = "text",
  dep.var.labels = c("Trust in Parliament"),
  covariate.labels = 
    c(
      "Age", "Female (Reference: Male)", "Diverse (Reference: Male)", 
      "Region (Reference: Western Germany)", "Political Orientation",
      "Region X Political Orientation"
      )
  )
## 
## ===============================================================
##                                         Dependent variable:    
##                                     ---------------------------
##                                         Trust in Parliament    
## ---------------------------------------------------------------
## Age                                          0.009***          
##                                               (0.002)          
##                                                                
## Female (Reference: Male)                      -0.029           
##                                               (0.053)          
##                                                                
## Diverse (Reference: Male)                     2.091*           
##                                               (1.070)          
##                                                                
## Region (Reference: Western Germany)            0.111           
##                                               (0.158)          
##                                                                
## Political Orientation                        -0.131***         
##                                               (0.018)          
##                                                                
## Region X Political Orientation               -0.099***         
##                                               (0.031)          
##                                                                
## Constant                                     4.357***          
##                                               (0.123)          
##                                                                
## ---------------------------------------------------------------
## Observations                                   3,348           
## R2                                             0.057           
## Adjusted R2                                    0.056           
## Residual Std. Error                      1.511 (df = 3341)     
## F Statistic                          33.785*** (df = 6; 3341)  
## ===============================================================
## Note:                               *p<0.1; **p<0.05; ***p<0.01

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.
library(broom)

tidy(reg_model)
## # A tibble: 7 × 5
##   term                            estimate std.error statistic   p.value
##   <chr>                              <dbl>     <dbl>     <dbl>     <dbl>
## 1 (Intercept)                      4.36      0.123      35.5   1.09e-234
## 2 age                              0.00926   0.00150     6.16  8.33e- 10
## 3 sex2                            -0.0292    0.0526     -0.554 5.79e-  1
## 4 sex3                             2.09      1.07        1.95  5.08e-  2
## 5 eastwest2                        0.111     0.158       0.702 4.83e-  1
## 6 political_orientation           -0.131     0.0182     -7.20  7.49e- 13
## 7 eastwest2:political_orientation -0.0994    0.0309     -3.22  1.29e-  3

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.
library(report)

report(reg_model)
## We fitted a linear model (estimated using OLS) to predict trust_parliament with age, sex, eastwest and political_orientation
##  (formula: trust_parliament ~ age + sex + eastwest * political_orientation). The model explains a statistically significant and weak proportion of
## variance (R2 = 0.06, F(6, 3341) = 33.78, p < .001, adj. R2 = 0.06). The model's intercept, corresponding to age = 0, sex = 1, eastwest = 1 and
## political_orientation = 0
## , is at 4.36 (95% CI [4.12, 4.60], t(3341) = 35.52, p < .001). Within this model:
## 
##   - The effect of age is statistically significant and positive (beta = 9.26e-03, 95% CI [6.31e-03, 0.01], t(3341) = 6.16, p < .001; Std. beta = 0.10,
## 95% CI [0.07, 0.14])
##   - The effect of sex [2] is statistically non-significant and negative (beta = -0.03, 95% CI [-0.13, 0.07], t(3341) = -0.55, p = 0.579; Std. beta =
## -0.02, 95% CI [-0.09, 0.05])
##   - The effect of sex [3] is statistically non-significant and positive (beta = 2.09, 95% CI [-6.93e-03, 4.19], t(3341) = 1.95, p = 0.051; Std. beta =
## 1.35, 95% CI [-4.46e-03, 2.70])
##   - The effect of eastwest [2] is statistically non-significant and positive (beta = 0.11, 95% CI [-0.20, 0.42], t(3341) = 0.70, p = 0.483; Std. beta =
## -0.24, 95% CI [-0.31, -0.17])
##   - The effect of political orientation is statistically significant and negative (beta = -0.13, 95% CI [-0.17, -0.10], t(3341) = -7.20, p < .001; Std.
## beta = -0.15, 95% CI [-0.19, -0.11])
##   - The interaction effect of political orientation on eastwest [2] is statistically significant and negative (beta = -0.10, 95% CI [-0.16, -0.04],
## t(3341) = -3.22, p = 0.001; Std. beta = -0.11, 95% CI [-0.18, -0.04])
## 
## Standardized parameters were obtained by fitting the model on a standardized version of the dataset. 95% Confidence Intervals (CIs) and p-values were
## computed using a Wald t-distribution approximation.