if (FALSE) {
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)")
}
## 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")
}
Run the code above in your browser using DataLab