Foreword

This package is meant for a particular use, which is to work with data from surveys to generate batch reports. To do so, we need to keep track of the question text and the latent associations used for modelling the data (PLS-PM).

To achieve this, reporttoolDT provides a new data structure (named Survey) which keeps track of the questions and associations, as well as other information. To users, Survey's should look and behave pretty much like a normal data.frame, but the internals help us automate tables, plots and reports.

Note: reporttoolDT is meant to be used with R6Frame, seamless and tabulR. These packages are loaded automatically when you call library(reporttoolDT).

Usage

For these examples, we'll start with some "raw data" from SPSS and go through the steps necessary to create tables, plots and reports. I recommend using reporttoolDT with dplyr:

Preparing the data

require(dplyr)
require(reporttoolDT)

sav <- read_data(system.file("extdata", "raw_data.sav", package = "reporttoolDT"))
srv <- survey_tbl(sav) %>%
  set_association(.common = TRUE) %>%
  set_config(name = "Example", segment = "B2C", cutoff = .3) %>%
  set_marketshare(CompanyA = .3, CompanyB = .5, CompanyC = .2) %>%
  set_translation(.language = "english") %>%
  latents_mean() 

For more information about the steps above, check out the "prepare" vignette. We are now ready to generate output from the Survey.

Tables

To generate tables, we can use the qtable() function from the tabulR package.

srv %>% group_by(q1) %>% qtable(q17)

We can also use latent_table() and manifest_table() to easily summarise the model variables:

srv %>% group_by(q1) %>% latent_table()

Recode

Let's say we wanted to recode "had reason to complain" as "no", and create a table of satisfaction for complaining and non-complaining customers (by company), we can call:

srv %>% 
  mutate(q17 = recode(q17, Nei = c("Nei", "Hadde grunn til å klage, men klaget ikke"))) %>%
  group_by(q1, q17) %>%
  qtable(epsi)

Charts

Creating charts works more or less exactly like qtable(), except we have two choices - bar_chart() and line_chart():

srv %>% group_by(q1) %>% bar_chart(epsi, margin = FALSE)

We can also use manifest_plot() and latent_plot() to visualize our model variables:

srv %>% group_by(q1) %>% latent_plot()

The plots are made using ggplot2. They are meant as a baseline, and can be further adjusted using ggplot2.

Output

To create PDF or Powerpoint output, we first create a workbook in R, and use to_ppt and to_excel to send tables and/or plots to the workbook. The workbook can then be saved with write_data after. Let's start with Excel:

wb <- excel_workbook()

# Add the latent table
srv %>% group_by(q1) %>% latent_table() %>% to_excel(wb)

# Add manifest table
srv %>% group_by(q1) %>% manifest_table() %>% to_excel(wb)

# Save
# write_data(wb, "reporttool example.xlsx")

We cannot send plots to Excel, but we can with Powerpoint:

if (require(ReporteRs)) {
   wb <- ppt_workbook()

  # Add the latent plot
  srv %>% group_by(q1) %>% latent_plot() %>% to_ppt(wb, title = "Latent plot")

  # And also satisfaction barchart
  srv %>% group_by(q1) %>% bar_chart(epsi, margin = FALSE) %>% to_ppt(wb, title = "Satisfaction")

  # Save
  # write_data(wb, "reporttool example.pptx") 
}

Reports

To generate a report we can use generate_report() with one of type = c("pdf", "ppt", "html"). To skip specifying the type, we can also use report_pdf(), report_ppt() or report_html() directly. Each of these functions expect a dataset as the first argument, which is then passed to the knit-environment when evaluating the .Rmd-template.

If a group is specified (or data is already grouped using group_by()), one report will be generated for each unique value in the grouping variable. The current group is made available as entity in the knit-environment.

More information

Survey-class:

vignette("survey", package = "reporttoolDT")

Preparing data:

vignette("prepare", package = "reporttoolDT")

Other functions:

vignette("other", package = "reporttoolDT")


itsdalmo/reporttoolDT documentation built on May 18, 2019, 7:11 a.m.