factorplot: Calculate Pairwise Differences

Description Usage Arguments Details Value Author(s) References Examples

Description

This function calculates all pairwise difference from the input data. The input data can be the result of a GLM (produced with glm), a multinomial logit model (produced with multinom from the nnet package), a general linear hypothesis test (produced with glht from the multcomp package), an object of class eff from the effects package or any vector of values and a corresponding variance-covariance matrix.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
## S3 method for class 'glm'
factorplot(obj, adjust.method="none", order="natural", 
    factor.variable=NULL, pval=.05, two.sided=TRUE, ...)
## S3 method for class 'lm'
factorplot(obj, adjust.method="none", order="natural", 
    factor.variable=NULL, pval=.05, two.sided=TRUE, ...)
## S3 method for class 'glht'
factorplot(obj, adjust.method="none", pval=.05, ...)
## S3 method for class 'summary.glht'
factorplot(obj, ...)
## S3 method for class 'multinom'
factorplot(obj, adjust.method="none", order="natural", 
    variable, pval = .05, two.sided=TRUE, ...)
## S3 method for class 'eff'
factorplot(obj, adjust.method="none", order="natural", 
    pval=0.05, two.sided=TRUE, ordby = NULL, ...)
## Default S3 method:
factorplot(obj, adjust.method="none", order="natural", 
    var, resdf, pval=0.05, two.sided=TRUE, ...)

Arguments

obj

An object of class glm or lm, glht, summary.glht, multinom or a vector of values (of class numeric) for which pairwise differences will be calculated.

factor.variable

String containing the name of the factor for which pairwise coefficient differences will be calculated (if a glm or lm class object is passed to the function)

variable

String containing the name of the column of the model matrix for which pairwise differences will be calculated if a multinom class object is passed to the function

var

Variance-covariance matrix to be used if obj is a numeric vector. This could also be a vector of quasi/floating variances from which a diagonal variance-covariance matrix will be produced

resdf

Residual degrees of freedom used as the degrees of freedom for the t-distribution from which p-values will be generated if obj is a numeric vector

pval

The (uncorrected) Type I error probability required, default = 0.05

two.sided

Logical argument indicating whether the hypothesis test should be against a two-sided alternative if TRUE (default) or a one-sided alternative if FALSE

order

One of ‘natural’, ‘alph’, or ‘size’ indicating how the levels of the factor should be ordered for presentation. The ‘natural’ option (the default) leaves the levels as they are in the factor contrasts. ‘alph’ sorts the levels alphabetically and ‘size’ sorts the levels by size of coefficient.

adjust.method

For objects of class multinom and numeric - one of the methods allowed by p.adjust in stats - ‘holm’, ‘hochberg’, ‘hommel’, ‘bonferroni’, ‘BH’, ‘BY’, ‘fdr’, ‘none’. See help for the p.adjust for more information on these different adjustment methods. For objects of class glm, lm or glht, additional arguments of ‘single-step’, ‘Shaffer’, ‘Westfall’ and ‘free’ are possible. See glht from the multcomp package for details.

ordby

For objects of class eff with interactions, ordby is a string indicating the variable by which the plot should be ordered.

...

Additional arguments to be passed to summary.glht, including, but not limited to level and alternative.

Details

This function calculates pairwise differences that can be passed to a novel plotting method that does not suffer from some of the same problems as floating/quasi confidence intervals and is easier to apprehend immediately than a compact letter display.

While the factorplot function and its print and summary methods work equally well regardless of the number of levels in the factor.variable, the plot function automatically scales the resulting graph to the appropriate size, but will be less useful as the number of contrasts gets large (e.g., > 30). If more than one factor covariate is present and the factor.variable option is NULL, the function generates a text-based menu in the R GUI that will allow the users to pick the term for which they want to calculate the results.

Value

b.diff

An upper-triangular matrix of pairwise differences between row and column levels of the factor

b.sd

An upper-triangular matrix of standard errors of the pairwise differences represented in b.diff

pval

An upper-triangular matrix of uncorrected (one-sided) p-values corresponding to the entries of b.diff

p

The p-value specified in the command

Author(s)

Dave Armstrong (Department of Political Science, UW-Milwaukee)

References

Easton, D.F., J. Peto and G.A.G. Babiker. 1991. Floating absolute risk: An alternative to relative risk in survival and case control analysis avoiding an arbitrary reference group. Statistics in Medicine 10: 1025–1035.
Firth, David and Renee X. de Menzes. 2004. Quasi-variances. Biometrika 91.1: 65–80.
Plummer, M. 2004. Improved estimates of floating absolute risk. Statistics in Medicine 23: 93–104.

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
## for lm/glm
x <- as.factor(round(runif(1000, .5,5.5)))
levels(x) <- paste("lab", 1:20, sep="")
X <- model.matrix(~x)
Y <- X %*% rnorm(ncol(X),0,4) + rnorm(1000)
mod <- lm(Y ~ x)
fp <- factorplot(mod, factor.variable="x",  pval = 0.05, order="alph")

## for glht
library(multcomp)
mod.glht <- glht(mod, linfct = mcp('x' = 'Tukey'))
fp2 <- factorplot(mod.glht, adjust.method='single-step')

## for vector of values
b <- c(0, mod$coef[-1])
v <- rbind(0, cbind(0, vcov(mod)[-1,-1]))
names(b) <- colnames(v) <- rownames(v) <- mod$xlevels[["x"]]
fp3 <- factorplot(b, var=v, resdf=mod$df.residual)

## for multinomial logit
data(france)
library(nnet)
multi.mod <- multinom(vote ~ retnat + lrself + male + age, data=france)
fp4 <- factorplot(multi.mod, variable="lrself")

Example output

Loading required package: mvtnorm
Loading required package: survival
Loading required package: TH.data
Loading required package: MASS

Attaching package: 'TH.data'

The following object is masked from 'package:MASS':

    geyser

# weights:  35 (24 variable)
initial  value 872.315349 
iter  10 value 655.272636
iter  20 value 559.902797
iter  30 value 551.176433
final  value 551.169697 
converged

factorplot documentation built on May 1, 2019, 11:29 p.m.