Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zeileis/ivreg
2SLS Regression with Diagnostics in R
https://github.com/zeileis/ivreg
instrumental-variables regression-diagnostics two-stage-least-squares-regression
Last synced: 2 months ago
JSON representation
2SLS Regression with Diagnostics in R
- Host: GitHub
- URL: https://github.com/zeileis/ivreg
- Owner: zeileis
- Created: 2019-09-24T00:49:57.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2023-06-24T16:56:16.000Z (over 1 year ago)
- Last Synced: 2023-12-19T18:51:17.899Z (about 1 year ago)
- Topics: instrumental-variables, regression-diagnostics, two-stage-least-squares-regression
- Language: R
- Homepage: https://zeileis.github.io/ivreg/
- Size: 19.4 MB
- Stars: 13
- Watchers: 5
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.Rmd
Awesome Lists containing this project
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
fig.path = "man/figures/README-"
)
```## Two-Stage Least-Squares Regression with Diagnostics
An implementation of instrumental variables regression using two-stage least-squares
(2SLS) estimation, based on the `ivreg()` function previously in the
[AER](https://CRAN.R-project.org/package=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.**Instrumental variables regression:**
```
library("ivreg")
ivreg(Q ~ P + D | D + F + A, data = Kmenta)
```**Via two-stage least squares (2SLS):**
```{r 2sls, echo=FALSE, results="hide"}
exams::tex2image("\\begin{eqnarray*}
y & = & X \\beta + \\varepsilon \\\\
\\widehat{X} & = & Z (Z^\\top Z)^{-1} Z^\\top X \\\\
\\widehat{\\beta}_{\\mathrm{2SLS}} & = & (\\widehat{X}^\\top \\widehat{X})^{-1} \\widehat{X}^\\top y
\\end{eqnarray*}",
format = "svg", header = "", pt = 14,
dir = file.path(getwd(), "man", "figures"), name = "README-2sls")
```**With diagnostics:**
```{r effects, echo=FALSE, results="hide", message=FALSE, fig.height=4.7, fig.width=5, fig.show="hide"}
library("ivreg")
library("effects")
library("car")
deq <- ivreg(Q ~ P + D | D + F + A, data = Kmenta)
plot(predictorEffect("P", deq, residuals = TRUE), partial.residuals = list(span = 1))
``````{r qqplot, echo=FALSE, results="hide", message=FALSE, fig.height=4.7, fig.width=5, fig.show="hide"}
qqPlot(deq, main = "QQ plot")
## mtext("QQ plot", line = 1.5, cex = 1.2, font = 2)
``````{r influenceplot, echo=FALSE, results="hide", message=FALSE, fig.height=4.7, fig.width=5, fig.show="hide"}
influencePlot(deq, main = "")
mtext("Influence plot", line = 2, cex = 1.2, font = 2)
```