knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "README-"
)

tidyforest

tidyforest contains a tidyverse workflow for running and presenting a logistic regression model in R. This is organised into 5 functions:

Install

install.packages("devtools")

and

devtools::install_github("riinuots/tidyforest")

Use

library(tidyforest)

mydata = data_melanoma()
dependent = 'status.factor' 
explanatory = c('sex.factor', 'ulcer.factor', 'stage.factor')
explanatory_names = c('Gender', 'Ulceration', 'Stage (thickness)')

tidyforest(mydata, dependent, explanatory, explanatory_names)

Note that outcome variable ("dependent") actually includes 3 levels: "Alive", "Died", and "Died of other causes". This example lumps the latter categories into once which might not be desired. You should always plot your data in an exploratory way (e.g. boxplots, barplots) before running advanced statistical models on it.

These warnings:

Warning messages:
1: Removed 21 rows containing missing values (geom_text). 
2: Removed 3 rows containing missing values (geom_errorbar). 
3: Removed 3 rows containing missing values (geom_point). 
4: Removed 3 rows containing missing values (geom_text). 

can safely be ignored, as they refer to the fact that the reference levels do not have a point and an errorbar (does not make sense), or that the explanatory_names are only printed once for the whole group (not on each line).

Or call the functions separetely

library(tidyforest)

mydata = data_melanoma()

mydata %>% str() #prints the structure and first few observations
dependent = 'status.factor'
explanatory = c('sex.factor', 'ulcer.factor', 'stage.factor')
explanatory_names = c('Gender', 'Ulceration', 'Stage (thickness)') #this is optional

glm_result = glm_tidyresult(mydata, dependent, explanatory)

or_plot(glm_result)
or_table_plot(glm_result, explanatory_names)


riinuots/tidyforest documentation built on May 27, 2019, 8:51 a.m.