Learn R Programming

rcompanion (version 1.13.2)

pairwiseDifferences: Pairwise differences for unreplicated CBD

Description

Calculates the differences in the response variable for each pair of levels of a grouping variable in an unreplicated complete block design.

Usage

pairwiseDifferences(formula = NULL, data = NULL, x = NULL, g = NULL,
  plotit = FALSE, factorize = FALSE)

Arguments

formula

A formula indicating the measurement variable and the grouping variable. e.g. y ~ group.

data

The data frame to use.

x

The vector of the response variable.

g

The vector of the grouping variable.

plotit

If TRUE, then produces bar plots of the differences.

factorize

If TRUE, then adds a column to the output data frame consisting of the differences as a factor variable. This output is added automatically if plotit = TRUE.

Value

A data frame of the paired groups, the differences in their response variables, and optionally the differences expressed as a factor variable. If plotit = TRUE, then also produce one or more plots.

Details

The main use of the function is to check the shape of the distribution of differences in responses for paired t-test, paired rank-sum test, Friedman test, or Quade test.

The function assumes that the data frame is already ordered by the blocking variable, so that the first observation of Group 1 is paired with the first observation of Group 2, and so on.

The function assumes that the data are in complete block design. That is, for any level of the grouping variable in Group 1 there exists one paired value in Group 2, and so on.

The input should include either formula and data; or x, and g.

References

http://rcompanion.org/handbook/F_10.html

Examples

Run this code
# NOT RUN {
### Two-sample paired data example with bar plot
data(Pooh)
Pooh.diff = pairwiseDifferences(Likert ~ Time, 
                                data=Pooh, 
                                plotit = TRUE)

### Unreplicated complete block design example with bar plots
data(BobBelcher)
Bob.diff = pairwiseDifferences(Likert ~ Instructor,
                               data=BobBelcher, 
                               factorize=TRUE)
library(lattice)
histogram(~ Difference.f | Comparison,
         data=Bob.diff,
         type = "count",
         layout=c(2,5))

# }

Run the code above in your browser using DataLab