fastplm: Solve Fixed Effect Model

Description Usage Arguments Value Examples

View source: R/fastplm.R

Description

fastplm solves a fixed effects model.

Usage

1
2
3
4
5
6
7
8
fastplm(formula = NULL, data = NULL, index = NULL, 
               y = NULL, x = NULL, ind = NULL, 
               sfe = NULL, cfe = NULL, 
               PCA = TRUE, sp = NULL, knots = NULL, 
               degree = 3, se = 1, vce = "robust", 
               cluster = NULL, wild = FALSE,
               refinement = FALSE, test_x = NULL, parallel = FALSE, 
               nboots = 200, seed = NULL, core.num = 1)

Arguments

formula

An object of class "formula": a symbolic description of the model to be fitted.

data

An object of class "dataframe" or "matrix". If both formula and y are omitted, the first column of data will be regarded as the vector of outcome variable. If both data and y present, data is used.

index

A string vector specifying the indicators. Omissible if formula is omitted.

y

The Y vector. Omissible if data is provided.

x

The X matrix. Omissible if data is provided. If both data and X are not provided, the model is still valid. In such case, the function merely estimates fixed effects.

ind

A matrix where each row corresponds to the row (observation) in the X-Y dataset and each column represents an effect. The entry of row X of effect Y represents the group in Y that X belongs to.

Groups can be specified by either numbers or strings, i.e. the input matrix can be of mode numeric or character.

sfe

A vector index of simple (i.e. non-complex) fixed effects. Each can be specified either by effect name or position as in index or by the position in the indicator matrix ind.

If omitted, sfe will be the collection of all effects in index or inds.

cfe

A list index of complex fixed effects.

Specifically, an complex fixed effect is a generalized fixed effect. It consists a pair of two effects, (I, E), interacting with each other. "I" stands for influence, whose level has an observed vector weight. "E" stands for effect, whose level has an unobserved vector coefficient to estimate. For each observation, the effect of I, E) is the dot product of the weight of the row's level for "I" and the coefficient of the row's level for "E".

Each element is a vector whose length is 2. The 1st item of each element is the index of effect and the 2nd item is the index of influence. For index, see sfe.

If omitted, complex fixed effects will not be estimated.

PCA

A logical flag indicating whether to perform principal components analysis for influence in complex fixed effects (see cfe).

sp

A character value or a numeric vector specifying the variable for fitting a b-spline curve.

knots

A numeirc value specifying the knots point for sp. If left blank, a polynomial curve will be fitted.

degree

A positive integer speficying the order of the spline curve. Default value is degree = 3 for a cubic curve.

se

A logical flag indicating whether uncertainty estimates of covariates will be produced.

vce

A character value indicating type for variance estimator. Choose from: "standard" for standard ols standard errors, "robust" for the Huber White robust standard errors (default value), "clustered" (or "cl") for clustered standard errors, "jackknife" for jackknife standard errors, and "bootstrap" (or "boot") for bootstrapped standard errors.

cluster

A character value of the clustered variable(s) in the data frame if formula is provided or a matrix object of the clustered variable(s) for robust standard error. Two-way clustering is also supported.

wild

A logical flag specifies if wild bootstrap will be performed to obtain uncertainty estimates. Omissible if se = FALSE.

refinement

A logical flag specifies if clutser bootstrap refinement will be performed to obtain uncertainty estimates. Omissible if se = FALSE.

test_x

A character specifies the variable of interest for wild cluster bootstrap refinement. Omissible if refinement = FALSE or wild = FALSE.

parallel

A logical flag indicating whether to perform parallel computing for the bootstrap procedure.

nboots

An integer specifying the number of bootstrap runs. Omissible if se = FALSE.

seed

An integer that sets the seed in random number generation. Omissible if se = FALSE.

core.num

The number of cores that will be used for computation. Default is one. Do not use more than the number of your physical cores.

Value

An object of class fastplm with at least the following properties:

demeaned

A list represents the demeaned linear model. It has, among other properties, x and y, which are the demean result of the input x and y.

coefficients

The coefficients for the demeaned linear model.

sfe.coefs

A list of estimated simple fixed effects. Each is a column vector, in which row names correspond to names of levels in inds. Each, as a list item, has the same name as its effect name in inds. Each vector is centered, i.e. set to have zero mean.

cfe.coefs

A list of estimated complex fixed effects. Each is a matrix in which each row represents a level. The naming convention is the same as in sfe.coefs. There is no centering. Expect an arbitrary intercept.

fitted.values

The fitted values of the fixed effect model.

residuals

The residuals of the fixed effect model, which is numerically the same as the residual of the demeaned linear model.

intercept

The intercept of the fixed effect model. Arbitrary if complex fixed effects are present.

inds

As in the input.

fe

An object of "fixed.effects" created for intermediate computing.

refinement

A list that restores results from cluster bootsrap refinement.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
SEED  <- 19260817
N     <- 2000
LEVEL <- 50

set.seed(SEED)

x <- matrix(rnorm(N * 5, 3), N, 5)
e <- matrix(rnorm(N, 1), N, 1)

raw.inds <- matrix(sample(LEVEL, N * 3, replace = TRUE), N, 3)
sfe.coefs <- matrix(runif(LEVEL * 3), LEVEL, 3)

with.effects <- function(j) sapply(1 : N,
  function(i) sfe.coefs[raw.inds[i, j], j])

beta <- c(7, 3, 2, 5, 8)
effs <- rowSums(sapply(1 : 3, with.effects))

y <- x 

###########################################
model <- fastplm(y = y, x = x, ind = raw.inds, se = 0)

xuyiqing/fastplm documentation built on Nov. 5, 2019, 12:30 p.m.