Test - Bartlett Test of Sphericity

From Q
Jump to: navigation, search

Conduct a Bartlett's test for sphericity on a set of variables

Conduct a Bartlett's test for sphericity on a set of variables.

How to run this test

  1. In Displayr, go to Insert > More > Test > Bartlett Test of Sphericity. In Q, go to Create > Test > Bartlett Test of Sphericity
  2. Specify the variables to use under Inputs > Input Variables
  3. Adjust the options (noted below)

Bartlett test.PNG

You should use numeric variables as inputs. If you use categorical or ordinal variables, they will be coerced to numeric based on their values for the purposes of running the test.

Example

An example output is shown below:

Options

INPUTS

Input Variables The variables that you would like to analyze.
Missing data See Missing Data Options.
Variable names Display Variable Names in the output, instead of Variable Labels.
More decimal places Display numeric values with 8 decimal places.

Additional Properties

When using this feature you can obtain additional information that is stored by the R code which produces the output.

  1. To do so, select Create > R Output.
  2. In the R CODE, paste: item = YourReferenceName
  3. Replace YourReferenceName with the name of your item. (eg: 'bartlett.test'). You can find this by selecting the item and then going to Properties > General > Name from the object inspector on the right.
  4. Below the first line of code, you can paste in snippets from below or type in str(item) to see a list of available information.

Test items.PNG

For a more in-depth discussion on extracting information from objects in R, checkout our blog post here.

Acknowledgements

The function cortest.bartlett from the R package psych is used to conduct the Bartlett test.

Code

form.setHeading("Bartlett Test of Sphericity");
form.dropBox({name: "inputVariables", label: "Input Variables", types: ["V:numeric, categorical, ordered categorical"], multi:true, min_inputs: 2, height: 8,
              prompt: "Select at least two Variables"});
form.comboBox({name: "missingType", 
               label: "Missing data", 
               alternatives: ["Error if missing data", "Exclude cases with missing data", "Use partial data (pairwise correlations)", "Imputation (replace missing values with estimates)"], 
               default_value: "Use partial data (pairwise correlations)",
               prompt: "Options for handling cases with missing data"});
form.checkBox({label: "Variable names", name: "formNames", default_value: false, prompt: "Display names instead of labels"});
form.checkBox({label: "More decimal places", name: "formDecimals", default_value: false, prompt: "Display numeric values with eight decimal places"});
library(flipU)
library(flipDimensionReduction)
library(flipFormat)
missing <- QInputs(missingType)

CheckVariableLengths(inputVariables, "The input variables")

bt <- BartlettTestOfSphericity(flipTransformations::AsNumeric(QDataFrame(inputVariables), binary = FALSE, remove.first = TRUE), 
                         weights = QCalibratedWeight, 
                         subset = QFilter,
                         missing = missing)
decimal.places <- if (formDecimals) 8 else NULL
bartlett.test <- SignificanceTest(bt, "Bartlett Test of Sphericity", inputVariables, filter = QFilter, weight = QCalibratedWeight,
                     missing = missing, show.labels = !formNames, decimal.places = decimal.places)

See Also