plotLSDerrors.data.frame: Plots a map of the supplied errors that occur in using the...

plotLSDerrors.data.frameR Documentation

Plots a map of the supplied errors that occur in using the computed LSD values for pairwise differences between predictions.

Description

Produces a plot of the errors that have been supplied in a data.frame. The data.frame includes two factors whose levels specify, for each LSD result, which combinations of factor levels are being compared. The function plotLSDerrors.alldiffs produces such data.frames.

Usage

## S3 method for class 'data.frame'
plotLSDerrors(object, LSDresults = "LSDresults", x, y, 
              alpha = 0.05, triangles = "both", 
              gridspacing = 0, title = NULL, 
              axis.labels = NULL, axis.text.size = 12, 
              colours = c("white","blue","red","grey"), 
              ggplotFuncs = NULL, printPlot = TRUE, ...)

Arguments

object

A data.frame containing the three columns specified by LSDresults, x and y.

LSDresults

A character giving the name of the column in object that contains the LSDresults values to be plotted. The column should be a character or factor with values or levels that are a subset of Ok,FN, FP and na.

x

A character giving the name of the column in object that contains the factor whose levels index the LSD values that are to be plotted in the same column.

y

A character giving the name of the column in object that contains the labels of the LSD values that are to be plotted as the rows.

alpha

A numeric giving the significance level for the LSD.

triangles

A character indicating whether the plot should include the lower, upper or both triangle(s). Here it is only used to adjust gridlines for the omission of the diagonal.

gridspacing

A numeric specifying the number(s) of rows and columns that form groups in the grid of differences. This is 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.

title

A character string giving the main title for the plot.

axis.labels

A character string giving the label to use for both the x- and y-axis.

axis.text.size

A numeric giving the size of the labels on the axes of the heatmap.

colours

A vector of colours to be passed to the ggplot function scale\_colour\_gradientn.

ggplotFuncs

A list, each element of which contains the results of evaluating a ggplot2 function. It is created by calling the list function with a ggplot2 function call for each element. These functions are applied in creating the ggplot object.

printPlot

A logical indicating whether or not the a plot is to be printed. This would be used when just the returned ggplot object is required.

...

Provision for passing arguments to functions called internally - not used at present.

Value

An object of class "ggplot", which can be plotted using print or otherwise manipulated.

Author(s)

Chris Brien

See Also

plotLSDs.data.frame, plotLSDs.alldiffs, exploreLSDs, ggplot

Examples

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

##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 * (Type + Species)) + 
                              (1|Benches:MainPlots),
                            data=na.omit(WaterRunoff.dat))
  TS.emm <- emmeans::emmeans(m1.lmer, specs = ~ Sources:Type)
  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:Type", 
                             vcov = TS.vcov, tdf = den.df)
  validAlldiffs(TS.diffs)
}  

## Plot LSD values for predictions obtained using asreml or lmerTest
if (exists("TS.diffs"))
{
  LSDresults <- within(reshape2::melt(TS.diffs$p.differences), 
                      { 
                        Var1 <- factor(Var1, levels=dimnames(TS.diffs$p.differences)[[1]])
                        Var2 <- factor(Var2, levels=levels(Var1))
                      })
  names(LSDresults) <- c("Rows","Columns","LSDresults")
  plotLSDerrors(LSDresults, x = "Rows", y = "Columns", gridspacing = rep(c(3,4), c(4,2)))
}

asremlPlus documentation built on Oct. 27, 2024, 5:06 p.m.