├── .Rbuildignore ├── .github ├── .gitignore └── workflows │ └── pkgdown.yaml ├── .gitignore ├── DESCRIPTION ├── NAMESPACE ├── NEWS.md ├── R ├── CigaretteDemand.R ├── Kmenta.R ├── SchoolingReturns.R ├── ivreg.R ├── ivreg.fit.R ├── ivregDiagnostics.R ├── ivregMethods.R └── summary.ivreg.R ├── README.Rmd ├── README.md ├── _pkgdown.yml ├── data ├── CigaretteDemand.RData ├── Kmenta.RData └── SchoolingReturns.RData ├── docs ├── 404.html ├── apple-touch-icon-120x120.png ├── apple-touch-icon-152x152.png ├── apple-touch-icon-180x180.png ├── apple-touch-icon-60x60.png ├── apple-touch-icon-76x76.png ├── apple-touch-icon.png ├── articles │ ├── Diagnostics-for-2SLS-Regression.html │ ├── Diagnostics-for-2SLS-Regression_files │ │ ├── accessible-code-block-0.0.1 │ │ │ └── empty-anchor.js │ │ ├── anchor-sections-1.0 │ │ │ ├── anchor-sections.css │ │ │ └── anchor-sections.js │ │ ├── figure-html │ │ │ ├── unnamed-chunk-11-1.png │ │ │ ├── unnamed-chunk-12-1.png │ │ │ ├── unnamed-chunk-14-1.png │ │ │ ├── unnamed-chunk-17-1.png │ │ │ ├── unnamed-chunk-18-1.png │ │ │ ├── unnamed-chunk-19-1.png │ │ │ ├── unnamed-chunk-20-1.png │ │ │ ├── unnamed-chunk-21-1.png │ │ │ ├── unnamed-chunk-22-1.png │ │ │ ├── unnamed-chunk-23-1.png │ │ │ ├── unnamed-chunk-24-1.png │ │ │ ├── unnamed-chunk-28-1.png │ │ │ ├── unnamed-chunk-30-1.png │ │ │ ├── unnamed-chunk-36-1.png │ │ │ ├── unnamed-chunk-39-1.png │ │ │ ├── unnamed-chunk-4-1.png │ │ │ ├── unnamed-chunk-42-1.png │ │ │ ├── unnamed-chunk-5-1.png │ │ │ ├── unnamed-chunk-6-1.png │ │ │ └── unnamed-chunk-9-1.png │ │ ├── header-attrs-2.10 │ │ │ └── header-attrs.js │ │ ├── header-attrs-2.5 │ │ │ └── header-attrs.js │ │ └── header-attrs-2.8 │ │ │ └── header-attrs.js │ ├── index.html │ ├── ivreg.html │ └── ivreg_files │ │ ├── accessible-code-block-0.0.1 │ │ └── empty-anchor.js │ │ ├── anchor-sections-1.0 │ │ ├── anchor-sections.css │ │ └── anchor-sections.js │ │ ├── figure-html │ │ └── modelplot-1.png │ │ ├── header-attrs-2.10 │ │ └── header-attrs.js │ │ ├── header-attrs-2.5 │ │ └── header-attrs.js │ │ ├── header-attrs-2.8 │ │ └── header-attrs.js │ │ ├── kePrint-0.0.1 │ │ └── kePrint.js │ │ └── lightable-0.0.1 │ │ └── lightable.css ├── authors.html ├── bootstrap-toc.css ├── bootstrap-toc.js ├── docsearch.css ├── docsearch.js ├── extra.css ├── favicon-16x16.png ├── favicon-32x32.png ├── favicon.ico ├── index.html ├── link.svg ├── logo.png ├── logo_wide.png ├── news │ └── index.html ├── pkgdown.css ├── pkgdown.js ├── pkgdown.yml ├── reference │ ├── CigaretteDemand.html │ ├── Kmenta.html │ ├── Rplot001.png │ ├── Rplot002.png │ ├── Rplot003.png │ ├── Rplot004.png │ ├── Rplot005.png │ ├── Rplot006.png │ ├── Rplot007.png │ ├── Rplot008.png │ ├── Rplot009.png │ ├── SchoolingReturns.html │ ├── figures │ │ ├── README-2sls.svg │ │ ├── README-effects-1.png │ │ ├── README-influenceplot-1.png │ │ └── README-qqplot-1.png │ ├── index.html │ ├── ivreg.fit.html │ ├── ivreg.html │ ├── ivregDiagnostics-1.png │ ├── ivregDiagnostics-2.png │ ├── ivregDiagnostics-3.png │ ├── ivregDiagnostics-4.png │ ├── ivregDiagnostics-5.png │ ├── ivregDiagnostics-6.png │ ├── ivregDiagnostics-7.png │ ├── ivregDiagnostics-8.png │ ├── ivregDiagnostics-9.png │ ├── ivregDiagnostics.html │ └── ivregMethods.html └── sitemap.xml ├── logo.png ├── man ├── CigaretteDemand.Rd ├── Kmenta.Rd ├── SchoolingReturns.Rd ├── figures │ ├── README-2sls.svg │ ├── README-effects-1.png │ ├── README-influenceplot-1.png │ └── README-qqplot-1.png ├── ivreg.Rd ├── ivreg.fit.Rd ├── ivregDiagnostics.Rd ├── ivregMethods.Rd └── summary.ivreg.Rd ├── pkgdown ├── assets │ └── logo_wide.png ├── extra.css ├── favicon │ ├── apple-touch-icon-120x120.png │ ├── apple-touch-icon-152x152.png │ ├── apple-touch-icon-180x180.png │ ├── apple-touch-icon-60x60.png │ ├── apple-touch-icon-76x76.png │ ├── apple-touch-icon.png │ ├── favicon-16x16.png │ ├── favicon-32x32.png │ └── favicon.ico ├── logo-favicon.png └── logo.svg ├── tests ├── testthat.R └── testthat │ ├── test-case-deletion.R │ ├── test-ivreg.R │ ├── test-ivreg.fit.R │ ├── test-predict.R │ ├── test-robust-2SLS.R │ ├── test-stage1.R │ └── test-vcov.R └── vignettes ├── .gitignore ├── Diagnostics-for-2SLS-Regression.Rmd ├── ivreg.Rmd └── ivreg.bib /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^README\.Rmd$ 2 | ^README\.html$ 3 | ^docs$ 4 | ^doc$ 5 | ^pkgdown$ 6 | ^_pkgdown\.yml$ 7 | ^logo\.png$ 8 | ^.*\.Rproj$ 9 | ^\.Rproj\.user$ 10 | ^.github* 11 | ^Meta$ 12 | -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.github/workflows/pkgdown.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | 4 | on: 5 | push: 6 | branches: main 7 | 8 | name: pkgdown 9 | 10 | jobs: 11 | pkgdown: 12 | runs-on: ubuntu-latest 13 | # Only restrict concurrency for non-PR jobs 14 | concurrency: 15 | group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} 16 | env: 17 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 18 | steps: 19 | - uses: actions/checkout@v3 20 | 21 | - uses: r-lib/actions/setup-pandoc@v2 22 | 23 | - uses: r-lib/actions/setup-r@v2 24 | with: 25 | use-public-rspm: true 26 | 27 | - uses: r-lib/actions/setup-r-dependencies@v2 28 | with: 29 | extra-packages: any::pkgdown, local::. 30 | needs: website 31 | 32 | - name: Build site 33 | run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) 34 | shell: Rscript {0} 35 | 36 | - name: Deploy to GitHub pages 37 | if: github.event_name != 'pull_request' 38 | uses: JamesIves/github-pages-deploy-action@v4.4.1 39 | with: 40 | clean: false 41 | branch: gh-pages 42 | folder: docs 43 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | README.html 2 | .Rproj.user 3 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: ivreg 2 | Title: Instrumental-Variables Regression by '2SLS', '2SM', or '2SMM', with Diagnostics 3 | Version: 0.6-5 4 | Date: 2025-01-19 5 | Authors@R: c(person(given = "John", family = "Fox", role = "aut", email = "jfox@mcmaster.ca", comment = c(ORCID = "0000-0002-1196-8012")), 6 | person(given = "Christian", family = "Kleiber", role = "aut", email = "Christian.Kleiber@unibas.ch", comment = c(ORCID = "0000-0002-6781-4733")), 7 | person(given = "Achim", family = "Zeileis", role = c("aut", "cre"), email = "Achim.Zeileis@R-project.org", comment = c(ORCID = "0000-0003-0918-3766")), 8 | person(given = "Nikolas", family = "Kuschnig", role = "ctb", email = "nikolas.kuschnig@wu.ac.at", comment = c(ORCID = "0000-0002-6642-2543")), 9 | person(given = "R Core Team", role = "ctb", email = "R-core@R-project.org")) 10 | Description: Instrumental variable estimation for linear models by two-stage least-squares (2SLS) regression or by robust-regression via M-estimation (2SM) or MM-estimation (2SMM). The main ivreg() model-fitting function is designed to provide a workflow as similar as possible to standard lm() regression. A wide range of methods is provided for fitted ivreg model objects, including extensive functionality for computing and graphing regression diagnostics in addition to other standard model tools. 11 | License: GPL (>= 2) 12 | Depends: R (>= 3.6.0) 13 | Imports: car (>= 3.0-9), 14 | Formula, 15 | lmtest, 16 | MASS, 17 | stats 18 | Suggests: 19 | AER, 20 | effects (>= 4.2.0), 21 | knitr, 22 | insight, 23 | parallel, 24 | rmarkdown, 25 | sandwich, 26 | testthat, 27 | modelsummary, 28 | gt, 29 | ggplot2 30 | Encoding: UTF-8 31 | LazyData: true 32 | VignetteBuilder: knitr 33 | BugReports: https://github.com/zeileis/ivreg/issues/ 34 | URL: https://zeileis.github.io/ivreg/ 35 | RoxygenNote: 7.3.2 36 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(Anova,ivreg) 4 | S3method(Boot,ivreg) 5 | S3method(alias,ivreg) 6 | S3method(anova,ivreg) 7 | S3method(avPlot,ivreg) 8 | S3method(avPlots,ivreg) 9 | S3method(ceresPlot,ivreg) 10 | S3method(ceresPlots,ivreg) 11 | S3method(coef,ivreg) 12 | S3method(confint,ivreg) 13 | S3method(cooks.distance,influence.ivreg) 14 | S3method(cooks.distance,ivreg) 15 | S3method(crPlot,ivreg) 16 | S3method(crPlots,ivreg) 17 | S3method(deviance,ivreg) 18 | S3method(dfbeta,influence.ivreg) 19 | S3method(dfbeta,ivreg) 20 | S3method(effects::Effect,ivreg) 21 | S3method(formula,ivreg) 22 | S3method(hatvalues,influence.ivreg) 23 | S3method(hatvalues,ivreg) 24 | S3method(infIndexPlot,influence.ivreg) 25 | S3method(infIndexPlot,ivreg) 26 | S3method(influence,ivreg) 27 | S3method(influence,rivreg) 28 | S3method(influencePlot,influence.ivreg) 29 | S3method(influencePlot,ivreg) 30 | S3method(insight::find_formula,ivreg) 31 | S3method(linearHypothesis,ivreg) 32 | S3method(mcPlot,ivreg) 33 | S3method(mcPlots,ivreg) 34 | S3method(model.matrix,influence.ivreg) 35 | S3method(model.matrix,ivreg) 36 | S3method(model.matrix,ivreg_projected) 37 | S3method(ncvTest,ivreg) 38 | S3method(outlierTest,ivreg) 39 | S3method(plot,ivreg) 40 | S3method(predict,ivreg) 41 | S3method(print,ivreg) 42 | S3method(print,summary.ivreg) 43 | S3method(qqPlot,influence.ivreg) 44 | S3method(qqPlot,ivreg) 45 | S3method(qr,ivreg) 46 | S3method(residuals,ivreg) 47 | S3method(rstudent,influence.ivreg) 48 | S3method(rstudent,ivreg) 49 | S3method(sandwich::bread,ivreg) 50 | S3method(sandwich::estfun,ivreg) 51 | S3method(sandwich::vcovHC,ivreg) 52 | S3method(spreadLevelPlot,ivreg) 53 | S3method(summary,ivreg) 54 | S3method(terms,ivreg) 55 | S3method(update,ivreg) 56 | S3method(vcov,ivreg) 57 | S3method(weights,ivreg) 58 | export(ivreg) 59 | export(ivreg.fit) 60 | import(Formula) 61 | importFrom(MASS,rlm) 62 | importFrom(car,Anova) 63 | importFrom(car,Boot) 64 | importFrom(car,avPlot) 65 | importFrom(car,avPlots) 66 | importFrom(car,ceresPlot) 67 | importFrom(car,ceresPlots) 68 | importFrom(car,crPlot) 69 | importFrom(car,crPlots) 70 | importFrom(car,infIndexPlot) 71 | importFrom(car,influencePlot) 72 | importFrom(car,linearHypothesis) 73 | importFrom(car,mcPlot) 74 | importFrom(car,mcPlots) 75 | importFrom(car,ncvTest) 76 | importFrom(car,outlierTest) 77 | importFrom(car,qqPlot) 78 | importFrom(car,spreadLevelPlot) 79 | importFrom(graphics,plot) 80 | importFrom(lmtest,coeftest) 81 | importFrom(lmtest,lrtest) 82 | importFrom(lmtest,lrtest.default) 83 | importFrom(lmtest,waldtest) 84 | importFrom(lmtest,waldtest.default) 85 | importFrom(stats,.getXlevels) 86 | importFrom(stats,.vcov.aliased) 87 | importFrom(stats,alias) 88 | importFrom(stats,anova) 89 | importFrom(stats,coef) 90 | importFrom(stats,cooks.distance) 91 | importFrom(stats,delete.response) 92 | importFrom(stats,deviance) 93 | importFrom(stats,df.residual) 94 | importFrom(stats,dfbeta) 95 | importFrom(stats,fitted) 96 | importFrom(stats,formula) 97 | importFrom(stats,getCall) 98 | importFrom(stats,hatvalues) 99 | importFrom(stats,influence) 100 | importFrom(stats,lm) 101 | importFrom(stats,lm.fit) 102 | importFrom(stats,lm.influence) 103 | importFrom(stats,lm.wfit) 104 | importFrom(stats,mad) 105 | importFrom(stats,model.frame) 106 | importFrom(stats,model.matrix) 107 | importFrom(stats,model.offset) 108 | importFrom(stats,model.response) 109 | importFrom(stats,model.weights) 110 | importFrom(stats,na.omit) 111 | importFrom(stats,na.pass) 112 | importFrom(stats,naresid) 113 | importFrom(stats,pchisq) 114 | importFrom(stats,pf) 115 | importFrom(stats,predict) 116 | importFrom(stats,printCoefmat) 117 | importFrom(stats,qnorm) 118 | importFrom(stats,qt) 119 | importFrom(stats,quantile) 120 | importFrom(stats,residuals) 121 | importFrom(stats,rstudent) 122 | importFrom(stats,terms) 123 | importFrom(stats,update) 124 | importFrom(stats,vcov) 125 | importFrom(stats,weighted.mean) 126 | importFrom(stats,weights) 127 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # Version 0.6-5 2 | 3 | * Better documentation for summary and inference methods for `ivreg()` objects 4 | with a dedicated manual page `?summary.ivreg`. Along with the `summary()` 5 | method this also documents the methods for `confint()`, `anova()`, 6 | `Anova()`, and `linearHypothesis()`. All of these take an argument `vcov.` 7 | so that alternative (e.g., so-called "robust") covariance matrices can be 8 | plugged in. The `vcov.` processing is made somewhat more convenient and 9 | consistent (suggested by Diogo Ferrari). 10 | 11 | 12 | # Version 0.6-4 13 | 14 | * Fixed bug in computing larger of stage-1 and -2 hatvalues in 15 | `hatvalues.ivreg()` (reported by Vasilis Syrgkanis). 16 | 17 | 18 | # Version 0.6-3 19 | 20 | * Enhanced `predict.ivreg()` method, which optionally provides standard errors, 21 | confidence intervals, and prediction intervals for predicted values. 22 | 23 | * The `tinytable` rather than the `kableExtra` package (recently not actively maintained) 24 | is used now for the `modelsummary` table shown in the package vignette (contributed 25 | by Vincent Arel-Bundock). 26 | 27 | * Further small improvements in the package vignettes. 28 | 29 | * Improve non-anchored links in manual pages (prompted by CRAN). 30 | 31 | 32 | # Version 0.6-2 33 | 34 | * Achim Zeileis took over maintenance, both on CRAN and on GitHub. The GitHub 35 | source repository is now at with the web 36 | page at . 37 | 38 | * Avoid partial argument matches by calling `model.matrix(..., contrasts.arg = ...)` 39 | rather than just `contrasts` (reported by Kevin Tappe). 40 | 41 | * Make names of arguments of `influencePlot.ivreg()` and `outlierTest.ivreg()` 42 | consistent with the corresponding generic functions from the car package. 43 | 44 | 45 | # Version 0.6-1 46 | 47 | * `method` is now an explicit argument to `ivreg()` and not just passed through `...` 48 | to `ivreg.fit()`. 49 | 50 | * More efficient computation of regression diagnostics (thanks to improvements 51 | implemented by Nikolas Kuschnig). 52 | 53 | * In models without any exogenous variables (i.e., not even an exogenous `(Intercept)`) 54 | the `$instruments` element in the fitted model object was erroneously empty, leading 55 | to some incorrect subsequent computations. Also the `$endogenous` element was an 56 | unnamed (rather than named) vector. Both problems have been fixed now. 57 | (Reported by Luke Sonnet.) 58 | 59 | * In the `summary()` method the default is now `diagnostics = NULL` (rather than 60 | always `TRUE`). It is now only set to `TRUE` if there are both endogenous and 61 | instrument variables, and `FALSE` otherwise. (Reported by Brantly Callaway.) 62 | 63 | * Small fixes. 64 | 65 | 66 | # Version 0.6-0 67 | 68 | * Three-part right-hand side `formula`s are supported now to facilitate specification 69 | of models with many exogenous regressors. For example, if there is one exogenous 70 | regressor `ex` and one endogenous regressor `en` with instrument `in`, a formula 71 | with three parts on the right-hand side can now also be used: `y ~ ex | en | in`. 72 | This is equivalent to specifying: `y ~ en + ex | in + ex`. 73 | 74 | * Robust-regression estimators are provided as an alternative to ordinary 75 | least squares (OLS) both in stage 1 and 2 by means of `rlm()` from package 76 | [MASS](https://CRAN.R-project.org/package=MASS). Specifically, in addition to 77 | 2-stage least squares (2SLS, `method = "OLS"`, default) `ivreg()` now supports 78 | 2-stage M-estimation (2SM, `method = "M"`) and 2-stage MM-estimation (2SMM, 79 | `method = "MM"`). 80 | 81 | * Dedicated `confint()` method allowing specification of the variance-covariance 82 | matrix `vcov.` and degrees of freedom `df` to be used (as in the `summary()` 83 | method). 84 | 85 | * Include information about which `"regressors"` are endogenous variables and 86 | which `"instruments"` are instruments for the endogenous variables in the 87 | fitted model objects from `ivreg()` and `ivreg.fit()`. Both provide elements 88 | `$endogenous` and `$instruments` which are named integer vectors provided 89 | that endogenous/instrument variables exist, and integers of length zero if 90 | not. 91 | 92 | * Include `df.residual1` element in `ivreg` objects with the residual degrees 93 | of freedom from the stage-1 regression. 94 | 95 | * Add `coef(..., component = "stage1")`, `vcov(..., component = "stage1")`, and 96 | `confint(..., component = "stage1")` for the estimated coefficients and 97 | corresponding variance-covariance matrix and confidence intervals from the 98 | stage-1 regression (only for the endogenous regressors). (Prompted by a request 99 | from Grant McDermott.) 100 | 101 | * Add `residuals(..., type = "stage1")` with the residuals from the stage-1 102 | regression (only for the endogenous regressors). 103 | 104 | * The `coef()`, `vcov()`, and `confint()` methods gained a `complete = TRUE` argument 105 | assuring that the elements pertaining to aliased coefficients are included. 106 | By setting `complete = FALSE` these elements are dropped. 107 | 108 | * Include demonstration how to use `ivreg()` results in model summary tables 109 | and plots using the [modelsummary](https://CRAN.R-project.org/package=modelsummary) 110 | package. 111 | 112 | * Small edits to the Diagnostics vignette. 113 | 114 | 115 | # Version 0.5-0 116 | 117 | * Initial version of the `ivreg` package: An implementation of instrumental 118 | variables regression using two-stage least-squares (2SLS) estimation, based on 119 | the `ivreg()` function previously in the 120 | [AER](https://CRAN.R-project.org/package=AER) package. In addition to standard 121 | regression functionality (parameter estimation, inference, predictions, etc.) 122 | the package provides various regression diagnostics, including hat values, 123 | deletion diagnostics such as studentized residuals and Cook's distances; 124 | graphical diagnostics such as component-plus-residual plots and added-variable 125 | plots; and effect plots with partial residuals. 126 | 127 | * An overview of the package, documentation, examples, and vignettes are provided 128 | at `https://john-d-fox.github.io/ivreg/`. 129 | -------------------------------------------------------------------------------- /R/CigaretteDemand.R: -------------------------------------------------------------------------------- 1 | #' U.S. Cigarette Demand Data 2 | #' 3 | #' Determinants of cigarette demand for the 48 continental US States in 1995 and 4 | #' compared between 1995 and 1985. 5 | #' 6 | #' The data are taken from the online complements to Stock and Watson (2007) and 7 | #' had been prepared as panel data (in long form) in \code{\link[AER]{CigarettesSW}} 8 | #' from the AER package (Kleiber and Zeileis 2008). Here, the data are provided by 9 | #' state (in wide form), readily preprocessed to contain all variables needed for 10 | #' illustrations of OLS and IV regressions. More related examples from Stock and 11 | #' Watson (2007) are provided in the AER package in \code{\link[AER]{StockWatson2007}}. 12 | #' A detailed discussion of the various cigarette demand examples with R code 13 | #' is provided by Hanck et al. (2020, Chapter 12). 14 | #' 15 | #' @usage data("CigaretteDemand", package = "ivreg") 16 | #' 17 | #' @format A data frame with 48 rows and 10 columns. 18 | #' \describe{ 19 | #' \item{packs}{Number of cigarette packs per capita sold in 1995.} 20 | #' \item{rprice}{Real price in 1995 (including sales tax).} 21 | #' \item{rincome}{Real per capita income in 1995.} 22 | #' \item{salestax}{Sales tax in 1995.} 23 | #' \item{cigtax}{Cigarette-specific taxes (federal and average local excise taxes) in 1995.} 24 | #' \item{packsdiff}{Difference in \code{log(packs)} (between 1995 and 1985).} 25 | #' \item{pricediff}{Difference in \code{log(rprice)} (between 1995 and 1985).} 26 | #' \item{incomediff}{Difference in \code{log(rincome)} (between 1995 and 1985).} 27 | #' \item{salestaxdiff}{Difference in \code{salestax} (between 1995 and 1985).} 28 | #' \item{cigtaxdiff}{Difference in \code{cigtax} (between 1995 and 1985).} 29 | #' } 30 | #' 31 | #' @source Online complements to Stock and Watson (2007). 32 | #' @seealso \code{\link[AER]{CigarettesSW}}. 33 | #' @references Hanck, C., Arnold, M., Gerber, A., and Schmelzer, M. (2020). 34 | #' \emph{Introduction to Econometrics with R}. \url{https://www.econometrics-with-r.org/} 35 | #' 36 | #' Kleiber, C. and Zeileis, A. (2008). \emph{Applied Econometrics with R}. Springer-Verlag 37 | #' 38 | #' Stock, J.H. and Watson, M.W. (2007). \emph{Introduction to Econometrics}, 2nd ed., Addison Wesley. 39 | #' 40 | #' @examples 41 | #' ## load data 42 | #' data("CigaretteDemand", package = "ivreg") 43 | #' 44 | #' ## basic price elasticity: OLS vs. IV 45 | #' cig_ols <- lm(log(packs) ~ log(rprice), data = CigaretteDemand) 46 | #' cig_iv <- ivreg(log(packs) ~ log(rprice) | salestax, data = CigaretteDemand) 47 | #' cbind(OLS = coef(cig_ols), IV = coef(cig_iv)) 48 | #' 49 | #' ## adjusting for income differences (exogenous) 50 | #' cig_iv2 <- ivreg(log(packs) ~ log(rprice) + log(rincome) | salestax + log(rincome), 51 | #' data = CigaretteDemand) 52 | #' ## adding a second instrument for log(rprice) 53 | #' cig_iv3 <- update(cig_iv2, . ~ . | . + cigtax) 54 | #' 55 | #' ## comparison using heteroscedasticity-consistent standard errors 56 | #' library("lmtest") 57 | #' library("sandwich") 58 | #' coeftest(cig_iv2, vcov = vcovHC, type = "HC1") 59 | #' coeftest(cig_iv3, vcov = vcovHC, type = "HC1") 60 | #' 61 | #' ## long-run price elasticity using differences between 1995 and 1985 62 | #' cig_ivdiff1 <- ivreg(packsdiff ~ pricediff + incomediff | incomediff + salestaxdiff, 63 | #' data = CigaretteDemand) 64 | #' cig_ivdiff2 <- update(cig_ivdiff1, . ~ . | . - salestaxdiff + cigtaxdiff) 65 | #' cig_ivdiff3 <- update(cig_ivdiff1, . ~ . | . + cigtaxdiff) 66 | #' coeftest(cig_ivdiff1, vcov = vcovHC, type = "HC1") 67 | #' coeftest(cig_ivdiff2, vcov = vcovHC, type = "HC1") 68 | #' coeftest(cig_ivdiff3, vcov = vcovHC, type = "HC1") 69 | "CigaretteDemand" 70 | -------------------------------------------------------------------------------- /R/Kmenta.R: -------------------------------------------------------------------------------- 1 | #' Partly Artificial Data on the U.S. Economy 2 | #' 3 | #' These are partly contrived data from Kmenta (1986), constructed 4 | #' to illustrate estimation of a simultaneous-equation econometric model. The data 5 | #' are an annual time-series for the U.S. economy from 1922 to 1941. The values of the 6 | #' exogenous variables D, and F, and A are real, while those of the endogenous 7 | #' variables Q and P are simulated according to the linear simultaneous equation model 8 | #' fit in the examples. 9 | #' 10 | #' @usage data("Kmenta", package = "ivreg") 11 | #' 12 | #' @format A data frame with 20 rows and 5 columns. 13 | #' \describe{ 14 | #' \item{Q}{food consumption per capita.} 15 | #' \item{P}{ratio of food prices to general consumer prices.} 16 | #' \item{D}{disposable income in constant dollars.} 17 | #' \item{F}{ratio of preceding year's prices received by farmers to general consumer prices.} 18 | #' \item{A}{time in years.} 19 | #' } 20 | #' 21 | #' @source Kmenta, J. (1986) \emph{Elements of Econometrics}, 2nd ed., Macmillan. 22 | #' @seealso \code{\link{ivreg}}. 23 | #' 24 | #' @examples 25 | #' data("Kmenta", package = "ivreg") 26 | #' deq <- ivreg(Q ~ P + D | D + F + A, data = Kmenta) # demand equation 27 | #' seq <- ivreg(Q ~ P + F + A | D + F + A, data = Kmenta) # supply equation 28 | #' summary(deq, tests = TRUE) 29 | #' summary(seq, tests = TRUE) 30 | "Kmenta" 31 | -------------------------------------------------------------------------------- /R/SchoolingReturns.R: -------------------------------------------------------------------------------- 1 | #' U.S. Returns to Schooling Data 2 | #' 3 | #' Data from the U.S. National Longitudinal Survey of Young Men (NLSYM) in 1976 4 | #' but using some variables dating back to earlier years. 5 | #' 6 | #' Investigating the causal link of schooling on earnings in a classical model 7 | #' for wage determinants is problematic because it can be argued that schooling 8 | #' is endogenous. Hence, one possible strategy is to use an exogonous variable 9 | #' as an instrument for the years of education. In his well-known study, Card (1995) 10 | #' uses geographical proximity to a college when growing up as such an instrument, 11 | #' showing that this significantly increases both the years of education and the 12 | #' wage level obtained on the labor market. Using instrumental variables regression 13 | #' Card (1995) shows that the estimated returns to schooling are much higher than 14 | #' when simply using ordinary least squares. 15 | #' 16 | #' The data are taken from the supplementary material for Verbeek (2004) and are based 17 | #' on the work of Card (1995). The U.S. National Longitudinal Survey of Young Men 18 | #' (NLSYM) began in 1966 and included 5525 men, then aged between 14 and 24. 19 | #' Card (1995) employs labor market information from the 1976 NLSYM interview which 20 | #' also included information about educational attainment. Out of the 3694 men 21 | #' still included in that wave of NLSYM, 3010 provided information on both wages 22 | #' and education yielding the subset of observations provided in \code{SchoolingReturns}. 23 | #' 24 | #' The examples replicate the results from Verbeek (2004) who used the simplest 25 | #' specifications from Card (1995). Including further region or family background 26 | #' characteristics improves the model significantly but does not affect much the 27 | #' main coefficients of interest, namely that of years of education. 28 | #' 29 | #' @usage data("SchoolingReturns", package = "ivreg") 30 | #' 31 | #' @format A data frame with 3010 rows and 22 columns. 32 | #' \describe{ 33 | #' \item{wage}{Raw wages in 1976 (in cents per hour).} 34 | #' \item{education}{Education in 1976 (in years).} 35 | #' \item{experience}{Years of labor market experience, computed as \code{age - education - 6}.} 36 | #' \item{ethnicity}{Factor indicating ethnicity. Is the individual African-American 37 | #' (\code{"afam"}) or not (\code{"other"})?} 38 | #' \item{smsa}{Factor. Does the individual reside in a SMSA (standard metropolitan statistical area) in 1976?} 39 | #' \item{south}{Factor. Does the individual reside in the South in 1976?} 40 | #' \item{age}{Age in 1976 (in years).} 41 | #' \item{nearcollege}{Factor. Did the individual grow up near a 4-year college?} 42 | #' \item{nearcollege2}{Factor. Did the individual grow up near a 2-year college?} 43 | #' \item{nearcollege4}{Factor. Did the individual grow up near a 4-year public or private college?} 44 | #' \item{enrolled}{Factor. Is the individual enrolled in college in 1976?} 45 | #' \item{married}{factor. Is the individual married in 1976?} 46 | #' \item{education66}{Education in 1966 (in years).} 47 | #' \item{smsa66}{Factor. Does the individual reside in a SMSA in 1966?} 48 | #' \item{south66}{Factor. Does the individual reside in the South in 1966?} 49 | #' \item{feducation}{Father's educational attainment (in years). Imputed with average if missing.} 50 | #' \item{meducation}{Mother's educational attainment (in years). Imputed with average if missing.} 51 | #' \item{fameducation}{Ordered factor coding family education class (from 1 to 9).} 52 | #' \item{kww}{Knowledge world of work (KWW) score.} 53 | #' \item{iq}{Normed intelligence quotient (IQ) score} 54 | #' \item{parents14}{Factor coding living with parents at age 14: 55 | #' both parents, single mother, step parent, other} 56 | #' \item{library14}{Factor. Was there a library card in home at age 14?} 57 | #' } 58 | #' 59 | #' @source Supplementary material for Verbeek (2004). 60 | #' @references Card, D. (1995). Using Geographical Variation in College Proximity to Estimate the Return to 61 | #' Schooling. In: Christofides, L.N., Grant, E.K., and Swidinsky, R. (eds.), 62 | #' \emph{Aspects of Labour Market Behaviour: Essays in Honour of John Vanderkamp}, 63 | #' University of Toronto Press, Toronto, 201-222. 64 | #' 65 | #' Verbeek, M. (2004). \emph{A Guide to Modern Econometrics}, 2nd ed. John Wiley. 66 | #' 67 | #' @examples 68 | #' ## load data 69 | #' data("SchoolingReturns", package = "ivreg") 70 | #' 71 | #' ## Table 5.1 in Verbeek (2004) / Table 2(1) in Card (1995) 72 | #' ## Returns to education: 7.4% 73 | #' m_ols <- lm(log(wage) ~ education + poly(experience, 2, raw = TRUE) + ethnicity + smsa + south, 74 | #' data = SchoolingReturns) 75 | #' summary(m_ols) 76 | #' 77 | #' ## Table 5.2 in Verbeek (2004) / similar to Table 3(1) in Card (1995) 78 | #' m_red <- lm(education ~ poly(age, 2, raw = TRUE) + ethnicity + smsa + south + nearcollege, 79 | #' data = SchoolingReturns) 80 | #' summary(m_red) 81 | #' 82 | #' ## Table 5.3 in Verbeek (2004) / similar to Table 3(5) in Card (1995) 83 | #' ## Returns to education: 13.3% 84 | #' m_iv <- ivreg(log(wage) ~ education + poly(experience, 2, raw = TRUE) + ethnicity + smsa + south | 85 | #' nearcollege + poly(age, 2, raw = TRUE) + ethnicity + smsa + south, 86 | #' data = SchoolingReturns) 87 | #' summary(m_iv) 88 | "SchoolingReturns" 89 | -------------------------------------------------------------------------------- /R/ivreg.fit.R: -------------------------------------------------------------------------------- 1 | #' Fitting Instrumental-Variable Regressions by 2SLS, 2SM, or 2SMM Estimation 2 | #' 3 | #' Fit instrumental-variable regression by two-stage least squares (2SLS). This is 4 | #' equivalent to direct instrumental-variables estimation when the number of 5 | #' instruments is equal to the number of predictors. Alternative robust-regression 6 | #' estimation is also supported, based on M-estimation (22M) or MM-estimation (2SMM). 7 | #' 8 | #' \code{\link{ivreg}} is the high-level interface to the work-horse function 9 | #' \code{ivreg.fit}. \code{ivreg.fit} is essentially a convenience interface to 10 | #' \code{\link[stats:lmfit]{lm.fit}} (or \code{\link[stats:lmfit]{lm.wfit}}) 11 | #' for first projecting \code{x} onto the image of 12 | #' \code{z}, then running a regression of \code{y} on the projected 13 | #' \code{x}, and computing the residual standard deviation. 14 | #' 15 | #' @aliases ivreg.fit 16 | #' 17 | #' @importFrom MASS rlm 18 | #' @importFrom stats mad 19 | #' 20 | #' @param x regressor matrix. 21 | #' @param y vector for the response variable. 22 | #' @param z instruments matrix. 23 | #' @param weights an optional vector of weights to be used in the fitting 24 | #' process. 25 | #' @param offset an optional offset that can be used to specify an a priori 26 | #' known component to be included during fitting. 27 | #' @param method the method used to fit the stage 1 and 2 regression: 28 | #' \code{"OLS"} for traditional 2SLS regression (the default), 29 | #' \code{"M"} for M-estimation, or \code{"MM"} for MM-estimation, with the 30 | #' latter two robust-regression methods implemented via the \code{\link[MASS]{rlm}} 31 | #' function in the \pkg{MASS} package. 32 | #' @param rlm.args a list of optional arguments to be passed to the \code{\link[MASS]{rlm}} 33 | #' function in the \pkg{MASS} package if robust regression is used for the stage 1 and 2 regressions. 34 | #' @param \dots further arguments passed to \code{\link[stats:lmfit]{lm.fit}} 35 | #' or \code{\link[stats:lmfit]{lm.wfit}}, respectively. 36 | #' @return \code{ivreg.fit} returns an unclassed list with the following 37 | #' components: 38 | #' \item{coefficients}{parameter estimates, from the stage-2 regression.} 39 | #' \item{residuals}{vector of model residuals.} 40 | #' \item{residuals1}{matrix of residuals from the stage-1 regression.} 41 | #' \item{residuals2}{vector of residuals from the stage-2 regression.} 42 | #' \item{fitted.values}{vector of predicted means for the response.} 43 | #' \item{weights}{either the vector of weights used (if any) or \code{NULL} (if none).} 44 | #' \item{offset}{either the offset used (if any) or \code{NULL} (if none).} 45 | #' \item{estfun}{a matrix containing the empirical estimating functions.} 46 | #' \item{n}{number of observations.} 47 | #' \item{nobs}{number of observations with non-zero weights.} 48 | #' \item{p}{number of columns in the model matrix x of regressors.} 49 | #' \item{q}{number of columns in the instrumental variables model matrix z} 50 | #' \item{rank}{numeric rank of the model matrix for the stage-2 regression.} 51 | #' \item{df.residual}{residual degrees of freedom for fitted model.} 52 | #' \item{cov.unscaled}{unscaled covariance matrix for the coefficients.} 53 | #' \item{sigma}{residual standard error; when method is \code{"M"} or \code{"MM"}, this 54 | #' is based on the MAD of the residuals (around 0) --- see \code{\link[stats]{mad}}.} 55 | #' \item{x}{projection of x matrix onto span of z.} 56 | #' \item{qr}{QR decomposition for the stage-2 regression.} 57 | #' \item{qr1}{QR decomposition for the stage-1 regression.} 58 | #' \item{rank1}{numeric rank of the model matrix for the stage-1 regression.} 59 | #' \item{coefficients1}{matrix of coefficients from the stage-1 regression.} 60 | #' \item{df.residual1}{residual degrees of freedom for the stage-1 regression.} 61 | #' \item{exogenous}{columns of the \code{"regressors"} matrix that are exogenous.} 62 | #' \item{endogenous}{columns of the \code{"regressors"} matrix that are endogenous.} 63 | #' \item{instruments}{columns of the \code{"instruments"} matrix that are 64 | #' instruments for the endogenous variables.} 65 | #' \item{method}{the method used for the stage 1 and 2 regressions, one of \code{"OLS"}, 66 | #' \code{"M"}, or \code{"MM"}.} 67 | #' \item{rweights}{a matrix of robustness weights with columns for each of the stage-1 68 | #' regressions and for the stage-2 regression (in the last column) if the fitting method is 69 | #' \code{"M"} or \code{"MM"}, \code{NULL} if the fitting method is \code{"OLS"}.} 70 | #' \item{hatvalues}{a matrix of hatvalues. For \code{method = "OLS"}, the matrix consists of two 71 | #' columns, for each of the stage-1 and stage-2 regression; for \code{method = "M"} or \code{"MM"}, 72 | #' there is one column for \emph{each} stage-1 regression and for the stage-2 regression. } 73 | #' @seealso \code{\link{ivreg}}, \code{\link[stats:lmfit]{lm.fit}}, 74 | #' \code{\link[stats:lmfit]{lm.wfit}}, \code{\link[MASS]{rlm}}, \code{\link[stats]{mad}} 75 | #' @keywords regression 76 | #' @examples 77 | #' ## data 78 | #' data("CigaretteDemand", package = "ivreg") 79 | #' 80 | #' ## high-level interface 81 | #' m <- ivreg(log(packs) ~ log(rprice) + log(rincome) | salestax + log(rincome), 82 | #' data = CigaretteDemand) 83 | #' 84 | #' ## low-level interface 85 | #' y <- m$y 86 | #' x <- model.matrix(m, component = "regressors") 87 | #' z <- model.matrix(m, component = "instruments") 88 | #' ivreg.fit(x, y, z)$coefficients 89 | #' 90 | #' @export 91 | ivreg.fit <- function(x, y, z, weights, offset, method = c("OLS", "M", "MM"), 92 | rlm.args=list(), ...) 93 | { 94 | 95 | method <- match.arg(method, c("OLS", "M", "MM")) 96 | 97 | ## model dimensions 98 | n <- NROW(y) 99 | p <- ncol(x) 100 | 101 | ## defaults 102 | if(missing(z)) z <- NULL 103 | if(missing(weights)) weights <- NULL 104 | if(missing(offset)) offset <- rep(0, n) 105 | 106 | ## sanity checks 107 | stopifnot(n == nrow(x)) 108 | if(!is.null(z)) stopifnot(n == nrow(z)) 109 | if(!is.null(weights)) stopifnot(n == NROW(weights)) 110 | stopifnot(n == NROW(offset)) 111 | 112 | ## project regressors x on image of instruments z 113 | if(!is.null(z)) { 114 | if(ncol(z) < ncol(x)) warning("more regressors than instruments") 115 | auxreg <- if(is.null(weights)) lm.fit(z, x, ...) else lm.wfit(z, x, weights, ...) 116 | xz <- as.matrix(auxreg$fitted.values) 117 | # pz <- z %*% chol2inv(auxreg$qr$qr) %*% t(z) 118 | colnames(xz) <- colnames(x) 119 | } else { 120 | auxreg <- NULL 121 | xz <- x 122 | } 123 | 124 | if (method == "OLS"){ 125 | hats <- if (!is.null(auxreg)) cbind(lm.influence(auxreg, do.coef = FALSE)$hat, 0) 126 | else cbind(NA, matrix(0, nrow=n, ncol=1)) 127 | } 128 | 129 | ## infer endogenous variables in x and instruments in z 130 | 131 | exog <- structure(seq_along(colnames(x)), .Names = colnames(x)) 132 | if(!is.null(auxreg)) { 133 | endo <- which(colMeans(as.matrix(auxreg$residuals^2)) > sqrt(.Machine$double.eps)) 134 | inst <- rowMeans(as.matrix(coef(auxreg)^2)[, -endo, drop = FALSE]) 135 | inst <- which(inst < sqrt(.Machine$double.eps) | is.nan(inst)) 136 | endo <- exog[endo] 137 | exog <- exog[-endo] 138 | } else { 139 | endo <- inst <- integer() 140 | } 141 | 142 | # robust regression for stage 1 143 | if (method != "OLS" && length(endo) > 0){ 144 | rlm.args$x <- z 145 | rlm.args$method <- method 146 | if (!is.null(weights)) rlm.args$weights <- weights 147 | residuals <- matrix(0, n, p) 148 | hats <- rwts <- matrix(0, n, length(endo) + 1) 149 | coef <- coef(auxreg) 150 | j <- 0 151 | for (en in endo){ 152 | j <- j + 1 153 | rlm.args$y <- x[, en] 154 | xz[, en] <- fitted(st1 <- do.call(rlm, rlm.args)) 155 | residuals[ , en] <- residuals(st1) 156 | coef[, en] <- coef(st1) 157 | rwts[, j] <- st1$w 158 | hats[, j] <- hatvalues(st1) 159 | } 160 | auxreg$residuals <- residuals 161 | auxreg$coefficients <- coef 162 | } 163 | 164 | ## main regression 165 | fit <- if (method == "OLS") { 166 | if(is.null(weights)) lm.fit(xz, y, offset = offset, ...) 167 | else lm.wfit(xz, y, weights, offset = offset, ...) 168 | } else { 169 | # robust regression for stage 2 170 | rlm.args$y <- y - offset 171 | rlm.args$x <- xz 172 | do.call(rlm, rlm.args) 173 | } 174 | if (method != "OLS") { 175 | rwts[, ncol(rwts)] <- fit$w 176 | hats[, ncol(hats)] <- hatvalues(fit) 177 | rownames(hats) <- rownames(rwts) <- names(y) 178 | colnames(hats) <- colnames(rwts) <- c(names(endo), "stage_2") 179 | fit$df.residual <- n - length(na.omit(coef(fit))) 180 | } else { 181 | hats[, 2] <- lm.influence(fit, do.coef = FALSE)$hat 182 | colnames(hats) <- c("stage_1", "stage_2") 183 | } 184 | 185 | ## model fit information 186 | ok <- which(!is.na(fit$coefficients)) 187 | yhat <- drop(x[, ok, drop = FALSE] %*% fit$coefficients[ok]) + offset 188 | names(yhat) <- names(y) 189 | res <- y - yhat 190 | ucov <- chol2inv(fit$qr$qr[1:length(ok), 1:length(ok), drop = FALSE]) 191 | colnames(ucov) <- rownames(ucov) <- names(fit$coefficients[ok]) 192 | sigma <- if (method == "OLS") { 193 | rss <- if(is.null(weights)) sum(res^2) else sum(weights * res^2) 194 | sqrt(rss/fit$df.residual) ## NOTE: Stata divides by n here and uses z tests rather than t tests... 195 | } else { 196 | if (is.null(weights)) mad(res, 0) else mad(sqrt(weights) * res, 0) 197 | } 198 | 199 | rval <- list( 200 | coefficients = fit$coefficients, 201 | residuals = res, 202 | residuals1 = auxreg$residuals, 203 | residuals2 = fit$residuals, 204 | fitted.values = yhat, 205 | weights = weights, 206 | offset = if(identical(offset, rep(0, n))) NULL else offset, 207 | n = n, 208 | nobs = if(is.null(weights)) n else sum(weights > 0), 209 | p = p, 210 | q = ncol(z), 211 | rank = fit$rank, 212 | df.residual = fit$df.residual, 213 | cov.unscaled = ucov, 214 | sigma = sigma, 215 | # hatvalues = hat, 216 | x = xz, 217 | qr = fit$qr, 218 | qr1 = auxreg$qr, 219 | rank1 = auxreg$rank, 220 | coefficients1 = coef(auxreg), 221 | df.residual1 = auxreg$df.residual, 222 | exogenous = exog, 223 | endogenous = endo, 224 | instruments = inst, 225 | method = method, 226 | rweights = if (method == "OLS") NULL else rwts, 227 | hatvalues = hats 228 | ) 229 | 230 | return(rval) 231 | } 232 | -------------------------------------------------------------------------------- /README.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: github_document 3 | --- 4 | 5 | 6 | 7 | ```{r, include = FALSE} 8 | knitr::opts_chunk$set( 9 | fig.path = "man/figures/README-" 10 | ) 11 | ``` 12 | 13 | ## Two-Stage Least-Squares Regression with Diagnostics 14 | 15 | An implementation of instrumental variables regression using two-stage least-squares 16 | (2SLS) estimation, based on the `ivreg()` function previously in the 17 | [AER](https://CRAN.R-project.org/package=AER) package. In addition to standard regression 18 | functionality (parameter estimation, inference, predictions, etc.) the package provides 19 | various regression diagnostics, including hat values, deletion diagnostics such as 20 | studentized residuals and Cook's distances; graphical diagnostics such as 21 | component-plus-residual plots and added-variable plots; and effect plots with partial 22 | residuals. 23 | 24 | 25 | **Instrumental variables regression:** 26 | 27 | ``` 28 | library("ivreg") 29 | ivreg(Q ~ P + D | D + F + A, data = Kmenta) 30 | ``` 31 | 32 | 33 | **Via two-stage least squares (2SLS):** 34 | 35 | ```{r 2sls, echo=FALSE, results="hide"} 36 | exams::tex2image("\\begin{eqnarray*} 37 | y & = & X \\beta + \\varepsilon \\\\ 38 | \\widehat{X} & = & Z (Z^\\top Z)^{-1} Z^\\top X \\\\ 39 | \\widehat{\\beta}_{\\mathrm{2SLS}} & = & (\\widehat{X}^\\top \\widehat{X})^{-1} \\widehat{X}^\\top y 40 | \\end{eqnarray*}", 41 | format = "svg", header = "", pt = 14, 42 | dir = file.path(getwd(), "man", "figures"), name = "README-2sls") 43 | ``` 44 | 45 | 2SLS 46 | 47 | 48 | **With diagnostics:** 49 | 50 | ```{r effects, echo=FALSE, results="hide", message=FALSE, fig.height=4.7, fig.width=5, fig.show="hide"} 51 | library("ivreg") 52 | library("effects") 53 | library("car") 54 | deq <- ivreg(Q ~ P + D | D + F + A, data = Kmenta) 55 | plot(predictorEffect("P", deq, residuals = TRUE), partial.residuals = list(span = 1)) 56 | ``` 57 | 58 | ```{r qqplot, echo=FALSE, results="hide", message=FALSE, fig.height=4.7, fig.width=5, fig.show="hide"} 59 | qqPlot(deq, main = "QQ plot") 60 | ## mtext("QQ plot", line = 1.5, cex = 1.2, font = 2) 61 | ``` 62 | 63 | ```{r influenceplot, echo=FALSE, results="hide", message=FALSE, fig.height=4.7, fig.width=5, fig.show="hide"} 64 | influencePlot(deq, main = "") 65 | mtext("Influence plot", line = 2, cex = 1.2, font = 2) 66 | ``` 67 | 68 | Effects plot 69 | QQ plot 70 | Influence plot 71 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ## Two-Stage Least-Squares Regression with Diagnostics 5 | 6 | An implementation of instrumental variables regression using two-stage 7 | least-squares (2SLS) estimation, based on the `ivreg()` function 8 | previously in the [AER](https://CRAN.R-project.org/package=AER) package. 9 | In addition to standard regression functionality (parameter estimation, 10 | inference, predictions, etc.) the package provides various regression 11 | diagnostics, including hat values, deletion diagnostics such as 12 | studentized residuals and Cook’s distances; graphical diagnostics such 13 | as component-plus-residual plots and added-variable plots; and effect 14 | plots with partial residuals. 15 | 16 | **Instrumental variables regression:** 17 | 18 | library("ivreg") 19 | ivreg(Q ~ P + D | D + F + A, data = Kmenta) 20 | 21 | **Via two-stage least squares (2SLS):** 22 | 23 | 2SLS 24 | 25 | **With diagnostics:** 26 | 27 | Effects plot 28 | QQ plot 29 | Influence plot 30 | -------------------------------------------------------------------------------- /_pkgdown.yml: -------------------------------------------------------------------------------- 1 | url: "https://zeileis.github.io/ivreg/" 2 | 3 | template: 4 | assets: "pkgdown/assets/" 5 | opengraph: 6 | image: 7 | src: logo.png 8 | alt: "ivreg" 9 | twitter: 10 | creator: "@AchimZeileis" 11 | card: summary 12 | 13 | reference: 14 | - title: "Instrumental Variables Regression" 15 | contents: 16 | - ivreg 17 | - ivreg.fit 18 | - summary.ivreg 19 | - ivregMethods 20 | - ivregDiagnostics 21 | - title: "Data Sets" 22 | contents: 23 | - CigaretteDemand 24 | - Kmenta 25 | - SchoolingReturns 26 | -------------------------------------------------------------------------------- /data/CigaretteDemand.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/data/CigaretteDemand.RData -------------------------------------------------------------------------------- /data/Kmenta.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/data/Kmenta.RData -------------------------------------------------------------------------------- /data/SchoolingReturns.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/data/SchoolingReturns.RData -------------------------------------------------------------------------------- /docs/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Page not found (404) • ivreg 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 30 | 31 | 32 | 33 | 34 |
35 |
87 | 88 | 89 | 90 | 91 |
92 |
93 | 96 | 97 | Content not found. Please use links in the navbar. 98 | 99 |
100 | 101 | 105 | 106 |
107 | 108 | 109 | 110 |
114 | 115 |
116 |

117 |

Site built with pkgdown 2.0.7.

118 |
119 | 120 |
121 |
122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /docs/apple-touch-icon-120x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/apple-touch-icon-120x120.png -------------------------------------------------------------------------------- /docs/apple-touch-icon-152x152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/apple-touch-icon-152x152.png -------------------------------------------------------------------------------- /docs/apple-touch-icon-180x180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/apple-touch-icon-180x180.png -------------------------------------------------------------------------------- /docs/apple-touch-icon-60x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/apple-touch-icon-60x60.png -------------------------------------------------------------------------------- /docs/apple-touch-icon-76x76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/apple-touch-icon-76x76.png -------------------------------------------------------------------------------- /docs/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/apple-touch-icon.png -------------------------------------------------------------------------------- /docs/articles/Diagnostics-for-2SLS-Regression_files/accessible-code-block-0.0.1/empty-anchor.js: -------------------------------------------------------------------------------- 1 | // Hide empty tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) --> 2 | // v0.0.1 3 | // Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020. 4 | 5 | document.addEventListener('DOMContentLoaded', function() { 6 | const codeList = document.getElementsByClassName("sourceCode"); 7 | for (var i = 0; i < codeList.length; i++) { 8 | var linkList = codeList[i].getElementsByTagName('a'); 9 | for (var j = 0; j < linkList.length; j++) { 10 | if (linkList[j].innerHTML === "") { 11 | linkList[j].setAttribute('aria-hidden', 'true'); 12 | } 13 | } 14 | } 15 | }); 16 | -------------------------------------------------------------------------------- /docs/articles/Diagnostics-for-2SLS-Regression_files/anchor-sections-1.0/anchor-sections.css: -------------------------------------------------------------------------------- 1 | /* Styles for section anchors */ 2 | a.anchor-section {margin-left: 10px; visibility: hidden; color: inherit;} 3 | a.anchor-section::before {content: '#';} 4 | .hasAnchor:hover a.anchor-section {visibility: visible;} 5 | -------------------------------------------------------------------------------- /docs/articles/Diagnostics-for-2SLS-Regression_files/anchor-sections-1.0/anchor-sections.js: -------------------------------------------------------------------------------- 1 | // Anchor sections v1.0 written by Atsushi Yasumoto on Oct 3rd, 2020. 2 | document.addEventListener('DOMContentLoaded', function() { 3 | // Do nothing if AnchorJS is used 4 | if (typeof window.anchors === 'object' && anchors.hasOwnProperty('hasAnchorJSLink')) { 5 | return; 6 | } 7 | 8 | const h = document.querySelectorAll('h1, h2, h3, h4, h5, h6'); 9 | 10 | // Do nothing if sections are already anchored 11 | if (Array.from(h).some(x => x.classList.contains('hasAnchor'))) { 12 | return null; 13 | } 14 | 15 | // Use section id when pandoc runs with --section-divs 16 | const section_id = function(x) { 17 | return ((x.classList.contains('section') || (x.tagName === 'SECTION')) 18 | ? x.id : ''); 19 | }; 20 | 21 | // Add anchors 22 | h.forEach(function(x) { 23 | const id = x.id || section_id(x.parentElement); 24 | if (id === '') { 25 | return null; 26 | } 27 | let anchor = document.createElement('a'); 28 | anchor.href = '#' + id; 29 | anchor.classList = ['anchor-section']; 30 | x.classList.add('hasAnchor'); 31 | x.appendChild(anchor); 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-11-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-11-1.png -------------------------------------------------------------------------------- /docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-12-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-12-1.png -------------------------------------------------------------------------------- /docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-14-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-14-1.png -------------------------------------------------------------------------------- /docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-17-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-17-1.png -------------------------------------------------------------------------------- /docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-18-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-18-1.png -------------------------------------------------------------------------------- /docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-19-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-19-1.png -------------------------------------------------------------------------------- /docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-20-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-20-1.png -------------------------------------------------------------------------------- /docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-21-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-21-1.png -------------------------------------------------------------------------------- /docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-22-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-22-1.png -------------------------------------------------------------------------------- /docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-23-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-23-1.png -------------------------------------------------------------------------------- /docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-24-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-24-1.png -------------------------------------------------------------------------------- /docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-28-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-28-1.png -------------------------------------------------------------------------------- /docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-30-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-30-1.png -------------------------------------------------------------------------------- /docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-36-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-36-1.png -------------------------------------------------------------------------------- /docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-39-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-39-1.png -------------------------------------------------------------------------------- /docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-42-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-42-1.png -------------------------------------------------------------------------------- /docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-5-1.png -------------------------------------------------------------------------------- /docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-9-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/articles/Diagnostics-for-2SLS-Regression_files/figure-html/unnamed-chunk-9-1.png -------------------------------------------------------------------------------- /docs/articles/Diagnostics-for-2SLS-Regression_files/header-attrs-2.10/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/Diagnostics-for-2SLS-Regression_files/header-attrs-2.5/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/Diagnostics-for-2SLS-Regression_files/header-attrs-2.8/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/index.html: -------------------------------------------------------------------------------- 1 | 2 | Articles • ivreg 6 | 7 | 8 |
9 |
53 | 54 | 55 | 56 |
57 |
58 | 61 | 62 | 71 |
72 |
73 | 74 | 75 |
78 | 79 |
80 |

Site built with pkgdown 2.0.7.

81 |
82 | 83 |
84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /docs/articles/ivreg_files/accessible-code-block-0.0.1/empty-anchor.js: -------------------------------------------------------------------------------- 1 | // Hide empty tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) --> 2 | // v0.0.1 3 | // Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020. 4 | 5 | document.addEventListener('DOMContentLoaded', function() { 6 | const codeList = document.getElementsByClassName("sourceCode"); 7 | for (var i = 0; i < codeList.length; i++) { 8 | var linkList = codeList[i].getElementsByTagName('a'); 9 | for (var j = 0; j < linkList.length; j++) { 10 | if (linkList[j].innerHTML === "") { 11 | linkList[j].setAttribute('aria-hidden', 'true'); 12 | } 13 | } 14 | } 15 | }); 16 | -------------------------------------------------------------------------------- /docs/articles/ivreg_files/anchor-sections-1.0/anchor-sections.css: -------------------------------------------------------------------------------- 1 | /* Styles for section anchors */ 2 | a.anchor-section {margin-left: 10px; visibility: hidden; color: inherit;} 3 | a.anchor-section::before {content: '#';} 4 | .hasAnchor:hover a.anchor-section {visibility: visible;} 5 | -------------------------------------------------------------------------------- /docs/articles/ivreg_files/anchor-sections-1.0/anchor-sections.js: -------------------------------------------------------------------------------- 1 | // Anchor sections v1.0 written by Atsushi Yasumoto on Oct 3rd, 2020. 2 | document.addEventListener('DOMContentLoaded', function() { 3 | // Do nothing if AnchorJS is used 4 | if (typeof window.anchors === 'object' && anchors.hasOwnProperty('hasAnchorJSLink')) { 5 | return; 6 | } 7 | 8 | const h = document.querySelectorAll('h1, h2, h3, h4, h5, h6'); 9 | 10 | // Do nothing if sections are already anchored 11 | if (Array.from(h).some(x => x.classList.contains('hasAnchor'))) { 12 | return null; 13 | } 14 | 15 | // Use section id when pandoc runs with --section-divs 16 | const section_id = function(x) { 17 | return ((x.classList.contains('section') || (x.tagName === 'SECTION')) 18 | ? x.id : ''); 19 | }; 20 | 21 | // Add anchors 22 | h.forEach(function(x) { 23 | const id = x.id || section_id(x.parentElement); 24 | if (id === '') { 25 | return null; 26 | } 27 | let anchor = document.createElement('a'); 28 | anchor.href = '#' + id; 29 | anchor.classList = ['anchor-section']; 30 | x.classList.add('hasAnchor'); 31 | x.appendChild(anchor); 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /docs/articles/ivreg_files/figure-html/modelplot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/articles/ivreg_files/figure-html/modelplot-1.png -------------------------------------------------------------------------------- /docs/articles/ivreg_files/header-attrs-2.10/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/ivreg_files/header-attrs-2.5/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/ivreg_files/header-attrs-2.8/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/ivreg_files/kePrint-0.0.1/kePrint.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function(){ 2 | if (typeof $('[data-toggle="tooltip"]').tooltip === 'function') { 3 | $('[data-toggle="tooltip"]').tooltip(); 4 | } 5 | if ($('[data-toggle="popover"]').popover === 'function') { 6 | $('[data-toggle="popover"]').popover(); 7 | } 8 | }); 9 | -------------------------------------------------------------------------------- /docs/articles/ivreg_files/lightable-0.0.1/lightable.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * lightable v0.0.1 3 | * Copyright 2020 Hao Zhu 4 | * Licensed under MIT (https://github.com/haozhu233/kableExtra/blob/master/LICENSE) 5 | */ 6 | 7 | .lightable-minimal { 8 | border-collapse: separate; 9 | border-spacing: 16px 1px; 10 | width: 100%; 11 | margin-bottom: 10px; 12 | } 13 | 14 | .lightable-minimal td { 15 | margin-left: 5px; 16 | margin-right: 5px; 17 | } 18 | 19 | .lightable-minimal th { 20 | margin-left: 5px; 21 | margin-right: 5px; 22 | } 23 | 24 | .lightable-minimal thead tr:last-child th { 25 | border-bottom: 2px solid #00000050; 26 | empty-cells: hide; 27 | 28 | } 29 | 30 | .lightable-minimal tbody tr:first-child td { 31 | padding-top: 0.5em; 32 | } 33 | 34 | .lightable-minimal.lightable-hover tbody tr:hover { 35 | background-color: #f5f5f5; 36 | } 37 | 38 | .lightable-minimal.lightable-striped tbody tr:nth-child(even) { 39 | background-color: #f5f5f5; 40 | } 41 | 42 | .lightable-classic { 43 | border-top: 0.16em solid #111111; 44 | border-bottom: 0.16em solid #111111; 45 | width: 100%; 46 | margin-bottom: 10px; 47 | margin: 10px 5px; 48 | } 49 | 50 | .lightable-classic tfoot tr td { 51 | border: 0; 52 | } 53 | 54 | .lightable-classic tfoot tr:first-child td { 55 | border-top: 0.14em solid #111111; 56 | } 57 | 58 | .lightable-classic caption { 59 | color: #222222; 60 | } 61 | 62 | .lightable-classic td { 63 | padding-left: 5px; 64 | padding-right: 5px; 65 | color: #222222; 66 | } 67 | 68 | .lightable-classic th { 69 | padding-left: 5px; 70 | padding-right: 5px; 71 | font-weight: normal; 72 | color: #222222; 73 | } 74 | 75 | .lightable-classic thead tr:last-child th { 76 | border-bottom: 0.10em solid #111111; 77 | } 78 | 79 | .lightable-classic.lightable-hover tbody tr:hover { 80 | background-color: #F9EEC1; 81 | } 82 | 83 | .lightable-classic.lightable-striped tbody tr:nth-child(even) { 84 | background-color: #f5f5f5; 85 | } 86 | 87 | .lightable-classic-2 { 88 | border-top: 3px double #111111; 89 | border-bottom: 3px double #111111; 90 | width: 100%; 91 | margin-bottom: 10px; 92 | } 93 | 94 | .lightable-classic-2 tfoot tr td { 95 | border: 0; 96 | } 97 | 98 | .lightable-classic-2 tfoot tr:first-child td { 99 | border-top: 3px double #111111; 100 | } 101 | 102 | .lightable-classic-2 caption { 103 | color: #222222; 104 | } 105 | 106 | .lightable-classic-2 td { 107 | padding-left: 5px; 108 | padding-right: 5px; 109 | color: #222222; 110 | } 111 | 112 | .lightable-classic-2 th { 113 | padding-left: 5px; 114 | padding-right: 5px; 115 | font-weight: normal; 116 | color: #222222; 117 | } 118 | 119 | .lightable-classic-2 tbody tr:last-child td { 120 | border-bottom: 3px double #111111; 121 | } 122 | 123 | .lightable-classic-2 thead tr:last-child th { 124 | border-bottom: 1px solid #111111; 125 | } 126 | 127 | .lightable-classic-2.lightable-hover tbody tr:hover { 128 | background-color: #F9EEC1; 129 | } 130 | 131 | .lightable-classic-2.lightable-striped tbody tr:nth-child(even) { 132 | background-color: #f5f5f5; 133 | } 134 | 135 | .lightable-material { 136 | min-width: 100%; 137 | white-space: nowrap; 138 | table-layout: fixed; 139 | font-family: Roboto, sans-serif; 140 | border: 1px solid #EEE; 141 | border-collapse: collapse; 142 | margin-bottom: 10px; 143 | } 144 | 145 | .lightable-material tfoot tr td { 146 | border: 0; 147 | } 148 | 149 | .lightable-material tfoot tr:first-child td { 150 | border-top: 1px solid #EEE; 151 | } 152 | 153 | .lightable-material th { 154 | height: 56px; 155 | padding-left: 16px; 156 | padding-right: 16px; 157 | } 158 | 159 | .lightable-material td { 160 | height: 52px; 161 | padding-left: 16px; 162 | padding-right: 16px; 163 | border-top: 1px solid #eeeeee; 164 | } 165 | 166 | .lightable-material.lightable-hover tbody tr:hover { 167 | background-color: #f5f5f5; 168 | } 169 | 170 | .lightable-material.lightable-striped tbody tr:nth-child(even) { 171 | background-color: #f5f5f5; 172 | } 173 | 174 | .lightable-material.lightable-striped tbody td { 175 | border: 0; 176 | } 177 | 178 | .lightable-material.lightable-striped thead tr:last-child th { 179 | border-bottom: 1px solid #ddd; 180 | } 181 | 182 | .lightable-material-dark { 183 | min-width: 100%; 184 | white-space: nowrap; 185 | table-layout: fixed; 186 | font-family: Roboto, sans-serif; 187 | border: 1px solid #FFFFFF12; 188 | border-collapse: collapse; 189 | margin-bottom: 10px; 190 | background-color: #363640; 191 | } 192 | 193 | .lightable-material-dark tfoot tr td { 194 | border: 0; 195 | } 196 | 197 | .lightable-material-dark tfoot tr:first-child td { 198 | border-top: 1px solid #FFFFFF12; 199 | } 200 | 201 | .lightable-material-dark th { 202 | height: 56px; 203 | padding-left: 16px; 204 | padding-right: 16px; 205 | color: #FFFFFF60; 206 | } 207 | 208 | .lightable-material-dark td { 209 | height: 52px; 210 | padding-left: 16px; 211 | padding-right: 16px; 212 | color: #FFFFFF; 213 | border-top: 1px solid #FFFFFF12; 214 | } 215 | 216 | .lightable-material-dark.lightable-hover tbody tr:hover { 217 | background-color: #FFFFFF12; 218 | } 219 | 220 | .lightable-material-dark.lightable-striped tbody tr:nth-child(even) { 221 | background-color: #FFFFFF12; 222 | } 223 | 224 | .lightable-material-dark.lightable-striped tbody td { 225 | border: 0; 226 | } 227 | 228 | .lightable-material-dark.lightable-striped thead tr:last-child th { 229 | border-bottom: 1px solid #FFFFFF12; 230 | } 231 | 232 | .lightable-paper { 233 | width: 100%; 234 | margin-bottom: 10px; 235 | color: #444; 236 | } 237 | 238 | .lightable-paper tfoot tr td { 239 | border: 0; 240 | } 241 | 242 | .lightable-paper tfoot tr:first-child td { 243 | border-top: 1px solid #00000020; 244 | } 245 | 246 | .lightable-paper thead tr:last-child th { 247 | color: #666; 248 | vertical-align: bottom; 249 | border-bottom: 1px solid #00000020; 250 | line-height: 1.15em; 251 | padding: 10px 5px; 252 | } 253 | 254 | .lightable-paper td { 255 | vertical-align: middle; 256 | border-bottom: 1px solid #00000010; 257 | line-height: 1.15em; 258 | padding: 7px 5px; 259 | } 260 | 261 | .lightable-paper.lightable-hover tbody tr:hover { 262 | background-color: #F9EEC1; 263 | } 264 | 265 | .lightable-paper.lightable-striped tbody tr:nth-child(even) { 266 | background-color: #00000008; 267 | } 268 | 269 | .lightable-paper.lightable-striped tbody td { 270 | border: 0; 271 | } 272 | 273 | -------------------------------------------------------------------------------- /docs/authors.html: -------------------------------------------------------------------------------- 1 | 2 | Authors and Citation • ivreg 6 | 7 | 8 |
9 |
53 | 54 | 55 | 56 |
57 |
58 |
59 | 62 | 63 | 64 |
  • 65 |

    John Fox. Author. 66 |

    67 |
  • 68 |
  • 69 |

    Christian Kleiber. Author. 70 |

    71 |
  • 72 |
  • 73 |

    Achim Zeileis. Author, maintainer. 74 |

    75 |
  • 76 |
  • 77 |

    Nikolas Kuschnig. Contributor. 78 |

    79 |
  • 80 |
81 |
82 |
83 |

Citation

84 | Source: DESCRIPTION 85 |
86 |
87 | 88 | 89 |

Fox J, Kleiber C, Zeileis A (2023). 90 | ivreg: Instrumental-Variables Regression by '2SLS', '2SM', or '2SMM', with Diagnostics. 91 | R package version 0.6-3, https://zeileis.github.io/ivreg/. 92 |

93 |
@Manual{,
 94 |   title = {ivreg: Instrumental-Variables Regression by '2SLS', '2SM', or '2SMM', with Diagnostics},
 95 |   author = {John Fox and Christian Kleiber and Achim Zeileis},
 96 |   year = {2023},
 97 |   note = {R package version 0.6-3},
 98 |   url = {https://zeileis.github.io/ivreg/},
 99 | }
100 | 101 |
102 | 103 |
104 | 105 | 106 | 107 |
110 | 111 |
112 |

Site built with pkgdown 2.0.7.

113 |
114 | 115 |
116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | 6 | /* modified from https://github.com/twbs/bootstrap/blob/94b4076dd2efba9af71f0b18d4ee4b163aa9e0dd/docs/assets/css/src/docs.css#L548-L601 */ 7 | 8 | /* All levels of nav */ 9 | nav[data-toggle='toc'] .nav > li > a { 10 | display: block; 11 | padding: 4px 20px; 12 | font-size: 13px; 13 | font-weight: 500; 14 | color: #767676; 15 | } 16 | nav[data-toggle='toc'] .nav > li > a:hover, 17 | nav[data-toggle='toc'] .nav > li > a:focus { 18 | padding-left: 19px; 19 | color: #563d7c; 20 | text-decoration: none; 21 | background-color: transparent; 22 | border-left: 1px solid #563d7c; 23 | } 24 | nav[data-toggle='toc'] .nav > .active > a, 25 | nav[data-toggle='toc'] .nav > .active:hover > a, 26 | nav[data-toggle='toc'] .nav > .active:focus > a { 27 | padding-left: 18px; 28 | font-weight: bold; 29 | color: #563d7c; 30 | background-color: transparent; 31 | border-left: 2px solid #563d7c; 32 | } 33 | 34 | /* Nav: second level (shown on .active) */ 35 | nav[data-toggle='toc'] .nav .nav { 36 | display: none; /* Hide by default, but at >768px, show it */ 37 | padding-bottom: 10px; 38 | } 39 | nav[data-toggle='toc'] .nav .nav > li > a { 40 | padding-top: 1px; 41 | padding-bottom: 1px; 42 | padding-left: 30px; 43 | font-size: 12px; 44 | font-weight: normal; 45 | } 46 | nav[data-toggle='toc'] .nav .nav > li > a:hover, 47 | nav[data-toggle='toc'] .nav .nav > li > a:focus { 48 | padding-left: 29px; 49 | } 50 | nav[data-toggle='toc'] .nav .nav > .active > a, 51 | nav[data-toggle='toc'] .nav .nav > .active:hover > a, 52 | nav[data-toggle='toc'] .nav .nav > .active:focus > a { 53 | padding-left: 28px; 54 | font-weight: 500; 55 | } 56 | 57 | /* from https://github.com/twbs/bootstrap/blob/e38f066d8c203c3e032da0ff23cd2d6098ee2dd6/docs/assets/css/src/docs.css#L631-L634 */ 58 | nav[data-toggle='toc'] .nav > .active > ul { 59 | display: block; 60 | } 61 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | (function() { 6 | 'use strict'; 7 | 8 | window.Toc = { 9 | helpers: { 10 | // return all matching elements in the set, or their descendants 11 | findOrFilter: function($el, selector) { 12 | // http://danielnouri.org/notes/2011/03/14/a-jquery-find-that-also-finds-the-root-element/ 13 | // http://stackoverflow.com/a/12731439/358804 14 | var $descendants = $el.find(selector); 15 | return $el.filter(selector).add($descendants).filter(':not([data-toc-skip])'); 16 | }, 17 | 18 | generateUniqueIdBase: function(el) { 19 | var text = $(el).text(); 20 | var anchor = text.trim().toLowerCase().replace(/[^A-Za-z0-9]+/g, '-'); 21 | return anchor || el.tagName.toLowerCase(); 22 | }, 23 | 24 | generateUniqueId: function(el) { 25 | var anchorBase = this.generateUniqueIdBase(el); 26 | for (var i = 0; ; i++) { 27 | var anchor = anchorBase; 28 | if (i > 0) { 29 | // add suffix 30 | anchor += '-' + i; 31 | } 32 | // check if ID already exists 33 | if (!document.getElementById(anchor)) { 34 | return anchor; 35 | } 36 | } 37 | }, 38 | 39 | generateAnchor: function(el) { 40 | if (el.id) { 41 | return el.id; 42 | } else { 43 | var anchor = this.generateUniqueId(el); 44 | el.id = anchor; 45 | return anchor; 46 | } 47 | }, 48 | 49 | createNavList: function() { 50 | return $(''); 51 | }, 52 | 53 | createChildNavList: function($parent) { 54 | var $childList = this.createNavList(); 55 | $parent.append($childList); 56 | return $childList; 57 | }, 58 | 59 | generateNavEl: function(anchor, text) { 60 | var $a = $(''); 61 | $a.attr('href', '#' + anchor); 62 | $a.text(text); 63 | var $li = $('
  • '); 64 | $li.append($a); 65 | return $li; 66 | }, 67 | 68 | generateNavItem: function(headingEl) { 69 | var anchor = this.generateAnchor(headingEl); 70 | var $heading = $(headingEl); 71 | var text = $heading.data('toc-text') || $heading.text(); 72 | return this.generateNavEl(anchor, text); 73 | }, 74 | 75 | // Find the first heading level (`

    `, then `

    `, etc.) that has more than one element. Defaults to 1 (for `

    `). 76 | getTopLevel: function($scope) { 77 | for (var i = 1; i <= 6; i++) { 78 | var $headings = this.findOrFilter($scope, 'h' + i); 79 | if ($headings.length > 1) { 80 | return i; 81 | } 82 | } 83 | 84 | return 1; 85 | }, 86 | 87 | // returns the elements for the top level, and the next below it 88 | getHeadings: function($scope, topLevel) { 89 | var topSelector = 'h' + topLevel; 90 | 91 | var secondaryLevel = topLevel + 1; 92 | var secondarySelector = 'h' + secondaryLevel; 93 | 94 | return this.findOrFilter($scope, topSelector + ',' + secondarySelector); 95 | }, 96 | 97 | getNavLevel: function(el) { 98 | return parseInt(el.tagName.charAt(1), 10); 99 | }, 100 | 101 | populateNav: function($topContext, topLevel, $headings) { 102 | var $context = $topContext; 103 | var $prevNav; 104 | 105 | var helpers = this; 106 | $headings.each(function(i, el) { 107 | var $newNav = helpers.generateNavItem(el); 108 | var navLevel = helpers.getNavLevel(el); 109 | 110 | // determine the proper $context 111 | if (navLevel === topLevel) { 112 | // use top level 113 | $context = $topContext; 114 | } else if ($prevNav && $context === $topContext) { 115 | // create a new level of the tree and switch to it 116 | $context = helpers.createChildNavList($prevNav); 117 | } // else use the current $context 118 | 119 | $context.append($newNav); 120 | 121 | $prevNav = $newNav; 122 | }); 123 | }, 124 | 125 | parseOps: function(arg) { 126 | var opts; 127 | if (arg.jquery) { 128 | opts = { 129 | $nav: arg 130 | }; 131 | } else { 132 | opts = arg; 133 | } 134 | opts.$scope = opts.$scope || $(document.body); 135 | return opts; 136 | } 137 | }, 138 | 139 | // accepts a jQuery object, or an options object 140 | init: function(opts) { 141 | opts = this.helpers.parseOps(opts); 142 | 143 | // ensure that the data attribute is in place for styling 144 | opts.$nav.attr('data-toggle', 'toc'); 145 | 146 | var $topContext = this.helpers.createChildNavList(opts.$nav); 147 | var topLevel = this.helpers.getTopLevel(opts.$scope); 148 | var $headings = this.helpers.getHeadings(opts.$scope, topLevel); 149 | this.helpers.populateNav($topContext, topLevel, $headings); 150 | } 151 | }; 152 | 153 | $(function() { 154 | $('nav[data-toggle="toc"]').each(function(i, el) { 155 | var $nav = $(el); 156 | Toc.init($nav); 157 | }); 158 | }); 159 | })(); 160 | -------------------------------------------------------------------------------- /docs/docsearch.js: -------------------------------------------------------------------------------- 1 | $(function() { 2 | 3 | // register a handler to move the focus to the search bar 4 | // upon pressing shift + "/" (i.e. "?") 5 | $(document).on('keydown', function(e) { 6 | if (e.shiftKey && e.keyCode == 191) { 7 | e.preventDefault(); 8 | $("#search-input").focus(); 9 | } 10 | }); 11 | 12 | $(document).ready(function() { 13 | // do keyword highlighting 14 | /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ 15 | var mark = function() { 16 | 17 | var referrer = document.URL ; 18 | var paramKey = "q" ; 19 | 20 | if (referrer.indexOf("?") !== -1) { 21 | var qs = referrer.substr(referrer.indexOf('?') + 1); 22 | var qs_noanchor = qs.split('#')[0]; 23 | var qsa = qs_noanchor.split('&'); 24 | var keyword = ""; 25 | 26 | for (var i = 0; i < qsa.length; i++) { 27 | var currentParam = qsa[i].split('='); 28 | 29 | if (currentParam.length !== 2) { 30 | continue; 31 | } 32 | 33 | if (currentParam[0] == paramKey) { 34 | keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); 35 | } 36 | } 37 | 38 | if (keyword !== "") { 39 | $(".contents").unmark({ 40 | done: function() { 41 | $(".contents").mark(keyword); 42 | } 43 | }); 44 | } 45 | } 46 | }; 47 | 48 | mark(); 49 | }); 50 | }); 51 | 52 | /* Search term highlighting ------------------------------*/ 53 | 54 | function matchedWords(hit) { 55 | var words = []; 56 | 57 | var hierarchy = hit._highlightResult.hierarchy; 58 | // loop to fetch from lvl0, lvl1, etc. 59 | for (var idx in hierarchy) { 60 | words = words.concat(hierarchy[idx].matchedWords); 61 | } 62 | 63 | var content = hit._highlightResult.content; 64 | if (content) { 65 | words = words.concat(content.matchedWords); 66 | } 67 | 68 | // return unique words 69 | var words_uniq = [...new Set(words)]; 70 | return words_uniq; 71 | } 72 | 73 | function updateHitURL(hit) { 74 | 75 | var words = matchedWords(hit); 76 | var url = ""; 77 | 78 | if (hit.anchor) { 79 | url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; 80 | } else { 81 | url = hit.url + '?q=' + escape(words.join(" ")); 82 | } 83 | 84 | return url; 85 | } 86 | -------------------------------------------------------------------------------- /docs/extra.css: -------------------------------------------------------------------------------- 1 | /* Edit pkgdown/extra.css to customize the theme */ 2 | 3 | /* Color: 4 | * logo-purple: #8709b0; 5 | */ 6 | 7 | @import url('https://fonts.googleapis.com/css?family=Roboto:300,500'); 8 | 9 | body { 10 | font-family: 'Roboto', sans-serif; 11 | font-weight: 300; 12 | } 13 | 14 | /* The "default" hyperlinks: default bright blue, hover pinkish */ 15 | a { color: #8709b0;} 16 | 17 | /* Font size for the content and the navigation bar (top): increase 18 | * font size by a factor of 1.3 (1.3 elements, global) */ 19 | #navbar, div.contents { font-size: 1.3em; } 20 | 21 | #tocnav > ul > li > a:hover { 22 | color: #8709b0; 23 | } 24 | 25 | h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 { 26 | font-family: 'Roboto', sans-serif; 27 | font-weight: 500; 28 | } 29 | 30 | b, strong, th { 31 | font-weight: 500; 32 | } 33 | 34 | .navbar-brand { 35 | background-image: url('logo_wide.png'); 36 | background-repeat: no-repeat; 37 | background-position: 12.5px 5px; 38 | background-size: 110px auto; 39 | width: 200px; 40 | height: 58px; 41 | } 42 | 43 | .navbar-brand > .navbar-link { 44 | opacity: 0; 45 | width: 0; 46 | height: 0; 47 | display: block; 48 | font-size: 1.7em; 49 | line-height: 1em; 50 | width: 110px; 51 | height: 30px; 52 | float: left; 53 | } 54 | 55 | /* Adjust main navigation bar (top) to match the size of the 56 | * branding/logo */ 57 | .navbar-brand > .label { 58 | display: block; 59 | margin-left: 110px; 60 | margin-top: 14px; 61 | font-weight: normal; 62 | background-color: transparent; 63 | /*color: #8709b0;*/ 64 | color: #777; 65 | } 66 | 67 | /* Make the logo slightly smaller to avoid line breaks 68 | * on the collapsed view */ 69 | @media all and (max-width: 250px) { 70 | .navbar-brand { 71 | width: 110px; 72 | background-size: 100px; 73 | background-position: 10px 5px; 74 | height: 39px; 75 | } 76 | .navbar-brand > .navbar-link { height: 25px; width: 100px; } 77 | .navbar-brand > .label { margin-top: 10px; margin-left: 100px; } 78 | } 79 | 80 | .navbar .navbar-nav > li > a { 81 | margin: 11px 0.5em; 82 | padding: 8px 8px; 83 | } 84 | .navbar > .navbar-nav > li.dropdown.open > a, 85 | .navbar > .navbar-nav > li.dropdown.open:hover, 86 | .navbar > .navbar-nav > li.dropdown.open > a:hover { 87 | background-color: transparent; 88 | } 89 | 90 | .dropdown-menu > li { 91 | background-color: white; 92 | } 93 | .dropdown-menu > li > a:hover { 94 | color: #8709b0; 95 | } 96 | .navbar .navbar-nav > li:hover, 97 | .navbar .navbar-nav > li.dropdown:hover { 98 | background-color: #8709b0; 99 | } 100 | .navbar .navbar-nav > li > a:hover, .navbar .navbar-nav > li.dropdown > a:hover, 101 | .navbar .navbar-nav > li:hover > a, .navbar .navbar-nav > li.dropdown:hover > a { 102 | background-color: #8709b0; 103 | color: white; 104 | } 105 | .navbar .navbar-nav > .active { 106 | background-color: #ececec; 107 | } 108 | .navbar .navbar-nav > .active:hover { 109 | background-color: #8709b0; 110 | } 111 | .navbar .navbar-nav > .active:hover > *, 112 | .navbar .navbar-nav > .active > a:hover { 113 | color: white; 114 | background-color: transparent; 115 | } 116 | .navbar .navbar-nav > li.dropdown.open:hover, 117 | .navbar .navbar-nav > li.dropdown:hover { 118 | background-color: #8709b0; 119 | } 120 | .navbar .navbar-nav > li.dropdown.open:hover, 121 | .navbar .navbar-nav > li.dropdown:hover, 122 | .navbar .navbar-nav > li.dropdown > *:hover { 123 | color: white; 124 | } 125 | .navbar .navbar-nav > .active > a, 126 | .navbar .navbar-nav > .active > a:hover { 127 | background-color: transparent; 128 | } 129 | 130 | 131 | div#overview div.page-header h1 { 132 | margin-top: 22px; 133 | padding: 0; 134 | font-size: 250%; 135 | color: dimgray; 136 | } 137 | 138 | div#system-requirements th { 139 | text-align: center; 140 | } 141 | 142 | div.page-header h1 { 143 | font-size: 250%; 144 | color: dimgray; 145 | } 146 | 147 | div.page-header h4 { 148 | padding-top: 10px; 149 | font-size: 120%; 150 | } 151 | 152 | div.contents h1 { 153 | color: dimgray; 154 | font-size: 200%; 155 | padding-top: 80px; 156 | } 157 | 158 | div.contents h2 { 159 | font-size: 150%; 160 | padding-top: 70px; 161 | } 162 | 163 | div.contents h3 { 164 | font-size: 120%; 165 | padding-top: 60px; 166 | } 167 | 168 | div.contents h4 { 169 | font-size: 100%; 170 | padding-top: 60px; 171 | } 172 | 173 | pre { 174 | overflow-x: auto; 175 | font-size: 80%; 176 | line-height: 150%; 177 | } 178 | -------------------------------------------------------------------------------- /docs/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/favicon-16x16.png -------------------------------------------------------------------------------- /docs/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/favicon-32x32.png -------------------------------------------------------------------------------- /docs/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/favicon.ico -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Instrumental-Variables Regression by 2SLS, 2SM, or 2SMM, with Diagnostics • ivreg 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 31 | 32 | 33 | 34 | 35 |
    36 |
    88 | 89 | 90 | 91 | 92 |
    93 |
    94 |
    95 |

    Two-Stage Least-Squares Regression with Diagnostics 96 |

    97 |

    An implementation of instrumental variables regression using two-stage least-squares (2SLS) estimation, based on the ivreg() function previously in the AER package. In addition to standard regression functionality (parameter estimation, inference, predictions, etc.) the package provides various regression diagnostics, including hat values, deletion diagnostics such as studentized residuals and Cook’s distances; graphical diagnostics such as component-plus-residual plots and added-variable plots; and effect plots with partial residuals.

    98 |

    Instrumental variables regression:

    99 |
    library("ivreg")
    100 | ivreg(Q ~ P + D | D + F + A, data = Kmenta)
    101 |

    Via two-stage least squares (2SLS):

    102 |

    2SLS

    103 |

    With diagnostics:

    104 |

    Effects plotQQ plotInfluence plot

    105 |
    106 |
    107 | 108 | 146 |
    147 | 148 | 149 |
    153 | 154 |
    155 |

    156 |

    Site built with pkgdown 2.0.7.

    157 |
    158 | 159 |
    160 |
    161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | -------------------------------------------------------------------------------- /docs/link.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /docs/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/logo.png -------------------------------------------------------------------------------- /docs/logo_wide.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/logo_wide.png -------------------------------------------------------------------------------- /docs/pkgdown.css: -------------------------------------------------------------------------------- 1 | /* Sticky footer */ 2 | 3 | /** 4 | * Basic idea: https://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/ 5 | * Details: https://github.com/philipwalton/solved-by-flexbox/blob/master/assets/css/components/site.css 6 | * 7 | * .Site -> body > .container 8 | * .Site-content -> body > .container .row 9 | * .footer -> footer 10 | * 11 | * Key idea seems to be to ensure that .container and __all its parents__ 12 | * have height set to 100% 13 | * 14 | */ 15 | 16 | html, body { 17 | height: 100%; 18 | } 19 | 20 | body { 21 | position: relative; 22 | } 23 | 24 | body > .container { 25 | display: flex; 26 | height: 100%; 27 | flex-direction: column; 28 | } 29 | 30 | body > .container .row { 31 | flex: 1 0 auto; 32 | } 33 | 34 | footer { 35 | margin-top: 45px; 36 | padding: 35px 0 36px; 37 | border-top: 1px solid #e5e5e5; 38 | color: #666; 39 | display: flex; 40 | flex-shrink: 0; 41 | } 42 | footer p { 43 | margin-bottom: 0; 44 | } 45 | footer div { 46 | flex: 1; 47 | } 48 | footer .pkgdown { 49 | text-align: right; 50 | } 51 | footer p { 52 | margin-bottom: 0; 53 | } 54 | 55 | img.icon { 56 | float: right; 57 | } 58 | 59 | /* Ensure in-page images don't run outside their container */ 60 | .contents img { 61 | max-width: 100%; 62 | height: auto; 63 | } 64 | 65 | /* Fix bug in bootstrap (only seen in firefox) */ 66 | summary { 67 | display: list-item; 68 | } 69 | 70 | /* Typographic tweaking ---------------------------------*/ 71 | 72 | .contents .page-header { 73 | margin-top: calc(-60px + 1em); 74 | } 75 | 76 | dd { 77 | margin-left: 3em; 78 | } 79 | 80 | /* Section anchors ---------------------------------*/ 81 | 82 | a.anchor { 83 | display: none; 84 | margin-left: 5px; 85 | width: 20px; 86 | height: 20px; 87 | 88 | background-image: url(./link.svg); 89 | background-repeat: no-repeat; 90 | background-size: 20px 20px; 91 | background-position: center center; 92 | } 93 | 94 | h1:hover .anchor, 95 | h2:hover .anchor, 96 | h3:hover .anchor, 97 | h4:hover .anchor, 98 | h5:hover .anchor, 99 | h6:hover .anchor { 100 | display: inline-block; 101 | } 102 | 103 | /* Fixes for fixed navbar --------------------------*/ 104 | 105 | .contents h1, .contents h2, .contents h3, .contents h4 { 106 | padding-top: 60px; 107 | margin-top: -40px; 108 | } 109 | 110 | /* Navbar submenu --------------------------*/ 111 | 112 | .dropdown-submenu { 113 | position: relative; 114 | } 115 | 116 | .dropdown-submenu>.dropdown-menu { 117 | top: 0; 118 | left: 100%; 119 | margin-top: -6px; 120 | margin-left: -1px; 121 | border-radius: 0 6px 6px 6px; 122 | } 123 | 124 | .dropdown-submenu:hover>.dropdown-menu { 125 | display: block; 126 | } 127 | 128 | .dropdown-submenu>a:after { 129 | display: block; 130 | content: " "; 131 | float: right; 132 | width: 0; 133 | height: 0; 134 | border-color: transparent; 135 | border-style: solid; 136 | border-width: 5px 0 5px 5px; 137 | border-left-color: #cccccc; 138 | margin-top: 5px; 139 | margin-right: -10px; 140 | } 141 | 142 | .dropdown-submenu:hover>a:after { 143 | border-left-color: #ffffff; 144 | } 145 | 146 | .dropdown-submenu.pull-left { 147 | float: none; 148 | } 149 | 150 | .dropdown-submenu.pull-left>.dropdown-menu { 151 | left: -100%; 152 | margin-left: 10px; 153 | border-radius: 6px 0 6px 6px; 154 | } 155 | 156 | /* Sidebar --------------------------*/ 157 | 158 | #pkgdown-sidebar { 159 | margin-top: 30px; 160 | position: -webkit-sticky; 161 | position: sticky; 162 | top: 70px; 163 | } 164 | 165 | #pkgdown-sidebar h2 { 166 | font-size: 1.5em; 167 | margin-top: 1em; 168 | } 169 | 170 | #pkgdown-sidebar h2:first-child { 171 | margin-top: 0; 172 | } 173 | 174 | #pkgdown-sidebar .list-unstyled li { 175 | margin-bottom: 0.5em; 176 | } 177 | 178 | /* bootstrap-toc tweaks ------------------------------------------------------*/ 179 | 180 | /* All levels of nav */ 181 | 182 | nav[data-toggle='toc'] .nav > li > a { 183 | padding: 4px 20px 4px 6px; 184 | font-size: 1.5rem; 185 | font-weight: 400; 186 | color: inherit; 187 | } 188 | 189 | nav[data-toggle='toc'] .nav > li > a:hover, 190 | nav[data-toggle='toc'] .nav > li > a:focus { 191 | padding-left: 5px; 192 | color: inherit; 193 | border-left: 1px solid #878787; 194 | } 195 | 196 | nav[data-toggle='toc'] .nav > .active > a, 197 | nav[data-toggle='toc'] .nav > .active:hover > a, 198 | nav[data-toggle='toc'] .nav > .active:focus > a { 199 | padding-left: 5px; 200 | font-size: 1.5rem; 201 | font-weight: 400; 202 | color: inherit; 203 | border-left: 2px solid #878787; 204 | } 205 | 206 | /* Nav: second level (shown on .active) */ 207 | 208 | nav[data-toggle='toc'] .nav .nav { 209 | display: none; /* Hide by default, but at >768px, show it */ 210 | padding-bottom: 10px; 211 | } 212 | 213 | nav[data-toggle='toc'] .nav .nav > li > a { 214 | padding-left: 16px; 215 | font-size: 1.35rem; 216 | } 217 | 218 | nav[data-toggle='toc'] .nav .nav > li > a:hover, 219 | nav[data-toggle='toc'] .nav .nav > li > a:focus { 220 | padding-left: 15px; 221 | } 222 | 223 | nav[data-toggle='toc'] .nav .nav > .active > a, 224 | nav[data-toggle='toc'] .nav .nav > .active:hover > a, 225 | nav[data-toggle='toc'] .nav .nav > .active:focus > a { 226 | padding-left: 15px; 227 | font-weight: 500; 228 | font-size: 1.35rem; 229 | } 230 | 231 | /* orcid ------------------------------------------------------------------- */ 232 | 233 | .orcid { 234 | font-size: 16px; 235 | color: #A6CE39; 236 | /* margins are required by official ORCID trademark and display guidelines */ 237 | margin-left:4px; 238 | margin-right:4px; 239 | vertical-align: middle; 240 | } 241 | 242 | /* Reference index & topics ----------------------------------------------- */ 243 | 244 | .ref-index th {font-weight: normal;} 245 | 246 | .ref-index td {vertical-align: top; min-width: 100px} 247 | .ref-index .icon {width: 40px;} 248 | .ref-index .alias {width: 40%;} 249 | .ref-index-icons .alias {width: calc(40% - 40px);} 250 | .ref-index .title {width: 60%;} 251 | 252 | .ref-arguments th {text-align: right; padding-right: 10px;} 253 | .ref-arguments th, .ref-arguments td {vertical-align: top; min-width: 100px} 254 | .ref-arguments .name {width: 20%;} 255 | .ref-arguments .desc {width: 80%;} 256 | 257 | /* Nice scrolling for wide elements --------------------------------------- */ 258 | 259 | table { 260 | display: block; 261 | overflow: auto; 262 | } 263 | 264 | /* Syntax highlighting ---------------------------------------------------- */ 265 | 266 | pre, code, pre code { 267 | background-color: #f8f8f8; 268 | color: #333; 269 | } 270 | pre, pre code { 271 | white-space: pre-wrap; 272 | word-break: break-all; 273 | overflow-wrap: break-word; 274 | } 275 | 276 | pre { 277 | border: 1px solid #eee; 278 | } 279 | 280 | pre .img, pre .r-plt { 281 | margin: 5px 0; 282 | } 283 | 284 | pre .img img, pre .r-plt img { 285 | background-color: #fff; 286 | } 287 | 288 | code a, pre a { 289 | color: #375f84; 290 | } 291 | 292 | a.sourceLine:hover { 293 | text-decoration: none; 294 | } 295 | 296 | .fl {color: #1514b5;} 297 | .fu {color: #000000;} /* function */ 298 | .ch,.st {color: #036a07;} /* string */ 299 | .kw {color: #264D66;} /* keyword */ 300 | .co {color: #888888;} /* comment */ 301 | 302 | .error {font-weight: bolder;} 303 | .warning {font-weight: bolder;} 304 | 305 | /* Clipboard --------------------------*/ 306 | 307 | .hasCopyButton { 308 | position: relative; 309 | } 310 | 311 | .btn-copy-ex { 312 | position: absolute; 313 | right: 0; 314 | top: 0; 315 | visibility: hidden; 316 | } 317 | 318 | .hasCopyButton:hover button.btn-copy-ex { 319 | visibility: visible; 320 | } 321 | 322 | /* headroom.js ------------------------ */ 323 | 324 | .headroom { 325 | will-change: transform; 326 | transition: transform 200ms linear; 327 | } 328 | .headroom--pinned { 329 | transform: translateY(0%); 330 | } 331 | .headroom--unpinned { 332 | transform: translateY(-100%); 333 | } 334 | 335 | /* mark.js ----------------------------*/ 336 | 337 | mark { 338 | background-color: rgba(255, 255, 51, 0.5); 339 | border-bottom: 2px solid rgba(255, 153, 51, 0.3); 340 | padding: 1px; 341 | } 342 | 343 | /* vertical spacing after htmlwidgets */ 344 | .html-widget { 345 | margin-bottom: 10px; 346 | } 347 | 348 | /* fontawesome ------------------------ */ 349 | 350 | .fab { 351 | font-family: "Font Awesome 5 Brands" !important; 352 | } 353 | 354 | /* don't display links in code chunks when printing */ 355 | /* source: https://stackoverflow.com/a/10781533 */ 356 | @media print { 357 | code a:link:after, code a:visited:after { 358 | content: ""; 359 | } 360 | } 361 | 362 | /* Section anchors --------------------------------- 363 | Added in pandoc 2.11: https://github.com/jgm/pandoc-templates/commit/9904bf71 364 | */ 365 | 366 | div.csl-bib-body { } 367 | div.csl-entry { 368 | clear: both; 369 | } 370 | .hanging-indent div.csl-entry { 371 | margin-left:2em; 372 | text-indent:-2em; 373 | } 374 | div.csl-left-margin { 375 | min-width:2em; 376 | float:left; 377 | } 378 | div.csl-right-inline { 379 | margin-left:2em; 380 | padding-left:1em; 381 | } 382 | div.csl-indent { 383 | margin-left: 2em; 384 | } 385 | -------------------------------------------------------------------------------- /docs/pkgdown.js: -------------------------------------------------------------------------------- 1 | /* http://gregfranko.com/blog/jquery-best-practices/ */ 2 | (function($) { 3 | $(function() { 4 | 5 | $('.navbar-fixed-top').headroom(); 6 | 7 | $('body').css('padding-top', $('.navbar').height() + 10); 8 | $(window).resize(function(){ 9 | $('body').css('padding-top', $('.navbar').height() + 10); 10 | }); 11 | 12 | $('[data-toggle="tooltip"]').tooltip(); 13 | 14 | var cur_path = paths(location.pathname); 15 | var links = $("#navbar ul li a"); 16 | var max_length = -1; 17 | var pos = -1; 18 | for (var i = 0; i < links.length; i++) { 19 | if (links[i].getAttribute("href") === "#") 20 | continue; 21 | // Ignore external links 22 | if (links[i].host !== location.host) 23 | continue; 24 | 25 | var nav_path = paths(links[i].pathname); 26 | 27 | var length = prefix_length(nav_path, cur_path); 28 | if (length > max_length) { 29 | max_length = length; 30 | pos = i; 31 | } 32 | } 33 | 34 | // Add class to parent
  • , and enclosing
  • if in dropdown 35 | if (pos >= 0) { 36 | var menu_anchor = $(links[pos]); 37 | menu_anchor.parent().addClass("active"); 38 | menu_anchor.closest("li.dropdown").addClass("active"); 39 | } 40 | }); 41 | 42 | function paths(pathname) { 43 | var pieces = pathname.split("/"); 44 | pieces.shift(); // always starts with / 45 | 46 | var end = pieces[pieces.length - 1]; 47 | if (end === "index.html" || end === "") 48 | pieces.pop(); 49 | return(pieces); 50 | } 51 | 52 | // Returns -1 if not found 53 | function prefix_length(needle, haystack) { 54 | if (needle.length > haystack.length) 55 | return(-1); 56 | 57 | // Special case for length-0 haystack, since for loop won't run 58 | if (haystack.length === 0) { 59 | return(needle.length === 0 ? 0 : -1); 60 | } 61 | 62 | for (var i = 0; i < haystack.length; i++) { 63 | if (needle[i] != haystack[i]) 64 | return(i); 65 | } 66 | 67 | return(haystack.length); 68 | } 69 | 70 | /* Clipboard --------------------------*/ 71 | 72 | function changeTooltipMessage(element, msg) { 73 | var tooltipOriginalTitle=element.getAttribute('data-original-title'); 74 | element.setAttribute('data-original-title', msg); 75 | $(element).tooltip('show'); 76 | element.setAttribute('data-original-title', tooltipOriginalTitle); 77 | } 78 | 79 | if(ClipboardJS.isSupported()) { 80 | $(document).ready(function() { 81 | var copyButton = ""; 82 | 83 | $("div.sourceCode").addClass("hasCopyButton"); 84 | 85 | // Insert copy buttons: 86 | $(copyButton).prependTo(".hasCopyButton"); 87 | 88 | // Initialize tooltips: 89 | $('.btn-copy-ex').tooltip({container: 'body'}); 90 | 91 | // Initialize clipboard: 92 | var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', { 93 | text: function(trigger) { 94 | return trigger.parentNode.textContent.replace(/\n#>[^\n]*/g, ""); 95 | } 96 | }); 97 | 98 | clipboardBtnCopies.on('success', function(e) { 99 | changeTooltipMessage(e.trigger, 'Copied!'); 100 | e.clearSelection(); 101 | }); 102 | 103 | clipboardBtnCopies.on('error', function() { 104 | changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); 105 | }); 106 | }); 107 | } 108 | })(window.jQuery || window.$) 109 | -------------------------------------------------------------------------------- /docs/pkgdown.yml: -------------------------------------------------------------------------------- 1 | pandoc: 2.19.2 2 | pkgdown: 2.0.7 3 | pkgdown_sha: ~ 4 | articles: 5 | Diagnostics-for-2SLS-Regression: Diagnostics-for-2SLS-Regression.html 6 | ivreg: ivreg.html 7 | last_built: 2023-05-15T22:50Z 8 | urls: 9 | reference: https://zeileis.github.io/ivreg/reference 10 | article: https://zeileis.github.io/ivreg/articles 11 | 12 | -------------------------------------------------------------------------------- /docs/reference/Rplot001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/reference/Rplot001.png -------------------------------------------------------------------------------- /docs/reference/Rplot002.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/reference/Rplot002.png -------------------------------------------------------------------------------- /docs/reference/Rplot003.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/reference/Rplot003.png -------------------------------------------------------------------------------- /docs/reference/Rplot004.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/reference/Rplot004.png -------------------------------------------------------------------------------- /docs/reference/Rplot005.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/reference/Rplot005.png -------------------------------------------------------------------------------- /docs/reference/Rplot006.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/reference/Rplot006.png -------------------------------------------------------------------------------- /docs/reference/Rplot007.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/reference/Rplot007.png -------------------------------------------------------------------------------- /docs/reference/Rplot008.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/reference/Rplot008.png -------------------------------------------------------------------------------- /docs/reference/Rplot009.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/reference/Rplot009.png -------------------------------------------------------------------------------- /docs/reference/figures/README-effects-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/reference/figures/README-effects-1.png -------------------------------------------------------------------------------- /docs/reference/figures/README-influenceplot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/reference/figures/README-influenceplot-1.png -------------------------------------------------------------------------------- /docs/reference/figures/README-qqplot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/reference/figures/README-qqplot-1.png -------------------------------------------------------------------------------- /docs/reference/ivregDiagnostics-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/reference/ivregDiagnostics-1.png -------------------------------------------------------------------------------- /docs/reference/ivregDiagnostics-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/reference/ivregDiagnostics-2.png -------------------------------------------------------------------------------- /docs/reference/ivregDiagnostics-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/reference/ivregDiagnostics-3.png -------------------------------------------------------------------------------- /docs/reference/ivregDiagnostics-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/reference/ivregDiagnostics-4.png -------------------------------------------------------------------------------- /docs/reference/ivregDiagnostics-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/reference/ivregDiagnostics-5.png -------------------------------------------------------------------------------- /docs/reference/ivregDiagnostics-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/reference/ivregDiagnostics-6.png -------------------------------------------------------------------------------- /docs/reference/ivregDiagnostics-7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/reference/ivregDiagnostics-7.png -------------------------------------------------------------------------------- /docs/reference/ivregDiagnostics-8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/reference/ivregDiagnostics-8.png -------------------------------------------------------------------------------- /docs/reference/ivregDiagnostics-9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/docs/reference/ivregDiagnostics-9.png -------------------------------------------------------------------------------- /docs/sitemap.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | https://zeileis.github.io/ivreg/404.html 5 | 6 | 7 | https://zeileis.github.io/ivreg/articles/Diagnostics-for-2SLS-Regression.html 8 | 9 | 10 | https://zeileis.github.io/ivreg/articles/index.html 11 | 12 | 13 | https://zeileis.github.io/ivreg/articles/ivreg.html 14 | 15 | 16 | https://zeileis.github.io/ivreg/authors.html 17 | 18 | 19 | https://zeileis.github.io/ivreg/index.html 20 | 21 | 22 | https://zeileis.github.io/ivreg/news/index.html 23 | 24 | 25 | https://zeileis.github.io/ivreg/reference/CigaretteDemand.html 26 | 27 | 28 | https://zeileis.github.io/ivreg/reference/Kmenta.html 29 | 30 | 31 | https://zeileis.github.io/ivreg/reference/SchoolingReturns.html 32 | 33 | 34 | https://zeileis.github.io/ivreg/reference/index.html 35 | 36 | 37 | https://zeileis.github.io/ivreg/reference/ivreg.fit.html 38 | 39 | 40 | https://zeileis.github.io/ivreg/reference/ivreg.html 41 | 42 | 43 | https://zeileis.github.io/ivreg/reference/ivregDiagnostics.html 44 | 45 | 46 | https://zeileis.github.io/ivreg/reference/ivregMethods.html 47 | 48 | 49 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/logo.png -------------------------------------------------------------------------------- /man/CigaretteDemand.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/CigaretteDemand.R 3 | \docType{data} 4 | \name{CigaretteDemand} 5 | \alias{CigaretteDemand} 6 | \title{U.S. Cigarette Demand Data} 7 | \format{ 8 | A data frame with 48 rows and 10 columns. 9 | \describe{ 10 | \item{packs}{Number of cigarette packs per capita sold in 1995.} 11 | \item{rprice}{Real price in 1995 (including sales tax).} 12 | \item{rincome}{Real per capita income in 1995.} 13 | \item{salestax}{Sales tax in 1995.} 14 | \item{cigtax}{Cigarette-specific taxes (federal and average local excise taxes) in 1995.} 15 | \item{packsdiff}{Difference in \code{log(packs)} (between 1995 and 1985).} 16 | \item{pricediff}{Difference in \code{log(rprice)} (between 1995 and 1985).} 17 | \item{incomediff}{Difference in \code{log(rincome)} (between 1995 and 1985).} 18 | \item{salestaxdiff}{Difference in \code{salestax} (between 1995 and 1985).} 19 | \item{cigtaxdiff}{Difference in \code{cigtax} (between 1995 and 1985).} 20 | } 21 | } 22 | \source{ 23 | Online complements to Stock and Watson (2007). 24 | } 25 | \usage{ 26 | data("CigaretteDemand", package = "ivreg") 27 | } 28 | \description{ 29 | Determinants of cigarette demand for the 48 continental US States in 1995 and 30 | compared between 1995 and 1985. 31 | } 32 | \details{ 33 | The data are taken from the online complements to Stock and Watson (2007) and 34 | had been prepared as panel data (in long form) in \code{\link[AER]{CigarettesSW}} 35 | from the AER package (Kleiber and Zeileis 2008). Here, the data are provided by 36 | state (in wide form), readily preprocessed to contain all variables needed for 37 | illustrations of OLS and IV regressions. More related examples from Stock and 38 | Watson (2007) are provided in the AER package in \code{\link[AER]{StockWatson2007}}. 39 | A detailed discussion of the various cigarette demand examples with R code 40 | is provided by Hanck et al. (2020, Chapter 12). 41 | } 42 | \examples{ 43 | ## load data 44 | data("CigaretteDemand", package = "ivreg") 45 | 46 | ## basic price elasticity: OLS vs. IV 47 | cig_ols <- lm(log(packs) ~ log(rprice), data = CigaretteDemand) 48 | cig_iv <- ivreg(log(packs) ~ log(rprice) | salestax, data = CigaretteDemand) 49 | cbind(OLS = coef(cig_ols), IV = coef(cig_iv)) 50 | 51 | ## adjusting for income differences (exogenous) 52 | cig_iv2 <- ivreg(log(packs) ~ log(rprice) + log(rincome) | salestax + log(rincome), 53 | data = CigaretteDemand) 54 | ## adding a second instrument for log(rprice) 55 | cig_iv3 <- update(cig_iv2, . ~ . | . + cigtax) 56 | 57 | ## comparison using heteroscedasticity-consistent standard errors 58 | library("lmtest") 59 | library("sandwich") 60 | coeftest(cig_iv2, vcov = vcovHC, type = "HC1") 61 | coeftest(cig_iv3, vcov = vcovHC, type = "HC1") 62 | 63 | ## long-run price elasticity using differences between 1995 and 1985 64 | cig_ivdiff1 <- ivreg(packsdiff ~ pricediff + incomediff | incomediff + salestaxdiff, 65 | data = CigaretteDemand) 66 | cig_ivdiff2 <- update(cig_ivdiff1, . ~ . | . - salestaxdiff + cigtaxdiff) 67 | cig_ivdiff3 <- update(cig_ivdiff1, . ~ . | . + cigtaxdiff) 68 | coeftest(cig_ivdiff1, vcov = vcovHC, type = "HC1") 69 | coeftest(cig_ivdiff2, vcov = vcovHC, type = "HC1") 70 | coeftest(cig_ivdiff3, vcov = vcovHC, type = "HC1") 71 | } 72 | \references{ 73 | Hanck, C., Arnold, M., Gerber, A., and Schmelzer, M. (2020). 74 | \emph{Introduction to Econometrics with R}. \url{https://www.econometrics-with-r.org/} 75 | 76 | Kleiber, C. and Zeileis, A. (2008). \emph{Applied Econometrics with R}. Springer-Verlag 77 | 78 | Stock, J.H. and Watson, M.W. (2007). \emph{Introduction to Econometrics}, 2nd ed., Addison Wesley. 79 | } 80 | \seealso{ 81 | \code{\link[AER]{CigarettesSW}}. 82 | } 83 | \keyword{datasets} 84 | -------------------------------------------------------------------------------- /man/Kmenta.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Kmenta.R 3 | \docType{data} 4 | \name{Kmenta} 5 | \alias{Kmenta} 6 | \title{Partly Artificial Data on the U.S. Economy} 7 | \format{ 8 | A data frame with 20 rows and 5 columns. 9 | \describe{ 10 | \item{Q}{food consumption per capita.} 11 | \item{P}{ratio of food prices to general consumer prices.} 12 | \item{D}{disposable income in constant dollars.} 13 | \item{F}{ratio of preceding year's prices received by farmers to general consumer prices.} 14 | \item{A}{time in years.} 15 | } 16 | } 17 | \source{ 18 | Kmenta, J. (1986) \emph{Elements of Econometrics}, 2nd ed., Macmillan. 19 | } 20 | \usage{ 21 | data("Kmenta", package = "ivreg") 22 | } 23 | \description{ 24 | These are partly contrived data from Kmenta (1986), constructed 25 | to illustrate estimation of a simultaneous-equation econometric model. The data 26 | are an annual time-series for the U.S. economy from 1922 to 1941. The values of the 27 | exogenous variables D, and F, and A are real, while those of the endogenous 28 | variables Q and P are simulated according to the linear simultaneous equation model 29 | fit in the examples. 30 | } 31 | \examples{ 32 | data("Kmenta", package = "ivreg") 33 | deq <- ivreg(Q ~ P + D | D + F + A, data = Kmenta) # demand equation 34 | seq <- ivreg(Q ~ P + F + A | D + F + A, data = Kmenta) # supply equation 35 | summary(deq, tests = TRUE) 36 | summary(seq, tests = TRUE) 37 | } 38 | \seealso{ 39 | \code{\link{ivreg}}. 40 | } 41 | \keyword{datasets} 42 | -------------------------------------------------------------------------------- /man/SchoolingReturns.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/SchoolingReturns.R 3 | \docType{data} 4 | \name{SchoolingReturns} 5 | \alias{SchoolingReturns} 6 | \title{U.S. Returns to Schooling Data} 7 | \format{ 8 | A data frame with 3010 rows and 22 columns. 9 | \describe{ 10 | \item{wage}{Raw wages in 1976 (in cents per hour).} 11 | \item{education}{Education in 1976 (in years).} 12 | \item{experience}{Years of labor market experience, computed as \code{age - education - 6}.} 13 | \item{ethnicity}{Factor indicating ethnicity. Is the individual African-American 14 | (\code{"afam"}) or not (\code{"other"})?} 15 | \item{smsa}{Factor. Does the individual reside in a SMSA (standard metropolitan statistical area) in 1976?} 16 | \item{south}{Factor. Does the individual reside in the South in 1976?} 17 | \item{age}{Age in 1976 (in years).} 18 | \item{nearcollege}{Factor. Did the individual grow up near a 4-year college?} 19 | \item{nearcollege2}{Factor. Did the individual grow up near a 2-year college?} 20 | \item{nearcollege4}{Factor. Did the individual grow up near a 4-year public or private college?} 21 | \item{enrolled}{Factor. Is the individual enrolled in college in 1976?} 22 | \item{married}{factor. Is the individual married in 1976?} 23 | \item{education66}{Education in 1966 (in years).} 24 | \item{smsa66}{Factor. Does the individual reside in a SMSA in 1966?} 25 | \item{south66}{Factor. Does the individual reside in the South in 1966?} 26 | \item{feducation}{Father's educational attainment (in years). Imputed with average if missing.} 27 | \item{meducation}{Mother's educational attainment (in years). Imputed with average if missing.} 28 | \item{fameducation}{Ordered factor coding family education class (from 1 to 9).} 29 | \item{kww}{Knowledge world of work (KWW) score.} 30 | \item{iq}{Normed intelligence quotient (IQ) score} 31 | \item{parents14}{Factor coding living with parents at age 14: 32 | both parents, single mother, step parent, other} 33 | \item{library14}{Factor. Was there a library card in home at age 14?} 34 | } 35 | } 36 | \source{ 37 | Supplementary material for Verbeek (2004). 38 | } 39 | \usage{ 40 | data("SchoolingReturns", package = "ivreg") 41 | } 42 | \description{ 43 | Data from the U.S. National Longitudinal Survey of Young Men (NLSYM) in 1976 44 | but using some variables dating back to earlier years. 45 | } 46 | \details{ 47 | Investigating the causal link of schooling on earnings in a classical model 48 | for wage determinants is problematic because it can be argued that schooling 49 | is endogenous. Hence, one possible strategy is to use an exogonous variable 50 | as an instrument for the years of education. In his well-known study, Card (1995) 51 | uses geographical proximity to a college when growing up as such an instrument, 52 | showing that this significantly increases both the years of education and the 53 | wage level obtained on the labor market. Using instrumental variables regression 54 | Card (1995) shows that the estimated returns to schooling are much higher than 55 | when simply using ordinary least squares. 56 | 57 | The data are taken from the supplementary material for Verbeek (2004) and are based 58 | on the work of Card (1995). The U.S. National Longitudinal Survey of Young Men 59 | (NLSYM) began in 1966 and included 5525 men, then aged between 14 and 24. 60 | Card (1995) employs labor market information from the 1976 NLSYM interview which 61 | also included information about educational attainment. Out of the 3694 men 62 | still included in that wave of NLSYM, 3010 provided information on both wages 63 | and education yielding the subset of observations provided in \code{SchoolingReturns}. 64 | 65 | The examples replicate the results from Verbeek (2004) who used the simplest 66 | specifications from Card (1995). Including further region or family background 67 | characteristics improves the model significantly but does not affect much the 68 | main coefficients of interest, namely that of years of education. 69 | } 70 | \examples{ 71 | ## load data 72 | data("SchoolingReturns", package = "ivreg") 73 | 74 | ## Table 5.1 in Verbeek (2004) / Table 2(1) in Card (1995) 75 | ## Returns to education: 7.4\% 76 | m_ols <- lm(log(wage) ~ education + poly(experience, 2, raw = TRUE) + ethnicity + smsa + south, 77 | data = SchoolingReturns) 78 | summary(m_ols) 79 | 80 | ## Table 5.2 in Verbeek (2004) / similar to Table 3(1) in Card (1995) 81 | m_red <- lm(education ~ poly(age, 2, raw = TRUE) + ethnicity + smsa + south + nearcollege, 82 | data = SchoolingReturns) 83 | summary(m_red) 84 | 85 | ## Table 5.3 in Verbeek (2004) / similar to Table 3(5) in Card (1995) 86 | ## Returns to education: 13.3\% 87 | m_iv <- ivreg(log(wage) ~ education + poly(experience, 2, raw = TRUE) + ethnicity + smsa + south | 88 | nearcollege + poly(age, 2, raw = TRUE) + ethnicity + smsa + south, 89 | data = SchoolingReturns) 90 | summary(m_iv) 91 | } 92 | \references{ 93 | Card, D. (1995). Using Geographical Variation in College Proximity to Estimate the Return to 94 | Schooling. In: Christofides, L.N., Grant, E.K., and Swidinsky, R. (eds.), 95 | \emph{Aspects of Labour Market Behaviour: Essays in Honour of John Vanderkamp}, 96 | University of Toronto Press, Toronto, 201-222. 97 | 98 | Verbeek, M. (2004). \emph{A Guide to Modern Econometrics}, 2nd ed. John Wiley. 99 | } 100 | \keyword{datasets} 101 | -------------------------------------------------------------------------------- /man/figures/README-effects-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/man/figures/README-effects-1.png -------------------------------------------------------------------------------- /man/figures/README-influenceplot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/man/figures/README-influenceplot-1.png -------------------------------------------------------------------------------- /man/figures/README-qqplot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/man/figures/README-qqplot-1.png -------------------------------------------------------------------------------- /man/ivreg.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ivreg.R 3 | \name{ivreg} 4 | \alias{ivreg} 5 | \title{Instrumental-Variable Regression by 2SLS, 2SM, or 2SMM Estimation} 6 | \usage{ 7 | ivreg( 8 | formula, 9 | instruments, 10 | data, 11 | subset, 12 | na.action, 13 | weights, 14 | offset, 15 | contrasts = NULL, 16 | model = TRUE, 17 | y = TRUE, 18 | x = FALSE, 19 | method = c("OLS", "M", "MM"), 20 | ... 21 | ) 22 | } 23 | \arguments{ 24 | \item{formula, instruments}{formula specification(s) of the regression 25 | relationship and the instruments. Either \code{instruments} is missing and 26 | \code{formula} has three parts as in \code{y ~ x1 + x2 | z1 + z2 + z3} 27 | (recommended) or \code{formula} is \code{y ~ x1 + x2} and \code{instruments} 28 | is a one-sided formula \code{~ z1 + z2 + z3} (only for backward 29 | compatibility).} 30 | 31 | \item{data}{an optional data frame containing the variables in the model. 32 | By default the variables are taken from the environment of the 33 | \code{formula}.} 34 | 35 | \item{subset}{an optional vector specifying a subset of observations to be 36 | used in fitting the model.} 37 | 38 | \item{na.action}{a function that indicates what should happen when the data 39 | contain \code{NA}s. The default is set by the \code{na.action} option.} 40 | 41 | \item{weights}{an optional vector of weights to be used in the fitting 42 | process.} 43 | 44 | \item{offset}{an optional offset that can be used to specify an a priori 45 | known component to be included during fitting.} 46 | 47 | \item{contrasts}{an optional list. See the \code{contrasts.arg} of 48 | \code{\link[stats:model.matrix]{model.matrix.default}}.} 49 | 50 | \item{model, x, y}{logicals. If \code{TRUE} the corresponding components of 51 | the fit (the model frame, the model matrices, the response) are returned. These 52 | components are necessary for computing regression diagnostics.} 53 | 54 | \item{method}{the method used to fit the stage 1 and 2 regression: 55 | \code{"OLS"} for traditional 2SLS regression (the default), 56 | \code{"M"} for M-estimation, or \code{"MM"} for MM-estimation, with the 57 | latter two robust-regression methods implemented via the \code{\link[MASS]{rlm}} 58 | function in the \pkg{MASS} package.} 59 | 60 | \item{\dots}{further arguments passed to \code{\link{ivreg.fit}}.} 61 | } 62 | \value{ 63 | \code{ivreg} returns an object of class \code{"ivreg"} that inherits from 64 | class \code{"lm"}, with the following components: 65 | \item{coefficients}{parameter estimates, from the stage-2 regression.} 66 | \item{residuals}{vector of model residuals.} 67 | \item{residuals1}{matrix of residuals from the stage-1 regression.} 68 | \item{residuals2}{vector of residuals from the stage-2 regression.} 69 | \item{fitted.values}{vector of predicted means for the response.} 70 | \item{weights}{either the vector of weights used (if any) or \code{NULL} (if none).} 71 | \item{offset}{either the offset used (if any) or \code{NULL} (if none).} 72 | \item{estfun}{a matrix containing the empirical estimating functions.} 73 | \item{n}{number of observations.} 74 | \item{nobs}{number of observations with non-zero weights.} 75 | \item{p}{number of columns in the model matrix x of regressors.} 76 | \item{q}{number of columns in the instrumental variables model matrix z} 77 | \item{rank}{numeric rank of the model matrix for the stage-2 regression.} 78 | \item{df.residual}{residual degrees of freedom for fitted model.} 79 | \item{cov.unscaled}{unscaled covariance matrix for the coefficients.} 80 | \item{sigma}{residual standard deviation.} 81 | \item{qr}{QR decomposition for the stage-2 regression.} 82 | \item{qr1}{QR decomposition for the stage-1 regression.} 83 | \item{rank1}{numeric rank of the model matrix for the stage-1 regression.} 84 | \item{coefficients1}{matrix of coefficients from the stage-1 regression.} 85 | \item{df.residual1}{residual degrees of freedom for the stage-1 regression.} 86 | \item{exogenous}{columns of the \code{"regressors"} matrix that are exogenous.} 87 | \item{endogenous}{columns of the \code{"regressors"} matrix that are endogenous.} 88 | \item{instruments}{columns of the \code{"instruments"} matrix that are 89 | instruments for the endogenous variables.} 90 | \item{method}{the method used for the stage 1 and 2 regressions, one of \code{"OLS"}, 91 | \code{"M"}, or \code{"MM"}.} 92 | \item{rweights}{a matrix of robustness weights with columns for each of the stage-1 93 | regressions and for the stage-2 regression (in the last column) if the fitting method is 94 | \code{"M"} or \code{"MM"}, \code{NULL} if the fitting method is \code{"OLS"}.} 95 | \item{hatvalues}{a matrix of hatvalues. For \code{method = "OLS"}, the matrix consists of two 96 | columns, for each of the stage-1 and stage-2 regression; for \code{method = "M"} or \code{"MM"}, 97 | there is one column for \emph{each} stage=1 regression and for the stage-2 regression. } 98 | \item{df.residual}{residual degrees of freedom for fitted model.} 99 | \item{call}{the original function call.} 100 | \item{formula}{the model formula.} 101 | \item{na.action}{function applied to missing values in the model fit.} 102 | \item{terms}{a list with elements \code{"regressors"} and \code{"instruments"} 103 | containing the terms objects for the respective components.} 104 | \item{levels}{levels of the categorical regressors.} 105 | \item{contrasts}{the contrasts used for categorical regressors.} 106 | \item{model}{the full model frame (if \code{model = TRUE}).} 107 | \item{y}{the response vector (if \code{y = TRUE}).} 108 | \item{x}{a list with elements \code{"regressors"}, \code{"instruments"}, \code{"projected"}, 109 | containing the model matrices from the respective components (if \code{x = TRUE}). 110 | \code{"projected"} is the matrix of regressors projected on the image of the instruments.} 111 | } 112 | \description{ 113 | Fit instrumental-variable regression by two-stage least squares (2SLS). This is 114 | equivalent to direct instrumental-variables estimation when the number of 115 | instruments is equal to the number of regressors. Alternative robust-regression 116 | estimators are also provided, based on M-estimation (2SM) and MM-estimation 117 | (2SMM). 118 | } 119 | \details{ 120 | \code{ivreg} is the high-level interface to the work-horse function 121 | \code{\link{ivreg.fit}}. A set of standard methods (including \code{print}, 122 | \code{summary}, \code{vcov}, \code{anova}, \code{predict}, \code{residuals}, 123 | \code{terms}, \code{model.matrix}, \code{bread}, \code{estfun}) is available 124 | and described in \code{\link{ivregMethods}}. For methods related to regression 125 | diagnostics, see \code{\link{ivregDiagnostics}}. 126 | 127 | Regressors and instruments for \code{ivreg} are most easily specified in a 128 | formula with two parts on the right-hand side, e.g., \code{y ~ x1 + x2 | z1 129 | + z2 + z3}, where \code{x1} and \code{x2} are the explanatory variables and \code{z1}, 130 | \code{z2}, and \code{z3} are the instrumental variables. Note that exogenous regressors 131 | have to be included as instruments for themselves. 132 | 133 | For example, if there is 134 | one exogenous regressor \code{ex} and one endogenous regressor \code{en} 135 | with instrument \code{in}, the appropriate formula would be \code{y ~ en + 136 | ex | in + ex}. Alternatively, a formula with three parts on the right-hand 137 | side can also be used: \code{y ~ ex | en | in}. The latter is typically more convenient, if 138 | there is a large number of exogenous regressors. 139 | 140 | Moreover, two further equivalent specification strategies are possible that are 141 | typically less convenient compared to the strategies above. One option is to use 142 | an update formula with a \code{.} in the second part of the formula is used: 143 | \code{y ~ en + ex | . - en + in}. Another option is to use a separate formula 144 | for the instruments (only for backward compatibility with earlier versions): 145 | \code{formula = y ~ en + ex, instruments = ~ in + ex}. 146 | 147 | Internally, all specifications are converted to the version with two parts 148 | on the right-hand side. 149 | } 150 | \examples{ 151 | \dontshow{ if(!requireNamespace("sandwich")) { 152 | if(interactive() || is.na(Sys.getenv("_R_CHECK_PACKAGE_NAME_", NA))) { 153 | stop("not all packages required for the example are installed") 154 | } else q() }} 155 | ## data 156 | data("CigaretteDemand", package = "ivreg") 157 | 158 | ## model 159 | m <- ivreg(log(packs) ~ log(rprice) + log(rincome) | salestax + log(rincome), 160 | data = CigaretteDemand) 161 | summary(m) 162 | summary(m, vcov = sandwich::sandwich, df = Inf) 163 | 164 | ## ANOVA 165 | m2 <- update(m, . ~ . - log(rincome) | . - log(rincome)) 166 | anova(m, m2) 167 | car::Anova(m) 168 | 169 | ## same model specified by formula with three-part right-hand side 170 | ivreg(log(packs) ~ log(rincome) | log(rprice) | salestax, data = CigaretteDemand) 171 | 172 | # Robust 2SLS regression 173 | data("Kmenta", package = "ivreg") 174 | Kmenta1 <- Kmenta 175 | Kmenta1[20, "Q"] <- 95 # corrupted data 176 | deq <- ivreg(Q ~ P + D | D + F + A, data=Kmenta) # demand equation, uncorrupted data 177 | deq1 <- ivreg(Q ~ P + D | D + F + A, data=Kmenta1) # standard 2SLS, corrupted data 178 | deq2 <- ivreg(Q ~ P + D | D + F + A, data=Kmenta1, subset=-20) # standard 2SLS, removing bad case 179 | deq3 <- ivreg(Q ~ P + D | D + F + A, data=Kmenta1, method="MM") # 2SLS MM estimation 180 | car::compareCoefs(deq, deq1, deq2, deq3) 181 | round(deq3$rweights, 2) # robustness weights 182 | 183 | } 184 | \references{ 185 | Greene, W.H. (2003) \emph{Econometric Analysis}, 5th ed., Upper Saddle River: Prentice Hall. 186 | } 187 | \seealso{ 188 | \code{\link{ivreg.fit}}, \code{\link{ivregDiagnostics}}, \code{\link{ivregMethods}}, 189 | \code{\link[stats]{lm}}, \code{\link[stats:lmfit]{lm.fit}} 190 | } 191 | \keyword{regression} 192 | -------------------------------------------------------------------------------- /man/ivreg.fit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ivreg.fit.R 3 | \name{ivreg.fit} 4 | \alias{ivreg.fit} 5 | \title{Fitting Instrumental-Variable Regressions by 2SLS, 2SM, or 2SMM Estimation} 6 | \usage{ 7 | ivreg.fit( 8 | x, 9 | y, 10 | z, 11 | weights, 12 | offset, 13 | method = c("OLS", "M", "MM"), 14 | rlm.args = list(), 15 | ... 16 | ) 17 | } 18 | \arguments{ 19 | \item{x}{regressor matrix.} 20 | 21 | \item{y}{vector for the response variable.} 22 | 23 | \item{z}{instruments matrix.} 24 | 25 | \item{weights}{an optional vector of weights to be used in the fitting 26 | process.} 27 | 28 | \item{offset}{an optional offset that can be used to specify an a priori 29 | known component to be included during fitting.} 30 | 31 | \item{method}{the method used to fit the stage 1 and 2 regression: 32 | \code{"OLS"} for traditional 2SLS regression (the default), 33 | \code{"M"} for M-estimation, or \code{"MM"} for MM-estimation, with the 34 | latter two robust-regression methods implemented via the \code{\link[MASS]{rlm}} 35 | function in the \pkg{MASS} package.} 36 | 37 | \item{rlm.args}{a list of optional arguments to be passed to the \code{\link[MASS]{rlm}} 38 | function in the \pkg{MASS} package if robust regression is used for the stage 1 and 2 regressions.} 39 | 40 | \item{\dots}{further arguments passed to \code{\link[stats:lmfit]{lm.fit}} 41 | or \code{\link[stats:lmfit]{lm.wfit}}, respectively.} 42 | } 43 | \value{ 44 | \code{ivreg.fit} returns an unclassed list with the following 45 | components: 46 | \item{coefficients}{parameter estimates, from the stage-2 regression.} 47 | \item{residuals}{vector of model residuals.} 48 | \item{residuals1}{matrix of residuals from the stage-1 regression.} 49 | \item{residuals2}{vector of residuals from the stage-2 regression.} 50 | \item{fitted.values}{vector of predicted means for the response.} 51 | \item{weights}{either the vector of weights used (if any) or \code{NULL} (if none).} 52 | \item{offset}{either the offset used (if any) or \code{NULL} (if none).} 53 | \item{estfun}{a matrix containing the empirical estimating functions.} 54 | \item{n}{number of observations.} 55 | \item{nobs}{number of observations with non-zero weights.} 56 | \item{p}{number of columns in the model matrix x of regressors.} 57 | \item{q}{number of columns in the instrumental variables model matrix z} 58 | \item{rank}{numeric rank of the model matrix for the stage-2 regression.} 59 | \item{df.residual}{residual degrees of freedom for fitted model.} 60 | \item{cov.unscaled}{unscaled covariance matrix for the coefficients.} 61 | \item{sigma}{residual standard error; when method is \code{"M"} or \code{"MM"}, this 62 | is based on the MAD of the residuals (around 0) --- see \code{\link[stats]{mad}}.} 63 | \item{x}{projection of x matrix onto span of z.} 64 | \item{qr}{QR decomposition for the stage-2 regression.} 65 | \item{qr1}{QR decomposition for the stage-1 regression.} 66 | \item{rank1}{numeric rank of the model matrix for the stage-1 regression.} 67 | \item{coefficients1}{matrix of coefficients from the stage-1 regression.} 68 | \item{df.residual1}{residual degrees of freedom for the stage-1 regression.} 69 | \item{exogenous}{columns of the \code{"regressors"} matrix that are exogenous.} 70 | \item{endogenous}{columns of the \code{"regressors"} matrix that are endogenous.} 71 | \item{instruments}{columns of the \code{"instruments"} matrix that are 72 | instruments for the endogenous variables.} 73 | \item{method}{the method used for the stage 1 and 2 regressions, one of \code{"OLS"}, 74 | \code{"M"}, or \code{"MM"}.} 75 | \item{rweights}{a matrix of robustness weights with columns for each of the stage-1 76 | regressions and for the stage-2 regression (in the last column) if the fitting method is 77 | \code{"M"} or \code{"MM"}, \code{NULL} if the fitting method is \code{"OLS"}.} 78 | \item{hatvalues}{a matrix of hatvalues. For \code{method = "OLS"}, the matrix consists of two 79 | columns, for each of the stage-1 and stage-2 regression; for \code{method = "M"} or \code{"MM"}, 80 | there is one column for \emph{each} stage-1 regression and for the stage-2 regression. } 81 | } 82 | \description{ 83 | Fit instrumental-variable regression by two-stage least squares (2SLS). This is 84 | equivalent to direct instrumental-variables estimation when the number of 85 | instruments is equal to the number of predictors. Alternative robust-regression 86 | estimation is also supported, based on M-estimation (22M) or MM-estimation (2SMM). 87 | } 88 | \details{ 89 | \code{\link{ivreg}} is the high-level interface to the work-horse function 90 | \code{ivreg.fit}. \code{ivreg.fit} is essentially a convenience interface to 91 | \code{\link[stats:lmfit]{lm.fit}} (or \code{\link[stats:lmfit]{lm.wfit}}) 92 | for first projecting \code{x} onto the image of 93 | \code{z}, then running a regression of \code{y} on the projected 94 | \code{x}, and computing the residual standard deviation. 95 | } 96 | \examples{ 97 | ## data 98 | data("CigaretteDemand", package = "ivreg") 99 | 100 | ## high-level interface 101 | m <- ivreg(log(packs) ~ log(rprice) + log(rincome) | salestax + log(rincome), 102 | data = CigaretteDemand) 103 | 104 | ## low-level interface 105 | y <- m$y 106 | x <- model.matrix(m, component = "regressors") 107 | z <- model.matrix(m, component = "instruments") 108 | ivreg.fit(x, y, z)$coefficients 109 | 110 | } 111 | \seealso{ 112 | \code{\link{ivreg}}, \code{\link[stats:lmfit]{lm.fit}}, 113 | \code{\link[stats:lmfit]{lm.wfit}}, \code{\link[MASS]{rlm}}, \code{\link[stats]{mad}} 114 | } 115 | \keyword{regression} 116 | -------------------------------------------------------------------------------- /man/ivregDiagnostics.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ivregDiagnostics.R 3 | \name{influence.ivreg} 4 | \alias{influence.ivreg} 5 | \alias{ivregDiagnostics} 6 | \alias{rstudent.ivreg} 7 | \alias{cooks.distance.ivreg} 8 | \alias{dfbeta.influence.ivreg} 9 | \alias{hatvalues.ivreg} 10 | \alias{rstudent.influence.ivreg} 11 | \alias{hatvalues.influence.ivreg} 12 | \alias{cooks.distance.influence.ivreg} 13 | \alias{qqPlot.ivreg} 14 | \alias{qqPlot.influence.ivreg} 15 | \alias{influencePlot.ivreg} 16 | \alias{influencePlot.influence.ivreg} 17 | \alias{infIndexPlot.ivreg} 18 | \alias{infIndexPlot.influence.ivreg} 19 | \alias{model.matrix.influence.ivreg} 20 | \alias{avPlots.ivreg} 21 | \alias{avPlot.ivreg} 22 | \alias{mcPlots.ivreg} 23 | \alias{mcPlot.ivreg} 24 | \alias{Boot.ivreg} 25 | \alias{crPlots.ivreg} 26 | \alias{crPlot.ivreg} 27 | \alias{ceresPlots.ivreg} 28 | \alias{ceresPlot.ivreg} 29 | \alias{plot.ivreg} 30 | \alias{outlierTest.ivreg} 31 | \alias{spreadLevelPlot.ivreg} 32 | \alias{ncvTest.ivreg} 33 | \alias{deviance.ivreg} 34 | \alias{dfbeta.ivreg} 35 | \alias{influence.rivreg} 36 | \title{Deletion and Other Diagnostic Methods for \code{"ivreg"} Objects} 37 | \usage{ 38 | \method{influence}{ivreg}( 39 | model, 40 | sigma. = n <= 1000, 41 | type = c("stage2", "both", "maximum"), 42 | applyfun = NULL, 43 | ncores = NULL, 44 | ... 45 | ) 46 | 47 | \method{rstudent}{ivreg}(model, ...) 48 | 49 | \method{cooks.distance}{ivreg}(model, ...) 50 | 51 | \method{dfbeta}{influence.ivreg}(model, ...) 52 | 53 | \method{dfbeta}{ivreg}(model, ...) 54 | 55 | \method{hatvalues}{ivreg}(model, type = c("stage2", "both", "maximum", "stage1"), ...) 56 | 57 | \method{rstudent}{influence.ivreg}(model, ...) 58 | 59 | \method{hatvalues}{influence.ivreg}(model, ...) 60 | 61 | \method{cooks.distance}{influence.ivreg}(model, ...) 62 | 63 | \method{qqPlot}{influence.ivreg}( 64 | x, 65 | ylab = paste("Studentized Residuals(", deparse(substitute(x)), ")", sep = ""), 66 | distribution = c("t", "norm"), 67 | ... 68 | ) 69 | 70 | \method{influencePlot}{ivreg}(model, ...) 71 | 72 | \method{influencePlot}{influence.ivreg}(model, ...) 73 | 74 | \method{infIndexPlot}{ivreg}(model, ...) 75 | 76 | \method{infIndexPlot}{influence.ivreg}(model, ...) 77 | 78 | \method{model.matrix}{influence.ivreg}(object, ...) 79 | 80 | \method{avPlots}{ivreg}(model, terms, ...) 81 | 82 | \method{avPlot}{ivreg}(model, ...) 83 | 84 | \method{mcPlots}{ivreg}(model, terms, ...) 85 | 86 | \method{mcPlot}{ivreg}(model, ...) 87 | 88 | \method{Boot}{ivreg}( 89 | object, 90 | f = coef, 91 | labels = names(f(object)), 92 | R = 999, 93 | method = "case", 94 | ncores = 1, 95 | ... 96 | ) 97 | 98 | \method{crPlots}{ivreg}(model, terms, ...) 99 | 100 | \method{crPlot}{ivreg}(model, ...) 101 | 102 | \method{ceresPlots}{ivreg}(model, terms, ...) 103 | 104 | \method{ceresPlot}{ivreg}(model, ...) 105 | 106 | \method{plot}{ivreg}(x, ...) 107 | 108 | \method{qqPlot}{ivreg}(x, distribution = c("t", "norm"), ...) 109 | 110 | \method{outlierTest}{ivreg}(model, ...) 111 | 112 | \method{spreadLevelPlot}{ivreg}(x, main = "Spread-Level Plot", ...) 113 | 114 | \method{ncvTest}{ivreg}(model, ...) 115 | 116 | \method{deviance}{ivreg}(object, ...) 117 | 118 | \method{influence}{rivreg}(model, ...) 119 | } 120 | \arguments{ 121 | \item{model, x, object}{A \code{"ivreg"} or \code{"influence.ivreg"} object.} 122 | 123 | \item{sigma.}{If \code{TRUE} (the default for 1000 or fewer cases), the deleted value 124 | of the residual standard deviation is computed for each case; if \code{FALSE}, the 125 | overall residual standard deviation is used to compute other deletion diagnostics.} 126 | 127 | \item{type}{If \code{"stage2"} (the default), hatvalues are for the second stage regression; 128 | if \code{"both"}, the hatvalues are the geometric mean of the casewise hatvalues for the 129 | two stages; if \code{"maximum"}, the hatvalues are the larger of the casewise 130 | hatvalues for the two stages. In computing the geometric mean or casewise maximum hatvalues, 131 | the hatvalues for each stage are first divided by their average (number of coefficients in 132 | stage regression/number of cases); the geometric mean or casewise maximum values are then 133 | multiplied by the average hatvalue from the second stage.} 134 | 135 | \item{applyfun}{Optional loop replacement function that should work like 136 | \code{\link[base]{lapply}} with arguments \code{function(X, FUN, ...)}. The default 137 | is to use a loop unless the \code{ncores} argument is specified (see below).} 138 | 139 | \item{ncores}{Numeric, number of cores to be used in parallel computations. If set 140 | to an integer the \code{applyfun} is set to use either \code{\link[parallel:clusterApply]{parLapply}} 141 | (on Windows) or 142 | #ifdef windows 143 | \code{\link[parallel:mcdummies]{mclapply}} 144 | #endif 145 | #ifdef unix 146 | \code{\link[parallel]{mclapply}} 147 | #endif 148 | (otherwise) with the desired number of cores.} 149 | 150 | \item{...}{arguments to be passed down.} 151 | 152 | \item{ylab}{The vertical axis label.} 153 | 154 | \item{distribution}{\code{"t"} (the default) or \code{"norm"}.} 155 | 156 | \item{terms}{Terms for which added-variable plots are to be constructed; the default, 157 | if the argument isn't specified, is the \code{"regressors"} component of the model formula.} 158 | 159 | \item{f, labels, R}{see \code{\link[car]{Boot}}.} 160 | 161 | \item{method}{only \code{"case"} (case resampling) is supported: see \code{\link[car]{Boot}}.} 162 | 163 | \item{main}{Main title for the graph.} 164 | } 165 | \value{ 166 | In the case of \code{influence.ivreg}, an object of class \code{"influence.ivreg"} 167 | with the following components: 168 | \describe{ 169 | \item{\code{coefficients}}{the estimated regression coefficients} 170 | \item{\code{model}}{the model matrix} 171 | \item{\code{dfbeta}}{influence on coefficients} 172 | \item{\code{sigma}}{deleted values of the residual standard deviation} 173 | \item{\code{dffits}}{overall influence on the regression coefficients} 174 | \item{\code{cookd}}{Cook's distances} 175 | \item{\code{hatvalues}}{hatvalues} 176 | \item{\code{rstudent}}{Studentized residuals} 177 | \item{\code{df.residual}}{residual degrees of freedom} 178 | } 179 | In the case of other methods, such as \code{rstudent.ivreg} or 180 | \code{rstudent.influence.ivreg}, the corresponding diagnostic statistics. 181 | Many other methods (e.g., \code{crPlot.ivreg}, \code{avPlot.ivreg}, \code{Effect.ivreg}) 182 | draw graphs. 183 | } 184 | \description{ 185 | Methods for computing deletion and other regression diagnostics for 2SLS regression. 186 | It's generally more efficient to compute the deletion diagnostics via the \code{influence} 187 | method and then to extract the various specific diagnostics with the methods for 188 | \code{"influence.ivreg"} objects. Other diagnostics for linear models, such as 189 | added-variable plots (\code{\link[car]{avPlots}}) and component-plus-residual 190 | plots (\code{\link[car]{crPlots}}), also work, as do effect plots 191 | (e.g., \code{\link[effects]{predictorEffects}}) with residuals (see the examples below). 192 | The pointwise confidence envelope for the \code{\link[car]{qqPlot}} method assumes an independent random sample 193 | from the t distribution with degrees of freedom equal to the residual degrees of 194 | freedom for the model and so are approximate, because the studentized residuals aren't 195 | independent. 196 | 197 | For additional information, see the vignette 198 | \href{../doc/Diagnostics-for-2SLS-Regression.pdf}{Diagnostics for 2SLS Regression}. 199 | } 200 | \examples{ 201 | kmenta.eq1 <- ivreg(Q ~ P + D | D + F + A, data = Kmenta) 202 | summary(kmenta.eq1) 203 | car::avPlots(kmenta.eq1) 204 | car::mcPlots(kmenta.eq1) 205 | car::crPlots(kmenta.eq1) 206 | car::ceresPlots(kmenta.eq1) 207 | car::influencePlot(kmenta.eq1) 208 | car::influenceIndexPlot(kmenta.eq1) 209 | car::qqPlot(kmenta.eq1) 210 | car::spreadLevelPlot(kmenta.eq1) 211 | plot(effects::predictorEffects(kmenta.eq1, residuals = TRUE)) 212 | set.seed <- 12321 # for reproducibility 213 | confint(car::Boot(kmenta.eq1, R = 250)) # 250 reps for brevity 214 | car::outlierTest(kmenta.eq1) 215 | car::ncvTest(kmenta.eq1) 216 | 217 | } 218 | \seealso{ 219 | \code{\link{ivreg}}, \code{\link[car]{avPlots}}, 220 | \code{\link[car]{crPlots}}, \code{\link[effects]{predictorEffects}}, 221 | \code{\link[car]{qqPlot}}, \code{\link[car]{influencePlot}}, 222 | \code{\link[car]{infIndexPlot}}, \code{\link[car]{Boot}}, 223 | \code{\link[car]{outlierTest}}, \code{\link[car]{spreadLevelPlot}}, 224 | \code{\link[car]{ncvTest}}. 225 | } 226 | -------------------------------------------------------------------------------- /man/ivregMethods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ivregMethods.R 3 | \name{coef.ivreg} 4 | \alias{coef.ivreg} 5 | \alias{ivregMethods} 6 | \alias{vcov.ivreg} 7 | \alias{bread.ivreg} 8 | \alias{estfun.ivreg} 9 | \alias{terms.ivreg} 10 | \alias{model.matrix.ivreg} 11 | \alias{predict.ivreg} 12 | \alias{print.ivreg} 13 | \alias{update.ivreg} 14 | \alias{residuals.ivreg} 15 | \alias{Effect.ivreg} 16 | \alias{formula.ivreg} 17 | \alias{find_formula.ivreg} 18 | \alias{alias.ivreg} 19 | \alias{qr.ivreg} 20 | \alias{vcovHC.ivreg} 21 | \alias{model.matrix.ivreg_projected} 22 | \alias{weights.ivreg} 23 | \title{Methods for \code{"ivreg"} Objects} 24 | \usage{ 25 | \method{coef}{ivreg}(object, component = c("stage2", "stage1"), complete = TRUE, ...) 26 | 27 | \method{vcov}{ivreg}(object, component = c("stage2", "stage1"), complete = TRUE, ...) 28 | 29 | \method{bread}{ivreg}(x, ...) 30 | 31 | \method{estfun}{ivreg}(x, ...) 32 | 33 | \method{vcovHC}{ivreg}(x, ...) 34 | 35 | \method{terms}{ivreg}(x, component = c("regressors", "instruments", "full"), ...) 36 | 37 | \method{model.matrix}{ivreg}( 38 | object, 39 | component = c("regressors", "projected", "instruments"), 40 | ... 41 | ) 42 | 43 | \method{model.matrix}{ivreg_projected}(object, ...) 44 | 45 | \method{predict}{ivreg}( 46 | object, 47 | newdata, 48 | type = c("response", "terms"), 49 | na.action = na.pass, 50 | se.fit = FALSE, 51 | interval = c("none", "confidence", "prediction"), 52 | df = Inf, 53 | level = 0.95, 54 | weights, 55 | ... 56 | ) 57 | 58 | \method{print}{ivreg}(x, digits = max(3, getOption("digits") - 3), ...) 59 | 60 | \method{update}{ivreg}(object, formula., ..., evaluate = TRUE) 61 | 62 | \method{residuals}{ivreg}( 63 | object, 64 | type = c("response", "projected", "regressors", "working", "deviance", "pearson", 65 | "partial", "stage1"), 66 | ... 67 | ) 68 | 69 | \method{Effect}{ivreg}(focal.predictors, mod, ...) 70 | 71 | \method{formula}{ivreg}(x, component = c("complete", "regressors", "instruments"), ...) 72 | 73 | \method{find_formula}{ivreg}(x, ...) 74 | 75 | \method{alias}{ivreg}(object, ...) 76 | 77 | \method{qr}{ivreg}(x, ...) 78 | 79 | \method{weights}{ivreg}(object, type = c("variance", "robustness"), ...) 80 | } 81 | \arguments{ 82 | \item{object, model, mod}{An object of class \code{"ivreg"}.} 83 | 84 | \item{component}{For \code{\link{terms}}, \code{"regressors"}, \code{"instruments"}, or \code{"full"}; 85 | for \code{\link{model.matrix}}, \code{"projected"}, \code{"regressors"}, or \code{"instruments"}; 86 | for \code{\link{formula}}, \code{"regressors"}, \code{"instruments"}, or \code{"complete"}; 87 | for \code{\link{coef}} and \code{\link{vcov}}, \code{"stage2"} or \code{"stage1"}.} 88 | 89 | \item{complete}{If \code{TRUE}, the default, the returned coefficient vector (for \code{coef}) or coefficient-covariance matrix (for \code{vcov}) includes elements for aliased regressors.} 90 | 91 | \item{...}{arguments to pass down.} 92 | 93 | \item{x}{An object of class \code{"ivreg"}.} 94 | 95 | \item{newdata}{Values of predictors for which to obtain predicted values; if missing 96 | predicted (i.e., fitted) values are computed for the data to which the model was fit.} 97 | 98 | \item{type}{For \code{predict}, one of \code{"response"} (the default) or \code{"terms"}; 99 | for \code{residuals}, one of \code{"response"} (the default), \code{"projected"}, \code{"regressors"}, 100 | \code{"working"}, \code{"deviance"}, \code{"pearson"}, or \code{"partial"}; 101 | \code{type = "working"} and \code{"response"} are equivalent, as are 102 | \code{type = "deviance"} and \code{"pearson"}; for \code{weights}, \code{"variance"} (the default) 103 | for invariance-variance weights (which is \code{NULL} for an unweighted fit) 104 | or \code{"robustness"} for robustness weights (available for M or MM estimation).} 105 | 106 | \item{na.action}{\code{na} method to apply to predictor values for predictions; default is \code{\link{na.pass}}.} 107 | 108 | \item{se.fit}{Compute standard errors of predicted values (default \code{FALSE}).} 109 | 110 | \item{interval}{Type of interval to compute for predicted values: \code{"none"} (the default), 111 | \code{"confidence"} for confidence intervals for the expected response, or \code{"prediction"} for 112 | prediction intervals for future observations.} 113 | 114 | \item{df}{For \code{predict}, degrees of freedom for computing t-distribution confidence- or prediction-interval limits; the 115 | default, \code{Inf}, is equivalent to using the normal distribution; if \code{NULL}, 116 | \code{df} is taken from the residual degrees of freedom for the model. 117 | These tests are not to be confused with the \emph{regression diagnostics} provided elsewhere in the \pkg{ivreg} 118 | package: see \code{\link{ivregDiagnostics}}.} 119 | 120 | \item{level}{for confidence or prediction intervals, default \code{0.95}.} 121 | 122 | \item{weights}{Either a numeric vector or a one-sided formula to provide weights for prediction 123 | intervals when the fit is weighted. If \code{weights} and \code{newdata} are missing, the weights 124 | are those used for fitting the model.} 125 | 126 | \item{digits}{For printing.} 127 | 128 | \item{formula.}{To update model.} 129 | 130 | \item{evaluate}{If \code{TRUE}, the default, the updated model is evaluated; if \code{FALSE} the updated call is returned.} 131 | 132 | \item{focal.predictors}{Focal predictors for effect plot, see \code{\link[effects:effect]{Effect}}.} 133 | } 134 | \description{ 135 | Various methods for processing \code{"ivreg"} objects; for diagnostic methods, 136 | see \code{\link{ivregDiagnostics}}. 137 | } 138 | \seealso{ 139 | \code{\link{ivreg}}, \code{\link{ivreg.fit}}, \code{\link{ivregDiagnostics}} 140 | } 141 | -------------------------------------------------------------------------------- /man/summary.ivreg.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/summary.ivreg.R 3 | \name{confint.ivreg} 4 | \alias{confint.ivreg} 5 | \alias{summary.ivreg} 6 | \alias{print.summary.ivreg} 7 | \alias{anova.ivreg} 8 | \alias{Anova.ivreg} 9 | \alias{linearHypothesis.ivreg} 10 | \title{Summary and Inference Methods for \code{"ivreg"} Objects} 11 | \usage{ 12 | \method{confint}{ivreg}( 13 | object, 14 | parm, 15 | level = 0.95, 16 | component = c("stage2", "stage1"), 17 | complete = TRUE, 18 | vcov. = NULL, 19 | df = NULL, 20 | ... 21 | ) 22 | 23 | \method{summary}{ivreg}(object, vcov. = NULL, df = NULL, diagnostics = NULL, ...) 24 | 25 | \method{print}{summary.ivreg}( 26 | x, 27 | digits = max(3, getOption("digits") - 3), 28 | signif.stars = getOption("show.signif.stars"), 29 | ... 30 | ) 31 | 32 | \method{anova}{ivreg}(object, object2, test = "F", vcov. = NULL, ...) 33 | 34 | \method{Anova}{ivreg}(mod, test.statistic = c("F", "Chisq"), vcov. = NULL, ...) 35 | 36 | \method{linearHypothesis}{ivreg}( 37 | model, 38 | hypothesis.matrix, 39 | rhs = NULL, 40 | test = c("F", "Chisq"), 41 | vcov. = NULL, 42 | ... 43 | ) 44 | } 45 | \arguments{ 46 | \item{object, object2, model, mod}{An object of class \code{"ivreg"}.} 47 | 48 | \item{parm}{parameters for which confidence intervals are to be computed; a vector or numbers or names; the default is all parameters.} 49 | 50 | \item{level}{confidence level; the default is \code{0.95}.} 51 | 52 | \item{component}{Character indicating \code{"stage2"} or \code{"stage1"}.} 53 | 54 | \item{complete}{If \code{TRUE}, the default, the returned coefficient vector (for \code{coef}) or coefficient-covariance matrix (for \code{vcov}) includes elements for aliased regressors.} 55 | 56 | \item{vcov.}{Optionally either a coefficient covariance matrix or a function to compute such a covariance 57 | matrix from fitted \code{ivreg} model objects. If \code{NULL} (the default) the standard covariance matrix 58 | (based on the information matrix) is used. Alternatively, covariance matrices (e.g., clustered and/or 59 | heteroscedasticity-consistent) can be plugged in to adjust Wald tests or confidence intervals etc. 60 | In \code{summary}, if \code{diagnostics = TRUE}, \code{vcov.} must be a function (not a matrix) because 61 | the alternative covariances are also needed for certain auxiliary models in the diagnostic tests. 62 | If \code{vcov.} is a function, the \code{...} argument can be used to pass on further arguments to 63 | this function.} 64 | 65 | \item{df}{For \code{summary}, optional residual degrees of freedom to use in computing model summary.} 66 | 67 | \item{...}{arguments to pass down.} 68 | 69 | \item{diagnostics}{Report 2SLS "diagnostic" tests in model summary (default is \code{TRUE}). 70 | These tests are not to be confused with the \emph{regression diagnostics} provided elsewhere in the \pkg{ivreg} 71 | package: see \code{\link{ivregDiagnostics}}.} 72 | 73 | \item{x}{An object of class \code{"summary.ivreg"}.} 74 | 75 | \item{digits}{Minimal number of significant digits for printing.} 76 | 77 | \item{signif.stars}{Show "significance stars" in summary output?} 78 | 79 | \item{test, test.statistic}{Test statistics for ANOVA table computed by \code{anova}, \code{\link[car]{Anova}}, 80 | or \code{\link[car]{linearHypothesis}}. Only \code{test = "F"} is supported by \code{anova}; this is also 81 | the default for \code{Anova} and \code{linearHypothesis}, which also allow \code{test = "Chisq"} for 82 | asymptotic tests.} 83 | 84 | \item{hypothesis.matrix, rhs}{For formulating a linear hypothesis; see the documentation 85 | for \code{\link[car]{linearHypothesis}} for details.} 86 | } 87 | \description{ 88 | Summary method, including Wald tests and (by default) certain diagnostic tests, for 89 | \code{"ivreg"} model objects, as well as other related inference functions. 90 | } 91 | \examples{ 92 | \dontshow{ if(!requireNamespace("sandwich")) { 93 | if(interactive() || is.na(Sys.getenv("_R_CHECK_PACKAGE_NAME_", NA))) { 94 | stop("not all packages required for the example are installed") 95 | } else q() }} 96 | ## data and model 97 | data("CigaretteDemand", package = "ivreg") 98 | m <- ivreg(log(packs) ~ log(rincome) | log(rprice) | salestax, data = CigaretteDemand) 99 | 100 | ## summary including diagnostics 101 | summary(m) 102 | 103 | ## replicate global F test from summary (against null model) "by hand" 104 | m0 <- ivreg(log(packs) ~ 1, data = CigaretteDemand) 105 | anova(m0, m) 106 | 107 | ## or via linear hypothesis test 108 | car::linearHypothesis(m, c("log(rincome)", "log(rprice)")) 109 | 110 | ## confidence intervals 111 | confint(m) 112 | 113 | ## just the Wald tests for the coefficients 114 | library("lmtest") 115 | coeftest(m) 116 | 117 | ## plug in a heteroscedasticity-consistent HC1 covariance matrix (from sandwich) 118 | library("sandwich") 119 | ## - as a function passing additional type argument through ... 120 | coeftest(m, vcov = vcovHC, type = "HC1") 121 | ## - as a function without additional arguments 122 | hc1 <- function(object, ...) vcovHC(object, type = "HC1", ...) 123 | coeftest(m, vcov = hc1) 124 | ## - as a matrix 125 | vc1 <- vcovHC(m, type = "HC1") 126 | coeftest(m, vcov = vc1) 127 | 128 | ## in summary() with diagnostics = TRUE use one of the function specifications, 129 | ## the matrix is only possible when diagnostics = FALSE 130 | summary(m, vcov = vcovHC, type = "HC1") ## function + ... 131 | summary(m, vcov = hc1) ## function 132 | summary(m, vcov = vc1, diagnostics = FALSE) ## matrix 133 | 134 | ## in confint() and anova() any of the three specifications can be used 135 | anova(m0, m, vcov = vcovHC, type = "HC1") ## function + ... 136 | anova(m0, m, vcov = hc1) ## function 137 | anova(m0, m, vcov = vc1) ## matrix 138 | 139 | } 140 | \seealso{ 141 | \code{\link{ivreg}}, \code{\link{ivreg.fit}}, \code{\link{ivregDiagnostics}} 142 | } 143 | -------------------------------------------------------------------------------- /pkgdown/assets/logo_wide.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/pkgdown/assets/logo_wide.png -------------------------------------------------------------------------------- /pkgdown/extra.css: -------------------------------------------------------------------------------- 1 | /* Edit pkgdown/extra.css to customize the theme */ 2 | 3 | /* Color: 4 | * logo-purple: #8709b0; 5 | */ 6 | 7 | @import url('https://fonts.googleapis.com/css?family=Roboto:300,500'); 8 | 9 | body { 10 | font-family: 'Roboto', sans-serif; 11 | font-weight: 300; 12 | } 13 | 14 | /* The "default" hyperlinks: default bright blue, hover pinkish */ 15 | a { color: #8709b0;} 16 | 17 | /* Font size for the content and the navigation bar (top): increase 18 | * font size by a factor of 1.3 (1.3 elements, global) */ 19 | #navbar, div.contents { font-size: 1.3em; } 20 | 21 | #tocnav > ul > li > a:hover { 22 | color: #8709b0; 23 | } 24 | 25 | h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 { 26 | font-family: 'Roboto', sans-serif; 27 | font-weight: 500; 28 | } 29 | 30 | b, strong, th { 31 | font-weight: 500; 32 | } 33 | 34 | .navbar-brand { 35 | background-image: url('logo_wide.png'); 36 | background-repeat: no-repeat; 37 | background-position: 12.5px 5px; 38 | background-size: 110px auto; 39 | width: 200px; 40 | height: 58px; 41 | } 42 | 43 | .navbar-brand > .navbar-link { 44 | opacity: 0; 45 | width: 0; 46 | height: 0; 47 | display: block; 48 | font-size: 1.7em; 49 | line-height: 1em; 50 | width: 110px; 51 | height: 30px; 52 | float: left; 53 | } 54 | 55 | /* Adjust main navigation bar (top) to match the size of the 56 | * branding/logo */ 57 | .navbar-brand > .label { 58 | display: block; 59 | margin-left: 110px; 60 | margin-top: 14px; 61 | font-weight: normal; 62 | background-color: transparent; 63 | /*color: #8709b0;*/ 64 | color: #777; 65 | } 66 | 67 | /* Make the logo slightly smaller to avoid line breaks 68 | * on the collapsed view */ 69 | @media all and (max-width: 250px) { 70 | .navbar-brand { 71 | width: 110px; 72 | background-size: 100px; 73 | background-position: 10px 5px; 74 | height: 39px; 75 | } 76 | .navbar-brand > .navbar-link { height: 25px; width: 100px; } 77 | .navbar-brand > .label { margin-top: 10px; margin-left: 100px; } 78 | } 79 | 80 | .navbar .navbar-nav > li > a { 81 | margin: 11px 0.5em; 82 | padding: 8px 8px; 83 | } 84 | .navbar > .navbar-nav > li.dropdown.open > a, 85 | .navbar > .navbar-nav > li.dropdown.open:hover, 86 | .navbar > .navbar-nav > li.dropdown.open > a:hover { 87 | background-color: transparent; 88 | } 89 | 90 | .dropdown-menu > li { 91 | background-color: white; 92 | } 93 | .dropdown-menu > li > a:hover { 94 | color: #8709b0; 95 | } 96 | .navbar .navbar-nav > li:hover, 97 | .navbar .navbar-nav > li.dropdown:hover { 98 | background-color: #8709b0; 99 | } 100 | .navbar .navbar-nav > li > a:hover, .navbar .navbar-nav > li.dropdown > a:hover, 101 | .navbar .navbar-nav > li:hover > a, .navbar .navbar-nav > li.dropdown:hover > a { 102 | background-color: #8709b0; 103 | color: white; 104 | } 105 | .navbar .navbar-nav > .active { 106 | background-color: #ececec; 107 | } 108 | .navbar .navbar-nav > .active:hover { 109 | background-color: #8709b0; 110 | } 111 | .navbar .navbar-nav > .active:hover > *, 112 | .navbar .navbar-nav > .active > a:hover { 113 | color: white; 114 | background-color: transparent; 115 | } 116 | .navbar .navbar-nav > li.dropdown.open:hover, 117 | .navbar .navbar-nav > li.dropdown:hover { 118 | background-color: #8709b0; 119 | } 120 | .navbar .navbar-nav > li.dropdown.open:hover, 121 | .navbar .navbar-nav > li.dropdown:hover, 122 | .navbar .navbar-nav > li.dropdown > *:hover { 123 | color: white; 124 | } 125 | .navbar .navbar-nav > .active > a, 126 | .navbar .navbar-nav > .active > a:hover { 127 | background-color: transparent; 128 | } 129 | 130 | 131 | div#overview div.page-header h1 { 132 | margin-top: 22px; 133 | padding: 0; 134 | font-size: 250%; 135 | color: dimgray; 136 | } 137 | 138 | div#system-requirements th { 139 | text-align: center; 140 | } 141 | 142 | div.page-header h1 { 143 | font-size: 250%; 144 | color: dimgray; 145 | } 146 | 147 | div.page-header h4 { 148 | padding-top: 10px; 149 | font-size: 120%; 150 | } 151 | 152 | div.contents h1 { 153 | color: dimgray; 154 | font-size: 200%; 155 | padding-top: 80px; 156 | } 157 | 158 | div.contents h2 { 159 | font-size: 150%; 160 | padding-top: 70px; 161 | } 162 | 163 | div.contents h3 { 164 | font-size: 120%; 165 | padding-top: 60px; 166 | } 167 | 168 | div.contents h4 { 169 | font-size: 100%; 170 | padding-top: 60px; 171 | } 172 | 173 | pre { 174 | overflow-x: auto; 175 | font-size: 80%; 176 | line-height: 150%; 177 | } 178 | -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-120x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/pkgdown/favicon/apple-touch-icon-120x120.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-152x152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/pkgdown/favicon/apple-touch-icon-152x152.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-180x180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/pkgdown/favicon/apple-touch-icon-180x180.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-60x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/pkgdown/favicon/apple-touch-icon-60x60.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-76x76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/pkgdown/favicon/apple-touch-icon-76x76.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/pkgdown/favicon/apple-touch-icon.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/pkgdown/favicon/favicon-16x16.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/pkgdown/favicon/favicon-32x32.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/pkgdown/favicon/favicon.ico -------------------------------------------------------------------------------- /pkgdown/logo-favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeileis/ivreg/7105f6c095dd3dd36c2051d4f3a6573fa13c3678/pkgdown/logo-favicon.png -------------------------------------------------------------------------------- /pkgdown/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 20 | 22 | 25 | 29 | 33 | 34 | 44 | 45 | 67 | 69 | 70 | 72 | image/svg+xml 73 | 75 | 76 | 77 | 78 | 79 | 84 | ivreg 97 | 98 | 99 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library("testthat") 2 | library("ivreg") 3 | 4 | test_check("ivreg") 5 | -------------------------------------------------------------------------------- /tests/testthat/test-case-deletion.R: -------------------------------------------------------------------------------- 1 | m <- ivreg(Q ~ P + D | D + F + A, data=Kmenta) 2 | m1 <- update(m, subset = -1) 3 | test_that("dfbeta computed correctly 1", { 4 | expect_equal(dfbeta(m)[1, ], coef(m) - coef(m1)) 5 | }) 6 | 7 | m.ivreg <- ivreg(Q ~ P + D | P + D, data=Kmenta) # OLS 8 | m.lm <- lm(Q ~ P + D, data=Kmenta) 9 | 10 | test_that("hatvalues computed correctly", { 11 | expect_equal(as.vector(hatvalues(m.ivreg)), as.vector(hatvalues(m.lm))) 12 | }) 13 | 14 | test_that("Cook's distances computed correctly", { 15 | expect_equal(cooks.distance(m.ivreg), cooks.distance(m.lm)) 16 | }) 17 | 18 | test_that("dfbeta computed correctly 2", { 19 | expect_equal(dfbeta(m.ivreg), dfbeta(m.lm)) 20 | }) 21 | 22 | Kmenta2 <- Kmenta 23 | Kmenta2$Q[c(1, 4, 10)] <- NA 24 | m.miss <- update(m, data=Kmenta2, na.action=na.exclude) 25 | 26 | test_that("deletion statistics computed correctly with na.exclude", { 27 | expect_true(all(is.na(hatvalues(m.miss)[c(1, 4, 10)]))) 28 | expect_true(all(is.na(residuals(m.miss)[c(1, 4, 10)]))) 29 | expect_true(all(is.na(fitted(m.miss)[c(1, 4, 10)]))) 30 | expect_true(all(is.na(rstudent(m.miss)[c(1, 4, 10)]))) 31 | expect_true(all(is.na(dffits(m.miss)[c(1, 4, 10)]))) 32 | expect_true(all(is.na(cooks.distance(m.miss)[c(1, 4, 10)]))) 33 | expect_true(all(is.na(dfbeta(m.miss)[c(1, 4, 10), ]))) 34 | }) 35 | 36 | m.miss.2<- update(m, data=Kmenta2) 37 | nms <- rownames(Kmenta)[-c(1, 4, 10)] 38 | test_that("rownames of deletion statistics preserved with na.omit", { 39 | expect_equal(names(hatvalues(m.miss.2)), nms) 40 | expect_equal(names(residuals(m.miss.2)), nms) 41 | expect_equal(names(fitted(m.miss.2)), nms) 42 | expect_equal(names(rstudent(m.miss.2)), nms) 43 | expect_equal(names(dffits(m.miss.2)), nms) 44 | expect_equal(names(cooks.distance(m.miss.2)), nms) 45 | expect_equal(rownames(dfbeta(m.miss.2)), nms) 46 | }) 47 | 48 | m.ivreg.w <- ivreg(Q ~ P + D | P + D, weights=Q, data=Kmenta) # WLS 49 | m.lm.w <- lm(Q ~ P + D, data=Kmenta, weights=Q) 50 | 51 | test_that("hatvalues computed correctly with weights", { 52 | expect_equal(as.vector(hatvalues(m.ivreg.w)), as.vector(hatvalues(m.lm.w))) 53 | }) 54 | 55 | test_that("Cook's distances computed correctly with weights", { 56 | expect_equal(cooks.distance(m.ivreg.w), cooks.distance(m.lm.w)) 57 | }) 58 | 59 | test_that("rstudent computed correctly", { 60 | expect_equal(rstudent(m.ivreg), rstudent(m.lm)) 61 | }) 62 | 63 | mw <- ivreg(Q ~ P + D | D + F + A, weights=Q, data=Kmenta) 64 | m1w <- update(mw, subset = -10) 65 | test_that("dfbeta computed correctly with weights", { 66 | expect_equal(dfbeta(mw)[10, ], coef(mw) - coef(m1w)) 67 | }) 68 | 69 | test_that("rstudent computed correctly with weights", { 70 | expect_equal(rstudent(m.ivreg.w), rstudent(m.lm.w)) 71 | }) 72 | 73 | test_that("influence measures computed correctly in paralllel", { 74 | expect_equal(influence(m), influence(m, ncores=2)) 75 | }) 76 | 77 | -------------------------------------------------------------------------------- /tests/testthat/test-ivreg.R: -------------------------------------------------------------------------------- 1 | m.fitivreg <- with(Kmenta, ivreg.fit(cbind(1, P, D), Q, cbind(1, D, F, A))) 2 | m.ivreg <- ivreg(Q ~ P + D | D + F + A, data=Kmenta) 3 | 4 | test_that("2SLS coefficients are computed correctly", { 5 | expect_equal(as.vector(coef(m.fitivreg)), as.vector(coef(m.ivreg))) 6 | }) 7 | 8 | test_that("2SLS coefficient covariance matrix is computed correctly", { 9 | expect_equal(as.vector(m.fitivreg$sigma^2*m.fitivreg$cov.unscaled), as.vector(vcov(m.ivreg))) 10 | }) 11 | -------------------------------------------------------------------------------- /tests/testthat/test-ivreg.fit.R: -------------------------------------------------------------------------------- 1 | 2 | m.ivreg <- with(Kmenta, ivreg.fit(cbind(1, P, D), Q, cbind(1, D, F, A))) 3 | m.stage1 <- lm(cbind(1, P, D) ~ cbind(1, D, F, A) - 1, data=Kmenta) 4 | m.stage2 <- lm(Kmenta$Q ~ fitted(m.stage1) - 1) 5 | 6 | 7 | test_that("2SLS coefficients are computed correctly", { 8 | expect_equal(as.vector(coef(m.ivreg)), as.vector(coef(m.stage2))) 9 | }) 10 | 11 | se.ivreg <- as.vector(sqrt(diag(m.ivreg$sigma^2*m.ivreg$cov.unscaled))) 12 | se <- as.vector(sqrt(diag(vcov(m.stage2)))) 13 | residuals <- as.vector(with(Kmenta, Q - cbind(1, P, D) %*% coef(m.stage2))) 14 | se <- sqrt(sum(residuals^2)/(nrow(Kmenta) - 3))*se/sigma(m.stage2) 15 | 16 | test_that("2SLS coefficient standard errors are computed correctly", { 17 | expect_equal(se.ivreg, se) 18 | }) 19 | 20 | test_that("model residuals are computed correctly", { 21 | expect_equal(residuals, residuals(m.ivreg)) 22 | }) 23 | 24 | 25 | m.ivreg.w <- with(Kmenta, ivreg.fit(cbind(1, P, D), Q, cbind(1, D, F, A), weights=Q)) 26 | m.stage1.w <- lm(cbind(1, P, D) ~ cbind(1, D, F, A) - 1, weights=Q, data=Kmenta) 27 | m.stage2.w <- lm(Kmenta$Q ~ fitted(m.stage1.w) - 1, weights=Kmenta$Q) 28 | 29 | test_that("2SLS coefficients are computed correctly with weights", { 30 | expect_equal(as.vector(coef(m.ivreg.w)), as.vector(coef(m.stage2.w))) 31 | }) 32 | 33 | se.ivreg.w <- as.vector(sqrt(diag(m.ivreg.w$sigma^2*m.ivreg.w$cov.unscaled))) 34 | se.w <- as.vector(sqrt(diag(vcov(m.stage2.w)))) 35 | residuals <- as.vector(with(Kmenta, Q - cbind(1, P, D) %*% coef(m.stage2.w))) 36 | se.w <- sqrt(sum(Kmenta$Q*residuals^2)/(nrow(Kmenta) - 3))*se.w/sigma(m.stage2.w) 37 | 38 | test_that("2SLS coefficient standard errors are computed correctly with weights", { 39 | expect_equal(se.ivreg.w, se.w) 40 | }) 41 | -------------------------------------------------------------------------------- /tests/testthat/test-predict.R: -------------------------------------------------------------------------------- 1 | deq <- ivreg(Q ~ P + D | D + F + A, data=Kmenta) 2 | new <- expand.grid(P = seq(90, 110, by=20), D = seq(75, 125, by=20), 3 | F=c(70, 110), A=c(1, 20)) 4 | pr <- predict(deq, newdata=new, se.fit=TRUE, interval="prediction") 5 | X <- as.matrix(cbind(1, new[, c("P", "D")])) 6 | yhat <- X %*% coef(deq) 7 | se <- sqrt(diag(X %*% vcov(deq) %*% t(X))) 8 | t <- qt(.025, Inf, lower.tail=FALSE) 9 | lower <- yhat - t*sqrt(se^2 + sigma(deq)^2) 10 | upper <- yhat + t*sqrt(se^2 + sigma(deq)^2) 11 | test_that("predicted values, their std. errors, and prediction intervals are computed correctly", { 12 | expect_equal(as.vector(cbind(yhat, se, lower, upper)), as.vector(pr)) 13 | }) 14 | -------------------------------------------------------------------------------- /tests/testthat/test-robust-2SLS.R: -------------------------------------------------------------------------------- 1 | if (require(MASS)){ 2 | 3 | Kmenta1 <- Kmenta 4 | Kmenta1[20, "Q"] <- 95 # corrupted data 5 | deqr1 <- ivreg(Q ~ P + D | D + F + A, data=Kmenta1, method="MM") 6 | stg1 <- rlm(P ~ D + F + A, data=Kmenta1, method="MM") 7 | Kmenta1$P.hat <- fitted(stg1) 8 | stg2 <- rlm(Q ~ P.hat + D, data=Kmenta1, method="MM") 9 | 10 | test_that("robust 2SLS coefficients are computed correctly", { 11 | expect_equal(coef(deqr1), coef(stg2), check.attributes=FALSE) 12 | }) 13 | 14 | test_that("hatvalues are computed correctly for robust 2SLS, stage 2",{ 15 | hats <- c(hatvalues(lm(residuals(stg2) ~ model.matrix(stg2) - 1, weights=stg2$w)), 0) 16 | names(hats)[20] <- "1941" 17 | expect_equal(hats, hatvalues(deqr1)) 18 | }) 19 | 20 | test_that("hatvalues are computed correctly for robust 2SLS, stage 1",{ 21 | expect_equal(hatvalues(stg1), hatvalues(deqr1, type="stage1")) 22 | }) 23 | 24 | } 25 | -------------------------------------------------------------------------------- /tests/testthat/test-stage1.R: -------------------------------------------------------------------------------- 1 | set.seed(123) 2 | z1 <- rnorm(100) 3 | z2 <- rnorm(100) 4 | z3 <- rnorm(100) 5 | x1 <- z1 + z2 + rnorm(100) 6 | x2 <- z2 + z3 + rnorm(100) 7 | y <- 10 + z1 + x1 + x2 + rnorm(100) 8 | 9 | D <- data.frame(z1, z2, z3, x1, x2, y, const=1) 10 | 11 | m1 <- ivreg(y ~ z1 + x1 + x2 | z1 + z2 + z3, data=D) 12 | ml1 <- lm(cbind(x1, x2) ~ z1 + z2 + z3, data=D) 13 | 14 | test_that("stage1 coefficients are computed correctly", { 15 | expect_equal(as.vector(coef(m1, component="stage1")), as.vector(coef(ml1))) 16 | }) 17 | 18 | test_that("stage1 coefficient covariances are computed correctly", { 19 | expect_equal(vcov(m1, component="stage1"), vcov(ml1)) 20 | }) 21 | 22 | m2 <- ivreg(y ~ z1 + x1 + x2 + const | z1 + z2 + z3 + const, data=D) 23 | ml2 <- lm(cbind(x1, x2) ~ z1 + z2 + z3 + const, data=D) 24 | 25 | test_that("stage1 rank-deficient coefficients are computed correctly", { 26 | expect_equal(as.vector(coef(m2, component="stage1")), as.vector(coef(ml2))) 27 | }) 28 | 29 | test_that("stage1 rank-deficient coefficient covariances are computed correctly", { 30 | expect_equal(vcov(m2, component="stage1"), vcov(ml2)) 31 | }) 32 | 33 | test_that("stage1 rank-deficient coefficients are computed correctly, complete=FALSE", { 34 | expect_equal(as.vector(coef(m2, component="stage1", complete=FALSE)), 35 | as.vector(coef(ml2, complete=FALSE))) 36 | }) 37 | 38 | test_that("stage1 rank-deficient coefficient covariances are computed correctly, rank=FALSE", { 39 | expect_equal(vcov(m2, component="stage1", complete=FALSE), 40 | vcov(ml2, complete=FALSE)) 41 | }) 42 | 43 | 44 | y2 <- 10 + z1 + x1 + rnorm(100) 45 | 46 | D2 <- data.frame(z1, z2, z3, x1, y, const=1) 47 | 48 | m3 <- ivreg(y2 ~ z1 + x1 | z1 + z2 + z3, data=D2) 49 | ml3 <- lm(x1 ~ z1 + z2 + z3, data=D) 50 | 51 | test_that("stage1 coefficients are computed correctly with one endog x", { 52 | expect_equal(as.vector(coef(m3, component="stage1")), as.vector(coef(ml3))) 53 | }) 54 | 55 | test_that("stage1 coefficient covariances are computed correctly with one endog x", { 56 | expect_equal(vcov(m3, component="stage1"), vcov(ml3)) 57 | }) 58 | 59 | m4 <- ivreg(y2 ~ z1 + x1 + const | z1 + z2 + z3 + const, data=D) 60 | ml4 <- lm(x1 ~ z1 + z2 + z3 + const, data=D) 61 | 62 | test_that("stage1 rank-deficient coefficients are computed correctly with one endog x", { 63 | expect_equal(as.vector(coef(m4, component="stage1")), as.vector(coef(ml4))) 64 | }) 65 | 66 | test_that("stage1 rank-deficient coefficient covariances are computed correctly with one endog x", { 67 | expect_equal(vcov(m4, component="stage1"), vcov(ml4)) 68 | }) 69 | 70 | test_that("stage1 rank-deficient coefficients are computed correctly with one endog x, complete=FALSE", { 71 | expect_equal(as.vector(coef(m4, component="stage1", complete=FALSE)), 72 | as.vector(coef(ml4, complete=FALSE))) 73 | }) 74 | 75 | test_that("stage1 rank-deficient coefficient covariances are computed correctly with one endog x, rank=FALSE", { 76 | expect_equal(vcov(m4, component="stage1", complete=FALSE), 77 | vcov(ml4, complete=FALSE)) 78 | }) 79 | -------------------------------------------------------------------------------- /tests/testthat/test-vcov.R: -------------------------------------------------------------------------------- 1 | ## packages 2 | library("ivreg") 3 | library("lmtest") 4 | library("sandwich") 5 | 6 | ## data and models: full vs. trivial 7 | data("CigaretteDemand", package = "ivreg") 8 | m <- ivreg(log(packs) ~ log(rincome) | log(rprice) | salestax, data = CigaretteDemand) 9 | m0 <- ivreg(log(packs) ~ 1, data = CigaretteDemand) 10 | 11 | ## heteroscedasticity-consistent HC1 covariance _matrix_ on full model 12 | vc1 <- vcovHC(m, type = "HC1") 13 | 14 | ## custom HC1 covariance _function_ 15 | hc1 <- function(object, ...) vcovHC(object, type = "HC1", ...) 16 | 17 | ## confint 18 | test_that("confidence intervals are equal with vcov function and matrix", { 19 | expect_equal(confint(m, vcov = hc1), confint(m, vcov = vc1)) 20 | }) 21 | test_that("confidence intervals are equal with vcov function and function + ...", { 22 | expect_equal(confint(m, vcov = hc1), confint(m, vcov = vcovHC, type = "HC1")) 23 | }) 24 | 25 | ## coeftest 26 | test_that("confidence intervals are equal with vcov function and matrix", { 27 | expect_equal(coeftest(m, vcov = hc1), coeftest(m, vcov = vc1)) 28 | }) 29 | test_that("coefficient tests are equal with vcov function and function + ...", { 30 | expect_equal(coeftest(m, vcov = hc1), coeftest(m, vcov = vcovHC, type = "HC1")) 31 | }) 32 | 33 | ## anova 34 | test_that("analysis of variance is equal with vcov function and matrix", { 35 | expect_equal(anova(m0, m, vcov = hc1), anova(m0, m, vcov = vc1)) 36 | }) 37 | test_that("analysis of variance is equal with vcov function and function + ...", { 38 | expect_equal(anova(m0, m, vcov = hc1), anova(m0, m, vcov = vcovHC, type = "HC1")) 39 | }) 40 | 41 | ## summary 42 | test_that("model summary (w/o diagnostics) is equal with vcov function and matrix", { 43 | expect_equal(summary(m, vcov = hc1, diagnostics = FALSE), summary(m, vcov = vc1, diagnostics = FALSE)) 44 | }) 45 | test_that("model summary (w/o diagnostics) is equal with vcov function and function + ...", { 46 | expect_equal(summary(m, vcov = hc1, diagnostics = FALSE), summary(m, vcov = vcovHC, type = "HC1", diagnostics = FALSE)) 47 | }) 48 | test_that("model summary is equal with vcov function and function + ...", { 49 | expect_equal(summary(m, vcov = hc1), summary(m, vcov = vcovHC, type = "HC1")) 50 | }) 51 | -------------------------------------------------------------------------------- /vignettes/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | *.R 3 | -------------------------------------------------------------------------------- /vignettes/ivreg.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "ivreg: Two-Stage Least-Squares Regression with Diagnostics" 3 | author: "John Fox, Christian Kleiber, Achim Zeileis" 4 | date: "last modified: 2024-04-20" 5 | output: 6 | rmarkdown::html_vignette: 7 | highlight: monochrome 8 | toc: true 9 | vignette: > 10 | %\VignetteIndexEntry{ivreg: Two-Stage Least-Squares Regression with Diagnostics} 11 | %\VignetteEngine{knitr::rmarkdown} 12 | %\VignetteDepends{ivreg,car,effects,sandwich,modelsummary} 13 | %\VignetteKeywords{two-stage least squares, instrumental variables, diagnostics} 14 | %\VignettePackage{ivreg} 15 | %\VignetteEncoding{UTF-8} 16 | --- 17 | 18 | ```{r setup, include=FALSE} 19 | knitr::opts_chunk$set(echo = TRUE, fig.height=4, fig.width=4) 20 | ``` 21 | 22 | ## Overview 23 | 24 | The **ivreg** package provides a comprehensive implementation of instrumental variables 25 | regression using two-stage least-squares (2SLS) estimation. The standard 26 | regression functionality (parameter estimation, inference, robust covariances, 27 | predictions, etc.) is derived from and supersedes the `ivreg()` function in the 28 | [**AER**](https://CRAN.R-project.org/package=AER) package. Additionally, various 29 | regression diagnostics are supported, including hat values, deletion diagnostics such 30 | as studentized residuals and Cook's distances; graphical diagnostics such as 31 | component-plus-residual plots and added-variable plots; and effect plots with partial 32 | residuals. 33 | 34 | In order to provide all of this functionality the **ivreg** package integrates 35 | seamlessly with other packages by providing suitable S3 methods, specifically for generic functions in the 36 | [base-R](https://www.R-project.org/) **stats** package, and in the 37 | [**car**](https://CRAN.R-project.org/package=car), 38 | [**effects**](https://CRAN.R-project.org/package=effects), 39 | [**lmtest**](https://CRAN.R-project.org/package=lmtest), and 40 | [**sandwich**](https://CRAN.R-project.org/package=sandwich) packages, 41 | among others. 42 | 43 | The package is accompanied by two online vignettes, namely this introduction and an 44 | article introducing the regression diagnostics and graphics: 45 | 46 | * [ivreg: Two-Stage Least-Squares Regression with Diagnostics](https://zeileis.github.io/ivreg/articles/ivreg.html) 47 | * [Diagnostics for 2SLS Regression](https://zeileis.github.io/ivreg/articles/Diagnostics-for-2SLS-Regression.html) 48 | 49 | 50 | 51 | ## Installation 52 | 53 | The stable release version of [**ivreg**](https://CRAN.R-project.org/package=ivreg) 54 | is hosted on the Comprehensive R Archive Network 55 | (CRAN) at and can be installed along with all 56 | dependencies via 57 | 58 | ```{r installation-cran, eval=FALSE} 59 | install.packages("ivreg", dependencies = TRUE) 60 | ``` 61 | 62 | The development version of **ivreg** is hosted on GitHub at . 63 | It can be conveniently installed via the `install_github()` function in the 64 | [**remotes**](https://CRAN.R-project.org/package=remotes) package: 65 | 66 | ```{r installation-rforge, eval=FALSE} 67 | remotes::install_github("https://github.com/zeileis/ivreg/") 68 | ``` 69 | 70 | ## Instrumental variables regression 71 | 72 | The main function in the **ivreg** package is `ivreg()`, which is a high-level 73 | formula interface to the work-horse `ivreg.fit()` function; both functions return 74 | a list of quantities similar to that returned by `lm()` (including coefficients, coefficient variance-covariance 75 | matrix, residuals, etc.). In the case of `ivreg()`, the returned list is of class `"ivreg"`, 76 | for which a wide range of standard methods is available, including `print()`, 77 | `summary()`, `coef()`, `vcov()`, `anova()`, `predict()`, `residuals()`, `terms()`, 78 | `model.matrix()`, `formula()`, `update()`, `hatvalues()`, `dfbeta()`, and `rstudent()`. 79 | Moreover, methods for functionality from other packages is provided, 80 | and is described in more detail in a companion vignette. 81 | 82 | Regressors and instruments for `ivreg()` are most easily specified in a 83 | formula with two parts on the right-hand side, for example, `y ~ x1 + x2 | x1 + z1 + z2`, 84 | where `x1` and `x2` are, respectively, exogenous and endogenous explanatory variables, and `x1`, `z1`, and `z2` are 85 | instrumental variables. Both components on the right-hand side of the model formula include 86 | an implied intercept, unless, as in a linear model estimated by `lm()`, the intercept is 87 | explicitly excluded via `-1`. Exogenous explanatory variables, such as `x1` in the example, 88 | must be included among the instruments. A worked example is described immediately below. 89 | As listing exogenous variables in both parts on the right-hand side of the formula 90 | may become tedious if there are many of them, an additional convenience option is to 91 | use a three-part right side like `y ~ x1 | x2 | z1 + z2`, listing the exogenous, endogenous, 92 | and instrumental variables (for the endogenous variables only), respectively. 93 | 94 | 95 | ## Illustration: Returns to schooling 96 | 97 | As an initial demonstration of the **ivreg** package, we investigate 98 | the effect of schooling on earnings in a classical model for wage determination. 99 | The data are from the United States, and are provided in the package as 100 | `SchoolingReturns`. This data set was originally studied by David Card, and was subsequently 101 | employed, as here, to illustrate 2SLS estimation in introductory econometrics textbooks. The relevant variables for this 102 | illustration are: 103 | 104 | ```{r data} 105 | data("SchoolingReturns", package = "ivreg") 106 | summary(SchoolingReturns[, 1:8]) 107 | ``` 108 | 109 | A standard wage equation uses a semi-logarithmic linear regression for `wage`, estimated by 110 | ordinary least squares (OLS), with years of `education` as the primary explanatory variable, 111 | adjusting for a quadratic term in labor-market `experience`, as well as for factors 112 | coding `ethnicity`, residence in a city (`smsa`), and residence in the U.S. `south`: 113 | 114 | ```{r lm} 115 | m_ols <- lm(log(wage) ~ education + poly(experience, 2) + ethnicity + smsa + south, 116 | data = SchoolingReturns) 117 | summary(m_ols) 118 | ``` 119 | 120 | Thus, OLS estimation yields an estimate of `r round(100 * coef(m_ols)["education"], digits = 1)`% 121 | per year for returns to schooling. This estimate is problematic, however, because it can be argued 122 | that `education` is endogenous (and hence also `experience`, which is taken to be `age` minus 123 | `education` minus 6). We therefore use geographical proximity to a college when growing 124 | up as an exogenous instrument for `education`. Additionally, `age` is the natural 125 | exogenous instrument for `experience`, while the remaining explanatory variables can be considered 126 | exogenous and are thus used as instruments for themselves. 127 | Although it's a useful strategy to select an effective instrument or instruments for each endogenous 128 | explanatory variable, in 2SLS regression all of the instrumental variables are used to estimate all 129 | of the regression coefficients in the model. 130 | 131 | To fit this model with `ivreg()` we can simply extend the formula from `lm()` above, adding a second part after the `|` separator to specify the instrumental variables: 132 | 133 | ```{r ivreg} 134 | library("ivreg") 135 | m_iv <- ivreg(log(wage) ~ education + poly(experience, 2) + ethnicity + smsa + south | 136 | nearcollege + poly(age, 2) + ethnicity + smsa + south, 137 | data = SchoolingReturns) 138 | ``` 139 | 140 | Equivalently, the same model can also be specified slightly more concisely using three parts on the 141 | right-hand side indicating the exogenous variables, the endogenous variables, and the additional 142 | instrumental variables only (in addition to the exogenous variables). 143 | 144 | ```{r ivreg-alternative, eval=FALSE} 145 | m_iv <- ivreg(log(wage) ~ ethnicity + smsa + south | education + poly(experience, 2) | 146 | nearcollege + poly(age, 2), data = SchoolingReturns) 147 | ``` 148 | 149 | Both models yield the following results: 150 | 151 | ```{r ivreg-summary} 152 | summary(m_iv) 153 | ``` 154 | 155 | Thus, using two-stage least squares to estimate the regression yields a much larger 156 | coefficient for the returns to schooling, namely `r round(100 * coef(m_iv)["education"], digits = 1)`% per year. 157 | Notice as well that the standard errors of the coefficients are larger for 2SLS estimation 158 | than for OLS, and that, partly as a consequence, evidence for the effects of `ethnicity` 159 | and the quadratic component of `experience` is now weak. These differences are brought 160 | out more clearly when showing coefficients and standard errors side by side, e.g., using the 161 | `compareCoefs()` function from the **car** package or the `msummary()` function from the 162 | [**modelsummary**](https://CRAN.R-project.org/package=modelsummary) package: 163 | 164 | ```{r modelsummary, message=FALSE} 165 | library("modelsummary") 166 | m_list <- list(OLS = m_ols, IV = m_iv) 167 | msummary(m_list) 168 | ``` 169 | 170 | The change in coefficients and associated standard errors can also be brought out graphically 171 | using the `modelplot()` function from **modelsummary** which shows the coefficient estimates 172 | along with their 95% confidence intervals. Below we omit the intercept and experience terms 173 | as these are on a different scale than the other coefficients. 174 | 175 | ```{r modelplot, fig.height=5, fig.width = 7} 176 | modelplot(m_list, coef_omit = "Intercept|experience") 177 | ``` 178 | -------------------------------------------------------------------------------- /vignettes/ivreg.bib: -------------------------------------------------------------------------------- 1 | @Book{BelsleyKuhWelsch1980, 2 | title = {Regression Diagnostics: Identifying Influential Data and Sources of Collinearity}, 3 | author = {D. A. Belsley and E. Kuh and R. E. Welsch}, 4 | publisher = {John Wiley \& Sons}, 5 | address = {New York}, 6 | year = {1980}, 7 | doi = {10.1002/0471725153}, 8 | } 9 | 10 | @Article{Basmann1957, 11 | title = {A Generalized Classical Method of Linear Estimation of Coefficients in a Structural Equation}, 12 | author = {R. L. Basmann}, 13 | journal = {Econometrica}, 14 | volume = {25}, 15 | pages = {77--83}, 16 | year = {1957}, 17 | doi = {10.2307/1907743}, 18 | } 19 | 20 | @Book{Theil1971, 21 | title = {Principles of Econometrics}, 22 | author = {H. Theil}, 23 | publisher = {John Wiley \& Sons}, 24 | address = {New York}, 25 | year = {1971}, 26 | } 27 | 28 | @Article{Fox1979, 29 | title = {Simultaneous Equation Models and Two-Stage Least Squares}, 30 | author = {J. Fox}, 31 | journal = {Sociological Methodology}, 32 | volume = {10}, 33 | pages = {130--150}, 34 | year = {1979}, 35 | doi = {10.2307/270769}, 36 | } 37 | 38 | @Book{Greene2003, 39 | title = {Econometric Analysis}, 40 | author = {W. H. Greene}, 41 | year = {2003}, 42 | publisher = {Prentice Hall}, 43 | address = {Upper Saddle River}, 44 | edition = {5th}, 45 | } 46 | 47 | @Article{Phillips1977, 48 | title = {Recursions for the Two-Stage Least-Squares Estimators}, 49 | author = {G. D. A. Phillips}, 50 | journal = {Journal of Econometrics}, 51 | volume = {6}, 52 | pages = {65--77}, 53 | year = {1977}, 54 | doi = {10.1016/0304-4076(77)90055-0}, 55 | } 56 | 57 | @Article{Pregibon1981, 58 | title = {Logistic Regression Diagnostics}, 59 | author = {D. Pregibon}, 60 | journal = {The Annals of Statistics}, 61 | volume = {9}, 62 | pages = {705--724}, 63 | year = {1981}, 64 | doi = {10.1214/aos/1176345513}, 65 | } 66 | 67 | @Book{Kmenta1986, 68 | title = {Elements of Econometrics}, 69 | edition = {2nd}, 70 | author = {J. Kmenta}, 71 | publisher = {Macmillan}, 72 | address = {New York}, 73 | year = {1986}, 74 | } 75 | 76 | @Article{Cook1993, 77 | title = {Exploring Partial Residual Plots}, 78 | author = {R. D. Cook}, 79 | journal = {Technometrics}, 80 | volume = {35}, 81 | pages = {351--362}, 82 | year = {1993}, 83 | doi = {10.1080/00401706.1993.10485350}, 84 | } 85 | 86 | @Article{CookCroosDabrera1998, 87 | author = {R. D. Cook and R. Croos-Dabrera}, 88 | year = {1998}, 89 | title = {Partial Residual Plots in Generalized Linear Models}, 90 | journal = {Journal of the American Statistical Association}, 91 | volume = {93}, 92 | pages = {730--739}, 93 | doi = {10.1080/01621459.1998.10473725}, 94 | } 95 | 96 | @Article{FoxWeisberg2018, 97 | title = {Visualizing Fit and Lack of Fit in Complex Regression Models with Predictor Effect Plots and Partial Residuals}, 98 | author = {J. Fox and S. Weisberg}, 99 | year = {2018}, 100 | journal = {Journal of Statistical Software}, 101 | volume = {87}, 102 | number = {9}, 103 | pages = {1--27}, 104 | doi = {10.18637/jss.v087.i09}, 105 | } 106 | 107 | @Book{Fox2016, 108 | title = {Applied Regression Analysis and Generalized Linear Models}, 109 | edition = {3rd}, 110 | author = {J. Fox}, 111 | publisher = {Sage}, 112 | address = {Thousand Oaks}, 113 | year = {2016}, 114 | } 115 | 116 | @Book{Tukey1977, 117 | author = {J. W. Tukey}, 118 | year = {1977}, 119 | title = {Exploratory Data Analysis}, 120 | publisher = {Addison-Wesley}, 121 | address = {Reading}, 122 | } 123 | 124 | @Article{BreuschPagan1979, 125 | title = {A Simple Test for Heteroscedasticity and Random Coefficient Variation}, 126 | author = {T. S. Breusch and A. R. Pagan}, 127 | journal = {Econometrica}, 128 | volume = {47}, 129 | pages = {1287--1294}, 130 | year = {1979}, 131 | doi = {10.2307/1911963}, 132 | } 133 | 134 | @Article{CookWeisberg1983, 135 | title = {Diagnostics for Heteroscedasticity in Regression}, 136 | author = {R. D. Cook and S. Weisberg}, 137 | journal = {Biometrika}, 138 | volume = {70}, 139 | pages = {1--10}, 140 | year = {1983}, 141 | doi = {10.1093/biomet/70.1.1}, 142 | } 143 | 144 | @InProceedings{Huber1967, 145 | author = {P. J. Huber}, 146 | title = {The Behavior of Maximum Likelihood Estimation under Nonstandard Conditions}, 147 | editor = {L. M. LeCam and J. Neyman}, 148 | booktitle = {Proceedings of the Fifth {B}erkeley Symposium on Mathematical Statistics and Probability}, 149 | year = {1967}, 150 | address = {Berkeley}, 151 | publisher = {University of California Press}, 152 | } 153 | 154 | @Article{White1980, 155 | title = {A Heteroskedasticity-Consistent Covariance Matrix Estimator and a Direct Test for Heteroskedasticity}, 156 | author = {H. White}, 157 | journal = {Econometrica}, 158 | volume = {48}, 159 | pages = {817--838}, 160 | year = {1980}, 161 | doi = {10.2307/1912934}, 162 | } 163 | 164 | @Article{LongErvin2000, 165 | author = {J. S. Long and L. H. Ervin}, 166 | title = {Using Heteroscedasticity Consistent Standard Errors in the Linear Regression Model}, 167 | journal = {The American Statistician}, 168 | volume = {54}, 169 | pages = {217--224}, 170 | year = {2000}, 171 | doi = {10.1080/00031305.2000.10474549}, 172 | } 173 | 174 | @Article{FoxMonette1992, 175 | author = {J. Fox and G. Monette}, 176 | year = {1992}, 177 | title = {Generalized Collinearity Diagnostics}, 178 | journal = {Journal of the American Statistical Association}, 179 | volumje = {87}, 180 | pages = {178--183}, 181 | doi = {10.1080/01621459.1992.10475190}, 182 | } 183 | 184 | @Book{FoxWeisberg2019, 185 | author = {J. Fox and S. Weisberg}, 186 | title = {An {R} Companion to Applied Regression}, 187 | edition = {3rd}, 188 | publisher = {Sage}, 189 | address = {Thousand Oaks}, 190 | year = {2019}, 191 | } 192 | 193 | @Book{KleiberZeileis2008, 194 | title = {Applied Econometrics with {R}}, 195 | author = {C. Kleiber and A. Zeileis}, 196 | year = {2008}, 197 | publisher = {Springer-Verlag}, 198 | address = {New York}, 199 | } 200 | 201 | @Manual{R, 202 | title = {{R}: A Language and Environment for Statistical Computing}, 203 | author = {{R Core Team}}, 204 | organization = {R Foundation for Statistical Computing}, 205 | address = {Vienna, Austria}, 206 | year = {2020}, 207 | url = {https://www.R-project.org/}, 208 | } 209 | 210 | @Manual{sem, 211 | title = {{sem}: Structural Equation Models}, 212 | author = {J. Fox and Z. Nie and J. Byrnes}, 213 | year = {2020}, 214 | note = {R package version 3.1-11}, 215 | url = {https://CRAN.R-project.org/package=sem}, 216 | } 217 | 218 | @Article{Zeileis2006, 219 | title = {Object-Oriented Computation of Sandwich Estimators}, 220 | author = {A. Zeileis}, 221 | journal = {Journal of Statistical Software}, 222 | year = {2006}, 223 | volume = {16}, 224 | number = {9}, 225 | pages = {1--16}, 226 | doi = {10.18637/jss.v016.i09}, 227 | } 228 | 229 | @Manual{boot, 230 | title = {\pkg{boot}: Bootstrap {R} ({S-PLUS}) Functions}, 231 | author = {Angelo Canty and Brian D. Ripley}, 232 | year = {2020}, 233 | note = {\proglang{R} package version 1.3-25}, 234 | url = {https://CRAN.R-project.org/package=boot} 235 | } 236 | 237 | @Book{DavisonHinkley1997, 238 | title = {Bootstrap Methods and Their Applications}, 239 | author = {A. C. Davison and D. V. Hinkley}, 240 | publisher = {Cambridge University Press}, 241 | address = {Cambridge}, 242 | year = {1997}, 243 | } 244 | 245 | @InCollection{Card1995, 246 | author = {David Card}, 247 | title = {Using Geographical Variation in College Proximity to Estimate the Return to Schooling}, 248 | editor = {L. N. Christofides and E. K. Grant and R. Swidinsky}, 249 | booktitle = {Aspects of Labour Market Behaviour: Essays in Honour of John Vanderkamp}, 250 | year = {1995}, 251 | pages = {201--222}, 252 | publisher = {University of Toronto Press}, 253 | address = {Toronto} 254 | } 255 | 256 | @Book{Verbeek2004, 257 | author = {Marno Verbeek}, 258 | title = {A Guide to Modern Econometrics}, 259 | year = {2004}, 260 | edition = {2nd}, 261 | publisher = {John Wiley \& Sons}, 262 | address = {Chichester} 263 | } 264 | 265 | @Book{StockWatson2007, 266 | author = {James H. Stock and Mark W. Watson}, 267 | title = {Introduction to Econometrics}, 268 | year = {2007}, 269 | edition = {2nd}, 270 | publisher = {Addison-Wesley}, 271 | address = {Reading} 272 | } 273 | 274 | @Book{HanckArnoldGerberSchmelzer2020, 275 | author = {Christoph Hanck and Martin Arnold and Alexander Gerber and Martin Schmelzer}, 276 | title = {Introduction to Econometrics with {R}}, 277 | year={2020}, 278 | publisher = {Universit\"at Duisburg-Essen}, 279 | address = {Essen}, 280 | url = {https://www.Econometrics-with-R.org/} 281 | } 282 | 283 | @Incollection{ClevelandGrosseShyu1992, 284 | author = {W. S. Cleveland and E. Grosse and W. M. Shyu}, 285 | year = {1992}, 286 | title = {Local regression models}, 287 | pages = {309--376}, 288 | booktitle = {Statistical Models in {S}}, 289 | editor = {J.M. Chambers and T.J. Hastie}, 290 | publisher = {Wadsworth \& Brooks/Cole}, 291 | address = {Pacific Grove {CA}}, 292 | } 293 | 294 | @Manual{HesterEtAl2020, 295 | title = {remotes: {R} Package Installation from Remote Repositories, Including '{GitHub}'}, 296 | author = {Jim Hester and Gábor Csardi and Hadley Wickham and Winston Chang and Martin Morgan and Dan Tenenbaum}, 297 | year = {2020}, 298 | note = {R package version 2.1.1}, 299 | url = {https://CRAN.R-project.org/package=remotes}, 300 | } 301 | 302 | @Book{VenablesRipley2002, 303 | title = {Modern Applied Statistics with S}, 304 | author = {W. N. Venables and B. D. Ripley}, 305 | publisher = {Springer}, 306 | edition = {Fourth}, 307 | address = {New York}, 308 | year = {2002}, 309 | note = {ISBN 0-387-95457-0}, 310 | url = {http://www.stats.ox.ac.uk/pub/MASS4/}, 311 | } 312 | 313 | @Book{HuberRonchetti2009, 314 | title = {Robust Statistics}, 315 | author = {Huber, P. and Ronchetti, E. M.}, 316 | year = {2009}, 317 | edition = {2nd ed.}, 318 | publisher = {Wiley}, 319 | address = {Hoboken {NJ}} 320 | } 321 | --------------------------------------------------------------------------------