prepBoxPlots: Prepare data for box plots

Description Usage Arguments Value Examples

View source: R/hubert_t.R

Description

This function prepares the data for making box plots.

Usage

1
prepBoxPlots(A, groups = NULL, group_list = NULL, absolute = TRUE)

Arguments

A

Distance or similarity matrix, e.g. correlation

groups

CFA model in lavaan syntax. Either groups or group_list but not both must be supplied.

group_list

List of groupings. Either groups or group_list but not both must be supplied.

absolute

Use the absolute values of A (defaults to TRUE)

Value

multi: data frame for making box plots for block-specific tests

overall: data frame for making box plots for overall test

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
library(matrixStrucTest)
library(ggplot2)

data("big5")

# get column numbers for questionnaire items
items <- grep("[0-9]", colnames(big5))

# compute Spearman's correlation matrix
A <- cor(big5[, items], use = "complete.obs", method = "spearman")

groups <- "extrovert ~ E1 + E2 + E3 + E4 + E5 + E6 + E7 + E8 + E9 + E10
           neurotic ~ N1 + N2 + N3 + N4 + N5 + N6 + N7 + N8 + N9 + N10
           agreeable ~ A1 + A2 + A3 + A4 + A5 + A6 + A7 + A8 + A9 + A10
           conscientious ~ C1 + C2 + C3 + C4 + C5 + C6 + C7 + C8 + C9 + C10
           open ~ O1 + O2 + O3 + O4 + O5 + O6 + O7 + O8 + O9 + O10"

# Make box plots contrasting within and between group correlations
box <- prepBoxPlots(A = A, groups = groups, absolute = TRUE)

ggplot(aes(x = as.factor(delta), y = a), data = box$overall)+
  geom_boxplot()+
  theme_bw(22)+
  labs(x = expression(Delta), y="|a|")

dev.new(width = 12, height = 5)
ggplot(aes(x = as.factor(delta), y = a), data = box$multi)+
  geom_boxplot()+
  facet_grid(~block)+
  theme_bw(22)+
labs(x = expression(Delta), y = "|a|")

matrixStrucTest documentation built on July 18, 2019, 9:06 a.m.