Data - Sample Size Description

From Q
Jump to navigation Jump to search


Creates a box that displays the sample size based on a specified variable, taking into account any filters that have been applied.

How to Create a Sample Size Description

  1. Add the object by selecting from the menu Anything > Page Design > Sample Size DescriptionAutomate > Browse Online Library > Data > Sample Size Description
  2. Specify the variable to use as the Complete variable.

Example

The example below is the sample size description using a variable with n=74, accounting for any filters applied.


Options

The options in the Object Inspector are organized into two tabs: Inputs and Properties.

Inputs

Initial text The text to appear at the beginning of the sample size description. Defaults to "Base: ".

Total sample description The phrase describing the state where no filter has been applied. Defaults to "total sample". If a filter has been applied the label of the filter is shown instead.

Sample size description The phrase describing the concept of sample size. Defaults to "sample size: ".

Final text The text to appear at the end of the description. By default, nothing is shown.

Complete data variable A variable that must be supplied, which is used to compute the sample size. The sample size is defined as all cases that have no missing values in this variable and are included in any filter variable.

Properties

This tab contains options for formatting the size of the object, as well as the underlying R code used to create the visualization, and the JavaScript code use to customize the Object Inspector itself (see Object Inspector for more details about these options). Additional options are available by editing the code.

More Information

How to Display the Sample Size on an Online Dashboard

Code

var heading_text = "Sample Size Description";
if (!!form.setObjectInspectorTitle)
    form.setObjectInspectorTitle(heading_text);
else 
    form.setHeading(heading_text);

form.textBox({label: "Initial text", name: "formInitial", default_value: "Base: ", prompt: "The text before the sample description"})
form.textBox({label: "Total sample description", name: "formTotalSample", default_value: "total sample", prompt: "The text describing the sample when no filter is applied"})
form.textBox({label: "Sample size description", name: "formN", default_value: "; sample size: ", prompt: "The text describing the sample size"})
form.textBox({label: "Final text", name: "formFinal", required: false, prompt: "The text after the sample description"})
form.dropBox({label: "Complete data variable", 
              types:["Variable: Numeric, Date/Time, Money, Categorical, OrderedCategorical"], 
              name: "formComplete", 
              required: true, 
              prompt: "The sample size is computed as all observations included in the filter with no missing values on this variable."})
base <- attr(QFilter, "label")
if (base == "Total sample")
    base <- formTotalSample;
valid <- !is.na(formComplete) & QFilter
if (!is.null(QPopulationWeight))
    valid <- valid & !is.na(QPopulationWeight) & QPopulationWeight > 0
n <- sum(valid)
paste0(formInitial, base, formN, n, formFinal)