sort.predictions.frame {asremlPlus} | R Documentation |
Sorts a predictions.frame
according to the predicted values
associated with a factor.
Description
Sorts the rows of a predictions.frame
according to the predicted values
in the predictions.frame
. These predicted values are generally obtained using
predict.asreml
by specifying a classify
term comprised of one or
more variables. Generally, the values associated with one variable are sorted in
parallel within each combination of values of the other variables. When there is more
than one variable in the classify
term, the sorting is controlled using
one or more of sortFactor
, sortParallelToCombo
and sortOrder
.
If there is only one variable in the classify
then the predictions.frame
is sorted according to the order of the complete set of predictions.
Usage
## S3 method for class 'predictions.frame'
sort(x, decreasing = FALSE, classify, sortFactor = NULL,
sortParallelToCombo = NULL, sortNestingFactor = NULL,
sortOrder = NULL, ...)
Arguments
x |
|
decreasing |
A |
classify |
A |
sortFactor |
A |
sortParallelToCombo |
A |
sortNestingFactor |
A |
sortOrder |
A The following creates a |
... |
further arguments passed to or from other methods. Not used at present. |
Details
The basic technique is to change the order of the levels of the sortFactor
within the predictions.frame
so
that they are ordered for a subset of predicted values, one for each levels of the
sortFactor
. When the classify
term consists of more than one
variable then a subset of one combination of the values of variables other than
the sortFactor
, the sortParallelToCombo
combination, must be chosen for determining the
order of the sortFactor
levels. Then the sorting of the rows (and columns)
will be in parallel within each combination of the values of sortParallelToCombo
variables:
the classify
term, excluding the sortFactor
.
Value
The sorted predictions.frame
. Also, the sortFactor
and
sortOrder
attributes are set.
Author(s)
Chris Brien
See Also
as.predictions.frame
, print.predictions.frame
,
sort.alldiffs
,
predictPlus.asreml
, predictPresent.asreml
Examples
##Halve 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:
#Analyse pH
m1.asr <- asreml(fixed = pH ~ Benches + (Sources * (Type + Species)),
random = ~ Benches:MainPlots,
keep.order=TRUE, data= tmp)
current.asrt <- as.asrtests(m1.asr, NULL, NULL)
current.asrt <- as.asrtests(m1.asr)
current.asrt <- rmboundary(current.asrt)
m1.asr <- current.asrt$asreml.obj
#Get predictions and associated statistics
TS.diffs <- predictPlus.asreml(classify = "Sources:Type",
asreml.obj = m1.asr, tables = "none",
wald.tab = current.asrt$wald.tab,
present = c("Type","Species","Sources"))
#Use sort.predictions.frame and save order for use with other response variables
TS.preds <- TS.diffs$predictions
TS.preds.sort <- sort(TS.preds, sortFactor = "Sources",
sortParallelToCombo = list(Type = "Control"))
sort.order <- attr(TS.preds.sort, which = "sortOrder")
#Analyse Turbidity
m2.asr <- asreml(fixed = Turbidity ~ Benches + (Sources * (Type + Species)),
random = ~ Benches:MainPlots,
keep.order=TRUE, data= tmp)
current.asrt <- as.asrtests(m2.asr)
#Use pH sort.order to sort Turbidity alldiffs object
TS.diffs2 <- predictPlus(m2.asr, classify = "Sources:Type",
pairwise = FALSE, error.intervals = "Stand",
tables = "none", present = c("Type","Species","Sources"))
TS.preds2 <- TS.diffs2$predictions
TS.preds2.sort <- sort(TS.preds, sortFactor = "Sources", sortOder = sort.order)
## End(Not run)
## Use lmeTest and emmmeans to get predictions and associated statistics
if (requireNamespace("lmerTest", quietly = TRUE) &
requireNamespace("emmeans", quietly = TRUE))
{
#Analyse pH
m1.lmer <- lmerTest::lmer(pH ~ Benches + (Sources * (Type + Species)) +
(1|Benches:MainPlots),
data=na.omit(tmp))
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"))
#Use sort.predictions.frame and save order for use with other response variables
TS.preds.sort <- sort(TS.preds, classify = "Sources:Type", sortFactor = "Sources",
sortParallelToCombo = list(Type = "Control"))
sort.order <- attr(TS.preds.sort, which = "sortOrder")
#Analyse Turbidity
m2.lmer <- lmerTest::lmer(Turbidity ~ Benches + (Sources * (Type + Species)) +
(1|Benches:MainPlots),
data=na.omit(tmp))
TS.emm <- emmeans::emmeans(m2.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"))
}