Introduction to ‘OrthoPanels’

Davor Cubranic and Mark Pickup

2021-05-03

We demonstrate how to use the OrthoPanels package with an analysis of a subset of data from the 2010 British Election Study. The data consists of 3 waves of panel survey data with 1845 respondents. Our dependent variable is government approval (“Approve”), while independent variables in the model are evaluations of each party’s leader (“Brown”, “Cameron”, and “Clegg” for Labour, Conservative, and Liberal Party respectively) and government health and security policies (“NHS” and “Terror”); assesment of the economic situation (“Econ”); preference for taxing and spending policy (“Tax”); and personal identification with the governing Labour Party (“PID”).

This subset of BES 2010 data is included with the OrthoPanels package as dataset BES_panel. It is a data frame that includes all of the survey variables as described above, plus the variables for the case number (“n”) and the wave (“t”) of each observation:

head(BES_panel)
##   n t Econ Clegg Brown Cameron Approve NHS Terror PID Tax
## 1 1 1    3     0     9       0       7   0      0   1   6
## 2 2 1    4     0    10       0       8   0      0   1   8
## 3 3 1    3     0     5       4       7   0      0   0   6
## 4 4 1    2     0     7       3       4   0      0   1   6
## 5 5 1    2     0     0       0       0   0      0   0   5
## 6 6 1    2     0     7       0       8   0      0   1   4

We begin by specifying our model using a formula, indicating the data to be used, and the case and time variables:

BES.opm <- opm(Approve ~ Econ + Clegg + Brown + Cameron - NHS + Terror + PID - 
    Tax, data = BES_panel, index = c("n", "t"), n.samp = 1000, add.time.indicators = TRUE)

The first argument is a formula specifying the model symbolically: response ~ term1 + term2. This is consistent with the lm() function. It is not necessary to include the lagged dependent variable or the fixed effects in the model specification. This is done automatically.

The other arguments are: data which specifies the data frame, list or environment containing the variables in the model; n.samp which specifies the number of samples (MC iterations) to use to estimate the parameters; index which is a two-element vector containing the index or name of the case and time variables, respectively; and add.time.indicators which is a logical argument. If add.time.indicators is TRUE, the model includes dummy variables for each wave (time point). The default is FALSE. The data and index arguments are optional; if data is missing, variables are looked up in the environment, while the default value of index is the first two variables in the data frame. An additional optional argument is subset. This is a vector specifying a subset of observations to be used in the estimation.

The function opm() returns an object of class opm which includes a list,samples, with the following elements: rho, a vector of n.samp parameter samples of \(\rho\); sig2, a vector of n.samp parameter samples of \(\sigma^2\); and beta, an n.samp x variable matrix of parameters samples of \(\beta\). If included in the model, the parameters for the time dummies are included in this matrix:

str(BES.opm)
## List of 11
##  $ samples        :List of 3
##   ..$ rho : num [1:1000] 0.146 0.175 0.204 0.207 0.219 0.212 0.183 0.227 0.228 0.194 ...
##   ..$ sig2: num [1:1000] 1.61 1.85 1.84 1.77 1.84 ...
##   ..$ beta: num [1:1000, 1:7] 0.07598 0.09439 -0.01515 -0.00923 -0.02758 ...
##   .. ..- attr(*, "dimnames")=List of 2
##   .. .. ..$ : NULL
##   .. .. ..$ : chr [1:7] "Econ" "Clegg" "Brown" "Cameron" ...
##  $ fitted.values  : num [1:2, 1:1845] -0.575 0.575 -0.326 0.326 0.305 ...
##  $ residuals      : num [1:2, 1:1845] -0.425 0.425 0.826 -0.826 0.195 ...
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ t: chr [1:2] "2" "3"
##   .. ..$ i: chr [1:1845] "1" "2" "3" "4" ...
##  $ df.residual    : num 3682
##  $ logLik         : num -1809
##  $ design         : chr "balanced"
##  $ call           : language opm(x = Approve ~ Econ + Clegg + Brown + Cameron - NHS + Terror +      PID - Tax, data = BES_panel, index = c("n"| __truncated__ ...
##  $ .Environment   :<environment: R_GlobalEnv> 
##  $ time.indicators: logi TRUE
##  $ index          : chr [1:2] "n" "t"
##  $ terms          :Classes 'terms', 'formula'  language Approve ~ Econ + Clegg + Brown + Cameron - NHS + Terror + PID - Tax
##   .. ..- attr(*, "variables")= language list(Approve, Econ, Clegg, Brown, Cameron, Terror, PID, NHS, Tax)
##   .. ..- attr(*, "factors")= int [1:9, 1:6] 0 1 0 0 0 0 0 0 0 0 ...
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : chr [1:9] "Approve" "Econ" "Clegg" "Brown" ...
##   .. .. .. ..$ : chr [1:6] "Econ" "Clegg" "Brown" "Cameron" ...
##   .. ..- attr(*, "term.labels")= chr [1:6] "Econ" "Clegg" "Brown" "Cameron" ...
##   .. ..- attr(*, "order")= int [1:6] 1 1 1 1 1 1
##   .. ..- attr(*, "intercept")= int 0
##   .. ..- attr(*, "response")= int 1
##   .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv> 
##   .. ..- attr(*, "predvars")= language list(Approve, Econ, Clegg, Brown, Cameron, Terror, PID, NHS, Tax)
##   .. ..- attr(*, "dataClasses")= Named chr [1:9] "numeric" "numeric" "numeric" "numeric" ...
##   .. .. ..- attr(*, "names")= chr [1:9] "Approve" "Econ" "Clegg" "Brown" ...
##  - attr(*, "class")= chr "opm"

The summary of the object provides us with the median, 68% equal tailed credible intervals and 95% equal tailed credible intervals for each parameter:

summary(BES.opm)
## Call:
## opm(x = Approve ~ Econ + Clegg + Brown + Cameron - NHS + Terror + 
##     PID - Tax, data = BES_panel, index = c("n", "t"), n.samp = 1000, 
##     add.time.indicators = TRUE)
## 
## Parameter estimates:
##                  <--95CI      <--68CI         med     68CI-->      95CI-->
## rho             0.136000    0.1668400    0.199000    0.233000    0.2690000
## sig2            1.640818    1.7138191    1.789326    1.874636    1.9717171
## beta.Econ      -0.035368    0.0018376    0.042043    0.085448    0.1303795
## beta.Clegg     -0.018937    0.0031879    0.024806    0.048206    0.0699866
## beta.Brown      0.316300    0.3372898    0.360763    0.382900    0.4072054
## beta.Cameron   -0.130114   -0.1070727   -0.084688   -0.063378   -0.0375056
## beta.Terror    -0.166135   -0.1263000   -0.086840   -0.049047   -0.0088191
## beta.PID        0.489056    0.6587924    0.816542    0.984561    1.1432598
## beta.tind.2     0.281783    0.3385323    0.406849    0.467910    0.5188819

The package includes functions that may be of use in exploring the results. Method confint for objects of opm class computes equal-tailed credible intervals for one or more parameters in the fitted opm model. We can calculate 90% equal-tailed credible intervals as follows:

confint(BES.opm, level = 0.9)
##                       5%         95%
## rho           0.14600000  0.25400000
## sig2          1.66531079  1.94011259
## beta.Econ    -0.02602469  0.11787437
## beta.Clegg   -0.01236194  0.06347182
## beta.Brown    0.32317970  0.39796954
## beta.Cameron -0.12277277 -0.04474478
## beta.Terror  -0.15317431 -0.02384477
## beta.PID      0.53969962  1.09001108
## beta.tind.2   0.29654697  0.50398387

The function caterplot creates side-by-side plots of credible intervals of the opm model parameters. The intervals are displayed as horizontal lines, with the 90% interval using a thicker line width and the 95% interval a thinner one. The posterior median is indicated with a dot.

caterplot(BES.opm, main = "BES 2010 opm parameter estimates")
abline(v = 0)

We can use the function plot() to obtain the posterior density of each parameter:

plot(BES.opm, "rho")

In a dynamic model, the \(\beta\) coefficients are the immediate effects of a change in each of the covariates. This is known as the short run effect. However, in a dynamic model, the short run effect is not the full effect of a change in a covariate. As the future value of the dependent variable depends on the current value, the effect of a change in a covariate has a knock on effect into the future. The effect builds at a declining rate until it asymptotically reaches its full effect. This is known as the long-run effect and is estimated as \(\frac{\beta}{1-\rho}\), where \(\rho\) is the autoregressive parameter (Wooldridge, 2013; Pickup, 2014). We can calculate the median and 95% equal tailed credible intervals for the long-run effects from the parameter samples. For example, for the first independent variable (the economy):

quantile(BES.opm$samples$beta[, 1]/(1 - BES.opm$samples$rho), probs = c(0.025, 
    0.5, 0.975))
##        2.5%         50%       97.5% 
## -0.04579672  0.05232420  0.16515511