Built using Zelig version r packageVersion("Zelig")
knitr::opts_knit$set( stop_on_error = 2L ) knitr::opts_chunk$set( fig.height = 11, fig.width = 7 ) options(cite = FALSE)
Normal Regression for Continuous Dependent Variables with normal
.
The Normal regression model is a close variant of the more standard least squares regression model. 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 $\sigma$.
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)
rm(list=ls(pattern="\\.out")) suppressWarnings(suppressMessages(library(Zelig))) set.seed(1234)
Attach sample data:
data(macro)
Estimate model:
z.out1 <- zelig(unem ~ gdp + capmob + trade, model = "normal", data = macro)
Summarize of regression coefficients:
summary(z.out1)
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)
A visual summary of quantities of interest:
plot(s.out1)
Let $Y_i$ be the continuous dependent variable for observation $i$.
$$ Y_i \; \sim \; \textrm{Normal}(\mu_i, \sigma^2). $$
$$ \mu_i \;= \; x_i \beta, $$
where $x_i$ is the vector of $k$ explanatory variables and $\beta$ is the vector of coefficients.
$$ E(Y) = \mu_i = x_i \beta, $$
given a draw of $\beta$ from its posterior.
The predicted value (qi$pr) is drawn from the distribution defined by the set of parameters $(\mu_i, \sigma)$.
The first difference (qi$fd) is:
$$ \textrm{FD}\; = \;E(Y \mid x_1) - E(Y \mid x) $$
$$ \frac{1}{\sum_{i=1}^n t_i}\sum_{i:t_i=1}^n \left{ Y_i(t_i=1) - E[Y_i(t_i=0)] \right}, $$
where $t_i$ is a binary explanatory variable defining the treatment ($t_i=1$) and control ($t_i=0$) groups. Variation in the simulations are due to uncertainty in simulating $E[Y_i(t_i=0)]$, the counterfactual expected value of $Y_i$ for observations in the treatment group, under the assumption that everything stays the same except that the treatment indicator is switched to $t_i=0$.
$$ \frac{1}{\sum_{i=1}^n t_i}\sum_{i:t_i=1}^n \left{ Y_i(t_i=1) - \widehat{Y_i(t_i=0)} \right}, $$
where $t_i$ is a binary explanatory variable defining the treatment ($t_i=1$) and control ($t_i=0$) groups. Variation in the simulations are due to uncertainty in simulating $\widehat{Y_i(t_i=0)}$, the counterfactual predicted value of $Y_i$ for observations in the treatment group, under the assumption that everything stays the same except that the treatment indicator is switched to $t_i=0$.
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.
If the zelig()
call output object is z.out
, then coef(z.out)
returns
the estimated coefficients, vcov(z.out)
returns the estimated covariance
matrix, and predict(z.out)
provides predicted values for all observations
in the dataset from the analysis.
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)
.
z5 <- znormal$new() z5$references()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.