predictionplot.asreml {asreml3Plus}R Documentation

This function plots the predictions for a term, possibly with error bars.

Description

This function plots the predictions y that are based on classify stored in the data.frame data. The package ggplot2 is used to produce the plots. Line plots are produced when variables involving x.num or x.fac are involved in classify for the predictions; otherwise, bar charts are produced. Further, for line charts, the argument panels determines whether a single plot or multiple plots in a single window are produced; for bar charts, the argument panels is ignored.

Usage

predictionplot.asreml(classify, y, data, 
                      x.num = NULL, x.fac = NULL, nonx.fac.order = NULL,  
                      colour.scheme = "colour", panels = "multiple", 
                      graphics.device = NULL,
                      error.intervals = "Confidence",  titles = NULL, 
                      y.title = NULL, filestem = NULL, ggplotFuncs = NULL, ...)

Arguments

classify

a character string giving the combinations of the independent variables on which the predictions are based. It is an interaction type term formed from the independent variables, that is, separating the variable names with the : operator.

y

a character string giving the name of the variable that is to be plotted on the Y axis.

data

a data.frame containing the values of the variables to be plotted. It should be consistent with an object of class asremlPredict such as is stored in the pvals component of the predictions component of the value produced by predict.asreml; that is, in addition to variables classifying the predictions, it will include a column with the name specified in the y argument, usually predicted.value or backtransformed.predictions; each row contains a single predicted value. If error.intervals is not "none", then the predictions component and, if present, the backtransforms component should contain columns for the lower and upper values of the limits for the interval with names that begin with lower and upper, respectively. The second part of the name must be one of Confidence, StandardError or halfLeastSignificant. The last part needs to be consistent between the lower and upper limits.

x.num

A character string giving the name of the numeric covariate that corresponds to x.fac, is potentially included in terms in the fitted model and which corresponds to the x-axis variable. It should have the same number of unique values as the number of levels in x.fac.

x.fac

A character string giving the name of the factor that corresponds to x.num, is potentially included in terms in the fitted model and which corresponds to the x-axis variable. It should have the same number of levels as the number of unique values in x.num. The levels of x.fac must be in the order in which they are to be plotted - if they are dates, then they should be in the form yyyymmdd which can be achieved using as.Date.

nonx.fac.order

A character vector giving the order in which factors other than x.fac are to be plotted in facetted plots (i.e. where the number of non x factors is greater than 1). The first factor in the vector will be plotted on the X axis (if there is no x.num or x.fac. Otherwise, the order of plotting the factors is in columns (X facets) and then rows (Y facets). By default the order is in decreasing order for the numbers of levels of the non x factors.

colour.scheme

A character string specifying the colour scheme for the plots. The default is "colour" which produces coloured lines and bars, a grey background and white gridlines. A value of "black" results in black lines, grey bars and gridlines and a white background.

panels

Possible values are "single" and "multiple". When line plots are to be produced, because variables involving x.num or x.fac are involved in classify for the predictions, panels determines whether or not a single panel or multiple panels in a single window are produced. The panels argument is ignored for bar charts.

graphics.device

A character specifying a graphics device for plotting. The default is
graphics.device = NULL, which will result in plots being produced on the current graphics device. Setting it to "windows", for example, will result in a windows graphics device being opened.

error.intervals

A character string indicating the type of error interval, if any, to calculate and plot in order to indicate uncertainty in the results. Possible values are "none", "StandardError", "Confidence" and "halfLeastSignificant". Here, any option other than "none" will result in the interval limits contained in data being plotted.

titles

A list, each component of which is named for an object name and contains a character string giving a title to use in output (e.g. tables and graphs) for the object. Here they will be used for axis labels for nonresponse variables. For response variable labels see y.title.

filestem

A character sting giving the beginning of the name of the file in which to save the plot. If filestem = NULL, the plot is not saved. The remainder of the file name will be generated automatically and consists of the following elements separated by full stops: the classify term, Bar or Line and, if error.intervals is not "none", one of SE, CI or LSI. The file will be saved as a ‘png’ file in the current work directory.

y.title

The title to be displayed on the y axis of any plot.

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.

...

further arguments passed to ggplot.

Value

no values are returned.

See Also

predictiondiffs.asreml, pred.present.asreml, ggplot, Devices

Examples

## Not run: 
data(WaterRunoff.dat)
current.asr <- asreml(fixed = log.Turbidity ~ Benches + Sources + Type + Species +
                                Sources:Type + Sources:Species + 
                                Sources:xDay + Species:xDay + Species:Date,
                      data = WaterRunoff.dat, keep.order = TRUE)
current.asrt <- asrtests(current.asr, NULL, NULL)
predictions <- predict(current.asr, class="Species:Date:xDay", 
                       present = c("Type","Species","Sources"),
                       levels=list(xDay=unique(WaterRunoff.dat$xDay)))$predictions$pvals
predictions <- predictions[predictions$est.status == "Estimable",]
predictionplot.asreml(classify="Species:Date:xDay", y = "predicted.value", 
                      data = predictions, wald.tab = current.asrt$wald.tab, 
                      x.num = "xDay", x.fac = "Date", 
                      x.title = "Days since first observation",
                      y.title = "Predicted log(Turbidity)",
                      present = c("Type","Species","Sources"),
                      error.intervals = "none",
                      ggplotFuncs = list(ggtitle("Transformed turbidity over time")))
  
diffs <- predictparallel.asreml(classify="Species:Date:xDay", 
                                present=c("Type","Species","Sources"), 
                                asreml.obj = current.asr, tables = "none", 
                                x.num = "xDay", x.fac = "Date", 
                                x.pred.values=sort(unique(WaterRunoff.dat$xDay)),
                                x.plot.values=c(0,28,56,84),
                                wald.tab = current.asrt$wald.tab)
x.title <- "Days since first observation"
names(x.title) <- "xDay"
predictionplot.asreml(classify="Species:Date:xDay", y = "predicted.value", 
                      data = diffs$predictions, wald.tab = current.asrt$wald.tab, 
                      x.num = "xDay", x.fac = "Date", 
                      titles = x.title,
                      y.title = "Predicted log(Turbidity)")

## End(Not run)

[Package asreml3Plus version 2.0-14 Index]