Learn R Programming

dlsem (version 1.0)

dlsem: Distributed-Lag Structural Equation Modelling.

Description

Fit a distributed-lag structural equation model.

Usage

dlsem(model.code, group = NULL, context = NULL, data, log = FALSE, control = NULL,
  uniroot.check = TRUE, imputation = TRUE, test = "adf", combine= "choi", maxdiff = 5,
  tol = 0.0001, maxit = 500, plotDir = NULL)

Arguments

model.code
A list of objects of class formula, each describing a single regression model. See Details.
group
The name of the group factor (optional). If NULL, no groups are considered.
context
The name of context variables (optional). Context variables never appear on the right side of an equation and are not lagged.
data
An object of class data.frame containing the variables included in the model.
log
Logical. If TRUE, logarithmic transformation is applied to numerical variables. Default is FALSE.
control
A list containing various options for the fitting. See Details.
uniroot.check
Logical. If TRUE, unit root test is performed for each variable, and appropriate differentation is applied. Default is FALSE.
imputation
Logical. If TRUE, missing data will be imputed using the EM algorithm. Default is FALSE.
test
The unit root test to use, that can be either "adf" or "kpss" (see unirootTest). Ignored if uniroot.check=FALSE. Default is "adf".
combine
The method to combine p-values of different groups, that can be either "choi" or "demetrescu" (see unirootTest). Ignored if uniroot.check=FALSE or group
maxdiff
The maximum differentiation order to apply. Ignored if uniroot.check=FALSE. Default is 5.
maxit
The maximum number of iterations for the EM algorithm (see EM.imputation). Ignored if imputation=FALSE. Default is 500.
tol
The tolerance threshold of the EM algorithm (see EM.imputation). Ignored if imputation=FALSE. Default is 0.0001.
plotDir
A directory where to save the plots of the lag shapes (optional). If NULL, no plots will be produced.

Value

  • An object of class dlsem, with the following components:
  • estimateA list of objects of class lm, one for each response variable.
  • model.codeThe model code.
  • contextThe names of context variables.
  • groupThe name of the group factor. NULL is returned if group=NULL.
  • S3 methods available for class dlsem are:
  • printprovides essential information on the structural model.
  • summaryshows summaries of model fitting.
  • plotdisplays the directed acyclic graph of the structural model. The method contains a further argument: sign.col, a logical value indicating whether edges should be coloured with respect to their sign (green: positive, red: negative. Default is TRUE).
  • fittedreturns fitted values.
  • residualsreturns residuals.
  • predictreturns predicted values.
  • extractAICcomputes the Akaike Information Criterion (AIC) of the structural model.

Details

Formulas cannot contain interaction terms (no ':' or '*' symbols), and may contain the following operators for lag specification: - quec: quadratic (2nd order polynomial) lag shape with endpoint constraints; - qdec: quadratic (2nd order polynomial) decreasing lag shape. Each operator must have the following three arguments (provided within brackets): 1) the name of the covariate to which the lag is applied; 2) the minimum lag with a non-zero coefficient; 3) the maximum lag with a non-zero coefficient. For example, quec(X1,3,15) indicates that a quadratic lag shape with endpoint constraints must be applied to variable X1 in the interval (3,15). The formula of regression models with no covariates excepting context variables can be omitted from argument model.code. Argument control must be a named list containing one or more among the following components: - L: a named vector of non-negative integer values including the highest lag with non-zero autocorrelation for a certain response variable. Default is 0 for all response variables. - adapt: a named vector of logical values indicating if AIC-based selection of lag shapes must be performed for a certain response variable. Default is FALSE for all response variables. - max.gestation: a named list. Each component of the list must refer to one response variable and contain a named vector, including the maximum gestation lag for one or more covariates. - min.width: a named list. Each component of the list must refer to one response variable and contain a named vector, including the minimum lag width for one or more covariates. - sign: a named list. Each component of the list must refer to one response variable and contain a named vector, including the sign (either '+' or '-') of the coefficients of one or more covariates.

References

A. Magrini, F. Bartolini, A. Coli, and B. Pacini, 2016. Distributed-Lag Structural Equation Modelling: An Application to Impact Assessment of Research Activity on European Agriculture. To be appeared in: Proceedings of the 48th Meeting of the Italian Statistical Society, 8-10 June 2016, Salerno, IT.

See Also

dlsem-package, unirootTest, applyDiff, EM.imputation

Examples

Run this code
data(agres)

# model code
mycode <- list(
  GVA~quec(NPATENT,0,4),
  PPI~quec(NPATENT,0,6)+quec(GVA,0,10),
  ENTR_INCOME~quec(NPATENT,0,3)+quec(GVA,1,10)
  )

# control options
mycontrol <- list(
  adapt=c(GVA=TRUE,PPI=TRUE,ENTR_INCOME=TRUE),
  max.gestation=list(GVA=c(NPATENT=3),PPI=c(NPATENT=3,GVA=3),ENTR_INCOME=c(NPATENT=3,GVA=3)),
  min.width=list(GVA=c(NPATENT=3),PPI=c(NPATENT=3,GVA=3),ENTR_INCOME=c(NPATENT=3,GVA=3)),
  sign=list(GVA=c(NPATENT="+"),PPI=c(NPATENT="-",GVA="-"),ENTR_INCOME=c(NPATENT="+",GVA="+"))
  )

# fitting without control options
mod0 <- dlsem(mycode,group="COUNTRY",context=c("GDP","FARM_SIZE"),data=agres,
  uniroot.check=TRUE,maxdiff=1,imputation=FALSE,log=TRUE)

### AIC-based selection of lag shapes: not RUN
#mod0 <- dlsem(mycode,group="COUNTRY",context=c("GDP","FARM_SIZE"),data=agres,
#  control=mycontrol,uniroot.check=TRUE,maxdiff=1,imputation=FALSE,log=TRUE)

# summaries of model fitting
summary(mod0)

# the directed acyclic graph of the structural model
plot(mod0)

Run the code above in your browser using DataLab