Uses supplied predictions and standard errors of pairwise differences,
or the variance matrix of predictions to form, in an
alldiffs.object
, for those components not already present,
(i) a table of all pairwise differences of the predictions,
(ii) the p-value of each pairwise difference, and
(iii) the minimum, mean, maximum and accuracy of LSD values.
Predictions that are aliased (or nonestimable) are removed from the
predictions
component of the alldiffs.object
and
standard errors of differences involving them are removed from the sed
component.
If necessary, the order of the columns of the variables in the predictions
component are changed to be the initial columns of the predictions.frame
and to match their order in the classify
. Also, the rows of predictions
component are ordered so that they are in standard order for the variables in the
classify
. That is, the values of the last variable change with every row,
those of the second-last variable only change after all the values of the last
variable have been traversed; in general, the values of a variable are the same for
all the combinations of the values to the variables to its right in the
classify
. The sortFactor
or sortOrder
arguments can be used
to order of the values for the classify
variables, which is achieved using
sort.alldiffs
.
Each p-value is computed as the probability of a t-statistic as large as or larger
than the absolute value of the observed difference divided by its standard error. The
p-values are stored in the p.differences
component. The degrees of freedom of
the t-distribution is the degrees of freedom stored in the tdf
attribute of
the alldiffs.object
. This t-distibrution is also used in calculating
the LSD statistics stored in the LSD
component of the alldiffs.object
.
# S3 method for data.frame
allDifferences(predictions, classify, vcov = NULL,
differences = NULL, p.differences = NULL, sed = NULL,
LSD = NULL, LSDtype = "overall", LSDsupplied = NULL,
LSDby = NULL, LSDstatistic = "mean",
LSDaccuracy = "maxAbsDeviation",
retain.zeroLSDs = FALSE,
zero.tolerance = .Machine$double.eps ^ 0.5,
backtransforms = NULL,
response = NULL, response.title = NULL,
term = NULL, tdf = NULL,
x.num = NULL, x.fac = NULL,
level.length = NA,
pairwise = TRUE, alpha = 0.05,
transform.power = 1, offset = 0, scale = 1,
inestimable.rm = TRUE,
sortFactor = NULL, sortParallelToCombo = NULL,
sortNestingFactor = NULL, sortOrder = NULL,
decreasing = FALSE, ...)
A predictions.frame
, or a data.frame
, beginning
with the variables classifying the predictions and also containing columns
named predicted.value
, standard.error
and est.status
;
each row contains a single predicted value. It may also contain columns
for the lower and upper limits of error intervals for the predictions.
Note that the names standard.error
and
est.status
have been changed to std.error
and status
in the pvals
component produced by asreml-R4
; if the new names
are in the data.frame
supplied to predictions
, they will be
returned to the previous names.
A character
string giving the variables that define the margins
of the multiway table that has been predicted. Multiway tables are
specified by forming an interaction type term from the
classifying variables, that is, separating the variable names
with the :
operator.
A matrix
containing the variance matrix of the predictions; it is used in
computing the variance of linear transformations of the predictions.
A matrix
containing all pairwise differences between
the predictions; it should have the same number of rows and columns as there are
rows in predictions
.
A matrix
containing p-values for all pairwise differences
between the predictions; each p-value is computed as the probability of a t-statistic
as large as or larger than the observed difference divided by its standard error.
The degrees of freedom of the t distribution for computing it are computed as
the denominator degrees of freedom of the F value for the fixed term, if available;
otherwise, the degrees of freedom stored in the attribute tdf
are used;
the matrix should be of the same size as that for differences
.
A matrix
containing the standard errors of all pairwise differences
between the predictions; they are used in computing the p-values.
An LSD.frame
containing the mean, minimum and maximum LSD for determining
the significance of pairwise differences, as well as an assigned LSD and a measure
of the accuracy of the LSD. If LSD
is NULL
then the LSD.frame
stored in the LSD
component will be calculated and
the values of LSDtype
, LSDby
and LSDstatistic
added as attributes
of the alldiffs.object
. The LSD for a single prediction
assumes that any predictions to be compared are independent; this is not the case if
residual errors are correlated.
A character
string that can be overall
, factor.combinations
,
per.prediction
or supplied
. It determines whether the values stored in an
LSD.frame
are
(i) the overall
number of pairwise comparisons, c
, and the minimum, mean,
maximum and accuracy of all pairwise LSDs,
(ii) the number of pairwise comparisons, c
, and the minimum, mean, maximum and
acuracy for the pairwise LSDs for each factor.combination
, unless there is only
one prediction for a factor.combination
, when notional LSDs are calculated,
(iii) the per.prediction
number of pairwise comparisons, c
, and the minimum,
mean, maximum and accuracy, based, for each prediction, on all pairwise differences
involving that prediction, or
(iv) supplied
values of the LSD, specified with the LSDsupplied
argument; these
values are to be placed in the assignedLSD
column of the LSD.frame
stored in an alldiffs.object
so that they can be used in LSD calculations.
See LSD.frame
for further information on the calculation of the values in this
data.frame
.
A data.frame
or a named numeric
containing a set of LSD
values that correspond to the observed combinations of the values of the LSDby
variables
in the predictions.frame
or a single LSD value that is an overall LSD.
If a data.frame
, it may have a column for each LSDby
variable and a column
of LSD
values or a single column of LSD
values with rownames being the combinations
of the observed combinations of the values of the LSDby
variables. Any name can be used
for the column of LSD
values; assignedLSD
is sensible, but not obligatory. Otherwise,
a numeric
containing the LSD
values, each of which is named for the observed
combination of the values of the LSDby
variables to which it corresponds. (Applying the
function
dae::fac.combine
to the predictions
component is one way of
forming the required combinations for the (row) names.) The values supplied
will be incorporated into assignedLSD
column of the LSD.frame
stored as the
LSD
component of the alldiffs.object
.
A character
(vector) of variables names, being the names of the
factors
or numerics
in the classify
for each
combination of which a mean LSD, minLSD and maxLSD is stored in the LSD
component of the alldiffs.object
when LSDtype
is
factor.combinatons
.
A character
nominating one of minmum
, q10
, median
,
mean
, q90
or maximum
as the value(s) to use in the calculation of the
halfLeastSignificant
error.intervals
. Here q10
and q90
indicate
the sample quantiles corresponging to probabilities of 0.1 and 0.9, the function
quantile
being used to obtain them. The values of the nominated statistics are
stored in the column named assignedLSD
in an LSD.frame
.
LSDstatistic
is ignored if it is not NULL
.
A character
nominating one of maxAbsDeviation
, maxDeviation
,
q90Deviation
or RootMeanSqDeviation
as the statistic to be calculated as a measure
of the accuracy of assignedLSD
. The option q90Deviation
produces the sample quantile
corresponding to a probability of 0.90. The deviations are the differences between the LSDs used in
calculating the LSD statistics and each assigned LSD and the accuracy is expressed as a
proportion of the assigned LSD value. The calculated values are stored in the column named
accuracyLSD
in an LSD.frame
.
A logical
indicating whether to retain or omit LSDs that are zero when
calculating the summaries of LSDs.
A numeric
specifying the value such that if an LSD is less than it, it will be
considered to be zero.
A data.frame
containing the backtransformed values of the predicted
values that is consistent with the predictions
component, except
that the column named predicted.value
is replaced by one called
backtransformed.predictions
. Any error.interval
values will also
be the backtransformed values. Each row contains a single predicted value.
A character
specifying the response variable for the
predictions. It is stored as an attribute to the alldiffs.object
.
A character
specifying the title for the response variable
for the predictions. It is stored as an attribute to the alldiffs.object
.
A character
string giving the variables that define the term
that was fitted using asreml
and that corresponds to classify
.
It only needs to be specified when it is different to classify
; it
is stored as an attribute of the alldiffs.object
.
It is likely to be needed when the fitted model includes terms that involve
both a numeric
covariate and a factor
that
parallel each other; the classify
would include the covariate and
the term
would include the factor
.
an integer
specifying the degrees of freedom of the standard error. It is used as
the degrees of freedom for the t-distribution on which p-values and confidence
intervals are based.
It is stored as an attribute to the alldiffs.object
.
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
.
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
. However, the levels
can be non-numeric in nature, provided that x.num
is also set.
The maximum number of characters from the levels of factors to use in the row and column labels of the tables of pairwise differences and their p-values and standard errors.
A logical indicating whether all pairwise differences of the
predictions
and their standard errors and p-values are to be
computed and stored. If FALSE
, the components differences
and p.differences
will be NULL
in the returned
alldiffs.object
.
A numeric
giving the significance level for LSDs or one minus
the confidence level for confidence intervals.
It is stored as an attribute to the alldiffs.object
.
A numeric
specifying the power of a transformation, if
one has been applied to the response variable. Unless it is equal
to 1, the default, back-transforms of the predictions will be
obtained and presented in tables or graphs as appropriate.
The back-transformation raises the predictions to the power equal
to the reciprocal of transform.power
, unless it equals 0 in
which case the exponential of the predictions is taken.
A numeric
that has been added to each value of the
response after any scaling and before applying any power transformation.
A numeric
by which each value of the response has been multiplied
before adding any offset and applying any power transformation.
A logical
indicating whether rows for predictions that
are not estimable are to be removed from the components of the
alldiffs.object
.
A character
containing the name of the
factor
that indexes the set of predicted values that determines
the sorting of the components. If there is only one variable in the
classify
term then sortFactor
can be NULL
and
the order is defined by the complete set of predicted values.
If there is more than one variable in the classify
term
then sortFactor
must be set. In this case the sortFactor
is sorted in the same order within each combination of the values of
the sortParallelToCombo
variables: the classify
variables, excluding the
sortFactor
. There should be only one predicted value for
each unique value of sortFactor
within each set defined by a
combination of the values of the classify
variables, excluding the
sortFactor
factor
.
The order to use is determined by either sortParallelToCombo
or
sortOrder
.
A list
that specifies a combination of the values
of the factor
s and numeric
s, excluding sortFactor
, that
are in classify
. Each of the components of the supplied list
is named for a classify
variable and specifies a single value for it. The
combination of this set of values will be used to define a subset of the predicted
values whose order will define the order of sortFactor
. Each of the other
combinations of the values of the factor
s and numeric
s will be sorted
in parallel. If sortParallelToCombo
is NULL
then the first value of
each classify
variable, except for the sortFactor
factor
,
in the predictions
component is used to define sortParallelToCombo
.
If there is only one variable in the classify
then
sortParallelToCombo
is ignored.
A character
containing the name of the
factor
that defines groups of the sortFactor
within which the predicted
values are to be ordered.
If there is only one variable in the classify
then
sortNestingFactor
is ignored.
A character vector
whose length is the same as the number
of levels for sortFactor
in the predictions
component of the
alldiffs.object
. It specifies the desired order of the
levels in the reordered components of the alldiffs.object
.
The argument sortParallelToCombo
is ignored.
The following creates a sortOrder
vector levs
for factor
f
based on the values in x
:
levs <- levels(f)[order(x)]
.
A logical
passed to order
that detemines whether
the order for sorting the components of the alldiffs.object
is for increasing or decreasing magnitude of the predicted values.
provision for passsing arguments to functions called internally - not used at present.
An alldiffs.object
with components
predictions
, vcov
, differences
, p.differences
sed
, and LSD
.
The name of the response
, the response.title
,
the term
, the classify
, tdf
, alpha
, sortFactor
and the sortOrder
will be set as attributes to the object.
Note that the classify
in an alldiffs.object
is based on the
variables indexing the predictions, which may differ from the
classify
used to obtain the original predictions (for example,
when the alldiffs.object
s stores a linear transformation of predictions.
Also, see predictPlus.asreml
for more information.
asremlPlus-package
, as.alldiffs
, as.predictions.frame
,
sort.alldiffs
, subset.alldiffs
,
print.alldiffs
, renewClassify.alldiffs
,
redoErrorIntervals.alldiffs
,
recalcLSD.alldiffs
, plotPredictions.data.frame
,
predictPlus.asreml
,
predictPresent.asreml
# NOT RUN {
data(Oats.dat)
## Use asreml to get predictions and associated statistics
# }
# NOT RUN {
m1.asr <- asreml(Yield ~ Nitrogen*Variety,
random=~Blocks/Wplots,
data=Oats.dat)
current.asrt <- as.asrtests(m1.asr)
Var.pred <- asreml::predict.asreml(m1.asr, classify="Nitrogen:Variety",
sed=TRUE)
if (getASRemlVersionLoaded(nchar = 1) == "3")
Var.pred <- Var.pred$predictions
Var.preds <- Var.pred$pvals
Var.sed <- Var.pred$sed
Var.vcov <- NULL
wald.tab <- current.asrt$wald.tab
den.df <- wald.tab[match("Variety", rownames(wald.tab)), "denDF"]
# }
# NOT RUN {
## Use lmerTest and emmmeans to get predictions and associated statistics
if (requireNamespace("lmerTest", quietly = TRUE) &
requireNamespace("emmeans", quietly = TRUE))
{
m1.lmer <- lmerTest::lmer(Yield ~ Nitrogen*Variety + (1|Blocks/Wplots),
data=Oats.dat)
Var.emm <- emmeans::emmeans(m1.lmer, specs = ~ Nitrogen:Variety)
Var.preds <- summary(Var.emm)
den.df <- min(Var.preds$df)
## Modify Var.preds to be compatible with a predictions.frame
Var.preds <- as.predictions.frame(Var.preds, predictions = "emmean",
se = "SE", interval.type = "CI",
interval.names = c("lower.CL", "upper.CL"))
Var.vcov <- vcov(Var.emm)
Var.sed <- NULL
}
## Use the predictions obtained with either asreml or lmerTest
if (exists("Var.preds"))
{
## Order the Varieties in decreasing order for the predictions values in the
## first N level
Var.diffs <- allDifferences(predictions = Var.preds,
classify = "Nitrogen:Variety",
sed = Var.sed, vcov = Var.vcov, tdf = den.df,
sortFactor = "Variety", decreasing = TRUE)
print.alldiffs(Var.diffs, which="differences")
## Change the order of the factors in the alldiffs object and reorder components
Var.reord.diffs <- allDifferences(predictions = Var.preds,
classify = "Variety:Nitrogen",
sed = Var.sed, vcov = Var.vcov, tdf = den.df)
print.alldiffs(Var.reord.diffs, which="predictions")
}
# }
Run the code above in your browser using DataLab