survey_table: Create tables from surveys

Description Usage Arguments Details Author(s) Examples

Description

Function for creating summary tables of factors and numeric columns in a survey. You can also group the survey by other variables before passing it to survey_table to get scores/proportions by one or more variables.

Usage

1
2
3
4
5
survey_table(srv, ..., wide = TRUE, weight = TRUE, question = TRUE,
  filter_missing = TRUE, filter_response = TRUE, contrast = TRUE)

survey_table_(srv, dots, wide = TRUE, weight = TRUE, question = TRUE,
  filter_missing = TRUE, filter_response = TRUE, contrast = TRUE)

Arguments

srv

A survey object.

...

Columns to summarise. Accepts either numeric or factors, and a warning will be issued if it encounters text etc. When creating a table for factors, they must all have identical factor levels.

wide

If this is TRUE (the default), the output will be in a wide format.

weight

When TRUE, the average will be weighted (assumes weights are in column 'w').

question

When TRUE, the question text specified in the measurement model will be included in the table (provided they are not empty strings).

filter_missing

Set to FALSE to NOT remove observations with percent_missing above the cutoff that is set in config.

filter_response

When set to TRUE (default), the function will filter NA values in the response variables (i.e. ...) before counting observations and/or calculating mean or proportions

contrast

Set to FALSE if a contrast exist but you want to use the study average instead.

Details

The function does the following:

average

Produces an average for the tables, which is always the average for the first group (as set by group_by), and it is appropriately grouped for the remaining groups.

weight

Unless otherwise specified, this function will always weight the results for the average. This also means that the function requires that the weight column (w) is present in the data.

filter

Filters missing values NA for all groups and the variables that go into the table, as well as percent_missing which exceeds the cutoff in the surveys config. Setting filter_missing to FALSE overrides the filtering of percent_missing, while setting filter_response to FALSE does the same for filtering of response variables.

count

For both numeric and factor variables, this function always provides a count for the number of valid observations (after filtering) in each group. This count is not weighted. (Only the proportions themselves.)

missing

Turns implicit missing values into explicit missing values. When this is the case, counts will be 0 and the aggregated values will be NA (unless it is a factor and one of the other proportions are not NA, in this case, the proportions are set to 0 instead.)

spread

When wide is set to TRUE, the function spreads the results to a wide format. For numeric, the variables are put in separate columns. For factor variables, the proportions are spread by their respective levels (e.g. "Yes", "No" etc become columns.) An exception is made when grouping by several variables and there is only one response variable (numeric).)

Author(s)

Kristian D. Olsen

Examples

1
x %>% group_by(q7_service) %>% survey_table(image:loyal)

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