Learn R Programming

instruments (version 0.1.0)

iv.glm: Estimate generalized linear models with an instrumental variable.

Description

This function allows you to estimate two stage generalized linear models in one step.

Usage

iv.glm(model_formula, instrument_formula = NULL, data = NULL,
  family = binomial, link = "logit", ...)

Arguments

model_formula

The formula of the main regression problem.

instrument_formula

The formula for the first stage of the regression problem. Estimate an endogenous variable from one (or more) instruments. If blank, defaults to regular glm.

data

(optional) A data frame containing all variables for the regression model.

family

The distribution family of the outcome variable.

link

The link function to the outcome variable.

...

Additional arguments to pass to glm().

Examples

Run this code
# NOT RUN {
# Fake data
N <- 1000
z <- rnorm(N, 1, 1)
error <- rnorm(N, 1, 1)
x <- z + error + rnorm(N, 1, 1)
y <- rbinom(N, 1, invlogit(x + error))

# Fit glm
fit_glm <- glm( y ~ x, family = binomial(link = 'logit'))

# Fit with iv
fit_iv <- iv.glm(y ~ x, x ~ z, family = binomial, link = 'logit')

summary(fit_glm)
summary(fit_iv)
# }

Run the code above in your browser using DataLab