pairwise: Construct a Pairwise Contrast Matrix for 'rma' Objects

View source: R/pairwise.r

pairwiseR Documentation

Construct a Pairwise Contrast Matrix for 'rma' Objects

Description

Functions to construct a matrix of pairwise contrasts for objects of class "rma". \loadmathjax

Usage

pairwise(x, btt, btt2, ...)

Arguments

x

an object of class "rma".

btt

vector of indices to specify for which coefficients pairwise contrasts should be constructed. Can also be a string to grep for. See ‘Details’.

btt2

optional argument to specify a second set of coefficients that should also be included in the contrast matrix.

...

other arguments.

Value

When a meta-regression model includes a categorical moderator variable (i.e., a factor), there is often interest in testing whether the coefficients representing the various levels of the factor differ significantly from each other. The present function constructs the pairwise contrast matrix between all factor levels for a particular factor, which can be used together with the anova function to carry out such tests and the predict function to obtain corresponding confidence intervals.

The x argument is used to specify a meta-regression model and the btt argument the indices of the coefficients for which pairwise contrasts should be constructed. For example, with btt=2:4, contrasts are formed based on the second, third, and fourth coefficient of the model. Instead of specifying the coefficient numbers, one can specify a string for btt. In that case, grep will be used to search for all coefficient names that match the string.

At times, it may be useful to include a second set of coefficients in the contrast matrix (not as pairwise contrasts, but as ‘main effects’). This can be done via the btt2 argument.

When using the present function in a call to the anova or predict functions, argument x does not need to specified, as the function will then automatically construct the contrast matrix based on the model object passed to the anova or predict function. See below for examples.

Author(s)

Wolfgang Viechtbauer wvb@metafor-project.org https://www.metafor-project.org

References

Viechtbauer, W. (2010). Conducting meta-analyses in R with the metafor package. Journal of Statistical Software, 36(3), 1–48. ⁠https://doi.org/10.18637/jss.v036.i03⁠

See Also

rma.uni, rma.glmm, and rma.mv for functions to fit meta-regression models for which pairwise contrasts may be useful.

anova for a function to carry out tests of the pairwise contrasts and predict to obtain corresponding confidence/prediction intervals.

Examples

### calculate log risk ratios and corresponding sampling variances
dat <- escalc(measure="RR", ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat.bcg)

### mixed-effects meta-regression model with the allocation method as a moderator;
### by removing the intercept term, we obtain the estimated average effect for each
### factor level from the model
res <- rma(yi, vi, mods = ~ 0 + alloc, data=dat)
res

### construct the contrast matrix for the 'alloc' factor
pairwise(res, btt=1:3)
pairwise(res, btt="alloc")

### test all pairwise contrasts
anova(res, X=pairwise(btt=1:3))
anova(res, X=pairwise(btt="alloc"))

### obtain the corresponding confidence intervals
predict(res, newmods=pairwise(btt="alloc"))

### test all pairwise contrasts adjusting for multiple testing
anova(res, X=pairwise(btt="alloc"), adjust="bonf")

### fit the same model, but including the intercept term; then 'alternate' is the
### reference level and the coefficients for 'random' and 'systematic' already
### represent pairwise contrasts with this reference level
res <- rma(yi, vi, mods = ~ alloc, data=dat)
res

### in this case, we want to include these coefficients directly in the contrast
### matrix (btt2=2:3) but also include the pairwise contrast between them (btt=2:3)
pairwise(res, btt=2:3, btt2=2:3)
pairwise(res, btt="alloc", btt2="alloc")

### test all pairwise contrasts
anova(res, X=pairwise(btt=2:3, btt2=2:3))
anova(res, X=pairwise(btt="alloc", btt2="alloc"))

### obtain the corresponding confidence intervals
predict(res, newmods=pairwise(btt="alloc", btt2="alloc"))

### meta-regression model with 'ablat' and 'alloc' as moderators
res <- rma(yi, vi, mods = ~ ablat + alloc, data=dat)
res

### test all pairwise contrasts between the 'alloc' levels (while controlling for 'ablat')
anova(res, X=pairwise(btt="alloc", btt2="alloc"))
anova(res, X=pairwise(btt="alloc", btt2="alloc"))

### obtain the corresponding confidence intervals
predict(res, newmods=pairwise(btt="alloc", btt2="alloc"))

### an example of a meta-regression model with more factors levels
dat <- dat.bangertdrowns2004
res <- rma(yi, vi, mods = ~ 0 + factor(grade), data=dat)
res

### test all pairwise contrasts between the 'grade' levels
anova(res, X=pairwise(btt="grade"))

### obtain the corresponding confidence intervals
predict(res, newmods=pairwise(btt="grade"))

### test all pairwise contrasts adjusting for multiple testing
anova(res, X=pairwise(btt="grade"), adjust="bonf")

wviechtb/metafor documentation built on July 12, 2024, 6:33 a.m.