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

Description Usage Arguments Examples

View source: R/ivglm.R

Description

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

Usage

1
2
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# 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)

alexpavlakis/instruments documentation built on May 6, 2019, 1:34 a.m.