Package 'postHoc'

Title: Tools for Post-Hoc Analysis
Description: Implements a range of facilities for post-hoc analysis and summarizing linear models, generalized linear models and generalized linear mixed models, including grouping and clustering via pairwise comparisons using graph representations and efficient algorithms for finding maximal cliques of a graph. Includes also non-parametric toos for post-hoc analysis. It has S3 methods for printing summarizing, and producing plots, line and barplots suitable for post-hoc analyses.
Authors: Rodrigo Labouriau [aut, cre]
Maintainer: Rodrigo Labouriau <[email protected]>
License: GPL (>= 3)
Version: 0.1.3
Built: 2025-02-27 03:16:42 UTC
Source: https://github.com/cran/postHoc

Help Index


Constructs a matrix with all the contrasts for pairwise comparisons.

Description

Constructs a matrix with all the contrasts for pairwise comparisons.

Usage

AllContrasts(n)

Arguments

n

an integer number larger than 1 giving the number of contrasts defining the pairwise comparisons pairwise comparisons.

Details

This is an auxiliar function forming a contrast matrix of all possible. Generates an error if n is smaller than 2.

Value

a matrix of dimension n(n-1)/2 x n.

Author(s)

Rodrigo Labouriau

Examples

AllContrasts(3)

Wald approximation for the p-values of pairwise comparisons based on the design matrix

Description

Wald approximation for the p-values of pairwise comparisons based on the design matrix

Usage

ApproxWaldPvalues(Effects, CovMatrix, DesignMatrix, padjust = "fdr")

Arguments

Effects

a vector containing the effects

CovMatrix

the covariance matrix of the effects

DesignMatrix

design matrix

padjust

method for correcting for multiple testing as in the function p.adjust (default = "fdr", if NULL no adjustments is made)

Value

a vector of p-values.

Author(s)

Rodrigo Labouriau


Barplot method for objects of class PostHoc

Description

Barplot method for objects of class PostHoc

Usage

## S3 method for class 'PostHoc'
barplot(
  height,
  col = "lightblue",
  labelsCol = "black",
  space2max = 0,
  UseGrouping = TRUE,
  ylim = NULL,
  main = "",
  ylab = "",
  xlab = "",
  lty = 1,
  drawAxis = TRUE,
  rightshift = 0,
  additionalTextGrouping = "",
  superpose = FALSE,
  cex.grouping = 1,
  cex.ticks = 0.1,
  cex.lab = 1,
  ylog = FALSE,
  ...
)

Arguments

height

an object of class PostHoc to be printed

col

the colour of the bars (default = "lightblue")

labelsCol

the colour of the bars (default = "black")

space2max

space between the upper limit of the confidence interval and the label¨

UseGrouping

should the grouping be added to the plots (default = TRUE)

ylim

range of the vertical axis

main

character with the title of the plot (default = ”)

ylab

label of the vertical axis

xlab

label of the horizontal axis

lty

type of line

drawAxis

should the axis be drawn (default = TRUE)

rightshift

a number specifying a (small) right shift of the line

additionalTextGrouping

character vector with additional text to the grouping

superpose

should the graph be superposed to an existing graph (default = FALSE)

cex.grouping

size of the labels of groups

cex.ticks

size of the thicks defining the the limits of the confidence intervals

cex.lab

size of the labels

ylog

should the vertical axis be expressed in a logarithmic scale (default = FALSE)

...

parameters to be passed to the barlot function

Value

none

Author(s)

Rodrigo Labouriau

Examples

MM <- glm(Y ~ Treatment+0,  data=DeIdentifiedExample)
GG <- posthoc(MM)
barplot(GG)

A simple example for testing pairwise comparison methods

Description

A simple example of data for testing pairwise comparison methods composed of a normally distributed response and a factor with 7 levels.

Usage

data("DeIdentifiedExample")

Format

A data frame with 70 observations on the following 2 variables.

Y

a numeric vector containing a response variable

Treatment

a factor with 7 levels A B C D E F G

Details

De identified real dataset for testing

Source

A real data set with altered names, so that the source (irrelevant in this context) cannot be identified.

Examples

data(DeIdentifiedExample)
str(DeIdentifiedExample)

Calculates the Wald or a parametric bootstrap confidence intervals for GLMs and GLMMs

Description

posthoc is used to group or cluster the effects of liner, generalised linear and generalised linear mixed models according to significance of pairwise tests comparing the levels of the effects.

Usage

ExtractCI (Model, EffectIndices = NULL, EffectLabels = NULL,
         ParBootstrap = FALSE, Nboots = 999, digits = 4, coverage = 0.95,
         UpperBound = Inf, SignificanceLevel =  1-coverage,
         EffectsMatrix = NULL, Scale = 1.0, Location = 0.0,
         isBinomialModel = FALSE, BackTransform = TRUE)

Arguments

Model

a model of class lm, glm, glmerMod, lme or gls.

EffectIndices

a vector containing the indices of the effects to be analysed (default = NULL, indicating that all the levels are used).

EffectLabels

a character vector with the labels of the effects (default = NULL, which implies that the corresponding labels of the model coefficient are used).

ParBootstrap

logic flag indicating whether the confidence intervals should be calculated with parametric bootstrap (default is false, i.e. the Wald confidence interval is used).

Nboots

number of bootstrap samples used for the confidence interval. (default = 999).

digits

number of digits used when reporting the results

coverage

the coverage of the confidence intervals (default = 0.95)

UpperBound

an upper bound to the confidence intervals (default = Inf)

SignificanceLevel

the significance level of the pairwise comparisons (default = 0.05).

EffectsMatrix

matrix defining contrasts to be compared (bypasses the EffectIndices, default is NULL, meaning that standard inference is performed).

Scale

a scaling factor multiplying the output table (default = 1, i.e., no scaling is used).

Location

a location term added to the output table (default = 0, i.e., no location shift is performed).

isBinomialModel

a logical flag indicating whther the model is a binomial model different than the Bernoulli (default = FALSE, i.e. not a binomial model).

BackTransform

should the parameters and CIs be back transformed by applying the inverse link function (default = TRUE)

Details

Two possible methos for obtaining confidence intervals are available: Wald confidence intervals and parametric bootstrap confidence intervals.

Value

an object of (S3) class "PostHoc".

a matrix with three columns containing the effects, the lower bound and the upper bound of the confidence intervals for the effects.

Author(s)

Rodrigo Labouriau

Examples

MM <- glm(Y ~ Treatment+0,  data=DeIdentifiedExample)
ExtractCI (MM)

Group effects given the pairwise p-values

Description

Group effects given the pairwise p-values

Usage

FormGroupsClusters(
  PvaluesMatrix,
  CI = NULL,
  Effects,
  SignificanceLevel = 0.05,
  UpperCase = FALSE,
  RankLabels = TRUE,
  PlotAdj = FALSE,
  padjust = NULL,
  CalcClusters = FALSE,
  digits = 4
)

Arguments

PvaluesMatrix

a matrix containing the p-values of the comparisons of each possible pairs of effects in the lower triangle (excluding the diagonal)

CI

a matrix containing with three columns containint the effects, the lower limits and the upper limits of a confidence interval for the effects (default = NULL, indicating that no confidence intervals are available)

Effects

a vector containing the effects

SignificanceLevel

the significance level of the pairwise comparisons (default = 0.05)

UpperCase

should upper case letters be used for labelling the groups (default is FALSE)

RankLabels

should the labels of the grouping be sorted according to the value of the response (default=TRUE)

PlotAdj

should the associated graph be printed(default = FALSE)

padjust

method for correcting the p-values (before the calculations are performed) as in the function p.adjust (Default is NULL, indicating that no multiple testing corrections are used)

CalcClusters

should the clusters be calculated and displayed instead of grouping (Default is FALSE)

digits

number of digits in the output (default = 4)

Details

This is an auxiliar function forming a contrast matrix of all possible. Generates an error if n is smaller than 2. The function contructs, using the supplied matrix of p-values for all pairwise comparisosns, an undirected graph with vertices representing the levels of the effects, using the convention that two vertices are connected by an edge iff the p-value for testing equality the two vertices is larger than the prefixed significance level. The maximal cliques of this graph form the grouping of the levels of the effects.

Value

an object of (S3) class "PostHoc" with methods for print, summary, plot, barplot and lines defined. An object of class "PostHoc" contails the effects, grouping, the matrix of p-values of all pairwise comparisons, the graph (Gr) of adjacency, the confidence intervals of the effects, the significance levels, the number of digits to be used for printing, the list of maximal cliques of the graph Gr, the clusters (if calculated).

Author(s)

Rodrigo Labouriau

Examples

MM <- glm(Y ~ Treatment+0,  data=DeIdentifiedExample)
GG <- posthoc(MM)
Effects <- coef(MM)
PvaluesMatrix <- GG$PvaluesMatrix
TT <- FormGroupsClusters(PvaluesMatrix = PvaluesMatrix, Effects = Effects)
plot(TT)

Group effects for GLMs and GLMMs

Description

GroupClusterEffects is an alias of the function posthoc, temporarily kept for compatibility.

Usage

GroupClusterEffects (Model, EffectIndices = NULL, EffectLabels = NULL,
         EffectsMatrix = NULL, ParBootstrap = FALSE, Nboots = 999,
         SignificanceLevel = 0.05, UpperCase = FALSE,
         RankLabels = TRUE, WaldApproximation = FALSE,
         CalcClusters = FALSE, QUIET = TRUE, PlotAdj = FALSE,
         digits = 4, padjust = NULL, Scale = 1.0, Location = 0.0,
         isBinomialModel = FALSE, BackTransform = TRUE)

Arguments

Model

a model of class lm, glm, glmerMod, lme or gls.

EffectIndices

a vector containing the indices of the effects to be analysed (default = NULL, indicating that all the levels are used).

EffectLabels

a character vector with the labels of the effects (default = NULL, which implies that the corresponding labels of the model coefficient are used).

EffectsMatrix

matrix defining contrasts to be compared (bypasses the EffectIndices, default is NULL, meaning that standard inference is performed).

ParBootstrap

logic flag indicating whether the confidence intervals should be calculated with parametric bootstrap (default is false, i.e. the Wald confidence interval is used). Not implemented for objects of class lme.

Nboots

number of bootstrap samples used for the confidence interval. (default = 999).

SignificanceLevel

the significance level of the pairwise comparisons (default = 0.05).

UpperCase

should upper case letters be used for labelling the groups (default is FALSE).

RankLabels

should the labels of the grouping be sorted according to the value of the response (default=TRUE)

WaldApproximation

logic flag indicating whether a Wald approximated test should be used (defaut = FALSE).

CalcClusters

should the clusters be calculated and displayed instead of grouping (Default is FALSE)

QUIET

flag indicating whter the (large) output of the multcomp library should be temporarily re-directed (default = TRUE).

PlotAdj

should the associated graph be printed(default = FALSE).

digits

number of digits in the output (default = 4)

padjust

method for correcting the p-values (before the calculations are performed) as in the function p.adjust (Default is NULL, indicating that no multiple testing corrections are used)

Scale

a scaling factor multiplying the output table (default = 1, i.e., no scaling is used).

Location

a location term added to the output table (default = 0, i.e., no location shift is performed).

isBinomialModel

a logical flag indicating whther the model is a binomial model different than the Bernoulli (default = FALSE, i.e. not a binomial model).

BackTransform

should the effects and CIs be back transformed by applying the inverse link function (default = TRUE)

Details

The function contructs, using the supplied matrix of p-values for all pairwise comparisosns, an undirected graph with vertices representing the levels of the effects, using the convention that two vertices are connected by an edge iff the p-value for testing equality the two vertices is larger than the prefixed significance level. The maximal cliques of this graph form the grouping of the levels of the effects. The parameter BackTransform, indicating whether the effects and CIs should be beck transformed using the inverse of the link function is incorporated in this version, but was not present in the original function GroupClusterEffects. Since the default of the parameter BackTransform is TRUE any conflict with the old function GroupClusterEffect is generated, but the new facility is implemented.

Perform post hoc analyses via pairwise comparisons of all the effect levels, or of a supplied subset of effects (using the parameter "EffectIndices") or even linear combinations of effects (using the parameter "EffectsMatrix"). Uses the syntax of the function posthoc, which differs slightly from the original syntaxis of GroupClusterEffects.

Value

an object of (S3) class "PostHoc" with methods for print, summary, plot, barplot and lines defined. An object of class "PostHoc" contails the effects, grouping, the matrix of p-values of all pairwise comparisons, the graph (Gr) of adjacency, the confidence intervals of the effects, the significance levels, the number of digits to be used for printing, the list of maximal cliques of the graph Gr, the clusters (if calculated).

Author(s)

Rodrigo Labouriau

Examples

MM <- glm(Y ~ Treatment+0,  data=DeIdentifiedExample)
GG <- posthoc(MM)
print(GG)

Calculates all p-values of pairwise comparisons using a Kruskal-Wallis test

Description

Calculates all p-values of pairwise comparisons using a Kruskal-Wallis test

Usage

KruskalWallisAllPvalues(y, g, padjust = "fdr")

Arguments

y

is a vector with the response

g

is a single classification factor

padjust

the method for adjusting for multiple comparisons following the convention of the functions stats::p. adjust(default = "fdr"), NULL or "none" does not adjust

Value

a vector with the p-values for comparing all the possible pairs.

Author(s)

Rodrigo Labouriau

Examples

KruskalWallisAllPvalues(y = DeIdentifiedExample$Y,
                                  g = DeIdentifiedExample$Treatment)

Lines method for objects of class PostHoc

Description

Lines method for objects of class PostHoc

Usage

## S3 method for class 'PostHoc'
lines(
  x,
  col = "black",
  labelsCol = "black",
  space2max = 0,
  UseGrouping = TRUE,
  ylim = NULL,
  main = "",
  ylab = "",
  xlab = "",
  lty = 1,
  drawAxis = TRUE,
  rightshift = 0,
  additionalTextGrouping = "",
  superpose = FALSE,
  cex.grouping = 1,
  cex.ticks = 0.1,
  cex.lab = 1,
  ylog = FALSE,
  ...
)

Arguments

x

an object of class PostHoc to be printed

col

the colour of the lines (default = "black")

labelsCol

the colour of the bars (default = "black")

space2max

space between the upper limit of the confidence interval and the label¨

UseGrouping

should the grouping be added to the plots (default = TRUE)

ylim

range of the vertical axis

main

character with the title of the plot (default = ”)

ylab

label of the vertical axis

xlab

label of the horizontal axis

lty

type of line

drawAxis

should the axis be drawn (default = TRUE)

rightshift

a number specifying a (small) right shift of the line

additionalTextGrouping

character vector with additional text to the grouping

superpose

should the graph be superposed to an existing graph (default = FALSE)

cex.grouping

size of the labels of groups

cex.ticks

size of the thicks defining the the limits of the confidence intervals

cex.lab

size of the labels

ylog

should the vertical axis be expressed in a logarithmic scale (default = FALSE)

...

parameters to be passed to the function lines

Value

none

Author(s)

Rodrigo Labouriau

Examples

MM <- glm(Y ~ Treatment+0,  data = DeIdentifiedExample)
GG <- posthoc(MM)
lines(GG)

Confidence intervals for medians

Description

Confidence intervals for medians

Usage

MedianBootCI(y, g, Nboots = 9999, Coverage = 0.95, digits = 4)

Arguments

y

is a vector with the response.

g

is a single classification factor.

Nboots

number of bootstrap samples (default = 9999).

Coverage

the coverage probability of the confidence interval.

digits

the number of digits (devfault = 4) (default = 0.95) "none" does not adjust

Value

a matrix with three columns, the median, the lower bound and the upper bound of the confidence interval and one row for each level of g.

Author(s)

Rodrigo Labouriau

Examples

MedianBootCI (y = DeIdentifiedExample$Y,
                                  g = DeIdentifiedExample$Treatment)

Plot method for objects of class PostHoc

Description

Plot method for objects of class PostHoc

Usage

## S3 method for class 'PostHoc'
plot(x, y, ...)

Arguments

x

an object of class PostHoc to be printed.

y

an object of class PostHoc to be printed.

...

further arguments passed to or from other methods.

Value

none

Author(s)

Rodrigo Labouriau

Examples

MM <- glm(Y ~ Treatment + 0,  data = DeIdentifiedExample)
GG <- posthoc(MM)
plot(GG)

Group effects for GLMs and GLMMs

Description

posthoc is used to group or cluster the effects of liner, generalised linear and generalised linear mixed models according to significance of pairwise tests comparing the levels of the effects.

Usage

posthoc (Model, EffectIndices = NULL, EffectLabels = NULL,
         EffectsMatrix = NULL, ParBootstrap = FALSE, Nboots = 999,
         SignificanceLevel = 0.05, UpperCase = FALSE,
         RankLabels = TRUE, WaldApproximation = FALSE,
         CalcClusters = FALSE, QUIET = TRUE, PlotAdj = FALSE,
         digits = 4, padjust = NULL, Scale = 1.0, Location = 0.0,
         isBinomialModel = FALSE, BackTransform = TRUE)

Arguments

Model

a model of class lm, glm, glmerMod, lme or gls.

EffectIndices

a vector containing the indices of the effects to be analysed (default = NULL, indicating that all the levels are used).

EffectLabels

a character vector with the labels of the effects (default = NULL, which implies that the corresponding labels of the model coefficient are used).

EffectsMatrix

matrix defining contrasts to be compared (bypasses the EffectIndices, default is NULL, meaning that standard inference is performed).

ParBootstrap

logic flag indicating whether the confidence intervals should be calculated with parametric bootstrap (default is false, i.e. the Wald confidence interval is used). Not implemented for objects of class lme.

Nboots

number of bootstrap samples used for the confidence interval. (default = 999).

SignificanceLevel

the significance level of the pairwise comparisons (default = 0.05).

UpperCase

should upper case letters be used for labelling the groups (default is FALSE).

RankLabels

should the labels of the grouping be sorted according to the value of the response (default=TRUE)

WaldApproximation

logic flag indicating whether a Wald approximated test should be used (defaut = FALSE).

CalcClusters

should the clusters be calculated and displayed instead of grouping (Default is FALSE)

QUIET

flag indicating whter the (large) output of the multcomp library should be temporarily re-directed (default = TRUE).

PlotAdj

should the associated graph be printed(default = FALSE).

digits

number of digits in the output (default = 4)

padjust

method for correcting the p-values (before the calculations are performed) as in the function p.adjust (Default is NULL, indicating that no multiple testing corrections are used)

Scale

a scaling factor multiplying the output table (default = 1, i.e., no scaling is used).

Location

a location term added to the output table (default = 0, i.e., no location shift is performed).

isBinomialModel

a logical flag indicating whther the model is a binomial model different than the Bernoulli (default = FALSE, i.e. not a binomial model).

BackTransform

should the parameters and CIs be back transformed by applying the inverse link function (default = TRUE)

Details

The function contructs, using the supplied matrix of p-values for all pairwise comparisosns, an undirected graph with vertices representing the levels of the effects, using the convention that two vertices are connected by an edge iff the p-value for testing equality the two vertices is larger than the prefixed significance level. The maximal cliques of this graph form the grouping of the levels of the effects.

Perform post hoc analyses via pairwise comparisons of all the effect levels, or of a supplied subset of effects (using the parameter "EffectIndices") or even linear combinations of effects (using the parameter "EffectsMatrix")

Value

an object of (S3) class "PostHoc" with methods for print, summary, plot, barplot and lines defined. An object of class "PostHoc" contails the effects, grouping, the matrix of p-values of all pairwise comparisons, the graph (Gr) of adjacency, the confidence intervals of the effects, the significance levels, the number of digits to be used for printing, the list of maximal cliques of the graph Gr, the clusters (if calculated).

Author(s)

Rodrigo Labouriau

Examples

MM <- glm(Y ~ Treatment+0,  data=DeIdentifiedExample)
GG <- posthoc(MM)
print(GG)

Post-hoc analysis based on the Kruskal-Walis test

Description

posthocKW is used to group or cluster effects using the Kruskal-Wallis test for making a non-parametric based post-hoc analysis.

Usage

posthocKW (y, g, EffectIndices = NULL, EffectLabels = NULL,
         Nboots = 9999, SignificanceLevel = 0.05, UpperCase = FALSE,
         RankLabels = TRUE, CalcClusters = FALSE, PlotAdj = FALSE,
         digits = 4, padjust = NULL, Scale = 1.0, Location = 0.0)

Arguments

y

is a vector with the response.

g

is a single classification factor.

EffectIndices

a vector containing the indices of the effects to be analysed (default = NULL, indicating that all the levels are used).

EffectLabels

a character vector with the labels of the effects (default = NULL, which implies that the corresponding labels of the model coefficient are used).

Nboots

number of bootstrap samples used for the confidence interval. (default = 9999).

SignificanceLevel

the significance level of the pairwise comparisons (default = 0.05).

UpperCase

should upper case letters be used for labelling the groups (default is FALSE).

RankLabels

should the labels of the grouping be sorted according to the value of the response (default=TRUE)

CalcClusters

should the clusters be calculated and displayed instead of grouping (Default is FALSE)

PlotAdj

should the associated graph be printed(default = FALSE).

digits

number of digits in the output (default = 4)

padjust

method for correcting the p-values (before the calculations are performed) as in the function p.adjust (Default is NULL, indicating that no multiple testing corrections are used)

Scale

a scaling factor multiplying the output table (default = 1, i.e., no scaling is used).

Location

a location term added to the output table (default = 0, i.e., no location shift is performed).

Details

The function contructs, using Kruskal-Wallis rank sum tests all pairwise comparisosns, an undirected graph with vertices representing the levels of the effects, using the convention that two vertices are connected by an edge iff the p-value for testing equality the two vertices is larger than the prefixed significance level. The maximal cliques of this graph form the grouping of the levels of the effects.

Value

an object of (S3) class "PostHoc" with methods for print, summary, plot, barplot and lines defined. An object of class "PostHoc" contails the effects, grouping, the matrix of p-values of all pairwise comparisons, the graph (Gr) of adjacency, the confidence intervals of the effects, the significance levels, the number of digits to be used for printing, the list of maximal cliques of the graph Gr, the clusters (if calculated).

Author(s)

Rodrigo Labouriau

Examples

print( posthocKW(DeIdentifiedExample$Y, DeIdentifiedExample$Treatment) )

Print methods for objects of class PostHoc

Description

Print methods for objects of class PostHoc

Usage

## S3 method for class 'PostHoc'
print(x, digits = 4, ...)

Arguments

x

an object of class PostHoc to be printed

digits

number of digits in the output (default = 4)

...

further arguments passed to or from other methods.

Value

a dataframe with two variables, Levels a factor containing the levels of the effects and ParaeterCI which is a factor with the effects and the corresponding confidence intervals and the grouping combined in a character constructed in such a way that when printing this dataframe yields a table arranged in a suitable format.

Author(s)

Rodrigo Labouriau

Examples

MM <- glm(Y ~ Treatment + 0,  data = DeIdentifiedExample)
GG <- posthoc(MM)
print(GG)

Summary method for objects of class PostHoc

Description

Summary method for objects of class PostHoc

Usage

## S3 method for class 'PostHoc'
summary(object, ...)

Arguments

object

an object of class PostHoc to be printed.

...

further arguments passed to or from other methods.

Value

a dataframe constructed in such a way that when printing this dataframe yields a table arranged in a suitable format. The summary, differently than the print method displays also the matrix of p-values of all the pairwise comparisons.

Author(s)

Rodrigo Labouriau

Examples

MM <- glm(Y ~ Treatment + 0,  data = DeIdentifiedExample)
GG <- posthoc(MM)
summary(GG)

Calculates a Wald approximation for the p-values of pairwise comparisons

Description

Calculates a Wald approximation for the p-values of pairwise comparisons

Usage

WaldPvalues(Effects, CovMatrix, padjust = "fdr")

Arguments

Effects

a vector containing the effects

CovMatrix

the covariance matrix of the effects

padjust

method for correcting for multiple testing as in the function p.adjust (default = "fdr", if NULL no adjustments is made)

Value

a vector of p-values.

Author(s)

Rodrigo Labouriau