knitr::opts_knit$set(
        stop_on_error = 2L
)

Supported transformations

NOTE this stuff is broken right now, need to fix.

For convenience, you may wish to transform one or more of your covariates within the model estimation call. For example, imagine we want to natural log transform the variable dist in a linear regression:

cars <- transform(cars, distance = dist, dist.log = log(dist))
m.log <- lm(speed ~ log(distance), data = cars)
m.log2 <- lm(speed ~ dist.log, data = cars)

Then we want to find quantities of interest when the dist variable is 26 to 56 (the first to third quartile):

library(smargins)

summary(smargins(m.log, distance = c(26, 56)))

We could also estimate the model with dist as a polynomial. For example:

# Find range of polynomial values

m2 <- lm(speed ~ poly(distance, 2), data = cars)
summary(smargins(m2, distance = quantile(distance, seq(0, 1, .1))))

Splines and other transformations should generally work as expected.

library(splines)

m3 <- lm(speed ~ bs(distance, df = 4), data = cars)
summary(smargins(m3, distance = seq(min(distance), max(distance), 10)))


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