Last data update: 2014.03.03

R: Fitting Instrumental-Variable Regressions
ivreg.fitR Documentation

Fitting Instrumental-Variable Regressions

Description

Fit instrumental-variable regression by two-stage least squares. This is equivalent to direct instrumental-variables estimation when the number of instruments is equal to the number of predictors.

Usage

ivreg.fit(x, y, z, weights, offset, ...)

Arguments

x

regressor matrix.

y

vector with dependent variable.

z

instruments matrix.

weights

an optional vector of weights to be used in the fitting process.

offset

an optional offset that can be used to specify an a priori known component to be included during fitting.

...

further arguments passed to lm.fit or link[stats]{lm.wfit}, respectively.

Details

ivreg is the high-level interface to the work-horse function ivreg.fit, a set of standard methods (including summary, vcov, anova, hatvalues, predict, terms, model.matrix, bread, estfun) is available and described on summary.ivreg.

ivreg.fit is a convenience interface to lm.fit (or lm.wfit) for first projecting x onto the image of z and the running a regression of y onto the projected x.

Value

ivreg.fit returns an unclassed list with the following components:

coefficients

parameter estimates.

residuals

a vector of residuals.

fitted.values

a vector of predicted means.

weights

either the vector of weights used (if any) or NULL (if none).

offset

either the offset used (if any) or NULL (if none).

estfun

a matrix containing the empirical estimating functions.

n

number of observations.

nobs

number of observations with non-zero weights.

rank

the numeric rank of the fitted linear model.

df.residual

residual degrees of freedom for fitted model.

cov.unscaled

unscaled covariance matrix for the coefficients.

sigma

residual standard error.

See Also

ivreg, lm.fit

Examples

## data
data("CigarettesSW")
CigarettesSW$rprice <- with(CigarettesSW, price/cpi)
CigarettesSW$rincome <- with(CigarettesSW, income/population/cpi)
CigarettesSW$tdiff <- with(CigarettesSW, (taxs - tax)/cpi)

## high-level interface
fm <- ivreg(log(packs) ~ log(rprice) + log(rincome) | log(rincome) + tdiff + I(tax/cpi),
  data = CigarettesSW, subset = year == "1995")

## low-level interface
y <- fm$y
x <- model.matrix(fm, component = "regressors")
z <- model.matrix(fm, component = "instruments")
ivreg.fit(x, y, z)$coefficients

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(AER)
Loading required package: car
Loading required package: lmtest
Loading required package: zoo

Attaching package: 'zoo'

The following objects are masked from 'package:base':

    as.Date, as.Date.numeric

Loading required package: sandwich
Loading required package: survival
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/AER/ivreg.fit.Rd_%03d_medium.png", width=480, height=480)
> ### Name: ivreg.fit
> ### Title: Fitting Instrumental-Variable Regressions
> ### Aliases: ivreg.fit
> ### Keywords: regression
> 
> ### ** Examples
> 
> ## data
> data("CigarettesSW")
> CigarettesSW$rprice <- with(CigarettesSW, price/cpi)
> CigarettesSW$rincome <- with(CigarettesSW, income/population/cpi)
> CigarettesSW$tdiff <- with(CigarettesSW, (taxs - tax)/cpi)
> 
> ## high-level interface
> fm <- ivreg(log(packs) ~ log(rprice) + log(rincome) | log(rincome) + tdiff + I(tax/cpi),
+   data = CigarettesSW, subset = year == "1995")
> 
> ## low-level interface
> y <- fm$y
> x <- model.matrix(fm, component = "regressors")
> z <- model.matrix(fm, component = "instruments")
> ivreg.fit(x, y, z)$coefficients
 (Intercept)  log(rprice) log(rincome) 
   9.8949555   -1.2774241    0.2804048 
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>