knitr::opts_knit$set(
    stop_on_error = 2L
)
knitr::opts_chunk$set(
    fig.height = 11,
    fig.width = 7
)

options(cite = FALSE)

Examples

rm(list=ls(pattern="\\.out"))
suppressWarnings(suppressMessages(library(Zelig)))
set.seed(1234)

Basic Example

Attaching the sample dataset:

library(survival)
data(tobin)

Estimating linear regression using tobit:

## consider these two models:
m1 <- survreg(Surv(durable, durable>0, type='left') ~ age + quant,
              data=tobin, dist='gaussian')

Summarize estimated paramters:

summary(m1)

Setting values for the explanatory variables to their sample averages and simulating quantity of interest.

library(smargins)

m.sm <- smargins(m1, quant = seq(210, 280, 10))

summary(m.sm)

library(ggplot2)

ggplot(summary(m.sm), aes(x = quant, y = mean)) +
    geom_smooth(aes(ymin = lower_2.5, ymax = upper_97.5),
                stat = "identity")

Simulating First Differences

Set explanatory variables to their default(mean/mode) values, with high (80th percentile) and low (20th percentile) liquidity ratio (quant):

m.sm2 <- smargins(m1, quant = quantile(tobin$quant, prob = c(0.2, 0.8)))

summary(m.sm2)

Estimating the first difference for the effect of high versus low liquidity ratio on duration(\ durable):

summary(scompare(m.sm2, "quant"))
ggplot(scompare(m.sm2, "quant"), aes(x = .smargin_qi)) +
    geom_density(fill = "blue", alpha = 0.25)


izahn/smargins documentation built on Sept. 11, 2019, 2:08 p.m.