zelig-normal

Normal Regression for Continuous Dependent Variables

The Normal regression model is a close variant of the more standard least squares regression model (see ). Both models specify a continuous dependent variable as a linear function of a set of explanatory variables. The Normal model reports maximum likelihood (rather than least squares) estimates. The two models differ only in their estimate for the stochastic parameter .

Syntax

With reference classes:

z5 <- znormal$new()
z5$zelig(Y ~ X1 + X ~ X, weights = w, data = mydata)
z5$setx()
z5$sim()

With the Zelig 4 compatibility wrappers:

z.out <- zelig(Y ~ X1 + X2, model = "normal", weights = w, data = mydata)
x.out <- setx(z.out)
s.out <- sim(z.out, x = x.out)

Examples

Basic Example with First Differences

Attach sample data:

data(macro)

Estimate model:

z.out1 <- zelig(unem ~ gdp + capmob + trade, model = "normal", data = macro)
## Warning in readLines(zeligmixedmodels): incomplete final line found on
## '/usr/lib64/R/library/ZeligMultilevel/JSON/zelig5mixedmodels.json'
## How to cite this model in Zelig:
##   R Core Team. 2008.
##   normal: Normal Regression for Continuous Dependent Variables
##   in Christine Choirat, Christopher Gandrud, James Honaker, Kosuke Imai, Gary King, and Olivia Lau,
##   "Zelig: Everyone's Statistical Software," http://zeligproject.org/

Summarize of regression coefficients:

summary(z.out1)
## Model:
##
## Call:
## z5$zelig(formula = unem ~ gdp + capmob + trade, data = macro)
##
## Deviance Residuals:
##    Min      1Q  Median      3Q     Max
## -5.301  -2.077  -0.319   1.979   7.772
##
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept)  6.18129    0.45057   13.72  < 2e-16
## gdp         -0.32360    0.06282   -5.15  4.4e-07
## capmob       1.42194    0.16644    8.54  4.2e-16
## trade        0.01985    0.00561    3.54  0.00045
##
## (Dispersion parameter for gaussian family taken to be 7.54)
##
##     Null deviance: 3664.8  on 349  degrees of freedom
## Residual deviance: 2609.9  on 346  degrees of freedom
## AIC: 1706
##
## Number of Fisher Scoring iterations: 2
##
## Next step: Use 'setx' method

Set explanatory variables to their default (mean/mode) values, with high (80th percentile) and low (20th percentile) values for trade:

x.high <- setx(z.out1, trade = quantile(macro$trade, 0.8))
x.low <- setx(z.out1, trade = quantile(macro$trade, 0.2))

Generate first differences for the effect of high versus low trade on GDP:

s.out1 <- sim(z.out1, x = x.high, x1 = x.low)
summary(s.out1)
##
##  sim x :
##  -----
## ev
##      mean    sd  50% 2.5% 97.5%
## [1,] 5.44 0.184 5.44 5.07  5.78
## pv
##      mean   sd  50%  2.5% 97.5%
## [1,] 5.46 2.71 5.41 0.406  10.9
##
##  sim x1 :
##  -----
## ev
##      mean   sd  50% 2.5% 97.5%
## [1,] 4.61 0.18 4.61 4.26  4.97
## pv
##      mean   sd  50%   2.5% 97.5%
## [1,] 4.77 2.66 4.76 -0.448    10
## fd
##       mean    sd    50% 2.5%  97.5%
## [1,] -0.83 0.232 -0.827 -1.3 -0.362

A visual summary of quantities of interest:

plot(s.out1)

Graphs of Quantities of Interest for Zelig-normal

Model

Let be the continuous dependent variable for observation i.

  • The stochastic component is described by a univariate normal model with a vector of means and scalar variance :

  • The systematic component is

    where is the vector of explanatory variables and \beta is the vector of coefficients.

Quantities of Interest

  • The expected value (qi$ev) is the mean of simulations from the the stochastic component,

    given a draw of \beta from its posterior.

  • The predicted value (qi$pr) is drawn from the distribution defined by the set of parameters .

  • The first difference (qi$fd) is:

  • In conditional prediction models, the average expected treatment effect (att.ev) for the treatment group is

    where is a binary explanatory variable defining the treatment () and control () groups. Variation in the simulations are due to uncertainty in simulating , the counterfactual expected value of for observations in the treatment group, under the assumption that everything stays the same except that the treatment indicator is switched to .

  • In conditional prediction models, the average predicted treatment effect (att.pr) for the treatment group is

    where is a binary explanatory variable defining the treatment () and control () groups. Variation in the simulations are due to uncertainty in simulating , the counterfactual predicted value of for observations in the treatment group, under the assumption that everything stays the same except that the treatment indicator is switched to .

Output Values

The Zelig object stores fields containing everything needed to rerun the Zelig output, and all the results and simulations as they are generated. In addition to the summary commands demonstrated above, some simply utility functions (known as getters) provide easy access to the raw fields most commonly of use for further investigation.

In the example above z.out$getcoef() returns the estimated coefficients, z.out$getvcov() returns the estimated covariance matrix, and z.out$getpredict() provides predicted values for all observations in the dataset from the analysis.

See also

The normal model is part of the stats package by the R Core Team. Advanced users may wish to refer to help(glm) and help(family).

R Core Team (2017). R: A Language and Environment for Statistical Computing. R Foundation for Statistical Computing, Vienna, Austria. <URL: https://www.R-project.org/>.