linTransform.alldiffs | R Documentation |
alldiffs.object
.Effects the linear transformation of the predictions in the
supplied alldiffs.object
, the transformation being specified
by a matrix
or a formula
. The values of
the transformed values are stored in an alldiffs.object
.
A matrix
might be a contrast matrix
or
a matrix
of weights for the levels of a
factor
used to obtain the weighted average over
the levels of that factor
. A formula
gives
rise to a projection matrix
that linearly transforms
the predictions so that they conform to the model specified by the
formula
, this model being a submodel of that inherent
in the classify
.
If pairwise = TRUE
, all pairwise differences between the
linear transforms of the predictions
, their standard errors,
p-values and LSD statistics are computed as using
allDifferences.data.frame
.
This adds them to the alldiffs.object
as additional
list
components named differences
, sed
,
p.differences
and LSD
.
If a transformation has been applied (any one of
transform.power
is not one, scale
is not one and
offset
is nonzero), the backtransforms of the transformed
values and of the lower and upper limits of their error.intervals
are added to a data.frame
that is consistent with a
predictions.frame
. If transform.power
is other than
one, the standard.error
column of the data.frame
is set to NA
. This data.frame
is added to the
alldiffs.object
as a list
component called
backtransforms
.
The printing of the components produced is controlled by the
tables
argument. The order of plotting the levels of
one of the factors indexing the predictions can be modified
and is achieved using sort.alldiffs
.
## S3 method for class 'alldiffs'
linTransform(alldiffs.obj, classify = NULL, term = NULL,
linear.transformation = NULL, EGLS.linTransform = TRUE,
Vmatrix = FALSE, error.intervals = "Confidence",
avsed.tolerance = 0.25, accuracy.threshold = NA,
LSDtype = "overall", LSDsupplied = NULL,
LSDby = NULL, LSDstatistic = "mean",
LSDaccuracy = "maxAbsDeviation",
zero.tolerance = .Machine$double.eps ^ 0.5,
response = NULL, response.title = NULL,
x.num = NULL, x.fac = NULL,
tables = "all", level.length = NA,
pairwise = TRUE, alpha = 0.05,
inestimable.rm = TRUE, ...)
alldiffs.obj |
An |
classify |
A |
term |
A |
linear.transformation |
A If a In either case, as well as the values of the linear combinations, their standard errors, pairwise differences and associated statistics are returned. |
EGLS.linTransform |
A |
Vmatrix |
A |
error.intervals |
A |
avsed.tolerance |
A
|
accuracy.threshold |
A |
LSDtype |
A See |
LSDsupplied |
A |
LSDby |
A |
LSDstatistic |
A |
LSDaccuracy |
A |
zero.tolerance |
A |
response |
A |
response.title |
A |
x.num |
A |
x.fac |
A |
tables |
A |
level.length |
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. |
pairwise |
A |
alpha |
A |
inestimable.rm |
A |
... |
further arguments passed to |
For a matrix \mathbf{L}
, vector of
predictions \mathbf{p}
and variance matrix of the predictions
\mathbf{V}_p
, the linear transformed predictions are given
by \mathbf{Lp}
with variance matrix \mathbf{LV}_p\mathbf{L}^\mathrm{T}
.
The last matrix is used to compute the variance of pairwise
differences between the transformed values.
If linear.transformation
is a matrix
, \mathbf{M}
say, then the
linear-transformation matrix
, \mathbf{L}
, is just the supplied
matrix
\mathbf{M}
.
If linear.transformation
is a formula
and EGLS.linTransform
is TRUE
, then a matrix \mathbf{M}
is obtained that is the design matrix
for all of the terms in the formula
. Using \mathbf{M}
, the
linear-transformation matrix
, \mathbf{L}
, is formed as
\mathbf{M} (\mathbf{M}^\top \widehat{\mathbf{V}}^- \mathbf{M})^- (\mathbf{M}^\top \widehat{\mathbf{V}}^-)
.
On the other hand, for linear.transformation
a formula
and EGLS.linTransform
set to FALSE
, \mathbf{L}
is
formed as the sum of the orthogonal projection matrices obtained using
pstructure.formula
from the package dae
; grandMean
is set to TRUE
and orthogonalize
to "eigenmethods"
.
A alldiffs.object
with the linear transformation of the predictions
and their standard errors and all pairwise differences between the linear
transforms of their predictions, their standard errors and p-values
and LSD statistics.
If the supplied alldiffs.object
contained a backtransforms
component, then the returned alldiffs.object
will contain
a backtransforms
component with the backtransformed linear transformation
of the predictions. The backtransformation will, after backtransforming for any
power transformation, subtract the offset
and then divide by the scale
.
If error.intervals
is not "none"
, then the
predictions
component and, if present, the
backtransforms
component will contain columns for the lower
and upper values of the limits for the interval. The names of these
columns will consist of three parts separated by full stops:
1) the first part will be lower
or upper
;
2) the second part will be one of Confidence
,
StandardError
or halfLeastSignificant
;
3) the third component will be limits
.
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.
Also, if error.intervals
is "halfLeastSignificant"
, then those of
LSDtype
, LSDby
and LSDstatistic
that are not NULL
will be added as attributes of the object and of the predictions frame
;
additionally, LSDvalues
will be added as attribute of the
predictions frame
, LSDvalues
being the LSD values used in
calculating the error.intervals
.
Chris Brien
linTransform
, predictPlus.asreml
, as.alldiffs
,
print.alldiffs
, sort.alldiffs
,
subset.alldiffs
, allDifferences.data.frame
,
redoErrorIntervals.alldiffs
,
recalcLSD.alldiffs
, pickLSDstatistics.alldiffs
,
predictPresent.asreml
,
plotPredictions.data.frame
,
as.Date
, predict.asreml
data(WaterRunoff.dat)
##Use asreml to get predictions and associated statistics
## Not run:
asreml.options(keep.order = TRUE) #required for asreml-R4 only
current.asr <- asreml(fixed = pH ~ Benches + (Sources * (Type + Species)),
random = ~ Benches:MainPlots,
keep.order=TRUE, data= WaterRunoff.dat)
current.asrt <- as.asrtests(current.asr, NULL, NULL)
#Get additive predictions directly using predictPlus
diffs.sub <- predictPlus.asreml(classify = "Sources:Species", Vmatrix = TRUE,
linear.transformation = ~ Sources + Species,
asreml.obj = current.asr, tables = "none",
wald.tab = current.asrt$wald.tab,
present = c("Type","Species","Sources"))
## End(Not run)
## Use lmeTest and emmmeans to get predictions and associated statistics
if (requireNamespace("lmerTest", quietly = TRUE) &
requireNamespace("emmeans", quietly = TRUE))
{
m1.lmer <- lmerTest::lmer(pH ~ Benches + (Sources * Species) +
(1|Benches:MainPlots),
data=na.omit(WaterRunoff.dat))
SS.emm <- emmeans::emmeans(m1.lmer, specs = ~ Sources:Species)
SS.preds <- summary(SS.emm)
den.df <- min(SS.preds$df, na.rm = TRUE)
## Modify SS.preds to be compatible with a predictions.frame
SS.preds <- as.predictions.frame(SS.preds, predictions = "emmean",
se = "SE", interval.type = "CI",
interval.names = c("lower.CL", "upper.CL"))
## Form an all.diffs object and check its validity
SS.vcov <- vcov(SS.emm)
SS.diffs <- allDifferences(predictions = SS.preds, classify = "Sources:Species",
vcov = SS.vcov, tdf = den.df)
validAlldiffs(SS.diffs)
#Get additive predictions
diffs.sub <- linTransform(SS.diffs, classify = "Sources:Species",
linear.transformation = ~ Sources + Species,
Vmatrix = TRUE, tables = "none")
}
##Calculate contrasts from prediction obtained using asreml or lmerTest
if (exists("diffs.sub"))
{
#Contrast matrix for differences between each species and non-planted for the last source
L <- cbind(matrix(rep(0,7*32), nrow = 7, ncol = 32),
diag(1, nrow = 7),
matrix(rep(-1, 7), ncol = 1))
rownames(L) <- as.character(diffs.sub$predictions$Species[33:39])
diffs.L <- linTransform(diffs.sub,
classify = "Sources:Species",
linear.transformation = L,
tables = "predictions")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.