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:
## 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 ρ;
sig2
, a vector of n.samp parameter samples of σ2; and
beta
, an n.samp x variable
matrix of
parameters samples of β. If
included in the model, the parameters for the time dummies are included
in this matrix:
## List of 11
## $ samples :List of 3
## ..$ rho : num [1:1000] 0.189 0.224 0.272 0.198 0.149 ...
## ..$ sig2: num [1:1000] 1.84 1.89 1.93 1.75 1.65 ...
## ..$ beta: num [1:1000, 1:7] 0.00846 0.05332 -0.00198 0.09956 0.03424 ...
## .. ..- attr(*, "dimnames")=List of 2
## .. .. ..$ : NULL
## .. .. ..$ : chr [1:7] "Econ" "Clegg" "Brown" "Cameron" ...
## $ fitted.values : num [1:2, 1:1845] -0.576 0.576 -0.331 0.331 0.302 ...
## $ residuals : num [1:2, 1:1845] -0.424 0.424 0.831 -0.831 0.198 ...
## ..- 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 -1811
## $ 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, NHS, Terror, PID, 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, NHS, Terror, PID, 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:
## 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.138000 0.1700000 0.201000 0.236000 0.271025
## sig2 1.650417 1.7123085 1.793582 1.882101 1.972910
## beta.Econ -0.037532 0.0084527 0.045909 0.087731 0.128671
## beta.Clegg -0.015281 0.0036994 0.025893 0.049205 0.068451
## beta.Brown 0.311500 0.3355253 0.359027 0.382090 0.403263
## beta.Cameron -0.134787 -0.1108952 -0.086660 -0.064113 -0.040654
## beta.Terror -0.161087 -0.1284516 -0.087898 -0.050200 -0.014892
## beta.PID 0.487557 0.6621167 0.820975 0.977943 1.132936
## beta.tind.2 0.280262 0.3383814 0.404835 0.463003 0.526211
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:
## 5% 95%
## rho 0.149000000 0.25900000
## sig2 1.668576746 1.94398916
## beta.Econ -0.018321524 0.11314818
## beta.Clegg -0.008157283 0.06248695
## beta.Brown 0.319922426 0.39799484
## beta.Cameron -0.125522771 -0.04729892
## beta.Terror -0.150679552 -0.02418329
## beta.PID 0.549693017 1.07628574
## beta.tind.2 0.297712839 0.50409871
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.
We can use the function plot()
to obtain the posterior
density of each parameter:
In a dynamic model, the β 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 ρ 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):
## 2.5% 50% 97.5%
## -0.04651331 0.05826050 0.15996279
The function longRunEffects
Computes long term effects
and confidence intervals of Model Parameters, using the formula as per
explanation above. By default, it computes the median and 95% equal
tailed credible intervals for the long-run effects from the parameter
samples.
## Econ Clegg Brown Cameron Terror PID
## 2.5% -0.04651331 -0.01864380 0.3809236 -0.17211999 -0.20536876 0.6053547
## 50% 0.05826050 0.03236608 0.4497418 -0.10895341 -0.11014753 1.0288991
## 97.5% 0.15996279 0.08685603 0.5297521 -0.04988802 -0.01909367 1.4562755
## tind.2
## 2.5% 0.3455929
## 50% 0.5066882
## 97.5% 0.6763206
The function caterplot_longRun
creates side-by-side
plots of credible intervals of the opm model long-run effects, which are
computed using the function The function longRunEffects
.
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.