plotPredictions.data.frame | R Documentation |
This function plots the predictions y
that are based on
classify
and 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.
## S3 method for class 'data.frame'
plotPredictions(data, classify, y,
x.num = NULL, x.fac = NULL, nonx.fac.order = NULL,
colour.scheme = "colour", panels = "multiple",
graphics.device = NULL,
error.intervals = "Confidence", interval.annotate = TRUE,
titles = NULL, y.title = NULL,
filestem = NULL, printPlot = TRUE, ggplotFuncs = NULL, ...)
data |
A If |
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 |
y |
A character string giving the name of the variable that is to be plotted on the Y axis. |
x.num |
A |
x.fac |
A character string giving the name of the factor that corresponds to
|
nonx.fac.order |
A character vector giving the order in which factors other
than |
colour.scheme |
A character string specifying the colour scheme for the plots.
The default is |
panels |
Possible values are |
graphics.device |
A |
error.intervals |
A character string indicating the type of error interval, if any,
to plot in order to indicate uncertainty in the results.
Possible values are |
interval.annotate |
A |
titles |
A |
y.title |
The title to be displayed on the y axis of any plot. |
filestem |
A character sting giving the beginning of the name of the file in which to
save the plot. If |
printPlot |
A |
ggplotFuncs |
A |
... |
further arguments passed to |
An object of class ggplot
, which can be plotted using print
or otherwise manipulated.
Chris Brien
allDifferences.data.frame
, predictPresent.asreml
,
redoErrorIntervals.alldiffs
,
recalcLSD.alldiffs
, ggplot
, Devices
## Not run:
data(WaterRunoff.dat)
asreml.options(keep.order = TRUE) #required for asreml-R4 only
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 <- as.asrtests(current.asr, NULL, NULL)
#### Get the observed combinations of the factors and variables in classify
class.facs <- c("Species","Date","xDay")
levs <- as.data.frame(table(WaterRunoff.dat[class.facs]))
levs <- as.list(levs[levs$Freq != 0, class.facs])
levs$xDay <- as.numfac(levs$xDay)
predictions <- predict(current.asr, classify="Species:Date:xDay",
parallel = TRUE, levels = levs,
present = c("Type","Species","Sources"))
#### for asreml-R3
predictions <- predictions$predictions$pvals
predictions <- predictions[predictions$est.status == "Estimable",]
#### for asreml-R4
predictions <- predictions$pvals
predictions <- predictions[predictions$status == "Estimable",]
#### end
plotPredictions(classify="Species:Date:xDay", y = "predicted.value",
data = predictions,
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 <- predictPlus(classify="Species:Date:xDay",
present=c("Type","Species","Sources"),
asreml.obj = current.asr, tables = "none",
x.num = "xDay", x.fac = "Date",
parallel = TRUE, levels = levs,
x.plot.values=c(0,28,56,84),
wald.tab = current.asrt$wald.tab)
x.title <- "Days since first observation"
names(x.title) <- "xDay"
plotPredictions(classify="Species:Date:xDay", y = "predicted.value",
data = diffs$predictions,
x.num = "xDay", x.fac = "Date",
titles = x.title,
y.title = "Predicted log(Turbidity)")
## End(Not run)
## Use lmerTest and emmmeans to get predictions and associated statistics
if (requireNamespace("lmerTest", quietly = TRUE) &
requireNamespace("emmeans", quietly = TRUE))
{
data(Ladybird.dat)
m1.lmer <- lmerTest::lmer(logitP ~ Host*Cadavers*Ladybird + (1|Run),
data=Ladybird.dat)
HCL.emm <- emmeans::emmeans(m1.lmer, specs = ~ Host:Cadavers:Ladybird)
HCL.preds <- summary(HCL.emm)
den.df <- min(HCL.preds$df)
## Modify HCL.preds to be compatible with a predictions.frame
HCL.preds <- as.predictions.frame(HCL.preds, predictions = "emmean",
se = "SE", interval.type = "CI",
interval.names = c("lower.CL", "upper.CL"))
## Plot the predictions
plotPredictions(HCL.preds, y = "predicted.value", "Host:Cadavers:Ladybird")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.