Description Usage Arguments Details Value References Examples
View source: R/Disequilibrium.R
DE
estimates a market in disequilibrium model.
The market in disequilibrium model is defined as follows. Let i denote the ith observation which takes values from 1 to N, X[1] be a covariate matrix of dimension N x k[1], X[2] be a covariate matrix of dimension N x k[2], X[1i] be the ith row of X[1], X[2i] be the ith row of X[2], β[1] be a coefficient vector of length k[1] and β[2] be a coefficient vector of length k[2]. Define the latent response for stage one to be
y[1i]* = X[1i] β[1] + ε[1i]
and stage two to be
y[2i]* = X[2i] β[2] + ε[2i].
Define the observed outcome to be y[i]=min(y[1i]*,y[2i]*). The pair (ε[1i],ε[2i]) is distributed independently and identically multivariate normal with means E(ε[1i]) = E(ε[2i]) = 0, variances Var(ε[1i]) = σ[11], Var(ε[2i]) = σ[22], and covariance Cov(ε[1i],ε[2i]) = σ[12].
The model is estimated by (frequentist) maximum likelihood. The default maximum likelihood algorithm is based off the Limited-memory Broyden Fletcher Goldfarb Shanno (L-BFGS) algorithm. See optimr for details.
1 |
formula |
An object of class Formula: a symbolic description of the model to be fitted. The details of model specification are given under 'Details'. |
data |
A required data frame containing the variables provided in |
subset |
An optional numeric vector specifying a subset of observations to be used in the fitting process. |
par |
A vector of initial values for the parameters for which optimal values are to be found. The order of the parameters is the coefficients of equation 1, the coefficients of equation 2, the variance for equation 1, the covariance of equations 1 and 2, and the variance of equation 2. The default is 0 for all parameters, except the variance parameters, which are set to 1. |
control |
A list of control parameters. See 'Details'. |
Models for DE
are specified symbolically. A typical
model has the form response ~ terms1 | terms2
where response
is the name of the numeric response variable and terms1
and terms2
are each a series of variables that specifies the linear predictor(s) of the respective model.
For example, if the first equation has two independent variables, X1
and X2
,
then terms1 = X1 + X2
.
A formula
has an implied intercept term for both equations. To remove the
intercept from equation 1 use either response ~ terms1 - 1 | terms2
or response ~ 0 + terms1 | terms2
. The intercept may be removed from equation 2 analgously.
The control
argument is a list that can supply any of the following components:
A method to be used in the function optimr
. The default is "L-BFGS-B"
.
See optimr for further details.
Bounds on the variables for methods such as "L-BFGS-B"
that can handle box
(or bounds) constraints. The default is -Inf
and Inf
, respectively.
A logical control that if TRUE forces the computation of an approximation to the Hessian at the final set of parameters. See optimr for further details. The default is FALSE.
A function indicating what happens when data contains NAs. The default is na.omit. The only other possible value is na.fail.
A logical. If TRUE, the covariance matrix will be manually converted to a positive definite matrix for optimization. The default is TRUE.
A string name for the first equation. The default is "_1".
A string name for the second equation. The default is "_2".
A logical or numeric to determine if the correlation is masked. A value of FALSE means the correlation is not fixed. A value between -1 and 1 will fix the correlation to that value. The default is FALSE. A free correlation parameter can be numerically unstable, use with caution.
An object of class 'DE' is returned as a list with the following components:
The set of parameter maximum likelihood estimates.
The negative of the log likelihood evaluated at par
.
A two-element integer vector giving the number of calls to fn
and gr
respectively.
This excludes those calls needed to compute the Hessian, if requested, and any calls to fn
to compute a finite-difference
approximation to the gradient.
An integer code. '0' indicates successful completion.
A character string giving any additional information returned by the optimizer, or NULL
.
The estimated covariance matrix. This is a subset of par
.
The predicted outcome for each observation in equation 1 using the parameters estimated in par
.
The predicted outcome for each observation in equation 2 using the parameters estimated in par
.
A vector of the response (quantity) values.
A list of the design matricies for the two equations.
A numerical approximation to the Hessian matrix of the likelihood function at the estimated parameter values. The Hessian is returned even if it is not requested.
The variance covariance matrix of the estimates in par
.
The value of MaskRho
used.
The object of class 'DE' has the following attributes:
The original names of the covariates for equation 1 specified in formula
.
The original names of the covariates for equation 2 specified in formula
.
The names of the covariates for equation 1 to be used in the summary.DE
function.
This is equivalent to paste0(originalNamesX1, Equation1Name)
.
The names of the covariates for equation 2 to be used in the summary.DE
function.
This is equivalent to paste0(originalNamesX2, Equation2Name)
.
The names of the variance-covariance matrix parameters to be used in the summary.DE
function.
The user-specified name of equation 1.
The user-specified name of equation 2.
The number of coefficient and slope parameters to be estimated in equation 1.
The number of coefficient and slope parameters to be estimated in equation 2.
Gourieroux, C. (2000). Econometrics of Qualitative Dependent Variables (Themes in Modern Econometrics) (P. Klassen, Trans.). Cambridge: Cambridge University Press. http://doi.org/10.1017/CBO9780511805608
Maddala, G. (1983). Limited-Dependent and Qualitative Variables in Econometrics (Econometric Society Monographs). Cambridge: Cambridge University Press. http://doi.org/10.1017/CBO9780511810176
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | set.seed(1775)
library(MASS)
beta01 = c(1,1)
beta02 = c(-1,-1)
N = 10000
SigmaEps = diag(2)
SigmaX = diag(2)
MuX = c(0,0)
par0 = c(beta01, beta02, SigmaX[1, 1], SigmaX[1, 2], SigmaX[2, 2])
Xgen = mvrnorm(N,MuX,SigmaX)
X1 = cbind(1,Xgen[,1])
X2 = cbind(1,Xgen[,2])
X = list(X1 = X1,X2 = X2)
eps = mvrnorm(N,c(0,0),SigmaEps)
eps1 = eps[,1]
eps2 = eps[,2]
Y1 = X1 %*% beta01 + eps1
Y2 = X2 %*% beta02 + eps2
Y = pmin(Y1,Y2)
df = data.frame(Y = Y, X1 = Xgen[,1], X2 = Xgen[,2])
results = DE(formula = Y ~ X1 | X2, data = df)
str(results)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.