plotPvalues.alldiffs {asremlPlus} R Documentation

## Plots a heat map of p-values for pairwise differences between predictions.

### Description

Produces a heat-map plot of the p-values for pairwise differences between predictions that is stored in the `p.differences` component of an `all.diffs` object. This is generally a matrix whose rows and columns are labelled by the levels of one or more factors, the set of labels being the same for rows and columns. The `sections` argument allows multiple plots to be produced, one for each combination of the levels of the factors listed in `sections`. Otherwise, a single plot is produced for all observed combinations of the levels of the factors in the `classify` for the `alldiffs.object`. The plots are produced using `plotPvalues.data.frame`. The order of plotting the levels of one of the factors indexing the predictions can be modified and is achieved using `sort.alldiffs`.

### Usage

```plotPvalues(object, ...)
## S3 method for class 'alldiffs'
plotPvalues(object, sections = NULL,
gridspacing = 0, factors.per.grid = 0,
show.sig = FALSE, triangles = "both",
title = NULL, axis.labels = TRUE, sep=",",
colours = RColorBrewer::brewer.pal(3, "Set2"),
ggplotFuncs = NULL, printPlot = TRUE,
sortFactor = NULL, sortWithinVals = NULL,
sortOrder = NULL, decreasing = FALSE, ...)```

### Arguments

 `object` An `alldiffs.object` with a `p.differences` component that is not `NULL`. `sections` A `character` listing the names of the factors that are to be used to break the plot into sections. A separate plot will be produced for each observed combination of the levels of these factors. `gridspacing` A `numeric` specifying the number(s) of rows and columns that form groups in the grid of differences. An alternative is to specify the `factors.per.grid` argument to have the grid spacings automatically calculated. Grids are most useful when two or more factors index the rows and columns. If a single, nonzero number, k say, is given then a grid line is placed after every kth row and column. If a vector of values is given then the number of grid lines is the length of the vector and the spacing between each is specified by the elements of the vector. `factors.per.grid` A `numeric` specifying the number of factors to include within each grid of differences. The `gridspacing` will then be computed based on the numbers of combinations observed within the levels of the remaining factors in a single plot. The `gridspacing` argument to this function will be ignored if `factors.per.grid` is greater than zero. Grids are most useful when two or more factors index the rows and columns of each plot. `show.sig` A `logical` that specifies whether asterisks indicating the level of significance are to be added to the plot. If they are then ‘***’ indicates that p <= 0.001, ‘**’ that 0.001 < p <= 0.01, ‘*’ that 0.01 < p <= 0.05 ‘.’ that 0.05 < p <= 0.10. `triangles` A `character` indicating whether the plot should include the `lower`, `upper` or `both` traingle(s). `title` A `character` string giving the main title for the plot and to which is appended the levels combination of the sectioning factors, if any, for each plot. `axis.labels` A `logical` indicating whether a label is to be added to the x- and y-axes. If TRUE, the label is the comma-separated list of factors whose levels combinations are involved in the prediction differences for which the p-values are calculated. `colours` A vector of of colours to be passed to the `ggplot` function `scale\_colour\_gradientn`. `sep` A `character` giving the characters separating the levels of different factors in the row and column names of the `p.differences` component. `ggplotFuncs` A `list`, each element of which contains the results of evaluating a `ggplot` function. It is created by calling the `list` function with a `ggplot` function call for each element. It is passed to `ggplot` via `plotPvalues.data.frame`. `printPlot` A `logical` indicating whether or not the a plot is to be printed. This would be used when just the returned `data.frame` is required. `sortFactor` A `character` containing the name of the `factor` that indexes the set of predicted values that determines the sorting of the components of the `alldiffs.object` by `sort.alldiffs`. If `NULL` then sorting is not carried out. If there is more than one variable in the `classify` term then `sortFactor` is sorted for the predicted values within each combination of the values of the sortWithin variables: the `classify` variables, excluding the `sortFactor`. There should be only one predicted value for each unique value of `sortFactor` within each set defined by a combination of the values of the sortWithin variables. `sortWithinVals` A `list` with a component named for each `factor` and `numeric` that is a `classify` variable for the predictions, excluding `sortFactor`. Each component should contain a single value that is a value of the variable. The combination of this set of values will be used to define a subset of the predicted values whose order will define the order of `sortFactor` to be used for all combinations of the `sortWithinVals` variables. If `sortWithinVals` is `NULL` then the first value of each sortWithin variable in `predictions` component is used to define `sortWithinVals`. If there is only one variable in the classify then `sortWithinVals` is ignored. `sortOrder` A `character vector` whose length is the same as the number of levels for `sortFactor` in the `predictions` component of the `alldiffs.object`. It specifies the desired order of the levels in the reordered components of the `alldiffs.object`. The argument `sortWithinVals` is ignored. The following creates a `sortOrder` vector `levs` for factor `f` based on the values in `x`: `levs <- levels(f)[order(x)]`. `decreasing` A `logical` passed to `order` that detemines whether the order for sorting the `alldiffs.object` components is for increasing or decreasing magnitude of the predicted values. `...` Provision for passsing arguments to functions called internally - not used at present.

### Value

A `data.frame` with the columns `X1`, `X2`, `p`, `sections1` and `sections2`. This data.frame is formed from the `p.differences` component of `object` and is used in producng the plot.

### Author(s)

Chris Brien

`plotPvalues.data.frame`, `allDifferences.data.frame`, `sort.alldiffs`, `subset.alldiffs`, `ggplot`

### Examples

```##Subset WaterRunoff data to reduce time to execute
data(WaterRunoff.dat)
tmp <- subset(WaterRunoff.dat, Date == "05-18" & Benches != "3")

##Use asreml to get predictions and associated statistics

## Not run:
asreml.options(keep.order = TRUE) #required for asreml-R4 only
current.asr <- asreml(fixed = pH ~ Benches + (Sources * (Type + Species)),
random = ~ Benches:MainPlots,
keep.order=TRUE, data= tmp)
current.asrt <- as.asrtests(current.asr, NULL, NULL)
TS.diffs <- predictPlus.asreml(classify = "Sources:Type",
asreml.obj = current.asr, tables = "none",
wald.tab = current.asrt\$wald.tab,
present = c("Type","Species","Sources"))

## End(Not run)

## Use lmeTest and emmmeans to get predictions and associated statistics

if (requireNamespace("lmerTest", quietly = TRUE) &
requireNamespace("emmeans", quietly = TRUE))
{
m1.lmer <- lmerTest::lmer(pH ~ Benches + Sources * Species +
(1|Benches:MainPlots),
data=tmp)
TS.emm <- emmeans::emmeans(m1.lmer, specs = ~ Sources:Species)
TS.preds <- summary(TS.emm)
den.df <- min(TS.preds\$df, na.rm = TRUE)
## Modify TS.preds to be compatible with a predictions.frame
TS.preds <- as.predictions.frame(TS.preds, predictions = "emmean",
se = "SE", interval.type = "CI",
interval.names = c("lower.CL", "upper.CL"))

## Form an all.diffs object and check its validity
TS.vcov <- vcov(TS.emm)
TS.diffs <- allDifferences(predictions = TS.preds, classify = "Sources:Species",
vcov = TS.vcov, tdf = den.df)
validAlldiffs(TS.diffs)
}

## Plot p-values for predictions obtained using asreml or lmerTest
if (exists("TS.diffs"))
{
plotPvalues(TS.diffs, gridspacing = rep(c(3,4), c(4,2)), show.sig = TRUE)

plotPvalues(TS.diffs, sections = "Sources", show.sig = TRUE, axis.labels = TRUE)

}
```

[Package asremlPlus version 4.2-32 Index]
{"ft_lang_label":"__label__en","ft_lang_prob":0.7129513,"math_prob":0.9641181,"size":8035,"snap":"2021-31-2021-39","text_gpt3_token_len":2066,"char_repetition_ratio":0.1302453,"word_repetition_ratio":0.03464567,"special_character_ratio":0.23335408,"punctuation_ratio":0.15979044,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99330354,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-08-04T15:43:02Z\",\"WARC-Record-ID\":\"<urn:uuid:cb3df6ec-d67a-45df-b7d9-036787946d6a>\",\"Content-Length\":\"13084\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:2cfb6658-6c18-4388-9360-1e8d1d1868c1>\",\"WARC-Concurrent-To\":\"<urn:uuid:61b5831c-e3f0-4753-9ffb-8820a4d8d8c0>\",\"WARC-IP-Address\":\"137.208.57.46\",\"WARC-Target-URI\":\"https://search.r-project.org/CRAN/refmans/asremlPlus/html/plotPvalues.alldiffs.html\",\"WARC-Payload-Digest\":\"sha1:MFTZ33YO45YL5UDLO5QMFVJHCOPU3YX5\",\"WARC-Block-Digest\":\"sha1:IJYR6ZZFBHR7UUJ7OSIW27WD3UFGHBZU\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-31/CC-MAIN-2021-31_segments_1627046154878.27_warc_CC-MAIN-20210804142918-20210804172918-00487.warc.gz\"}"}