Tables - Descriptive Statistics
Creates a table of descriptive statistics (i.e., the mean, N, number of missing values, standard deviation, range, sum, minimum, 25th percentile, median, 75th percentile, and maximum).
How to Create a Table of Descriptive Statistics
- Add the object:
- In Displayr: Insert > More > Tables > Descriptive Statistics
- In Q: Create > Tables > Descriptive Statistics
- In Inputs > Variables, specify the variables you wish to see in the rows of the table.
Example
The table below includes the descriptive statistics for the variables Q2. Gender, Q3. Age, RD34 070622, Q1. Coke, Q1. Diet Coke, and Q4. Frequency.
Options
The options in the Object Inspector are organized into two tabs: Inputs and Properties.
Inputs
Variables The variables to appear in the rows, as categories.
Variable names Displays Variable Names in the output.
Filter The data is automatically filtered using any filters.
Weight The data is automatically weighted filtered using any weights.
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
Code
var __webpack_modules__ = ({});
// The module cache
var __webpack_module_cache__ = {};
// The require function
function __webpack_require__(moduleId) {
// Check if module is in cache
var cachedModule = __webpack_module_cache__[moduleId];
if (cachedModule !== undefined) {
return cachedModule.exports;
}
// Create a new module (and put it into the cache)
var module = (__webpack_module_cache__[moduleId] = {
exports: {}
});
// Execute the module function
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
// Return the exports of the module
return module.exports;
}
// webpack/runtime/rspack_version
(() => {
__webpack_require__.rv = () => ("1.7.2")
})();
// webpack/runtime/rspack_unique_id
(() => {
__webpack_require__.ruid = "bundler=rspack@1.7.2";
})();
var displayr = Q.isOnTheWeb();
var variables_prompt = displayr ? "Variables are found in Data Sources (bottom-left)" :
"Variables are shown in the 'Variables and Questions' tab.";
var heading_text = 'Descriptive Statistics';
if (!!form.setObjectInspectorTitle)
form.setObjectInspectorTitle(heading_text, heading_text);
else
form.setHeading(heading_text);
form.dropBox({ label: "Variables",
types: ["Variable: Numeric, Date, Money, Categorical, OrderedCategorical"],
name: "formVariables",
multi: true, prompt: variables_prompt });
form.checkBox({ label: "Variable names", name: "formNames", default_value: false, prompt: "Display names instead of labels" });
library(flipFormat)
library(flipTransformations)
raw.data = ProcessQVariables(data.frame(if (length(formVariables) == 1) formVariables[[1]] else formVariables))
names(raw.data) = if(!formNames) lapply(formVariables, Labels) else lapply(formVariables, flipFormat::Names)
raw.data = flipU::CopyAttributes(raw.data[QFilter,, drop = FALSE], raw.data)
raw.data = AsNumeric(raw.data, binary = FALSE)
summarize <- function(x)
{
w = QPopulationWeight[QFilter]
n <- length(x)
if (is.null(w))
w <- rep(1, n)
if (length(w) != n)
StopForUserError("The weight is from a different data file to the variables.")
w[is.na(w) | w < 0 | is.na(x)] <- 0
x <- x[w > 0]
w <- w[w > 0]
N <- length(x)
require(Hmisc)
five = wtd.quantile(x, w, c(0, .25, .5, .75, 1))
names(five)[c(1,3,5)] <- c("Min.", "Med.", "Max.")
c("Ave." = ave <- wtd.mean(x, w),
N = N,
"Miss." = n - N,
"St.Dev." = sqrt(wtd.var(x, w)),
"Range" = as.numeric(five[5] - five[1]),
Sum = ave * sum(w),
five)
}
summary <- t(sapply(raw.data, summarize))