gge_coef: Dotwhisker plot

gge_coefR Documentation

Dotwhisker plot

Description

This is a wrap function for the function dwplot from the package dotwhisker

Usage

gge_coef(
  model,
  xlab = "Coefficient Estimate",
  ylab = "",
  var.order = NULL,
  model.id = NULL,
  title = NULL,
  subtitle = NULL,
  footnote = NULL,
  legend.position = "top",
  legend.title = "",
  title.position = "left",
  hc = FALSE,
  hc.type = c("hc3", "hc0", "hc1", "hc2", "hc4")
)

Arguments

model

either an object from lm, glm, or a nnet::multinom or a tidy data.frame with the model summary. If the data frame is provided, it must contain a column named term (the name of the covariates), estimate (the point estimate), and either std.error (standard errors of the estimates) or conf.low or conf.high (low and high intervals of the point estimate). If there are more than one model in the data.frame, it must contain a column with labels identifying each model.

xlab

string with text to display in the x-axis

ylab

string with text to display in the y-axis

var.order

A vector of variable names that specifies the order in which the variables are to appear along the y-axis of the plot. If a data.frame is provided, the order of the y-axis will follow the order of the rows in the data.frame

model.id

a string with the name of the column that contain the id of each model

title

a string, the title of the plot

subtitle

a string, the subtitle of the plot

footnote

a string, the footnote of the plot

legend.position

a string (top, bottom, left (Default)), right

legend.title

a string with the title of the legend

title.position

a string (or an number) with center (or .5), left (or 0), or right (or 1)

hc

boolean, if TRUE robust standard errors (heteroskedasticity corrected) are returned

hc.type

a string with the method to compute the standard errors (see hccm)

Details

Robust standard errors are computed when hc=T only when the parameter model is an object from lm, glm.

Examples

library(magrittr)
set.seed(77)

data = tibble::data_frame(n = 300,
                          x1   = rnorm(n,3,1),
                          x2   = rexp(n),
                          cat1 = sample(c(0,1), n, replace=TRUE),
                          cat2 = sample(letters[1:4], n, replace=TRUE),
                          y    = -10*x1*cat1 + 10*x2*(3*(cat2=='a')
                                 -3*(cat2=='b') +1*(cat2=='c') -1*(cat2=='d')) + 
                              rnorm(n,0,10), 
                          y.bin = ifelse(y < mean(y), 0, 1),
                          y.mul = 1+ifelse( - x1 - x2 + rnorm(n,sd=10) < 0, 0,
                                    ifelse( - 2*x2 + rnorm(n,sd=10) < 0, 1, 2)),
                          )

model.g1 = lm(y ~ x1, data)
model.g2 = lm(y ~ x1 + x2, data)
model.g  = lm(y ~ x1*cat1 + x2*cat2, data)
model.bin = glm(y.bin ~ x1+x2*cat2, data=data, family='binomial')
model.mul <- nnet::multinom(y.mul ~ x1 + x2, data)


gge_coef(model.g)
gge_coef(model.g, hc=TRUE)
gge_coef(tidye(model.g) %>% dplyr::arrange(estimate), hc=TRUE)

gge_coef(model.bin)
gge_coef(model.bin, hc=TRUE)
gge_coef(tidye(model.g))

## many models at once
models=tidye(list('Standard Model'=model.bin)) %>%
    dplyr::bind_rows(tidye(list('Robust std. error'=model.bin), hc=TRUE) )
gge_coef(models)
gge_coef(models, model.id='model')

## list of models
gge_coef(list(model.g, model.g1, model.g2), model.id='model')
gge_coef(list('Complete model'=model.g, "One Covar"=model.g1,
              "Two covars"=model.g2), model.id='model' )

## pipe can be used
## modelg %>% gge_coef


DiogoFerrari/edar documentation built on May 8, 2022, 8:26 a.m.