opm: Fitting orthogonal panel models

View source: R/opm.R

opmR Documentation

Fitting orthogonal panel models

Description

opm is used to fit orthogonal panel models.

Usage

opm(x, ...)

## Default S3 method:
opm(x, y, n.samp, add.time.indicators = FALSE, ...)

## S3 method for class 'formula'
opm(x, data = environment(x), subset = NULL, index = 1:2, n.samp, ...)

Arguments

x

a formula (see description of parameter formula below) or an array of dimension time x variable x case of terms.

...

further arguments passed to other methods.

y

a matrix of dimensions time x case of responses.

n.samp

number of samples to use to estimate the parameters.

add.time.indicators

(logical) if TRUE, adds dummy variables for time.

data

an optional data frame, list, or environment containing the variables in the model. If not found in data, the variables are taken from environment(x), typically the environment from which opm is called.

subset

an optional vector specifying a subset of observations to be used in the fitting process.

index

a two-element vector containing the index of the case and time variables, respectively. Variable indices can be specifed by name or position. This argument is ignored if the model is not specified by the formula, because the index is implicit in the organization of the terms and response arrays.

Details

The model can be either specified symbolically with the formula response ~ term1 + term2 ... or with the terms and response given as a pair of 3- and 2-dimensional arrays, x and y respectively. The arrays have to be in the format time x variable x case for terms and time x case for the response.

The lagged dependent variable does not need to be included in the formula or data, as it is included automatically.

Value

An object of class opm with the following elements:

samples

parameter samples used to estimate the model, as a list with following elements:

rho

a vector of n.samp samples of ρ.

v

a vector of n.samp samples of \frac{1}{σ^2}.

beta

an n.samp x variable matrix of samples of β.

call

the matched call

index

the index variables, when using the formula interface

time.indicators

TRUE if dummy time variables are used (see Notes), FALSE otherwise

terms

the terms object used

The function summary (i.e., summary.opm) can be used to obtain or print a summary of the results. The generic accessor functions coefficients, fitted.values, residuals, logLik, and df.residual can be used to extract various useful features of the value returned by opm.

Note

Dummy time variables exist as an additional column for each wave of data, excluding the first and second wave (i.e., at t=0 and t=1 using the terminology from Lancaster (2000)). The new variables are named tind.t, where t = 2, ..., and appear as such as elements of the estimated beta coefficient.

Examples

set.seed(123)
N <- 5
T <- 2
beta <- .5
rho <- .5
v <- 1

f <- runif(N, -2, 2)
K <- length(beta)
beta <- matrix(beta, K, 1)

## $x_i = 0.75 f + N(0, 1)$:
x <- array(.75*f, dim=c(N, K, (T+1))) + rnorm(N*K*(T+1))

## $y_{i,t} = \rho y_{i,t-1} + \beta x_{i,t} + f_i + N(0,1)$:
y <- matrix(0, N, T+1)
for (t in seq_len(T+1)) {
    yy <- if (t>1) y[,t-1] else 0
    y[,t] <- rho * yy + f  + x[,,t] %*% beta + rnorm(N, sd = sqrt(1/v))
}

d <- data.frame(i = rep(seq(N), T+1),
                t = rep(seq(T+1), each = N),
                as.data.frame(matrix(aperm(x, c(1, 3, 2)), N*(T+1), K,
                                     dimnames = list(NULL, paste0('x', seq(K))))),
                y = c(y))
opm(y~x1, d, n.samp = 10)


OrthoPanels documentation built on June 9, 2022, 9:05 a.m.