| Version: | 4.4.51 |
| Date: | 2025-08-22 |
| Title: | Augments 'ASReml-R' in Fitting Mixed Models and Packages Generally in Exploring Prediction Differences |
| Depends: | R (≥ 3.5.0) |
| Imports: | dae, devtools, doParallel, dplyr, foreach, ggplot2, graphics, grDevices, methods, nloptr, parallel, qqplotr, RColorBrewer, reshape2, rlang, stats, sticky, stringr, tryCatchLog, utils |
| Suggests: | emmeans (≥ 1.8.8), lattice, lmerTest, pbkrtest, R.rsp, testthat, tictoc |
| Enhances: | asreml |
| VignetteBuilder: | R.rsp |
| SystemRequirements: | asreml |
| LazyData: | true |
| Description: | Assists in automating the selection of terms to include in mixed models when 'asreml' is used to fit the models. Procedures are available for choosing models that conform to the hierarchy or marginality principle, for fitting and choosing between two-dimensional spatial models using correlation, natural cubic smoothing spline and P-spline models. A history of the fitting of a sequence of models is kept in a data frame. Also used to compute functions and contrasts of, to investigate differences between and to plot predictions obtained using any model fitting function. The content falls into the following natural groupings: (i) Data, (ii) Model modification functions, (iii) Model selection and description functions, (iv) Model diagnostics and simulation functions, (v) Prediction production and presentation functions, (vi) Response transformation functions, (vii) Object manipulation functions, and (viii) Miscellaneous functions (for further details see 'asremlPlus-package' in help). The 'asreml' package provides a computationally efficient algorithm for fitting a wide range of linear mixed models using Residual Maximum Likelihood. It is a commercial package and a license for it can be purchased from 'VSNi' https://vsni.co.uk/ as 'asreml-R', who will supply a zip file for local installation/updating (see https://asreml.kb.vsni.co.uk/). It is not needed for functions that are methods for 'alldiffs' and 'data.frame' objects. The package 'asremPlus' can also be installed from http://chris.brien.name/rpackages/. |
| License: | MIT + file LICENSE |
| URL: | http://chris.brien.name |
| BugReports: | https://github.com/briencj/asremlPlus/issues |
| NeedsCompilation: | no |
| Packaged: | 2025-08-20 03:46:47 UTC; briencj |
| Author: | Chris Brien |
| Maintainer: | Chris Brien <chris.brien@adelaide.edu.au> |
| Repository: | CRAN |
| Date/Publication: | 2025-08-21 09:10:08 UTC |
Augments 'ASReml-R' in Fitting Mixed Models and Packages Generally in Exploring Prediction Differences
Description
Assists in automating the selection of terms to include in mixed models when 'asreml' is used to fit the models. Procedures are available for choosing models that conform to the hierarchy or marginality principle, for fitting and choosing between two-dimensional spatial models using correlation, natural cubic smoothing spline and P-spline models. A history of the fitting of a sequence of models is kept in a data frame. Also used to compute functions and contrasts of, to investigate differences between and to plot predictions obtained using any model fitting function. The content falls into the following natural groupings: (i) Data, (ii) Model modification functions, (iii) Model selection and description functions, (iv) Model diagnostics and simulation functions, (v) Prediction production and presentation functions, (vi) Response transformation functions, (vii) Object manipulation functions, and (viii) Miscellaneous functions (for further details see 'asremlPlus-package' in help). The 'asreml' package provides a computationally efficient algorithm for fitting a wide range of linear mixed models using Residual Maximum Likelihood. It is a commercial package and a license for it can be purchased from 'VSNi' <https://vsni.co.uk/> as 'asreml-R', who will supply a zip file for local installation/updating (see <https://asreml.kb.vsni.co.uk/>). It is not needed for functions that are methods for 'alldiffs' and 'data.frame' objects. The package 'asremPlus' can also be installed from <http://chris.brien.name/rpackages/>.
Version: 4.4.51
Date: 2025-08-22
Index
Note that many of the function below are S3 methods so that the suffix can be omitted. Of course, whether or not the suffix is omitted, the object supplied to the first argument must be of the class specified by the suffix. For example getFormulae.asreml is a getFormulae method for an asreml.object and so .asreml can be omitted and the object supplied to the first argument must be of class asreml.
| (i) Data | |
Oats.dat
| Data for an experiment to investigate nitrogen response of |
| 3 oats varieties. | |
Wheat.dat
| Data for an experiment to investigate 25 varieties of |
| wheat. | |
WaterRunoff.dat
| Data for an experiment to investigate the quality of |
| water runoff over time | |
| (ii) Model modification | |
addSpatialModel.asrtests
| Adds, to a supplied model, a spatial model that accounts for |
| local spatial variation. | |
addSpatialModelOnIC.asrtests
| Uses information criteria to decide whether to add a spatial |
| model to account for local spatial variation. | |
changeTerms.asrtests
| Adds and drops terms from one or both of the fixed or random |
| model, replaces the residual (rcov) model with a new model | |
| and changes bounds or initial values of terms. | |
iterate.asrtests
| Subject the fitted asreml.obj stored in an asrtests.object |
| to further iterations of the fitting process. | |
newfit.asreml
| Refits an asreml model with changed arguments by extracting, |
modifying and evaluating its call - an alternate to |
|
| update.asreml. | |
reparamSigDevn.asrtests
| Reparamterizes each random (deviations) term |
| involving 'devn.fac' to a fixed term and ensures | |
| that the same term, with 'trend.num' replacing | |
| 'devn.fac', is included if any other term with | |
| 'trend.num' is included in 'terms'. | |
rmboundary.asrtests
| Removes any boundary or singular variance components |
| from the fit stored in 'asreml.obj' and records their | |
removal in an asrtests.object. |
|
setvarianceterms.call
| Allows the setting of bounds and initial values |
| for terms in the 'random' and 'residual' arguments of an | |
| 'asreml' call. | |
| (iii) Model selection and description | |
addto.test.summary
| Adds a row to a test.summary data.frame. |
changeModelOnIC.asrtests
| Uses information criteria to decide whether to change an |
| already fitted model. | |
chooseModel.asrtests
| Determines and records the set of significant terms using an |
asrtests.object, taking into account the hierarchy |
|
| or marginality relations of the terms.. | |
chooseModel.data.frame
| Determines the set of significant terms from results stored |
in a data.frame, taking into account the marginality |
|
| relations of terms and recording the tests used in a | |
data.frame. |
|
chooseSpatialModelOnIC.asrtests
| Uses information criteria to choose the best fitting |
| spatial model for accounting for local spatial variation. | |
getTestPvalue.asrtests
| Gets the p-value for a test recorded in the test.summary |
data.frame of an asrtests.object. |
|
infoCriteria.asreml
| Computes AIC and BIC for models. |
infoCriteria.list
| Computes AIC and BIC for models. |
R2adj.asreml
| Calculates the adjusted coefficient of determination for a |
| specified combination of fixed and random terms. | |
recalcWaldTab.asrtests
| Recalculates the denDF, F.inc and P values for a table |
| of Wald test statistics obtained using 'wald.asreml'. | |
REMLRT.asreml
| Performs a REML ratio test. |
bootREMLRT.asreml
| Performs a REML ratio test using the parametric |
| bootstrap. | |
testranfix.asrtests
| Tests for a single fixed or random term in model |
| fitted using 'asreml' and records the result in an | |
asrtests.object. |
|
testresidual.asrtests
| Fits a new residual formula using 'asreml', tests |
| whether the change is significant and records the | |
result in an asrtests.object. |
|
testswapran.asrtests
| Tests, using a REMLRT, the significance of the difference |
| between the current random model and one in which oldterms | |
| are dropped and newterms are added. The result is recorded | |
in an asrtests.object. |
|
| (iv) Model diagnostics and simulation | |
plotVariofaces
| Plots empirical variogram faces, including envelopes, |
| from supplied residuals as described by Stefanova, Smith | |
| & Cullis (2009). | |
variofaces.asreml
| Calculates and plots empirical variogram faces, including |
| envelopes, as described by Stefanova, Smith & Cullis (2009). | |
estimateV.asreml
| Forms the estimated variance, random or residual matrix for |
| the observations from the variance parameter estimates. | |
simulate.asreml
| Produce sets of simulated data from a multivariate normal |
| distribution and save quantities related to the simulated data. | |
| (v) Prediction production and presentation | |
addBacktransforms.alldiffs
| Adds or recalculates the backtransforms component of an |
alldiffs.object. |
|
allDifferences.data.frame
| Using supplied predictions and standard errors of pairwise |
| differences or the variance matrix of predictions, forms | |
| all pairwise differences between the set of predictions, and | |
| p-values for the differences. | |
exploreLSDs
| Explores the computed LSD values for pairwise differences |
| between predictions. | |
findLSDminerrors
| Find LSD values that minimize the number of errors in |
| pairwise comparisons of predictions. | |
linTransform.alldiffs
| Calculates a linear transformation of the |
predictions stored in an alldiffs.object. |
|
pairdiffsTransform.alldiffs
| Calculates the differences between nominated pairs of |
predictions stored in an alldiffs.object |
|
pickLSDstatistics
| Pick LSDstatistics whose values minimize the number of |
| errors in pairwise comparisons of predictions. | |
plotLSDerrors.data.frame
| Plots a map of the supplied errors that occur in using the |
| computed LSD values for pairwise differences between | |
| predictions. | |
plotLSDerrors.alldiffs
| Plots a map of the errors that occur in using the computed |
| LSD values for pairwise differences between predictions. | |
plotLSDs.data.frame
| Plots a heat map of computed LSD values for pairwise |
| differences between predictions. | |
plotLSDs.alldiffs
| Plots a heat map of computed LSD values for pairwise |
| differences between predictions. | |
plotPredictions.data.frame
| Plots the predictions for a term, possibly with |
| error bars. | |
plotPvalues.alldiffs
| Plots the p-values in the p.differences components |
of an alldiffs.object as a heat map. |
|
plotPvalues.data.frame
| Plots the p-values in data.frame as a heat map. |
predictPlus.asreml
| Forms the predictions and associated statistics for |
| a term, using an asreml object and a wald.tab and | |
| taking into account that a numeric vector | |
| and a factor having parallel values may occur in the | |
| model. It stores the results in an object of class | |
| 'alldifffs' and may print the results. It can be | |
| when there are not parallel values. | |
predictPresent.asreml
| Forms the predictions for each of one or more terms |
| and presents them in tables and/or graphs. | |
ratioTransform.alldiffs
| Calculates the ratios of nominated pairs of predictions |
stored in an alldiffs.object. |
|
recalcLSD.alldiffs
| Adds or recalculates the LSD.frame that is a |
component of an alldiffs.object. |
|
redoErrorIntervals.alldiffs
| Adds or replaces the error intervals stored in the |
prediction component of an alldiffs.object. |
|
renewClassify.alldiffs
| Renews the components in an alldiffs.object |
| according to a new classify. | |
sort.alldiffs
| Sorts the components in an alldiffs.object |
| according to the predicted values associated with a factor. | |
subset.alldiffs
| Subsets the components in an alldiffs.object according |
| to the supplied condition. | |
sort.predictions.frame
| Sorts a predictions.frame according to the |
| predicted values. associated with a factor. | |
| (vi) Response transformation | |
angular
| Applies the angular transformation to proportions. |
angular.mod
| Applies the modified angular transformation to a |
| vector of counts. | |
powerTransform
| Performs a combination of a linear and a power |
| transformation on a variable. The transformed | |
| variable is stored in the 'data.frame data'. | |
| (vii) Object manipulation | |
as.alldiffs
| Forms an alldiffs.object from the supplied |
| predictions, along with those statistics, associated with | |
| the predictions and their pairwise differences, that have | |
| been supplied. | |
asrtests
| Pseudonym for as.asrtests. |
as.asrtests
| Forms an asrtests.object that stores |
| (i) a fitted asreml object, | |
| (ii) a pseudo-anova table for the fixed terms and | |
| (iii) a history of changes and hypothesis testing | |
| used in obtaining the model. | |
as.predictions.frame
| Forms a predictions.frame from a data.frame, ensuring |
| that the correct columns are present. | |
convAsremlobj.asreml
| Recreates an asreml object so that it is compatible with the |
currently loaded asreml version. |
|
convEffectNames2DataFrame.asreml
| Converts the effects names for a term stored in the component of an |
asreml object into a data.frame. |
|
facCombine.alldiffs
| Combines several factors into one in the components of |
an alldiffs.object. |
|
facRecast.alldiffs
| Reorders and/or revises the factor levels using the order of |
old levels in levels.order and the new labels for the |
|
levels given in newlabels. |
|
facRename.alldiffs
| Renames factors in the prediction component |
of an alldiffs.object. |
|
getFormulae.asreml
| Gets the formulae from an asreml object. |
is.alldiffs
| A single-line function that tests whether an object is |
| of class alldiffs. | |
is.asrtests
| A single-line function that tests whether an object is |
| of class asrtests. | |
is.predictions.frame
| A single-line function that tests whether an object is |
of classes predictions.frame and data.frame. |
|
makeTPPSplineMats.data.frame
| Make the spline basis matrices and data needed to fit |
| Tensor Product P-Splines. | |
print.alldiffs
| Prints the values in an alldiffs.object in a nice format. |
print.asrtests
| Prints the values in an asrtests.object. |
print.LSDdata
| Prints the components of a list containing data on the |
| LSDs for all pairwise differences of predictions. | |
print.predictions.frame
| Prints the values in a predictions.frame, with or without |
| title and heading. | |
print.test.summary
| Prints a data.frame containing a test.summary. |
print.wald.tab
| Prints a data.frame containing a Wald or pseudoanova table. |
printFormulae.asreml
| Prints the formulae from an asreml object. |
sort.alldiffs
| Sorts the components of an alldiffs.object according to |
| the predicted values associated with a factor. | |
subset.alldiffs
| Subsets the components in an alldiffs.object according |
| to the supplied condition. | |
subset.list
| Forms a list that contains a subset of the components of |
the supplied list. |
|
validAlldiffs
| Checks that an object is a valid alldiffs.object. |
validAsrtests
| Checks that an object is a valid asrtests.object. |
validPredictionsFrame
| Checks that an object is a valid predictions.frame. |
| (viii) Miscellaneous | |
getASRemlVersionLoaded
| Finds the version of asreml that is loaded and |
| returns the initial characters in version. | |
isCompoundSymmetric
| Tests whether an object of class matrix is |
| compound symmetric | |
loadASRemlVersion
| Ensures that a specific version of asreml is loaded. |
num.recode
| Recodes the unique values of a vector using the values |
| in a new vector. | |
permute.square
| Permutes the rows and columns of a square matrix. |
permute.to.zero.lowertri
| Permutes a square matrix until all the lower |
| triangular elements are zero. | |
The functions whose names end in 'alldiffs" utilize an alldiffs.object that stores:
(i) a predictions.frame, being a data frame containing predicted values, variables indexing them and their standard errors and estimability status;
the lower and upper limits of error intervals will be included when these are requested,
(ii) optionally, square matrices containing all pairwise differences, the standard errors and p-values of the differences,
and a data.frame containing LSD values and their summary statistics,
(iii) optionally, the variance matrix of the predictions, and
(iv) if the response was transformed for analysis, a data frame with backtransforms of the predicted values.
The functions whose names end in 'asrtests', which are most of the model functions, utilize an asrtests.object that stores:
(i) the currently fitted model in asreml.obj,
(ii) the table of test statistics for the fixed effects in wald.tab, and
(iii) a data frame that contains a history of the changes made to the model in test.summary.
Author(s)
Chris Brien [aut, cre] (ORCID: <https://orcid.org/0000-0003-0581-1817>)
Maintainer: Chris Brien <chris.brien@adelaide.edu.au>
References
Butler, D. G., Cullis, B. R., Gilmour, A. R., Gogel, B. J. and Thompson, R. (2023). ASReml-R Reference Manual Version 4.2. VSN International Ltd, https://asreml.kb.vsni.co.uk/
See Also
asreml
Examples
## Not run:
## Analyse wheat dat using asreml and asremlPlus (see the WheatSpatial Vignette for details)
## Set up for analysis
library(dae)
library(asreml)
library(asremlPlus)
## use ?Wheat.dat for data set details
data(Wheat.dat)
# Add row and column covariates for the spatial modelling
tmp.dat <- within(Wheat.dat,
{
cColumn <- dae::as.numfac(Column)
cColumn <- cColumn - mean(unique(cColumn))
cRow <- dae::as.numfac(Row)
cRow <- cRow - mean(unique(cRow))
})
# Fit an initial model - Row and column random
current.asr <- do.call(asreml,
list(yield ~ Rep + WithinColPairs + Variety,
random = ~ Row + Column,
residual = ~ Row:Column,
data = tmp.dat))
# Intialize a model sequence by loading the current fit into an asrtests object
current.asrt <- as.asrtests(current.asr, NULL, NULL, IClikelihood = "full",
label = "Initial model")
# Check for and remove any boundary terms and print a summary of the fit in the asrtests object
current.asrt <- rmboundary(current.asrt)
print(current.asrt)
## Compare a series of information criteria to select a linear mixed model for the data
# Check the need for the term for within Column pairs (a post hoc factor)
current.asrt <- changeModelOnIC(current.asrt, dropFixed = "WithinColPairs",
label = "Try dropping withinColPairs", IClikelihood = "full")
print(current.asrt)
# Fit an ar1 model for local spatial variation
spatial.ar1.asrt <- addSpatialModelOnIC(current.asrt, spatial.model = "corr",
row.covar = "cRow", col.covar = "cColumn",
row.factor = "Row", col.factor = "Column",
IClikelihood = "full")
spatial.ar1.asrt <- rmboundary(spatial.ar1.asrt)
infoCriteria(list(nonspatial = current.asrt$asreml.obj,
ar1 = spatial.ar1.asrt$asreml.obj))
print(spatial.ar1.asrt)
# Choose a model for local spatial variation from several potential models
suppressWarnings(
spatial.asrts <- chooseSpatialModelOnIC(current.asrt,
row.covar = "cRow", col.covar = "cColumn",
row.factor = "Row", col.factor = "Column",
dropRandom = "Row + Column",
rotateX = TRUE, ngridangles = NULL,
asreml.option = "grp", return.asrts = "all"))
# Output the results
print(spatial.asrts$spatial.IC)
print(R2adj(spatial.asrts$asrts$TPNCSS$asreml.obj, include.which.random = ~ .))
print(spatial.asrts$best.spatial.mod)
print(spatial.asrts$asrts$TPNCSS)
printFormulae(spatial.asrts$asrts$TPNCSS$asreml.obj)
## Diagnosting checking using residual plots and variofaces
# Get current fitted asreml object and update to include standardized residuals
current.asr <- spatial.asrts$asrts$TPNCSS$asreml.obj
current.asr <- update(current.asr, aom=TRUE)
Wheat.dat$res <- residuals(current.asr, type = "stdCond")
Wheat.dat$fit <- fitted(current.asr)
# Do residuals-versus-fitted values plot
with(Wheat.dat, plot(fit, res))
# Plot variofaces
variofaces(current.asr, V=NULL, units="addtores",
maxiter=50, update = FALSE,
ncores = parallel::detectCores())
# Plot normal quantile plot
ggplot(data = Wheat.dat, mapping = aes(sample = res)) +
stat_qq_band(bandType = "ts") + stat_qq_line() + stat_qq_point() +
labs(x = "Theoretical Quantiles", y = "Sample Quantiles",
title = "Normal probability plot") +
theme(plot.title = element_text(size = 12, face = "bold")) + theme_bw()
## Prediction production and presentation
# Get Variety predictions and all pairwise prediction differences and p-values
Var.diffs <- predictPlus(classify = "Variety",
asreml.obj=current.asr,
error.intervals="halfLeast",
wald.tab=current.asrt$wald.tab,
sortFactor = "Variety",
tables = "predictions")
# Plot the Variety predictions, with halfLSD intervals, and the p-values
plotPredictions(Var.diffs$predictions,
classify = "Variety", y = "predicted.value",
error.intervals = "half")
plotPvalues(Var.diffs)
## End(Not run)
A large data set comprising the end of imaging data from a chick pea experiment conducted in high-throughput greenhouses
Description
The data collected after imaging had been completed on the 1056 plants in the experiment reported by Atieno et al. (2017). The design employed for the experiment was a split-plot design in which two consecutive carts formed a main plot. The split-plot design assigned 245 genotypes to main plots, the genotypes being unequally replicated 2 or 3 times. Treatments (non-saline, saline) were randomized to the two subplots (carts) within each main plot.
The columns in the data.frame are: Smarthouse, Lane, Position, Zone, Mainplot, Subplot, Replicate, xLane, xPosition, Genotypes, Treatments, Biomass, PlantHeight, SenescenceRank, TotalPods, FilledPods, EmptyPods, SeedNo, TotalSeedWt, SeedWt100.
The columns Smarthouse, Lane and Position uniquely identify the rows of observations. Zones are groups of 4 Lanes, Mainplots are the 44 pairs of consecutive Subplots within each Zone, and a Subplot is a cart containing a single plant. The columns xLane and xPosition are numeric covariates for location within a Smarthouse. Genotypes and Treatments indicate the genotype and treatment that each plant was allocated. The response variables are Biomass, PlantHeight, SenescenceRank, TotalPods, FilledPods, EmptyPods, SeedNo, TotalSeedWt and SeedWt100.
Usage
data(ChickpeaEnd.dat)
Format
A data.frames with 1056 rows by 20 columns.
References
Atieno, J., Li, Y., Langridge, P., Dowling, K., Brien, C., Berger, B., Varshney, R. K., and Sutton, T. (2017). Exploring genetic variation for salinity tolerance in chickpea using image-based phenotyping. Scientific Reports, 7, 1300. doi:10.1038/s41598-017-01211-7
Description of an LSD frame
Description
A data.frame that stores
Least Significant differences (LSDs) for predictions for a fitted model.
Value
A data.frame that can be a component of an alldiffs.object and that
contains LSD values and statistics to be used in determining the significance of the
pairwise differences. In particular, they are used in calculating
halfLeastSignificant limits to be included in a predictions.frame.
Exactly what an LSD.frame contains is
determined by the following arguments to functions that return an
alldiffs.object: LSDtype, LSDby, LSDstatistic,
LSDaccuracy and LSDsupplied. The rownames of the LSD.frame
indicate, for each of its rows, for what group of predictions the entries in the row were calculated,
this being controlled by the LSDtype and LSDby arguments. The values for
all of the LSD arguments are stored as attributes to the alldiffs.object and the
predictions and, if present backtransforms, components of the
alldiffs.object.
An LSD.frame always has the eight columns c, minimumLSD, meanLSD,
maximumLSD, assignedLSD, accuracyLSD, falsePos and
falseNeg.
-
c: This gives the number of pairwise comparison of predictions for the combinations of the factor levels given by the row name. If the row name isoverallthen it is for all predictions. -
minimumLSD, meanLSD, maximumLSD: These are computed for eitheroverall,factor.combinations,per.predictionorsuppliedLSD values, as specified by theLSDtypeargument. ThemeanLSDis calculated using the square root of the mean of the variances of set of pairwise differences appropriate to the specificLSDtypeargument.For
overall, the mean, minimum and maximum of the LSDs for all pairwise comparisons are computed.If
factor.combinationswas specified forLSDtypewhen the LSDs were being calculated, then theLSD.framecontains a row for each combination of the values of thefactorsandnumericsspecified byLSDby. The values in a row are calculated from the LSD values for the pairwise differences for each combination of thefactorsandnumericsvalues, unless there is only one prediction for a combination, when notional LSDs are calculated that are based on the standard error of the prediction multiplied by the square root of two.For
per.prediction, the minimum, mean and maximum LSD, based, for each prediction, on the LSD values for all pairwise differences involving that prediction are computed.For
supplied, theLSD.frameis set up based on the setting ofLSDby: a single row with nameoverallifLSDbyisNULLor, ifLSDbyis a vector offactorandnumericnames, rows for each observed combinations of the values of the namedfactorsandnumerics. TheLSDsuppliedargument is used to provide the values to be stored in the columnassignedLSD. -
assignedLSD: TheassignedLSDcolumn contains the values that are assigned for use in calculatinghalfLeastSignificanterror.intervals. Its contents are determined byLSDstatisticandLSDsuppliedarguments. TheLSDsuppliedargument allows the direct specification of values to be placed in theassignedLSDcolumn of theLSD.frame. The default is to use the values in themeanLSDcolumn. -
LSDaccuracy: TheLSDaccuracygives an indication of the proportion that the correct LSD for a singlepredicted.valuemight deviate from itsassignedLSDvalue. The contents of theaccuracyLSDcolumn is controlled by theLSDaccuracyargument. -
falsePosandfalseNeg: These columns contain the number of false positives and negatives if theassignedLSDvalue(s) is(are) used to determine the significance of the pairwise predictions differences. Each LSD value in theassignedLSDcolumn is used to determine the significance of pairwise differences that involve predictions for the combination of values given by the row name for the LSD value.
See recalcLSD.alldiffs for more information.
Author(s)
Chris Brien
See Also
recalcLSD.alldiffs, redoErrorIntervals.alldiffs,
predictPresent.asreml,
predictPlus.asreml
Examples
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.diffs <- predictPlus(m1.asr, classify="Nitrogen:Variety",
wald.tab = current.asrt$wald.tab,
tables = "none")
## End(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)
#Get predictions
Var.emm <- emmeans::emmeans(m1.lmer, specs = ~ Nitrogen:Variety)
Var.preds <- summary(Var.emm)
## 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
#Set up an alldiffs object, which includes overall LSDs
Var.diffs <- allDifferences(predictions = Var.preds, classify = "Variety:Nitrogen",
sed = Var.sed, vcov = Var.vcov, tdf = 45)
}
if (exists("Var.diffs"))
{
## Use recalcLSD to get LSDs for within Variety differences
Var.LSD.diffs <- recalcLSD(Var.diffs,
LSDtype = "factor.combinations", LSDby = "Variety")
print(Var.LSD.diffs$LSD)
}
Data for an experiment to investigate whether ladybirds transfer aphids
Description
Welham et al. (2015, Example 8.2) describe a three-factor factorial experiment to investigate whether ladybirds transfer fungus to live aphids on plants. The three factors are Host plant (beans, trefoil), infected Cadavers (5, 10, 20), and Ladybird (-, +). A generalized randomized complete-block design is used to assign the three factors to 2 Runs, each of which involves 36 containers with a plant and live aphids. The response to be analyzed is the logit of the proportion of live aphids that were infected.
The columns in the data frame are: ID, Run, Plant, Host, Ladybird, Cadavers, Live, Infected, logitP, Prop. The column ID numbers the observations. Live, Infected, logitP, Prop are response variables.
Usage
data(Ladybird.dat)
Format
A data.frame containing 72 observations of 10 variables.
Author(s)
Chris Brien
Source
Welham, S. J., Gezan, S. A., Clark, S. J., & Mead, A. (2015). Statistical Methods in Biology: Design and Analysis of Experiments and Regression. Boca Raton: Chapman and Hall/CRC..
Data for an experiment to investigate nitrogen response of 3 oats varieties
Description
Yates (1937) describes a split-plot experiment that investigates the effects of three varieties of oats and four levels of Nitrogen fertilizer. The varieties are assigned to the main plots using a randomized complete block design with 6 blocks and the nitrogen levels are randomly assigned to the subplots in each main plot.
The columns in the data frame are: Blocks, Wplots, Subplots, Variety, Nitrogen, xNitrogen, Yield. The column xNitrogen is a numeric version of the factor Nitrogen. The response variable is Yield.
Usage
data(Oats.dat)
Format
A data.frame containing 72 observations of 7 variables.
Author(s)
Chris Brien
Source
Yates, F. (1937). The Design and Analysis of Factorial Experiments. Imperial Bureau of Soil Science, Technical Communication, 35, 1-95.
Calculates the adjusted coefficient of determination for a specified combination of fixed and random terms.
Description
Calculates the adjusted coefficient of determination (R2) that measures the contributions to the total variance exhibited by the observations of a specified combination of fixed and random terms in a fitted linear mixed model.
Note that the adjusted R2 can be negative, which indicates that the contribution of the terms to the total variance is very small relative to the sum of the degrees of freedom of the terms.
Piepho's (2023) method for GLMMs has not been implemented. This function is not available for ASReml-R version 3.
Usage
## S3 method for class 'asreml'
R2adj(asreml.obj,
include.which.fixed = ~ ., orthogonalize = "hybrid",
include.which.random = NULL,
bound.exclusions = c("F","B","S","C"), ...)
Arguments
asreml.obj |
An |
include.which.fixed |
A Note that the contribution of a subset of the fixed terms is only unique if the effects for the fixed terms are orthogonal; if the effects are not orthogonal then the contributions will depend on the order of the terms in the formula. Also, determining the joint contribution of a subset of the fixed terms in the model may be computationally demanding because the projection matrices have to be formed for all fixed terms and these projections matrices have to be orthogonalized. A heavy computational burden is most likely when the effects for the fixed terms are not orthogonal, for example, when numeric covariates are included amongst the terms. |
orthogonalize |
A |
include.which.random |
A |
bound.exclusions |
A |
... |
Provision for passing arguments to functions called internally - not used at present. |
Details
The method used to compute the adjusted R2 under a linear mixes model (LMM) is that
described by Piepho (2023). Here, the method has been extended to allow computation
of the adjusted R2 for a subset of the fixed terms. A set of orthogonalized
projectors for all of the fixed terms in the model (a set of
\mathbf{Q}_i\mathrm{s}) is obtained and the combined contribution of the
fixed terms nominated in include.which.fixed is obtained by computing the
average semisquared bias, ASSB, for the nominated fixed terms as:
\Sigma_i \{(\mathbf{Q}_i \mathbf{X}\boldsymbol{\beta})^\mathrm{T}\mathbf{Q}_i \mathbf{X}\boldsymbol{\beta} + \textnormal{trace}(\mathbf{X}^\mathrm{T} \mathbf{Q}_i \mathbf{X} \mathrm{var}(\boldsymbol{\beta})) \} / (n - 1)
Of the two methods, eigenmethods is least likely to fail, but it does
not establish the marginality between the terms. It is often needed when
there is nonorthogonality between terms, such as when there are several linear
covariates. It can also be more efficient in these circumstances.
The process can be computationally expensive, particularly for a large data set (500 or more observations) and/or when many terms are to be orthogonalized, particularly if they are not orthogonal.
If the error "Matrix is not idempotent" should occur then, especially if
there are many terms, one might try using set.daeTolerance from the
dae package to reduce the tolerance used in determining if values are
either the same or are zero; it may be necessary to lower the tolerance to as
low as 0.001. Also, setting orthogonalize to eigenmethods is
worth a try.
In doing the computations, no changes are made to the fitted model, nor is the
formula stored in asreml.obj referred to. Instead, the
names of the terms referred to are those stored in the coefficients
component of the asreml.obj. Use
attr(asreml.obj$coefficients$fixed, which = "terms") to access the attribute
for fixed terms; substitute random for fixed to see the names of the
random terms. For fixed terms. the term names are the same as those in the
Wald table produced by wald.asreml, and, for random terms, the same as those
in the vparameters component of the asreml.obj. Two asreml
formula functions whose terms can differ from their formulation in a
model formula are at and str.)
The function estimateV.asreml is used to calculate the variance matrices
required in calculating the adjusted R2.
Value
A numeric that is the adjusted R2, expressed as a percentage. It has attributes
include.which.fixed, include.which.random and missing.termmatrix
(use attr(x, which = "name") to access the attribute name).
The missing.termmatrix attribute will be NULL, unless the design matrix
could not be obtained for one or more model terms. If is is not NULL, it will be
a list of terms whose design matices could not be produced and so are not included in
the variance matrix estimate. An NA will be returned for the adjusted R2 if
missing.termmatrix is not NULL or a generalized inverse could
not be computed for the variance matrix estimate.
Author(s)
Chris Brien
References
Piepho, H.-P. (2023). An adjusted coefficient of determination (R2) for generalized linear mixed models in one go. Biometrical Journal, 65(7), 2200290. doi:10.1002/bimj.202200290.
See Also
asreml, estimateV.asreml.
Examples
## Not run:
data(Oats.dat)
current.asr <- asreml(Yield ~ Nitrogen*Variety,
random=~Blocks/Wplots,
data=Oats.dat)
R2.adj.fix <- R2adj.asreml(current.asr)
R2.adj.ran <- R2adj.asreml(current.asr,
include.which.fixed = NULL, include.which.random = ~ .)
R2.adj.tot <- R2adj.asreml(current.asr, include.which.random = ~ .)
R2.adj.tot <- R2adj.asreml(current.asr, include.which.random = ~ Blocks)
R2.adj.add <- R2adj.asreml(current.asr, include.which.fixed = ~ Nitrogen + Variety)
R2.adj.int <- R2adj.asreml(current.asr,
include.which.fixed = ~ . - (Nitrogen + Variety))
R2.adj.int <- R2adj.asreml(current.asr, include.which.fixed = ~ Nitrogen:Variety)
## End(Not run)
Performs a REML ratio test to compare two models.
Description
Extracts the REML log likelihood and the number of variance
parameters from two asreml objects. It assumes that the
first asreml object corresponds to the null hypothesis and
the second asreml object to the alternative hypothesis for the
test being conducted. That is, the second
asreml object is the result of fitting a model that is a
reduced version of the model for the first object. In the case
where the reduced model is obtained by setting positively-constrained
variance parameters in the full model to zero, the positive.zero
argument should be set to TRUE so that
the p-value is computed using a mixture of chi-square distributions as
described in Self and Liang (1987).
The function checks that the models do not differ in either their fixed or sparse models.
Usage
## S3 method for class 'asreml'
REMLRT(h0.asreml.obj, h1.asreml.obj,
positive.zero = FALSE, bound.test.parameters = "none",
DF = NULL, bound.exclusions = c("F","B","S","C"), ...)
Arguments
h0.asreml.obj |
|
h1.asreml.obj |
|
positive.zero |
Indicates whether the hypothesized values for the
variance components being tested are on the boundary
of the parameter space. For example, this is true
for positively-constrained variance components that,
under the reduced model, are zero. This argument does
not need to be set if |
bound.test.parameters |
Indicates whether for the variance components
being tested, at least some of the hypothesized values
are on the boundary of the parameter space.
The possibilities are |
DF |
A |
bound.exclusions |
A |
... |
Provision for passing arguments to functions called internally - not used at present. |
Value
A data.frame containing the log of the likelihood ratio, its degrees of
freedom, its p-value and the number of bound parameters in each of the two models
being compared.
Note
If DF is not NULL, the supplied value is used. Otherwise DF
is determined from the information in h1.asreml.obj and
h0.asreml.obj. In this case, the degrees of freedom for the test
are computed as the difference between the two models in the number of variance
parameters whose estimates do not have a code for bound specified in
bound.exclusions.
If ASReml-R version 4 is being used then the codes specified in bound.exclusions are
not restricted to a subset of the default codes, but a warning is issued if a code other
than these is specified.
For ASReml-R version 3, only a subset of the default codes are allowed:
F (Fixed), B (Boundary), C (Constrained) and
S (Singular).
The test statistic is calculated as 2(log(REML)_1 - log(REML)_0).
This procedure is only appropriate when the null hypothesis is that (i) all parameters are on the boundary of the parameter space (ii) all parameters are in the interior of the parameter space, or (iii) there are two parameters, one of which is on the boundary and the other is not. Other cases have been discussed by Self and Liang (1987), but are not implemented here.
Author(s)
Chris Brien
References
Self, S.G., and Liang, K-Y. (1987) Asymptotic Properties of Maximum Likelihood Estimators and Likelihood Ratio Tests Under Nonstandard Conditions. Journal of the American Statistical Association, 82, 605-10.
See Also
infoCriteria.asreml, testranfix.asrtests
Examples
## Not run:
REMLRT(ICV.max, ICV.red, bound.test.parameters = "onlybound")
## End(Not run)
Data for an experiment to investigate the quality of water runoff over time
Description
This data is from an experiment to investigate the quality of water runoff. However, it has been modified to hide the true identity of the Species and Sources. It is used to provide executable examples of the functions listed under Examples.
Usage
data(WaterRunoff.dat)
Format
A data.frame containing 440 observations of 13 variables.
Author(s)
Chris Brien
Source
Kazemi, F. (pers. comm.)
See Also
chooseModel.asrtests, reparamSigDevn.asrtests,
plotPredictions.data.frame, predictPlus.asreml,
predictPresent.asreml
Data for a 1976 experiment to investigate 25 varieties of wheat
Description
The data appears in Gilmour et al. (1995) and is from a field experiment designed to compare the
performance of 25 varieties of spring wheat. An analysis of it using asreml is presented by
Butler et al. (2023, Section 7.6), although they suggest that it is a barley experiment.
It is used in the Wheat vignettes [Enter vignette(package = "asremlPlus")] as an
executable example of the use of the asremlPlus to analyse a data set.
The experiment was conducted at Slate Hall Farm, UK, in 1976 and was designed as
a balanced lattice square with 6 replicates laid out in a 10 \times 15 rectangular
grid. The columns in the data frame are: Rep, Row, Column, WithinColPairs, Variety, yield.
The response variable is the grain yield.
Usage
data(Wheat.dat)
Format
A data.frame containing 150 observations of 6 variables.
Author(s)
Chris Brien
Source
Butler, D. G., Cullis, B. R., Gilmour, A. R., Gogel, B. J. and Thompson, R. (2023). ASReml-R Reference Manual Version 4.2. VSN International Ltd, https://asreml.kb.vsni.co.uk/.
Gilmour, A. R., et al. (1995) Average Information REML: An efficient algorithm for variance parameter estimation in linear mixed models. Biometrics, 51, 1440-1450.
Adds or recalculates the backtransforms component of an alldiffs.object.
Description
Given an alldiffs.object, adds or recalculate its backtransforms component.
The values of transform.power, offset, scale and transform.function
from the backtransforms component will be used, unless this component is NULL
when the values supplied in the call will be used.
Usage
## S3 method for class 'alldiffs'
addBacktransforms(alldiffs.obj,
transform.power = 1, offset = 0, scale = 1,
transform.function = "identity", ...)
Arguments
alldiffs.obj |
An |
transform.power |
A |
offset |
A |
scale |
A |
transform.function |
A |
... |
Provision for passing arguments to functions called internally - not used at present. |
Value
An alldiffs.object with components
predictions, vcov, differences, p.differences,
sed, LSD and backtransforms.
The backtransforms component will have the attributes (i) LSDtype,
LSDby and LSDstatistic added from the predictions component and
(ii) transform.power, offset, scale, and link.
Author(s)
Chris Brien
See Also
asremlPlus-package, as.alldiffs, sort.alldiffs,
subset.alldiffs, print.alldiffs,
renewClassify.alldiffs, redoErrorIntervals.alldiffs,
plotPredictions.data.frame,
predictPlus.asreml, predictPresent.asreml
Examples
##Subset WaterRunoff data to reduce time to execute
data(WaterRunoff.dat)
tmp <- subset(WaterRunoff.dat, Date == "05-18" & Benches != "3")
##Use asreml to get predictions and associated statistics
## Not run:
asreml.options(keep.order = TRUE) #required for asreml-R4 only
current.asr <- asreml(fixed = log.Turbidity ~ Benches + (Sources * (Type + Species)),
random = ~ Benches:MainPlots,
keep.order=TRUE, data= tmp)
current.asrt <- as.asrtests(current.asr, NULL, NULL)
TS.diffs <- predictPlus(classify = "Sources:Type",
asreml.obj = current.asr,
wald.tab = current.asrt$wald.tab,
present = c("Sources", "Type", "Species"))
## 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(log.Turbidity ~ Benches + (Sources * (Type + Species)) +
(1|Benches:MainPlots),
data=tmp)
TS.emm <- emmeans::emmeans(m1.lmer, specs = ~ Sources:Species)
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"))
## Form an all.diffs object and check its validity
TS.vcov <- vcov(TS.emm)
TS.diffs <- allDifferences(predictions = TS.preds, classify = "Sources:Species",
vcov = TS.vcov, tdf = den.df)
validAlldiffs(TS.diffs)
}
## Recalculate the back-transforms of the predictions obtained using asreml or lmerTest
if (exists("TS.diffs"))
{
TS.diffs <- addBacktransforms.alldiffs(TS.diffs, transform.power = 0)
}
Adds, to a supplied model, a spatial model that accounts for local spatial variation.
Description
Adds either a correlation, two-dimensional tensor-product natural cubic
smoothing spline (TPNCSS), or a two-dimensional tensor-product penalized P-spline
model (TPPS) to account for the local spatial variation exhibited by a response variable
measured on a potentially irregular grid of rows and columns of the units. The data may
be arranged in sections, for each of which there is a grid and for which the model is to
be fitted separately. Also, the rows and columns of a grid are not necessarily one
observational unit wide. For TPPS models for which the order of differencing the
penalty matrix is two, the an optimal rotation of the null-space eigenvectors of the
penalty matrix can be investigated.
No hypothesis testing or comparison of information criteria is made. To use information
criteria to decide whether to change the model use chooseSpatialModelOnIC.asrtests.
The model fit supplied in the asrtests.obj should not include terms that will
be included in the local spatial model. All spatial model terms are fitted as fixed or
random. Consequently, the residual model does not have to be iid.
One or more rows is added for each section to the test.summary
data.frame. Convergence and the occurrence of fixed correlations in fitting the
model is checked and a note included in the action if there was not.
All components of the asrtests.object are updated for the new model.
Usage
## S3 method for class 'asrtests'
addSpatialModel(asrtests.obj, spatial.model = "TPPS",
sections = NULL,
row.covar = "cRow", col.covar = "cCol",
row.factor = "Row", col.factor = "Col",
corr.funcs = c("ar1", "ar1"), corr.orders = c(0, 0),
row.corrFitfirst = TRUE,
allow.corrsJointFit = TRUE, nugget.variance = TRUE,
dropFixed = NULL, dropRandom = NULL,
nsegs = NULL, nestorder = c(1,1),
degree = c(3,3), difforder = c(2,2),
usRandLinCoeffs = TRUE,
rotateX = FALSE, ngridangles = NULL,
which.rotacriterion = "AIC", nrotacores = 1,
asreml.option = "grp", tpps4mbf.obj = NULL,
allow.unconverged = TRUE, allow.fixedcorrelation = TRUE,
checkboundaryonly = FALSE, update = TRUE, trace = FALSE,
maxit = 30, IClikelihood = "full", which.IC = "AIC", ...)
Arguments
asrtests.obj |
An |
spatial.model |
A single |
sections |
A single |
row.covar |
A single |
col.covar |
A single |
row.factor |
A single |
col.factor |
A single |
corr.funcs |
A single |
corr.orders |
A |
row.corrFitfirst |
A |
allow.corrsJointFit |
A |
nugget.variance |
A |
dropFixed |
A single An element that is The terms must match those in the |
dropRandom |
A single An element that is The terms must match those in the |
nsegs |
A pair of |
nestorder |
A |
degree |
A |
difforder |
A |
usRandLinCoeffs |
A |
rotateX |
A |
ngridangles |
A |
which.rotacriterion |
A single |
nrotacores |
A |
asreml.option |
A single |
tpps4mbf.obj |
An object made with |
allow.unconverged |
A |
allow.fixedcorrelation |
A |
checkboundaryonly |
If |
update |
If |
trace |
If |
maxit |
A |
IClikelihood |
A |
which.IC |
A |
... |
Further arguments passed to |
Details
The model to which the spatial models is to be added is supplied in the asrtests.obj. It should not include terms that will be included in the local spatial model. All spatial model terms are fitted as fixed or random. Consequently, the residual model does not have to be iid. The improvement in the fit resulting from the addition of a spatial model to the supplied model is evaluated. Note that the data must be in the order that corresponds to the residual argument with a variable to the right of another variable changes levels in the data frame faster than those of the other variable e.g. Row:Column implies that all levels for Column in consecutive rows of the data.frame with a single Row level.
For the corr spatial model, the default model is an autocorrelation model of order one (ar1) for each dimension. However, any of the single dimension correlation/variance models from asreml can be specified for each dimension, as can no correlation model for a dimension; the models for the two dimensions can differ. Using a forward selection procedure, a series of models are tried, without removing boundary or singular terms, beginning with the addition of row correlation and followed by the addition of column correlation or, if the row.corrFitfirst is set to FALSE, the reverse order. If the fitting of the first-fitted correlation did not result in a model change because the fitting did not converge or correlations were fixed, but the fit of the second correlation was successful, then adding the first correlation will be retried. If one of the metric correlation functions is specified (e.g. exp), then the row.covar or col.covar will be used in the spatial model. However, because the correlations are fitted separately for the two dimensions, the row.factor and col.factor are needed for all models and is used for a dimension that does not involve a correlation/variance function for the fit being performed. Also, the correlation models are fitted as random terms and so the correlation model will include a variance parameter for the grid even when ar1 is used to specify the correlation model, i.e. the model fitted is a variance model and there is no difference between ar1 and ar1v in fitting the model. The variance parameter for this term represents the spatial variance and the fit necessarily includes a nugget term, this being the residual variance. If any correlation is retained in the model, for a section if sections is not NULL, then the need for a nugget term is assessed by fixing the corresponding residual variance to one, unless there are multiple residual variances and these are not related to the sections. Once the fitting of the correlation model has been completed, the rmboundary function will be executed with the checkboundaryonly value supplied in the addSpatialModel.asrtests call. Finally, checking for bound and singular random terms associated with the correlation model and residual terms will be carried out when there are correlation terms in the model and checkboundaryonly has been set to FALSE; as many as possible will be removed from the fitted model, in some cases by fixing variance terms to one.
The tensor-product natural-cubic-smoothing-spline (TPNCSS) spatial model is as described by Verbyla et al. (2018), the tensor-product penalized-cubic-spline (TPPSC2) model with second-order differencing of the penalty is similar to that described by Rodriguez-Alvarez et al. (2018), and the tensor-product, first-difference-penalty, linear spline (TPPSL1) model is amongst those described by Piepho, Boer and Williams (2022). The fixed terms for the spline models are row.covar + col.covar + row.covar:col.covar and the random terms are spl(row.covar) + spl(col.covar) + dev(row.covar) + dev(col.covar) + spl(row.covar):col.covar + row.covar:spl(col.covar) + spl(row.covar):spl(col.covar), except that spl(row.covar) + spl(col.covar) is replaced with spl(row.covar):int(col.covar) + int(row.covar):spl(col.covar) in the TPPSC2 model, where int(.) indicates an intercept or constant value specific to its argument. For TPPSL1 models, the terms spl(row.covar):col.covar + row.covar:spl(col.covar) are omitted, The supplied model should not include any of these terms. However, any fixed or random main-effect Row or Column term that has been included as an initial model for comparison with a spatial model can be removed prior to fitting the spatial model using dropFixed or dropRandom. For the P-spline models with second-order differencing, the model matrices used to fit the pairs of random terms (i) spl(row.covar):int(col.covar) and spl(row.covar):col.covar and (ii) int(row.covar):spl(col.covar) and row.covar:spl(col.covar) are transformed using the spectral decomposition of their penalty matrices. An unstructured variance model is tried for each of these pairs. For TPPSC2, it is also possible to optimize the rotation of the null-space eigenvectors of the penalty matrix for each of these random-term pairs (for more information see Piepho, Boer and Williams, 2022). The optimization is achieved either using an optimizer or takes the form of a search over a grid of rotation angles for a reduced model; the fit of the full model with rotation using the optimal rotation angles will be returned.
The TPPCS and TPP1LS models are fitted using functions from the R package TPSbits authored by Sue Welham (2022). There are two methods for supplying the spline basis information produced by tpsmmb to asreml. The grp method adds it to the data.frame supplied in the data argument of the asreml call. The mbf method creates smaller data.frames with the spline basis information in the same environment as the internal function that calls the spline-fitting function. If it is desired to use in a later session, an asreml function, or asrtests function that calls asreml, (e.g. predict.asreml, predictPlus.asreml, or changeTerms.asrtests) on an asreml.object created using mbf terms, then the mbf data.frames will need to be recreated using makeTPPSplineMats.data.frame in the new session, supplying, if there has been rotation of the penalty matrix eigenvectors, the theta values that are returned as the attribute theta.opt of the asreml.obj.
All models utlize the function changeTerms.asrtests to fit the spatial model. Arguments from tpsmmb and changeTerms.asrtests can be supplied in calls to addSpatialModel.asrtests and will be passed on to the relevant function through the ellipses argument (...).
The data for experiment can be divided sections and the same spatial model fitted separately to each. The fit over all of the sections is assessed. For more detail see sections above.
Each combination of a row.coords and a col.coords does not have to specify a single observation; for example, to fit a local spatial model to the main units of a split-unit design, each combination would correspond to a main unit and all subunits of the main unit would have the same combination.
Value
An asrtests.object containing the components (i) asreml.obj,
possibly with attribute theta.opt,
(ii) wald.tab, and (iii) test.summary for the model that includes the
spatial model, unless the spatial model fails to be fitted when allow.unconverged
and/or allow.fixedcorrelation is set to FALSE. If the
asrtests.object is the result of fitting a TPPCS model with
an exploration of the rotation of the eigenvectors of the penalty matrix for the linear
components, then the asreml.obj will have an attribute theta.opt that contains
the optimal rotation angles of the eigenvectors.
Author(s)
Chris Brien
References
Piepho, H.-P., Boer, M. P., & Williams, E. R. (2022). Two-dimensional P-spline smoothing for spatial analysis of plant breeding trials. Biometrical Journal, 64, 835-857.
Rodriguez-Alvarez, M. X., Boer, M. P., van Eeuwijk, F. A., & Eilers, P. H. C. (2018). Correcting for spatial heterogeneity in plant breeding experiments with P-splines. Spatial Statistics, 23, 52-71.
Verbyla, A. P., De Faveri, J., Wilkie, J. D., & Lewis, T. (2018). Tensor Cubic Smoothing Splines in Designed Experiments Requiring Residual Modelling. Journal of Agricultural, Biological and Environmental Statistics, 23(4), 478-508.
Welham, S. J. (2022) TPSbits: Creates Structures to Enable Fitting and Examination of 2D Tensor-Product Splines using ASReml-R. Version 1.0.0 https://mmade.org/tpsbits/
See Also
as.asrtests,
makeTPPSplineMats.data.frame,
addSpatialModelOnIC.asrtests,
chooseSpatialModelOnIC.asrtests,
changeModelOnIC.asrtests,
changeTerms.asrtests,
rmboundary.asrtests,
testranfix.asrtests,
testresidual.asrtests,
newfit.asreml,
reparamSigDevn.asrtests,
changeTerms.asrtests,
infoCriteria.asreml
Examples
## Not run:
data(Wheat.dat)
#Add row and column covariates
Wheat.dat <- within(Wheat.dat,
{
cColumn <- dae::as.numfac(Column)
cColumn <- cColumn - mean(unique(cColumn))
cRow <- dae::as.numfac(Row)
cRow <- cRow - mean(unique(cRow))
})
#Fit initial model
current.asr <- asreml(yield ~ Rep + WithinColPairs + Variety,
random = ~ Row + Column,
data=Wheat.dat)
#Create an asrtests object, removing boundary terms
current.asrt <- as.asrtests(current.asr, NULL, NULL,
label = "Random Row and Column effects")
current.asrt <- rmboundary(current.asrt)
#Create an asrtests object with a P-spline spatial variation model
spatial.asrt <- addSpatialModel(current.asrt, spatial.model = "TPPS",
row.covar = "cRow", col.covar = "cColumn",
dropRowterm = "Row", dropColterm = "Column",
asreml.option = "grp")
infoCriteria(current.asrt$asreml.obj)
#Create an asrtests object with a P-spline spatial variation model
#that includes rotation of the eigenvectors of the penalty matrix
spatial.asrt <- addSpatialModel(current.asrt, spatial.model = "TPPS",
row.covar = "cRow", col.covar = "cColumn",
dropRowterm = "Row", dropColterm = "Column",
rotateX = TRUE,
which.rotacriterion = "dev",
nrotacores = parallel::detectCores(),
asreml.option = "mbf")
infoCriteria(current.asrt$asreml.obj)
## End(Not run)
Uses information criteria to decide whether to add a spatial model to account for local spatial variation.
Description
Adds either a correlation, two-dimensional tensor-product natural cubic
smoothing spline (TPNCSS), or a two-dimensional tensor-product penalized P-spline
model (TPPS) to account for the local spatial variation exhibited by a response variable
measured on a potentially irregular grid of rows and columns of the units. The data may
be arranged in sections for each of which there is a grid and for which the model is to
be fitted separately. Also, the rows and columns of a grid are not necessarily one
observational unit wide. The spatial model is only added if the information criterion of
the supplied model is decreased with the addition of the local spatial model. For
TPPS models for which the order of differencing the penalty matrix is two, the
improvement in the fit from rotating the eigenvectors of the penalty matrix can be
investigated; if there is no improvement, the unrotated fit will be returned.
A row is added for each section to the test.summary data.frame
of the asrtests.object stating whether or not the new model has been
swapped for a model in which the spatial model has been add to the supplied model.
Convergence and the occurrence of fixed correlations in fitting the
model is checked and a note included in the action if there was not.
All components of the asrtests.object are updated to exhibit the
differences between the supplied and the new model, if a spatial model is added.
Usage
## S3 method for class 'asrtests'
addSpatialModelOnIC(asrtests.obj, spatial.model = "TPPS",
sections = NULL,
row.covar = "cRow", col.covar = "cCol",
row.factor = "Row", col.factor = "Col",
corr.funcs = c("ar1", "ar1"), corr.orders = c(0, 0),
row.corrFitfirst = TRUE,
allow.corrsJointFit = TRUE, nugget.variance = TRUE,
dropFixed = NULL, dropRandom = NULL,
nsegs = NULL, nestorder = c(1,1),
degree = c(3,3), difforder = c(2,2),
usRandLinCoeffs = TRUE,
rotateX = FALSE, ngridangles = NULL,
which.rotacriterion = "AIC", nrotacores = 1,
asreml.option = "grp", tpps4mbf.obj = NULL,
allow.unconverged = TRUE, allow.fixedcorrelation = TRUE,
checkboundaryonly = FALSE, update = TRUE, trace = FALSE,
maxit = 30, IClikelihood = "full", which.IC = "AIC", ...)
Arguments
asrtests.obj |
An |
spatial.model |
A single |
sections |
A single |
row.covar |
A single |
col.covar |
A single |
row.factor |
A single |
col.factor |
A single |
corr.funcs |
A single |
corr.orders |
A |
row.corrFitfirst |
A |
allow.corrsJointFit |
A |
nugget.variance |
A |
dropFixed |
A single An element that is The terms must match those in the |
dropRandom |
A single An element that is The terms must match those in the |
nsegs |
A pair of |
nestorder |
A |
degree |
A |
difforder |
A |
usRandLinCoeffs |
A |
rotateX |
A |
ngridangles |
A |
which.rotacriterion |
A single |
nrotacores |
A |
asreml.option |
A single |
tpps4mbf.obj |
An object made with |
allow.unconverged |
A |
allow.fixedcorrelation |
A |
checkboundaryonly |
If |
update |
If |
trace |
If |
which.IC |
A |
maxit |
A |
IClikelihood |
A |
... |
Further arguments passed to |
Details
A fitted spatial model is only returned if it improves the fit over and above that of achieved with the model fit supplied in the asrtests.obj. To fit the spatial model without any hypotheses testing or comparison of information criteria use addSpatialModel.asrtests. The model fit supplied in the asrtests.obj should not include terms that will be included in the local spatial model. All spatial model terms are fitted as fixed or random. Consequently, the residual model does not have to be iid. Note that the data must be in the order that corresponds to the residual argument with a variable to the right of another variable changes levels in the data frame faster than those of the other variable e.g. Row:Column implies that all levels for Column in consecutive rows of the data.frame with a single Row level.
For the corr spatial model, the default model is an autocorrelation model of order one (ar1) for each dimension. However, any of the single dimension correlation/variance models from asreml can be specified for each dimension, as can no correlation model for a dimension; the models for the two dimensions can differ. Using a forward selection procedure, a series of models are tried, without removing boundary or singular terms, beginning with the addition of row correlation and followed by the addition of column correlation or, if the row.corrFitfirst is set to FALSE, the reverse order. If the fitting of the first-fitted correlation did not result in a model change because the fitting did not converge or correlations were fixed, but the fit of the second correlation was successful, then adding the first correlation will be retried. If one of the metric correlation functions is specified (e.g. exp), then the row.covar or col.covar will be used in the spatial model. However, because the correlations are fitted separately for the two dimensions, the row.factor and col.factor are needed for all models and is used for a dimension that does not involve a correlation/variance function for the fit being performed. Also, the correlation models are fitted as random terms and so the correlation model will include a variance parameter for the grid even when ar1 is used to specify the correlation model, i.e. the model fitted is a variance model and there is no difference between ar1 and ar1v in fitting the model. The variance parameter for this term represents the spatial variance and the fit necessarily includes a nugget term, this being the residual variance. If any correlation is retained in the model, for a section if sections is not NULL, then the need for a nuggest term is assessed by fixing the corresponding residual variance to one, unless there are multiple residual variances and these are not related to the sections. Once the fitting of the correlation model has been completed, the rmboundary function will be executed with the checkboundaryonly value supplied in the addSpatialModelOnIC.asrtests call. Finally, checking for bound and singular random terms associated with the correlation model and residual terms will be carried out when there are correlation terms in the model and checkboundaryonly has been set to FALSE; as many as possible will be removed from the fitted model, in some cases by fixing variance terms to one.
The tensor-product natural-cubic-smoothing-spline (TPNCSS) spatial model is as described by Verbyla et al. (2018), the tensor-product penalized-cubic-spline (TPPSC2) model with second-order differencing of the penalty is similar to that described by Rodriguez-Alvarez et al. (2018), and the tensor-product, first-difference-penalty, linear spline (TPPSL1) model is amongst those described by Piepho, Boer and Williams (2022). The fixed terms for the spline models are row.covar + col.covar + row.covar:col.covar and the random terms are spl(row.covar) + spl(col.covar) + dev(row.covar) + dev(col.covar) + spl(row.covar):col.covar + row.covar:spl(col.covar) + spl(row.covar):spl(col.covar), except that spl(row.covar) + spl(col.covar) is replaced with spl(row.covar):int(col.covar) + int(row.covar):spl(col.covar) in the TPPSC2 model, where int(.) indicates an intercept or constant value specific to its argument. For TPPSL1 models, the terms spl(row.covar):col.covar + row.covar:spl(col.covar) are omitted, The supplied model should not include any of these terms. However, any fixed or random main-effect Row or Column term that has been included as an initial model for comparison with a spatial model can be removed prior to fitting the spatial model using dropFixed or dropRandom. For the P-spline models with second-order differencing, the model matrices used to fit the pairs of random terms (i) spl(row.covar):int(col.covar) and spl(row.covar):col.covar and (ii) int(row.covar):spl(col.covar) and row.covar:spl(col.covar) are transformed using the spectral decomposition of their penalty matrices. An unstructured variance model is tried for each of these pairs and retained if it improves the fit. For TPPSC2, it is also possible to optimize the rotation of the null-space eigenvectors of the penalty matrix for each of these random-term pairs (for more information see Piepho, Boer and Williams, 2022). The optimization is achieved either using an optimizer or takes the form of a search over a grid of rotation angles for a reduced model; the fit of the full model with rotation using the optimal rotation angles will only be returned if it improves on the fit of the full, unrotated model.
The TPPCS and TPP1LS models are fitted using functions from the R package TPSbits authored by Sue Welham (2022). There are two methods for supplying the spline basis information produced by tpsmmb to asreml. The grp method adds it to the data.frame supplied in the data argument of the asreml call. The mbf method creates smaller data.frames with the spline basis information in the same environment as the internal function that calls the spline-fitting function. If it is desired to use in a later session, an asreml function, or asrtests function that calls asreml, (e.g. predict.asreml, predictPlus.asreml, or changeTerms.asrtests) on an asreml.object created using mbf terms, then the mbf data.frames will need to be recreated using makeTPPSplineMats.data.frame in the new session, supplying, if there has been rotation of the penalty matrix eigenvectors, the theta values that are returned as the attribute theta.opt of the asreml.obj.
All models utlize the function changeModelOnIC.asrtests to assess the model fit, the information criteria used in assessing the fit being calculated using infoCriteria. Any bound terms are removed from the model. Arguments from tpsmmb and changeModelOnIC.asrtests can be supplied in calls to addSpatialModelOnIC.asrtests and will be passed on to the relevant function through the ellipses argument (...).
The data for experiment can be divided sections and the same spatial model fitted separately to each. The fit over all of the sections is assessed. For more detail see sections above.
Each combination of a row.coords and a col.coords does not have to specify a single observation; for example, to fit a local spatial model to the main units of a split-unit design, each combination would correspond to a main unit and all subunits of the main unit would have the same combination.
Value
An asrtests.object containing the components (i) asreml.obj,
possibly with attribute theta.opt,
(ii) wald.tab, and (iii) test.summary for the model whose fit has
the smallest information criterion between the supplied and spatial model. The values
of the degrees of freedom and the information criteria in the test.summary are
differences between those of the changed model and those of the model supplied to
addSpatialModelOnIC. If the
asrtests.object is the result of fitting a TPPCS model with
an exploration of the rotation of the eigenvectors of the penalty matrix for the linear
components, then the asreml.obj will have an attribute theta.opt that contains
the optimal rotation angles of the eigenvectors.
Author(s)
Chris Brien
References
Piepho, H.-P., Boer, M. P., & Williams, E. R. (2022). Two-dimensional P-spline smoothing for spatial analysis of plant breeding trials. Biometrical Journal, 64, 835-857.
Rodriguez-Alvarez, M. X., Boer, M. P., van Eeuwijk, F. A., & Eilers, P. H. C. (2018). Correcting for spatial heterogeneity in plant breeding experiments with P-splines. Spatial Statistics, 23, 52-71.
Verbyla, A. P., De Faveri, J., Wilkie, J. D., & Lewis, T. (2018). Tensor Cubic Smoothing Splines in Designed Experiments Requiring Residual Modelling. Journal of Agricultural, Biological and Environmental Statistics, 23(4), 478-508.
Welham, S. J. (2022) TPSbits: Creates Structures to Enable Fitting and Examination of 2D Tensor-Product Splines using ASReml-R. Version 1.0.0 https://mmade.org/tpsbits/
See Also
as.asrtests,
makeTPPSplineMats.data.frame,
addSpatialModel.asrtests,
chooseSpatialModelOnIC.asrtests,
changeModelOnIC.asrtests,
changeTerms.asrtests,
rmboundary.asrtests,
testranfix.asrtests,
testresidual.asrtests,
newfit.asreml,
reparamSigDevn.asrtests,
changeTerms.asrtests,
infoCriteria.asreml
Examples
## Not run:
data(Wheat.dat)
#Add row and column covariates
Wheat.dat <- within(Wheat.dat,
{
cColumn <- dae::as.numfac(Column)
cColumn <- cColumn - mean(unique(cColumn))
cRow <- dae::as.numfac(Row)
cRow <- cRow - mean(unique(cRow))
})
#Fit initial model
current.asr <- asreml(yield ~ Rep + WithinColPairs + Variety,
random = ~ Row + Column,
data=Wheat.dat)
#Create an asrtests object, removing boundary terms
current.asrt <- as.asrtests(current.asr, NULL, NULL,
label = "Random Row and Column effects")
current.asrt <- rmboundary(current.asrt)
current.asrt <- addSpatialModelOnIC(current.asrt, spatial.model = "TPPS",
row.covar = "cRow", col.covar = "cColumn",
dropRowterm = "Row", dropColterm = "Column",
asreml.option = "grp")
infoCriteria(current.asrt$asreml.obj)
## End(Not run)
Adds a row to a test.summary data.frame.
Description
A row that summarizes the result of a proposed change to a model is added to a
test.summary data.frame. Only the values of those arguments for which there
are columns in test.summary will be included in the row.
Usage
addto.test.summary(test.summary, terms, DF = 1, denDF = NA,
p = NA, AIC = NA, BIC = NA,
action = "Boundary")
Arguments
test.summary |
A |
terms |
A |
DF |
A |
denDF |
A |
p |
A |
AIC |
A |
BIC |
A |
action |
A |
Value
A data.frame.
Author(s)
Chris Brien
See Also
asremlPlus-package, asrtests.object, print.test.summary
Examples
## Not run:
data(Wheat.dat)
## Fit an autocorrelation model
ar1.asr <- asreml(yield ~ Rep + WithinColPairs + Variety,
random = ~ Row + Column + units,
residual = ~ ar1(Row):ar1(Column),
data=Wheat.dat)
ar1.asrt <- as.asrtests(ar1.asr, NULL, NULL,
label = "Autocorrelation model")
ar1.asrt <- rmboundary.asrtests(ar1.asrt)
## Fit a tensor spline
Wheat.dat <- within(Wheat.dat,
{
cRow <- dae::as.numfac(Row)
cRow <- cRow - mean(unique(cRow))
cColumn <- dae::as.numfac(Column)
cColumn <- cColumn - mean(unique(cColumn))
})
ts.asr <- asreml(yield ~ Rep + cRow + cColumn + WithinColPairs +
Variety,
random = ~ spl(cRow) + spl(cColumn) +
dev(cRow) + dev(cColumn) +
spl(cRow):cColumn + cRow:spl(cColumn) +
spl(cRow):spl(cColumn),
residual = ~ Row:Column,
data=Wheat.dat)
ts.asrt <- as.asrtests(ts.asr, NULL, NULL,
label = "Tensor spline model")
ts.asrt <- rmboundary.asrtests(ts.asrt)
ar1.ic <- infoCriteria(ar1.asrt$asreml.obj)
ts.ic <- infoCriteria(ts.asrt$asreml.obj)
if (ar1.ic$AIC < ts.ic$AIC)
{
ic.diff <- ar1.ic - ts.ic
new.asrt <- ar1.asrt
new.asrt$test.summary <- addto.test.summary(ar1.asrt$test.summary,
terms = "Compare ar1 to ts",
DF = ic.diff$varDF,
AIC = ic.diff$AIC, BIC = ic.diff$BIC,
action = "Chose ar1")
} else
{
ic.diff <- ts.ic - ar1.ic
new.asrt <- ts.asrt
new.asrt$test.summary <- addto.test.summary(ts.asrt$test.summary,
terms = "Compare ar1 to ts",
DF = ic.diff$varDF,
AIC = ic.diff$AIC, BIC = ic.diff$BIC,
action = "Chose ts")
}
## End(Not run)
Using supplied predictions and standard errors of pairwise differences or the variance matrix of predictions, forms all pairwise differences between the set of predictions, and p-values for the differences.
Description
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 inestimable) 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-distribution is also used in calculating
the LSD statistics stored in the LSD component of the alldiffs.object.
Usage
## S3 method for class '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,
transform.function = "identity",
inestimable.rm = TRUE,
sortFactor = NULL, sortParallelToCombo = NULL,
sortNestingFactor = NULL, sortOrder = NULL,
decreasing = FALSE, ...)
Arguments
predictions |
A |
classify |
A |
vcov |
A |
differences |
A |
p.differences |
A |
sed |
A |
LSD |
An |
LSDtype |
A See |
LSDsupplied |
A |
LSDby |
A |
LSDstatistic |
A |
LSDaccuracy |
A |
retain.zeroLSDs |
A |
zero.tolerance |
A |
backtransforms |
A |
response |
A |
response.title |
A |
term |
A |
tdf |
an |
x.num |
A |
x.fac |
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 logical indicating whether all pairwise differences of the
|
alpha |
A |
transform.power |
A |
offset |
A |
scale |
A |
transform.function |
A |
inestimable.rm |
A |
sortFactor |
A |
sortParallelToCombo |
A |
sortNestingFactor |
A |
sortOrder |
A The following creates a |
decreasing |
A |
... |
provision for passsing arguments to functions called internally - not used at present. |
Value
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.objects stores a linear transformation of predictions.
Also, see predictPlus.asreml for more information.
Author(s)
Chris Brien
See Also
asremlPlus-package, as.alldiffs, as.predictions.frame,
sort.alldiffs, subset.alldiffs,
print.alldiffs, renewClassify.alldiffs,
redoErrorIntervals.alldiffs,
recalcLSD.alldiffs, pickLSDstatistics.alldiffs,
plotPredictions.data.frame,
predictPlus.asreml, predictPresent.asreml
Examples
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"]
## End(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")
}
Description of an alldiffs object
Description
An object of S3-class alldiffs that stores the predictions for a model,
along with supplied statistics for all pairwise differences. While
alldiffs.object can be constructed by defining a list with
the appropriate components, it can be formed by passing the components to
as.alldiffs, or from a predictions data.frame using
allDifferences.data.frame.
as.alldiffs is function that assembles an object of this class from
supplied components.
is.alldiffs is the membership function for this class; it tests
that an object is of class alldiffs.
validAlldiffs(object) can be used to test the validity of an object
with this class.
allDifferences.data.frame is the function that constructs an
object of this class by calculating components from statistics supplied via
its arguments and then using as.alldiffs to make the object.
Value
A list of class alldiffs containing the following components:
predictions, vcov, differences,
p.differences, sed, LSD and backtransforms.
Except for predictions, the components are optional and can be set
to NULL.
An alldiffs.object also has attributes response,
response.title, term, classify, tdf, alpha,
sortFactor and sortOrder, which may be set to NULL.
The details of the components are as follows:
-
predictions: Apredictions.frame, being adata.framebeginning with the variables classifying the predictions, in the same order as in theclassify, and also containing columns namedpredicted.value,standard.errorandest.status; each row contains a single predicted value. The number of rows should equal the number of unique combinations of theclassifyvariables and will be in standard order for theclassifyvariables. 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 theclassify.The
data.framemay also include columns for the lower and upper values of error intervals, either standard error, confidence or half-LSD intervals. The names of these columns will consist of three parts separated by full stops: 1) the first part will belowerorupper; 2) the second part will be one ofConfidence,StandardErrororhalfLeastSignificant; 3) the third component will belimits.Note that the names
standard.errorandest.statushave been changed tostd.errorandstatusin thepvalscomponent produced byasreml-R4; if the new names are in thedata.framesupplied topredictions, they will be returned to the previous names. -
differences: Amatrixcontaining all pairwise differences between the predictions; it should have the same number of rows and columns as there are rows inpredictions. -
p.differences: Amatrixcontaining 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 attributetdfare used; the matrix should be of the same size as that fordifferences. -
sed: Amatrixcontaining the standard errors of all pairwise differences between the predictions; they are used in computing the p-values inp.differences. -
vcov: Amatrixcontaining the variance matrix of the predictions; it is used in computing the variance of linear transformations of the predictions. -
LSD: AnLSD.framecontaining (i)c, the number of pairwise predictions comparisons for each LSD value and the mean, minimum, maximum and assigned LSD, (ii) the columnaccuracyLSDthat gives a measure of the accuracy of the assigned LSD. given the variation in LSD values, and (iii) the columnsfalse.posandfalse.negthat contain the number of false positives and negatives if theassignedLSDvalue(s) is(are) used to determine the significance of the pairwise predictions differences. The LSD values in theassignedLSDcolumn is used to determine the significance of pairwise differences that involve predictions for the combination of levels given by a row name. The value in theassignedLSDcolumn is specified using theLSDstatisticargument. -
backtransforms: When the response values have been transformed for analysis, adata.framecontaining the backtransformed values of the predicted values is added to thealldiffs.object. Thisdata.frameis consistent with thepredictionscomponent, except that the column namedpredicted.valueis replaced by one calledbacktransformed.predictions. Anyerror.intervalvalues will also be the backtransformed values. Each row contains a single predicted value.
The details of the attributes of an alldiffs.object are:
-
response: Acharacterspecifying the response variable for the predictions. -
response.title: Acharacterspecifying the title for the response variable for the predictions. -
term: Acharactergiving the variables that define the term that was fitted usingasremland that corresponds toclassify. It is often the same asclassify. -
classify: Acharactergiving the variables that define the margins of the multiway table used in the prediction. Multiway tables are specified by forming an interaction type term from the classifying variables, that is, separating the variable names with the:operator. -
tdf: Anintegerspecifying 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. -
alpha: Anintegerspecifying the significance level. It is used as the significance level calculating LSDs. -
LSDtype: If theLSDcomponent is notNULLthenLSDtypeis added as an attribute. Acharacternominating the type of grouping of seds to be used in combining LSDs. -
LSDby: If theLSDcomponent is notNULLthenLSDbyis added as an attribute. Acharactervectorcontaining the names of the factors and numerics within whose combinations the LSDs are to be summarized. -
LSDstatistic: If theLSDcomponent is notNULLthenLSDstatisticis added as an attribute. Acharacternominating what statistic to use in summarizing a set of LSDs. -
LSDaccuracy: If theLSDcomponent is notNULLthenLSDaccuracyis added as an attribute. Acharacternominating the method of calculating a measure of the accuracy of the LSDs stored in theassignedLSDcolumn of theLSD.frame. -
sortFactor:factorthat indexes the set of predicted values that determined the sorting of the components. -
sortOrder: Acharactervector that is the same length as the number of levels forsortFactorin thepredictionscomponent of thealldiffs.object. It specifies the order of the levels in the reordered components of thealldiffs.object.
The following creates a sortOrder vector levs for factor
f based on the values in x:
levs <- levels(f)[order(x)].
See predictPlus.asreml for more information.
Author(s)
Chris Brien
See Also
is.alldiffs, as.alldiffs, validAlldiffs, allDifferences.data.frame
Examples
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
## End(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"))
{
## Form an all.diffs object
Var.diffs <- as.alldiffs(predictions = Var.preds, classify = "Nitrogen:Variety",
sed = Var.sed, vcov = Var.vcov, tdf = den.df)
## Check the class and validity of the alldiffs object
is.alldiffs(Var.diffs)
validAlldiffs(Var.diffs)
}
Applies the angular transformation to proportions.
Description
Applies the angular transformation to numeric values.
It is given by \sin^{-1}(\sqrt{proportions})
Usage
angular(proportions, n)
Arguments
proportions |
The proportions. |
n |
The divisor(s) for each proportion |
Value
A numeric.
Author(s)
Chris Brien
See Also
Examples
n <-25
y <- rbinom(10, n, 0.5)
y <- c(y,0,n)
p <- y/n
p.ang <- angular(p, n)
Applies the modified angular transformation to a vector of counts.
Description
Applies the angular transformation to a vector of counts. A
modified transformation is used that is appropriate when N < 50 and the
proportion is not between 0.3 and 0.7. The transformation is given by
\sin^{-1}{\frac{count + 0.375}{n + 0.75}}.
Usage
angular.mod(count, n)
Arguments
count |
The numeric vector of counts. |
n |
The number(s) of observations from which the count(s) were obtained. |
Value
A numeric vector.
Author(s)
Chris Brien
See Also
Examples
n <-25
y <- rbinom(10, n, 0.5)
y <- c(y,0,n)
p.ang.mod <- angular.mod(y, n)
Forms an alldiffs.object from the supplied predictions, along with those statistics,
associated with the predictions and their pairwise differences, that have been supplied.
Description
Creates an alldiffs.object that consists of a list
containing the following components: predictions, vcov, differences,
p.differences, sed, LSD and backtransforms.
Predictions must be supplied to the function while the others will be set
only if they are supplied; those not supplied are set to NULL.
It also has attributes response, response.title, term,
classify, tdf, tdf, alpha, sortFactor and sortOrder.
which will be set to the values supplied or NULL if none are supplied.
Usage
as.alldiffs(predictions, vcov = NULL, differences = NULL,
p.differences = NULL, sed = NULL, LSD = NULL,
backtransforms = NULL,
response = NULL, response.title = NULL,
term = NULL, classify = NULL,
tdf = NULL, alpha = 0.05,
sortFactor = NULL, sortOrder = NULL)
Arguments
predictions |
A |
differences |
A |
p.differences |
A |
sed |
A |
vcov |
A |
LSD |
An |
backtransforms |
A |
response |
A |
response.title |
A |
term |
A |
classify |
A character string giving the variables that define the margins
of the multiway table used in the prediction. Multiway tables are
specified by forming an interaction type term from the
classifying variables, that is, separating the variable names
with the |
tdf |
an |
alpha |
A |
sortFactor |
A |
sortOrder |
A The following creates a |
Value
An S3-class alldiffs.object. Also, see predictPlus.asreml for
more information.
Author(s)
Chris Brien
See Also
asremlPlus-package, alldiffs.object, is.alldiffs, as.alldiffs,
print.alldiffs,
sort.alldiffs, subset.alldiffs, allDifferences.data.frame,
renewClassify.alldiffs, redoErrorIntervals.alldiffs, recalcLSD.alldiffs,
predictPlus.asreml, plotPredictions.data.frame, predictPresent.asreml
Examples
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
## End(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"))
{
## Form an all.diffs object
Var.diffs <- as.alldiffs(predictions = Var.preds, classify = "Nitrogen:Variety",
sed = Var.sed, vcov = Var.vcov, tdf = den.df)
## Check the class and validity of the alldiffs object
is.alldiffs(Var.diffs)
validAlldiffs(Var.diffs)
}
Forms an asrtests object that stores (i) a fitted asreml object, (ii) a pseudo-anova table for the fixed terms and (iii) a history of changes and hypothesis testing used in obtaining the model.
Description
An asrtests.object that is a list consisting of
the components asreml.obj, wald.tab and test.summary.
A call to as.asrtests with test.summary = NULL re-initializes the
test.summary
data.frame.
If there is no wald.tab, wald.asreml is called. In all cases,
recalcWaldTab is called and any changes made as specified by the
recalcWaldTab arguments supplied via ....
The label argument can be used to include an entry in test.summary
for the starting model. If a label is included, (i) the information criteria
calculated using the asreml.obj will be added to the test.summary, if
IClikelihood is not set to none and (ii) the number of variance
parameters is included in the denDF column, if IClikelihood is set to none.
Usage
as.asrtests(asreml.obj, wald.tab = NULL, test.summary = NULL,
denDF = "numeric", label = NULL,
IClikelihood = "none", bound.exclusions = c("F","B","S","C"), ...)
Arguments
asreml.obj |
an |
wald.tab |
A |
test.summary |
A |
denDF |
Specifies the method to use in computing approximate denominator
degrees of freedom when |
label |
A |
IClikelihood |
A |
bound.exclusions |
A |
... |
further arguments passed to |
Value
An object of S3-class asrtests that also inherits S3-class list.
Author(s)
Chris Brien
References
Kenward, M. G., & Roger, J. H. (1997). Small sample inference for fixed effects from restricted maximum likelihood. Biometrics, 53, 983-997.
See Also
asremlPlus-package, is.alldiffs, as.alldiffs,
recalcWaldTab,
testranfix.asrtests, chooseModel.asrtests,
rmboundary.asrtests,
reparamSigDevn.asrtests
Examples
## Not run:
data(Wheat.dat)
# Fit initial model
current.asr <- asreml(yield ~ Rep + WithinColPairs + Variety,
random = ~ Row + Column + units,
residual = ~ ar1(Row):ar1(Column),
data=Wheat.dat)
# Load current fit into an asrtests object
current.asrt <- as.asrtests(current.asr, NULL, NULL)
# Check for and remove any boundary terms
current.asrt <- rmboundary(current.asrt)
## End(Not run)
Forms a predictions.frame from a data.frame, ensuring that the correct
columns are present.
Description
Creates a predictions.frame from a data.frame by adding the
class predictions.frame to it, and renaming the columns containing
the predictions, se, est.status and error.intervals.
Usage
as.predictions.frame(data, classify = NULL,
predictions = NULL, se = NULL, est.status = NULL,
interval.type = NULL, interval.names = NULL)
Arguments
data |
A |
classify |
A |
predictions |
A |
se |
A |
est.status |
A |
interval.type |
A |
interval.names |
A |
Value
An S3-class predictions.frame.
Author(s)
Chris Brien
See Also
asremlPlus-package, predictions.frame,
is.predictions.frame, predictions.frame,
validPredictionsFrame
Examples
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
#Form predictions.frame changing asreml-R4 names to the standard names, if these are present
Var.preds <- as.predictions.frame(Var.pred$pvals, se = "std.error",
est.status = "status")
## End(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)
Var.preds <- as.predictions.frame(Var.preds, predictions = "emmean",
se = "SE", interval.type = "CI",
interval.names = c("lower.CL", "upper.CL"))
}
## Check the class and validity of the alldiffs object
if (exists("Var.preds"))
{
is.predictions.frame(Var.preds)
validPredictionsFrame(Var.preds)
}
Deprecated Functions in the Package asremlPlus
Description
These functions have been renamed and deprecated in asremlPlus:
addrm.terms.asreml and addrm.terms.asrtests ->
changeTerms.asrtests,alldiffs ->
as.alldiffs,asrtests->
as.asrtests,choose.model.asreml and choose.model.asrtests ->
chooseModel.asrtests,facRecode and facRecode.alldiffs ->
facRecast.alldiffs,info.crit and info.crit.asreml ->
infoCriteria.asreml,newrcov.asrtests ->
changeTerms.asrtests,plotvariofaces.asreml ->
plotVariofaces.data.frame,power.transform ->
powerTransform,predictiondiffs.asreml ->
allDifferences.data.frame,predictionplot.asreml ->
plotPredictions.data.frame,predictparallel.asreml ->
predictPlus.asreml,pred.present.asreml ->
predictPresent.asreml,recalc.wald.tab.asreml and recalc.wald.tab.asrtests ->
recalcWaldTab.asrtests,reorderClassify and reorderClassify.alldiffs ->
renewClassify.alldiffs,reml.lrt and reml.lrt.asreml ->
REMLRT.asreml,rmboundary.asreml ->
rmboundary.asrtests,setvarianceterms.asreml ->
setvarianceterms.call,sig.devn.reparam.asreml and sig.devn.reparam.asrtests ->
reparamSigDevn.asrtests,testranfix.asreml ->
testranfix.asrtests,testrcov.asreml and testrcov.asrtests ->
testresidual.asrtests,testswapran.asreml ->
testswapran.asrtests
Usage
addrm.terms.asreml(...)
addrm.terms.asrtests(...)
alldiffs(...)
asrtests(...)
choose.model.asreml(...)
choose.model.asrtests(...)
facRecode(...)
facRecode.alldiffs(...)
info.crit(...)
info.crit.asreml(...)
newrcov.asrtests(...)
plotvariofaces.asreml(...)
power.transform(...)
predictiondiffs.asreml(...)
predictionplot.asreml(...)
predictparallel.asreml(...)
pred.present.asreml(...)
recalc.wald.tab.asreml(...)
recalc.wald.tab.asrtests(...)
reml.lrt(...)
reml.lrt.asreml(...)
## S3 method for class 'alldiffs'
reorderClassify(...)
## S3 method for class 'asreml'
rmboundary(...)
setvarianceterms.asreml(...)
sig.devn.reparam.asreml(...)
sig.devn.reparam.asrtests(...)
testranfix.asreml(...)
testrcov.asreml(...)
testrcov.asrtests(...)
## S3 method for class 'asreml'
testswapran(...)
Arguments
... |
absorbs arguments passed from the old functions of the style foo.bar(). |
Author(s)
Chris Brien
The randomly-presented, startup tips.
Description
The intermittent, randomly-presented, startup tips.
Startup tips
Need help? The manual is a vignette and is in the vignettes subdirectory of the package's install directory.
Find out what has changed in asremlPlus: enter news(package = 'asremlPlus').
Need help getting started? Enter vignette(package = 'asremlPlus').
To avoid start-up message that ASReml-R is needed, load asreml before asremlPlus.
The methods for alldiffs and data.frame do not require asreml
Use suppressPackageStartupMessages() to eliminate all package startup messages.
To see all the intermittent, randomly-presented, startup tips enter ?asremlPlusTips.
To install the latest version: go to http://chris.brien.name/rpackages.
For versions between CRAN releases (and more) go to http://chris.brien.name/rpackages.
Author(s)
Chris Brien
Description of an asrtests object
Description
An object of S3-class asrtests that contains information derived from the fits of
a mixed model using asreml.
as.asrtests is function that makes an object of this class.
is.list is the membership function for this class; it tests
that an object is of class list.
validAsrtests can be used to test the validity of an
asrtests.object.
Value
A list that contains three components:
-
asreml.obj: an object of classasremlthat contains the fit of a model; -
wald.tab: Adata.framecontaining a pseudo-anova table for the fixed terms produced bywald.asreml. It hasrownamesthat correspond to the fixed terms that were fitted and four columns. If denominator degrees of freedom were calculated then the columns areDF,denDF,F.inc,Pr; otherwise the columns areDf,Sum of Sq,Wald statistic, andPr(Chisq). -
test.summary: Adata.framewith columnsterms,DF,denDF,p,AIC,BICandaction, each row of which summarizes the results of proposed changes to the fitted model.Possible codes for
actionare:Dropped,Retained,Swapped,Unswapped,Unchanged,Significant,Nonsignificant,Absent,Added,RemovedandBoundary. If the either of the models did not converge,unconvergedwill be added to the code.Unchangedis used whenallow.unconvergedisFALSE. Note that the logicalasreml.obj$convergealso reflects whether there is convergence.A row is added to the
test.summaryfor each term that is dropped, added or tested or a note that several terms have been added or removed. When values for the AIC and BIC are included in the row, then the DF are the number of fixed parameters in the model and denDF are the numbers of variance parameters. WhenchangeModelOnICadds a row then the values of the degrees of freedom and information criteria are differences between those for the model that is supplied and the model changed bychangeModelOnIC.
Author(s)
Chris Brien
See Also
as.asrtests, as.asrtests, validAsrtests
Uses the parametric bootstrap to calculate the p-value for a REML ratio test to compare two models.
Description
Extracts the REML log likelihood for two asreml objects
and forms the observed REML ratio statistic. It assumes that the second
asreml object is the result of fitting a model that is a reduced
version of the model for the first object and is considered to the null model.
Using the mean and V, nboot bootstrap samples of simulated
response values are generated in parallel; that is, ncores cores are used
and each is used to generate and analyse a sample. The full and reduced models
are fitted to the data and if either analysis fails to converge another sample
is generated and analysed using the current core, with a maximum of
max.retries attempts to obtain a sample that converges for both analysis.
Thus the maximum number of data sets that will be generated is
nboot * max.retries. If a bootstrap sample converges for both analyses,
the REML ratio test statistic is formed for it. The p-value is then calculated
as (k + 1) / (b + 1) where k is the number
of simulated ratio test statistics greater than the observed test statistic and
s is the number of bootstrap samples that were returned.
The function checks that the models do not differ in either their fixed
or sparse models. It also check the difference in the number of variance
parameters between the two fits to the models, taking into account the
bound.exclusions.
Usage
## S3 method for class 'asreml'
bootREMLRT(h0.asreml.obj, h1.asreml.obj,
nboot = 100, max.retries = 5, seed = NULL,
means=NULL, V = NULL, extra.matrix = NULL, ignore.terms = NULL,
fixed.spline.terms = NULL,
bound.exclusions = c("F","B","S","C"),
tolerance = 1E-10, update = TRUE, trace = FALSE,
ncores = 2, ...)
Arguments
h0.asreml.obj |
|
h1.asreml.obj |
|
nboot |
The number of bootstrap samples to be generated. |
max.retries |
The maximum number of attempts to generate a sample whose analyses converge for both models. |
seed |
A single value, interpreted as an integer, that specifies the
starting value of the random number generator. The "L'Ecuyer-CMRG" random
generator is used and |
means |
The |
V |
The fitted variance |
extra.matrix |
A |
ignore.terms |
A |
fixed.spline.terms |
A |
bound.exclusions |
A |
tolerance |
The value such that eigenvalues less than it are considered to be zero. |
update |
If |
trace |
If |
ncores |
A |
... |
Other arguments that are passed down to the function asreml. Changes to the models are not allowed. Other changes are dangerous and generally should be avoided. |
Value
A list with the following components:
REMLRT: the observed REML ratio statistic.
p: the bootstrap p-value for the observed test statistic.
DF: the calculated difference in DF for the variance parameters in the two models.
totalunconverged: the total number of unconverged analyses over the simulations.
REMLRT.sim: a
numericcontaining the values of the ratio statistics for the simulated data. It has an attribute calledna.actionthat can be retrieved usingattr(REMLRT.sim, which = "na.action"); it contains a list of the simulation numbers that were abandoned becausemax.retriesfailed to converge for both models.nunconverged: the number of unconverged analyses for each bootstrap sample, the maximum being
max.retries.
Note
A bootstrap sample is generated using a multivariate normal distribution with expected value as
specified by means and variance matrix given by V. Each simulated sample
is analysed according to the reduced model and, provided this analysis converges,
according to the full.model. If one of these analyses fails to converge, it is
abandoned and another sample is generated for this simulation. As many as
max.retries attempts are made to generate a data set for which both analyses
converge. If data set that converges for both analyses is not generated for a
simulation, NA is returned for that bootstrap sample. Hence, the maximum number
of data sets that will be generated is nboot * max.retries and less than
nboot samples will be generated if a data set that converges for both analyses
is not obtained within max.retries attempts.
If a bootstrap sample converges for both analyses, the REML ratio test statistic is calculated
as 2(log(REML)_F - log(REML)_R).
The DF is calculated from the information in full.asreml.obj and
reduced.asreml.obj. The degrees of freedom are computed as the difference
between the two models in the number of variance parameters whose estimates do
not have a code for bound specified in bound.exclusions.
If ASReml-R version 4 is being used then the codes specified in
bound.exclusions are not restricted to a subset of the default codes, but
a warning is issued if a code other than these is specified.
For ASReml-R version 3, only a subset of the default codes are allowed:
F (Fixed), B (Boundary), C (Constrained)
and S (Singular).
Author(s)
Chris Brien
See Also
REMLRT.asreml, infoCriteria.asreml, newfit.asreml,
testranfix.asrtests
Examples
## Not run:
bootREMLRT(ICV.max, ICV.red, ncores = parallel::detectCores())
## End(Not run)
Uses information criteria to decide whether to change an already fitted model.
Description
Uses information criteria to decide whether to change the fitted model
stored in the supplied asrtests.object according to the specified
modifications. The function changeTerms is
used to change the model. Thus, the model can be modified using a
combination of adding and removing sets of terms from one or both of the fixed
or random models, replacing the residual model and changing the bounds and/or initial
values of some terms. The model will be unchanged
if terms specified in dropFixed or dropRandom are not in the fitted
model.
A row is added to the test.summary data.frame of the
asrtests.object using the supplied label and stating
whether or not the new model has been swapped for the supplied model.
Convergence in fitting the model is checked and a note included in the
action if there was not. All components of the
asrtests.object are updated to exhibit the differences
between the supplied and new models.
To obtain a list of the information criteria for a set of models use
changeTerms.asrtests with IClikelihood set to
REML or full, or use infoCriteria.asreml.
Usage
## S3 method for class 'asrtests'
changeModelOnIC(asrtests.obj,
dropFixed = NULL, addFixed = NULL,
dropRandom = NULL, addRandom = NULL,
newResidual = NULL,
allow.absentDropTerms = FALSE, label = "Changed terms",
allow.unconverged = TRUE, allow.fixedcorrelation = TRUE,
checkboundaryonly = FALSE,
trace = FALSE, update = TRUE, denDF = "numeric",
set.terms = NULL, ignore.suffices = TRUE,
bounds = "P", initial.values = NA,
which.IC = "AIC", IClikelihood = "REML",
fixedDF = NULL, varDF = NULL,
bound.exclusions = c("F","B","S","C"),
...)
Arguments
asrtests.obj |
An |
dropFixed |
A single |
addFixed |
A single |
dropRandom |
A single |
addRandom |
A single |
newResidual |
A single |
allow.absentDropTerms |
A |
label |
A |
allow.unconverged |
A |
allow.fixedcorrelation |
A |
checkboundaryonly |
If |
trace |
If TRUE then partial iteration details are displayed when ASReml-R functions are invoked; if FALSE then no output is displayed. |
update |
If |
denDF |
Specifies the method to use in computing approximate denominator
degrees of freedom when |
set.terms |
A |
ignore.suffices |
A logical vector specifying whether the suffices of the
|
bounds |
A |
which.IC |
A |
IClikelihood |
A |
fixedDF |
A |
varDF |
A |
initial.values |
A character vector specifying the initial values for
the terms specified in |
bound.exclusions |
A |
... |
Further arguments passed to |
Value
An asrtests.object containing the components (i) asreml.obj,
(ii) wald.tab, and (iii) test.summary. The values of the degrees of
freedom and the information criteria are differences between those of the changed
model and those of the model supplied to changeModelOnIC.
Author(s)
Chris Brien
See Also
as.asrtests, rmboundary.asrtests,
testranfix.asrtests, testresidual.asrtests,
newfit.asreml, reparamSigDevn.asrtests,
chooseModel.asrtests, changeTerms.asrtests,
infoCriteria.asreml
Examples
## Not run:
data(Wheat.dat)
current.asr <- asreml(yield ~ Rep + WithinColPairs + Variety,
random = ~ Row + Column + units,
residual = ~ ar1(Row):ar1(Column),
data=Wheat.dat)
current.asrt <- as.asrtests(current.asr, NULL, NULL,
label = "Maximal model")
current.asrt <- rmboundary(current.asrt)
# Drop both Row and Column terms
current.asrt <- changeModelOnIC(current.asrt,
dropRandom = "Row + Column",
checkboundaryonly = TRUE,
which.IC = "AIC", IClikelihood = "full")
current.asrt <- iterate(current.asrt)
# Add and drop both fixed and random terms
current.asrt <- changeModelOnIC(current.asrt,
addFixed = "vRow", dropFixed = "WithinColPairs",
addRandom = "spl(vRow)", dropRandom = "units",
checkboundaryonly = TRUE,
which.IC = "AIC", IClikelihood = "full")
# Replace residual with model without Row autocorrelation
current.asrt <- changeModelOnIC(current.asrt,
newResidual = "Row:ar1(Column)",
label="Row autocorrelation",
IClikelihood = "full")
## End(Not run)
Adds and drops terms from one or both of the fixed or random model, replaces the residual (rcov) model with a new model and changes bounds or initial values of terms.
Description
The specified terms are simply added or dropped, without testing, from either the fixed or random model and/or the residual (rcov) model replaced. Also, the bounds and/or initial values of some terms can be changed. No hypothesis testing is performed, but a check is made for boundary or singular terms.
A row is added to the test.summary data.frame of the
asrtests.object using the supplied label and stating
which models have been changed. Information criteria can be included in the
row of the test.summary. Convergence in fitting the model is checked
and a note included in the action if there was not. All components of
the asrtests.object are updated.
To only change the terms based on a comparison of information
criteria use changeModelOnIC.asrtests.
Usage
## S3 method for class 'asrtests'
changeTerms(asrtests.obj,
dropFixed = NULL, addFixed = NULL,
dropRandom = NULL, addRandom = NULL,
newResidual = NULL, label = "Changed terms",
allow.unconverged = TRUE, allow.fixedcorrelation = TRUE,
checkboundaryonly = FALSE,
trace = FALSE, update = TRUE, denDF = "numeric",
set.terms = NULL, ignore.suffices = TRUE,
bounds = "P", initial.values = NA,
IClikelihood = "none", bound.exclusions = c("F","B","S","C"),
...)
Arguments
asrtests.obj |
An |
dropFixed |
A single |
addFixed |
A single |
dropRandom |
A single |
addRandom |
A single |
newResidual |
A single |
label |
A |
allow.unconverged |
A |
allow.fixedcorrelation |
A |
checkboundaryonly |
If |
trace |
If TRUE then partial iteration details are displayed when ASReml-R functions are invoked; if FALSE then no output is displayed. |
update |
If |
denDF |
Specifies the method to use in computing approximate denominator
degrees of freedom when |
set.terms |
A |
ignore.suffices |
A logical vector specifying whether the suffices of the
|
bounds |
A |
initial.values |
A character vector specifying the initial values for
the terms specified in |
IClikelihood |
A |
bound.exclusions |
A |
... |
Further arguments passed to |
Value
An asrtests.object containing the components (i) asreml.obj,
(ii) wald.tab, and (iii) test.summary.
Author(s)
Chris Brien
References
Kenward, M. G., & Roger, J. H. (1997). Small sample inference for fixed effects from restricted maximum likelihood. Biometrics, 53, 983-997.
See Also
as.asrtests, rmboundary.asrtests,
testranfix.asrtests, testresidual.asrtests,
newfit.asreml, reparamSigDevn.asrtests,
chooseModel.asrtests,
changeModelOnIC.asrtests, infoCriteria.asreml
Examples
## Not run:
terms <- "(Date/(Sources * (Type + Species)))"
current.asrt <- changeTerms(current.asrt, addFixed = terms)
current.asrt <- changeTerms(current.asrt, dropFixed = "A + B", denDF = "algebraic")
data(Wheat.dat)
current.asr <- asreml(yield ~ Rep + WithinColPairs + Variety,
random = ~ Row + Column + units,
residual = ~ ar1(Row):ar1(Column),
data=Wheat.dat)
current.asrt <- as.asrtests(current.asr, NULL, NULL)
current.asrt <- rmboundary(current.asrt)
# Add and drop both fixed and random terms
current.asrt <- changeTerms(current.asrt,
addFixed = "vRow", dropFixed = "WithinColPairs",
addRandom = "spl(vRow)", dropRandom = "units",
checkboundaryonly = TRUE)
# Replace residual with model without Row autocorrelation
current.asrt <- changeTerms(current.asrt,
newResidual = "Row:ar1(Column)",
label="Row autocorrelation")
## End(Not run)
Determines the set of significant terms using p-values and records the tests performed in a
data.frame, taking into account the
marginality relations of terms.
Description
Using p-values from hypothesis tests, determines the set of significant
terms, taking into account the hierarchy or marginality of terms.
In particular, a term will not be tested if it is marginal to (or nested in) one
that is significant.
For example, if A:B is significant, then neither A nor B will be tested.
The tests conducted in choosing selected model are listed in
a summary data.frame.
Usage
chooseModel(object, ...)
Arguments
object |
an object using which p-values can be obtained for use in model selection. |
... |
further arguments passed to or from other methods. |
Details
chooseModel is the generic function for the chooseModel method.
Use methods("chooseModel") to get all the methods for the chooseModel generic.
chooseModel.asrtests is a method for an asrtests.object. It uses
testranfix.asrtests to conduct tests to determine the p-values used
in the model selection.
chooseModel.data.frame is a method for a data.frame. It uses
the p-values stored in the data.frame in the model selection.
Author(s)
Chris Brien
See Also
chooseModel.asrtests, chooseModel.asrtests,
changeModelOnIC.asrtests, testranfix.asrtests
Determines and records the set of significant terms using an asrtests.object,
taking into account the hierarchy or marginality relations of the terms.
Description
Performs a series of hypothesis tests on a set of fixed and/or random terms taking
into account the marginality of terms. In particular, a term will not be tested if it is
marginal to (or nested in) one that is significant. For example, if A:B is significant, then
neither A nor B will be tested. For a random term, the term is removed from
the model fit, any boundary terms are removed using rmboundary.asrtests
and a REML likelihood ratio test is performed using REMLRT.asreml.
If it is not significant and drop.ran.ns is TRUE, the term is permanently removed
from the model. Note that if boundary terms are removed, the reduced model may not
be nested in the full model in which case the test is not valid. For fixed terms,
the Wald tests are performed and the p-value for the term obtained. If it is not
significant and drop.fix.ns is TRUE, the term is permanently removed
from the model. A row that records the outcome of a test is added to
test.summary for each term that is tested.
Usage
## S3 method for class 'asrtests'
chooseModel(object, terms.marginality=NULL,
alpha = 0.05, allow.unconverged = TRUE,
allow.fixedcorrelation = TRUE,
checkboundaryonly = FALSE, drop.ran.ns=TRUE,
positive.zero = FALSE, bound.test.parameters = "none",
drop.fix.ns=FALSE, denDF = "numeric", dDF.fault = "none",
dDF.values = NULL, trace = FALSE, update = TRUE,
set.terms = NULL, ignore.suffices = TRUE,
bounds = "P", initial.values = NA,
IClikelihood = "none", ...)
Arguments
object |
an |
terms.marginality |
A square matrix of ones and zeros with row and column names
being the names of the terms to be tested.
The names of fixed terms must match those in the |
alpha |
The significance level for the test. |
allow.unconverged |
A |
allow.fixedcorrelation |
A |
checkboundaryonly |
If |
drop.ran.ns |
A logical indicating whether to drop nonsignificant random terms from the model. |
positive.zero |
Indicates whether the hypothesized values for the
variance components being tested are on the boundary
of the parameter space. For example, this is true
for positively-constrained variance components that,
under the reduced model, are zero. This argument does
not need to be set if |
bound.test.parameters |
Indicates whether for the variance components
being tested, at least some of the hypothesized values
are on the boundary of the parameter space.
The possibilities are |
drop.fix.ns |
A logical indicating whether to drop a fixed term from the model when it is nonsignificant |
denDF |
Specifies the method to use in computing approximate denominator
degrees of freedom when |
dDF.fault |
A |
dDF.values |
A |
trace |
If TRUE then partial iteration details are displayed when ASReml-R functions are invoked; if FALSE then no output is displayed. |
update |
If |
set.terms |
A character vector specifying the terms that are to have
bounds and/or initial values set prior to fitting.
The names must match those in the |
ignore.suffices |
A logical vector specifying whether the suffices of the
|
bounds |
A |
initial.values |
A character vector specifying the initial values for
the terms specified in |
IClikelihood |
A |
... |
further arguments passed to |
Value
A list containing:
-
asrtests.obj: anasrtests.objectcontaining the components (i)asreml.obj, (ii)wald.tab, and (iii)test.summary.; -
sig.tests: acharacter vectorwhose elements are the significant terms amongst those tested.
Author(s)
Chris Brien
References
Kenward, M. G., & Roger, J. H. (1997). Small sample inference for fixed effects from restricted maximum likelihood. Biometrics, 53, 983-997.
See Also
chooseModel, chooseModel.data.frame,
as.asrtests, testranfix.asrtests,
testresidual.asrtests, REMLRT.asreml,
rmboundary.asrtests, newfit.asreml,
changeModelOnIC.asrtests, changeTerms.asrtests,
reparamSigDevn.asrtests
Examples
## Not run:
data(WaterRunoff.dat)
asreml.options(keep.order = TRUE) #required for asreml-R4 only
current.asr <- asreml(log.Turbidity ~ Benches + (Sources * (Type + Species)) * Date,
random = ~Benches:MainPlots:SubPlots:spl(xDay),
data = WaterRunoff.dat, keep.order = TRUE)
current.asrt <- as.asrtests(current.asr, NULL, NULL)
terms.treat <- c("Sources", "Type", "Species",
"Sources:Type", "Sources:Species")
terms <- sapply(terms.treat,
FUN=function(term){paste("Date:",term,sep="")},
simplify=TRUE)
terms <- c("Date", terms)
terms <- unname(terms)
marginality <- matrix(c(1,0,0,0,0,0, 1,1,0,0,0,0, 1,0,1,0,0,0,
1,0,1,1,0,0, 1,1,1,0,1,0, 1,1,1,1,1,1), nrow=6)
rownames(marginality) <- terms
colnames(marginality) <- terms
choose <- chooseModel(current.asrt, marginality)
current.asrt <- choose$asrtests.obj
sig.terms <- choose$sig.terms
## End(Not run)
Determines the set of significant terms from results stored in a data.frame,
taking into account the marginality relations of terms and recording the tests used
in a data.frame.
Description
Uses the p.values from a set of hypothesis tests that are stored in
the supplied data.frame to choose a model to describe the effects of the
terms corresponding to the p-values, taking into account the hierarchy or marginality
of terms. In particular, a term will not be tested if it is marginal to (or nested in)
one that is significant. For example, if A:B is significant, then neither A nor B will
be tested. The tests used in choosing the selected model are listed in the
data.frame choose.summary.
No change is made to the p.values, the DF and denDF being for
information only.
Usage
## S3 method for class 'data.frame'
chooseModel(object, terms=NULL, p.values = "Pr",
DF = "Df", denDF = "denDF", omit.DF = FALSE,
terms.marginality=NULL, alpha = 0.05, ...)
Arguments
object |
a |
terms |
A |
p.values |
A |
DF |
Can be a |
denDF |
Can be a |
omit.DF |
A |
terms.marginality |
A square matrix of ones and zeros with row and column names
being the names of the those terms in the |
alpha |
The significance level for the hypothesis testing. |
... |
Provision for passing arguments to functions called internally - not used at present. |
Value
A list containing:
-
choose.summary: adata.framesummarizing the tests carried out in choosing the significant terms; providedomit.DF =FALSE, it has the same columns as atest.summaryfrom anasrtests.object -
sig.tests: acharacter vectorwhose elements are the significant terms amongst those tested.
Author(s)
Chris Brien
See Also
chooseModel, chooseModel.asrtests
Examples
data("Ladybird.dat")
## Use asreml to get the table of p-values
## Not run:
m1.asr <- asreml(logitP ~ Host*Cadavers*Ladybird,
random = ~ Run,
data = Ladybird.dat)
current.asrt <- as.asrtests(m1.asr)
fixed.tab <- current.asrt$wald.tab
col.p <- "Pr"
df = "Df"
den.df = "denDF"
## End(Not run)
## Use lmeTest to get the table of p-values
if (requireNamespace("lmerTest", quietly = TRUE) &
requireNamespace("emmeans", quietly = TRUE))
{
m1.lmer <- lmerTest::lmer(logitP ~ Host*Cadavers*Ladybird + (1|Run),
data=Ladybird.dat)
fixed.tab <- anova(m1.lmer, type = "II")
col.p <- "Pr(>F)"
df = "NumDF"
den.df = "DenDF"
}
## Select a model using the table of p-values obtained with either asreml or lmerTest
if (exists("fixed.tab"))
{
term.marg <- dae::marginality(dae::pstructure(~ Host*Cadavers*Ladybird,
data = Ladybird.dat))
chosen <- chooseModel(fixed.tab, p.values = col.p, DF = df, denDF = den.df,
terms.marginality = term.marg)
}
Uses information criteria to choose the best fitting spatial model for accounting for local spatial variation.
Description
For a response variable measured on a potentially irregular grid of rows and
columns of the units, uses information criteria (IC) to decide whether the fit and
parsimony of the model fitted to a set of data can be improved by adding, to the fitted
model stored in the supplied asrtests.object, one of the following spatial
models to account for the local spatial variation:
(i) a two-dimensional first-order autocorrelation model, (ii) a two-dimensional
tensor-product natural cubic smoothing spline model (TPNCSS), (iii) a two-dimensional
tensor-product penalized P-spline model with second-difference penalties (TPPSC2) model,
or (iv) a two-dimensional tensor-product penalized linear spline model with
first-difference penalties (TPPSL1). The models from which to select can be reduced
to a subset of these four models. For each model, a term from the spatial model is
only added to the supplied model if the IC of the supplied model is decreased with
the addition of that term. If no model improves the IC when a local spatial variation
model is added, then the supplied, nonspatial model will be returned. The data can be
arranged in sections, for each of which there is a grid and for which the model is to
be fitted separately. Also, the rows and columns of a grid are not necessarily one
observational unit wide. For TPPSC2 models, the improvement in the fit from
rotating the eigenvectors of the penalty matrix can be investigated; if there is no
improvement, the unrotated fit will be returned.
One or more rows is added to the test.summary data.frame of the
asrtests.object, for each section and each spatial model,
stating whether or not the new model has been swapped for a model in which the
spatial model has been added to the supplied model. Convergence in fitting the
model is checked and a note included in the action if there was not.
All components of the asrtests.object are updated to exhibit the
differences between the supplied and any new model.
Usage
## S3 method for class 'asrtests'
chooseSpatialModelOnIC(asrtests.obj, trySpatial = "all",
sections = NULL,
row.covar = "cRow", col.covar = "cCol",
row.factor = "Row", col.factor = "Col",
corr.funcs = c("ar1", "ar1"), corr.orders = c(0, 0),
row.corrFitfirst = TRUE,
allow.corrsJointFit = TRUE, nugget.variance = TRUE,
dropFixed = NULL, dropRandom = NULL,
nsegs = NULL, nestorder = c(1,1),
usRandLinCoeffs = TRUE,
rotateX = FALSE, ngridangles = NULL,
which.rotacriterion = "AIC", nrotacores = 1,
asreml.option = "grp", tpps4mbf.obj = NULL,
allow.unconverged = TRUE, allow.fixedcorrelation = TRUE,
checkboundaryonly = FALSE, update = TRUE, trace = FALSE,
maxit = 30, IClikelihood = "full", which.IC = "AIC",
return.asrts = "best", ...)
Arguments
asrtests.obj |
An |
trySpatial |
A |
sections |
A single |
row.covar |
A single |
col.covar |
A single |
row.factor |
A single |
col.factor |
A single |
corr.funcs |
A single |
corr.orders |
A |
row.corrFitfirst |
A |
allow.corrsJointFit |
A |
nugget.variance |
A |
dropFixed |
A single An element that is The terms must match those in the |
dropRandom |
A single An element that is The terms must match those in the |
nsegs |
A pair of |
nestorder |
A |
usRandLinCoeffs |
A |
rotateX |
A |
ngridangles |
A |
which.rotacriterion |
A single |
nrotacores |
A |
asreml.option |
A single |
tpps4mbf.obj |
An object made with |
allow.unconverged |
A |
allow.fixedcorrelation |
A |
checkboundaryonly |
If |
update |
If |
trace |
If |
which.IC |
A |
maxit |
A |
IClikelihood |
A |
return.asrts |
A |
... |
Further arguments passed to |
Details
For each spatial model that is to be fitted, a fitted spatial model is only returned if it improves the fit over and above that achieved with the model fit supplied in the asrtests.obj, because terms in the spatial model are not added unless model fit is improved by their addition as measured by an IC. If return.asrts is all, then this applies to each spatial model specified by trySpatial. To force a spatial model to be fitted use addSpatialModel.asrtests. The model fit supplied in the asrtests.obj should not include terms that will be included in any local spatial model. All spatial model terms are fitted as fixed or random. Consequently, the residual model does not have to be iid. The improvement in the fit resulting from the addition of a spatial model to the supplied model is evaluated. Note that the data must be in the order that corresponds to the residual argument with a variable to the right of another variable changing levels in the data frame faster than those of the preceding variables e.g. Row:Column implies that all levels for Column are in consecutive rows of the data.frame that have a single Row level.
For the corr spatial model, the default model is an autocorrelation model of order one (ar1) for each dimension. However, any of the single dimension correlation/variance models from asreml can be specified for each dimension, as can no correlation model for a dimension; the models for the two dimensions can differ. Using a forward selection procedure, a series of models are tried, without removing boundary or singular terms, beginning with the addition of row correlation and followed by the addition of column correlation or, if the row.corrFitfirst is set to FALSE, the reverse order. If the fitting of the first-fitted correlation did not result in a model change because the fitting did not converge or correlations were fixed, but the fit of the second correlation was successful, then adding the first correlation will be retried. If one of the metric correlation functions is specified (e.g. exp), then the row.covar or col.covar will be used in the spatial model. However, because the correlations are fitted separately for the two dimensions, the row.factor and col.factor are needed for all models and are used for any dimension that does not involve a correlation/variance function for the fit being performed. Also, the correlation models are fitted as random terms and so the correlation model will include a variance parameter for the grid even when ar1 is used to specify the correlation model, i.e. the model fitted is a variance model and there is no difference between ar1 and ar1v in fitting the model. The variance parameter for this term represents the spatial variance and the fit necessarily includes a nugget term, this being the residual variance. If any correlation is retained in the model, for a section if sections is not NULL, then the need for a nuggest term is assessed by fixing the corresponding residual variance to one, unless there are multiple residual variances and these are not related to the sections. Once the fitting of the correlation model has been completed, the rmboundary function will be executed with the checkboundaryonly value supplied in the chooseSpatialModelOnIC.asrtests call. Finally, checking for bound and singular random terms associated with the correlation model and residual terms will be carried out when there are correlation terms in the model and checkboundaryonly has been set to FALSE; as many as possible will be removed from the fitted model, in some cases by fixing variance terms to one.
The tensor-product natural-cubic-smoothing-spline (TPNCSS) spatial model is as described by Verbyla et al. (2018), the tensor-product penalized-cubic-spline (TPPSC2) model with second-order differencing of the penalty is similar to that described by Rodriguez-Alvarez et al. (2018), and the tensor-product, first-difference-penalty, linear spline (TPPSL1) model is amongst those described by Piepho, Boer and Williams (2022). The fixed terms for the spline models are row.covar + col.covar + row.covar:col.covar and the random terms are spl(row.covar) + spl(col.covar) + dev(row.covar) + dev(col.covar) + spl(row.covar):col.covar + row.covar:spl(col.covar) + spl(row.covar):spl(col.covar), except that spl(row.covar) + spl(col.covar) is replaced with spl(row.covar):int(col.covar) + int(row.covar):spl(col.covar) in the TPPSC2 model, where int(.) indicates an intercept or constant value specific to its argument. For TPPSL1 models, the terms spl(row.covar):col.covar + row.covar:spl(col.covar) are omitted, The supplied model should not include any of these terms. However, any fixed or random main-effect Row or Column term that has been included as an initial model for comparison with a spatial model can be removed prior to fitting the spatial model using dropFixed or dropRandom. For the P-spline models with second-order differencing, the model matrices used to fit the pairs of random terms (i) spl(row.covar):int(col.covar) and spl(row.covar):col.covar and (ii) int(row.covar):spl(col.covar) and row.covar:spl(col.covar) are transformed using the spectral decomposition of their penalty matrices. An unstructured variance model is tried for each of these pairs and retained if it improves the fit. For TPPSC2, it is also possible to optimize the rotation of the null-space eigenvectors of the penalty matrix for each of these random-term pairs (for more information see Piepho, Boer and Williams, 2022). The optimization is achieved either using an optimizer or takes the form of a search over a grid of rotation angles for a reduced model; the fit of the full model with rotation using the optimal rotation angles will only be returned if it improves on the fit of the full, unrotated model.
The TPPSC2 and TPPSL1 models are fitted using functions from the R package TPSbits authored by Sue Welham (2022). There are two methods for supplying the spline basis information produced by tpsmmb to asreml. The grp method adds it to the data.frame supplied in the data argument of the asreml call. The mbf method creates smaller data.frames with the spline basis information in the same environment as the internal function that calls the spline-fitting function. If it is desired to use in a later session, an asreml function, or asrtests function that calls asreml, (e.g. predict.asreml, predictPlus.asreml, or changeTerms.asrtests) on an asreml.object created using mbf terms, then the mbf data.frames will need to be recreated using makeTPPSplineMats.data.frame in the new session, supplying, if there has been rotation of the penalty matrix eigenvectors, the theta values that are returned as the attribute theta.opt of the asreml.obj.
All models utlize the function changeModelOnIC.asrtests to assess the model fit, the information criteria used in assessing the fit being calculated using infoCriteria. Arguments from tpsmmb and changeModelOnIC.asrtests can be supplied in calls to chooseSpatialModelOnIC.asrtests and will be passed on to the relevant function though the ellipses argument (...).
The data for experiment can be divided into sections and an attempt to fit the same spatial model to each is made. The fit may differ for each of the sections, but the fit over all of the sections is assessed. For more detail see sections above.
Each combination of a row.coords and a col.coords does not have to specify a single observation; for example, to fit a local spatial model to the main units of a split-unit design, each combination would correspond to a main unit and all subunits of the main unit would have the same combination.
Value
A list containing four components: (i) asrts, (ii) spatial.IC,
(iii) best.spatial.mod, and (iv) best.spatial.IC.
The component asrts itself holds a list of one or more
asrtests.objects, either the best overall out of the supplied model and
the spatial models, or, for each spatial model, the best out of the supplied model
and that spatial model. Each asrtests.object contains the components:
(i) asreml.obj, (ii) wald.tab, and (iii) test.summary. If the
asrtests.object is the result of fitting a TPPSC2 model with
an exploration of the rotation of the eigenvectors of the penalty matrix for the linear
components, then the asreml.obj will have an attribute theta.opt that contains
the optimal rotation angles of the eigenvectors.
The spatial.IC component holds a data.frame with summary of the
values of the information criteria for the supplied model and those resulting from
adding the spatial models to the supplied model. In the case of a spatial correlation model,
the information criteria for the selected spatial correlation model is returned.
If a spatial model could not be fitted, then all returned values will be NA).
The best.spatial.mod component is a character giving the name of the best spatial
model, and best.spatial.AIC gives the value of its AIC.
Author(s)
Chris Brien
References
Piepho, H.-P., Boer, M. P., & Williams, E. R. (2022). Two-dimensional P-spline smoothing for spatial analysis of plant breeding trials. Biometrical Journal, 64, 835-857.
Rodriguez-Alvarez, M. X., Boer, M. P., van Eeuwijk, F. A., & Eilers, P. H. C. (2018). Correcting for spatial heterogeneity in plant breeding experiments with P-splines. Spatial Statistics, 23, 52-71.
Verbyla, A. P., De Faveri, J., Wilkie, J. D., & Lewis, T. (2018). Tensor Cubic Smoothing Splines in Designed Experiments Requiring Residual Modelling. Journal of Agricultural, Biological and Environmental Statistics, 23(4), 478-508.
Welham, S. J. (2022) TPSbits: Creates Structures to Enable Fitting and Examination of 2D Tensor-Product Splines using ASReml-R. Version 1.0.0 https://mmade.org/tpsbits/
See Also
as.asrtests,
makeTPPSplineMats.data.frame,
addSpatialModelOnIC.asrtests,
addSpatialModel.asrtests,
changeModelOnIC.asrtests,
changeTerms.asrtests,
rmboundary.asrtests,
testranfix.asrtests,
testresidual.asrtests,
newfit.asreml,
reparamSigDevn.asrtests,
changeTerms.asrtests,
infoCriteria.asreml
Examples
## Not run:
data(Wheat.dat)
#Add row and column covariates
Wheat.dat <- within(Wheat.dat,
{
cColumn <- dae::as.numfac(Column)
cColumn <- cColumn - mean(unique(cColumn))
cRow <- dae::as.numfac(Row)
cRow <- cRow - mean(unique(cRow))
})
#Fit initial model
current.asr <- asreml(yield ~ Rep + WithinColPairs + Variety,
random = ~ Row + Column,
data=Wheat.dat)
#Create an asrtests object, removing boundary terms
current.asrt <- as.asrtests(current.asr, NULL, NULL,
label = "Random Row and Column effects")
current.asrt <- rmboundary(current.asrt)
# Choose the best of four models for the local spatial variation
current.asrt <- chooseSpatialModelOnIC(current.asrt,
row.covar = "cRow", col.covar = "cColumn",
dropRowterm = "Row", dropColterm = "Column",
asreml.option = "grp")
## End(Not run)
Recreates an asreml object so that it is compatible with the currently loaded asreml version.
Description
Recreate an existing asreml object so that it is compatible with the currently loaded asreml version. It involves refitting the model stored in the asreml object.
Usage
## S3 method for class 'asreml'
convAsremlobj(asreml.obj, ...)
Arguments
asreml.obj |
An |
... |
Provision for passing arguments to functions called internally - not used at present. |
Value
An asreml object.
Author(s)
Chris Brien
References
Butler, D. G., Cullis, B. R., Gilmour, A. R., Gogel, B. J. and Thompson, R. (2023). ASReml-R Reference Manual Version 4.2. VSN International Ltd, https://asreml.kb.vsni.co.uk/.
See Also
newfit.asreml, update.asreml
Examples
## Not run:
m1.asr <- convAsremlobj(m1.asr)
## End(Not run)
Converts the effects names for a term stored in the component of an asreml object into a data.frame.
Description
Converts the effects names for a term stored in the component of an asreml object into
a data.frame that has a column for each factor and variable in the term.
It facilitates adding the effects to the data.frame supplied to asreml
for an analysis. This function can only be used with asreml v4.2 or later.
Usage
## S3 method for class 'asreml'
convEffectNames2DataFrame(asreml.obj, term, use = "design.matrix", sep = ":", ...)
Arguments
asreml.obj |
An object resulting from the fitting of
a model using |
term |
A |
use |
A |
sep |
A |
... |
Provision for passing arguments to functions called internally - not used at present. |
Value
A data.frame with columns for the factors and variables in term.
It includes the attribute effect.names that contains the extracted effects names
for the term
Author(s)
Chris Brien
References
Butler, D. G., Cullis, B. R., Gilmour, A. R., Gogel, B. J. and Thompson, R. (2023). ASReml-R Reference Manual Version 4.2. VSN International Ltd, https://asreml.kb.vsni.co.uk/.
Examples
## Not run:
G.dat <- convEffectNames2DataFrame(m1.asr, term = "Row:Column", use = "G.aom")
G.dat <- lapply(c("at(Smarthouse, 'SW'):Lane:Position",
"at(Smarthouse, 'SE'):Lane:Position"),
function(term, asreml.obj)
tmp <- convEffectNames2DataFrame.asreml(asreml.obj, term = term),
asreml.obj = m1.asr)
G.dat <- do.call(rbind, G.dat)
## End(Not run)
Forms the estimated variance, random or residual matrix for the observations from the variance parameter estimates.
Description
Forms the estimated variance (V), random (G) or (R) matrix
for the observations, a square symmetric matrix of order equal to the number of
observations. The estimates of the variance parameters and the information about
the random and residual models for which they were estimated are
obtained from the asreml object.
This function is not available in ASReml-R version 3.
Usage
## S3 method for class 'asreml'
estimateV(asreml.obj, which.matrix = "V",
extra.matrix = NULL, ignore.terms = NULL, fixed.spline.terms = NULL,
bound.exclusions = c("F","B","S","C"), ...)
Arguments
asreml.obj |
An |
which.matrix |
A |
extra.matrix |
A |
ignore.terms |
A |
fixed.spline.terms |
A |
bound.exclusions |
A |
... |
Provision for passing arguments to functions called internally - not used at present. |
Details
The information about the variance parameters in the fitted mixed model are obtained
from the G.param and R.param components of the asreml object. The
function can deal with the following variance functions in either the random or
residual models: id, diag, us, ar1, ar2,
ar3, sar,sar2, ma1, ma2, arma, exp,
gau, cor, corb and corg. All of these functions,
except us, can be combined with either v or h. It will also cope
with the following functions in the random model: at, str,
spl, dev, grp, fa and rr. Additionally, it can deal
with the function dsum in the residual model. For further information see
the ASReml-R User Guide Version 4 (Butler et al., 2023).
Value
A matrix containing the estimated variance matrix. It has an attribute
missing.termmatrix (use attr(x, which = "missing.termmatrix") to access the
atrribute). It will be NULL, unless the design matrix could not be obtained for
one or more model terms. If is is not NULL, it will be a list of terms that could
not be produced for inclusion in the variance matrix estimate, and NA will be
returned for the estimated variance matrix.
Author(s)
Chris Brien
References
Butler, D. G., Cullis, B. R., Gilmour, A. R., Gogel, B. J. and Thompson, R. (2023). ASReml-R Reference Manual Version 4.2. VSN International Ltd, https://asreml.kb.vsni.co.uk/.
See Also
asreml, simulate.asreml, variofaces.asreml.
Examples
## Not run:
data(Wheat.dat)
current.asr <- asreml(yield ~ Rep + WithinColPairs + Variety,
random = ~ Row + Column + units,
residual = ~ ar1(Row):ar1(Column),
data=Wheat.dat)
# Form variance matrix based on estimated variance parameters
V <- estimateV(current.asr)
## End(Not run)
Explores the computed LSD values for pairwise differences between predictions.
Description
Given an alldiffs.object with an sed component, the LSDs are
calculated for all pairwise comparisons of predictions. It then calculates
(i) a table of frequencies of the LSD values, (ii) the distinct values of the LSDs
after rounding, (iii) various statistics from the LSD values, (iv) a measure of
the accuracy of each of the LSD statistics, (v) the numbers of false positives and
false negatives for each of the LSD statistics if pairwise comparisons are based
on the LSD statistic, (vi) the accuracy of each statistic in
representing the LSD values for each prediction and (vii) a matrix containing
the LSD values for comparing each pair of predictions. Histograms of the
frequencies can also be produced.
Usage
## S3 method for class 'alldiffs'
exploreLSDs(alldiffs.obj, LSDtype = "overall", LSDby = NULL,
LSDaccuracy = "maxAbsDeviation", alpha = 0.05, digits = 3,
retain.zeroLSDs = FALSE,
zero.tolerance = .Machine$double.eps ^ 0.5,
plotHistogram = FALSE, ...)
Arguments
alldiffs.obj |
An |
LSDtype |
A See |
LSDby |
A |
LSDaccuracy |
A |
alpha |
A |
digits |
A |
retain.zeroLSDs |
A |
zero.tolerance |
A |
plotHistogram |
A |
... |
Provision for passing arguments to functions called internally - not used at present. |
Details
The false positives and negatives are computed by comparing, for each pair of predictions
within each levels-combination of the LSDby variables, the
significance of the pair difference determined using (i) the true LSD that is computed from the
standard error of differences for the pair and (ii) the approximate LSD that is a statistic
computed from the true LSDs for all pairwise difference within each levels-combination of the
LSDby variables. The number of false positives is the number of pairwise differences for
which a difference is declared significant using the approximate LSD, but not using the true LSD.
The number of false negatives is the number of pairwise differences for which a difference is
declared nonsignificant using the approximate LSD, but significant using the true LSD.
The LSD accuracy for a set of LSDs is a function of the deviations of those LSDs and an LSD statistic calculated from them; the accuracy is expressed as a proportion of the value of the LSD statistic.
Value
A list with components
frequencies, distinct.vals, statistics, accuracy, per.pred.accuracy
and LSD:
frequenciesis adata.framewith the frequency distribution of the LSD values;distinct.valsis alist, each component of which contains the distinct values of the LSDs after rounding;statisticsis adata.framewith the minimum, quantile10, quantile25, mean, median, quantile75, quantile90, and maximum of the LSD values;accuracyis adata.framewith the accuracies of the minimum, quantile10, quantile25, mean, median, quantile75, quantile90, and maximum of the LSD values with respect to the values from which these statistics are calculated;false.posis adata.framewith the numbers of false positives for the pairwise comparisons within each levels-combination of theLSDbyvariables when each of the minimum, quantile10, quantile25, mean, median, quantile75, quantile90, and maximum of the LSD values is used as an approximate LSD in determining the significance of the pairwise differences;false.negis adata.framewith the numbers of false negatives for the pairwise comparisons within each levels-combination of theLSDbyvariables when each of the minimum, quantile10, quantile25, mean, median, quantile75, quantile90, and maximum of the LSD values is used as an approximate LSD in determining the significance of the pairwise differences;per.pred.accuracyis adata.framewith the accuracies of the minimum, quantile10, quantile25, mean, median, quantile75, quantile90, and maximum of the LSD values for a set of predictions when these statistics are used to represent the LSDs for the comparisons amongst the set of predictions;LSDis a squarematrixcontaining the LSD values for all pairwise comparisons of the predictions contained in the suppliedalldiffs.obj.
In the statistics, accuracy, false.pos and false.neg data.frames,
c is the number of pairwise comparisons on which the values in the same row are based.
The accuracy measure is specified by the LSDaccuracy argument.
Author(s)
Chris Brien
See Also
asremlPlus-package, plotLSDs.data.frame, plotLSDs.alldiffs,
plotLSDerrors.alldiffs, plotLSDerrors.data.frame, recalcLSD.alldiffs,
pickLSDstatistics.alldiffs, redoErrorIntervals.alldiffs
Examples
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)
TS.diffs <- predictPlus(classify = "Sources:Type",
asreml.obj = current.asr,
wald.tab = current.asrt$wald.tab,
present = c("Sources", "Type", "Species"))
## 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 * (Type + Species)) +
(1|Benches:MainPlots),
data=na.omit(WaterRunoff.dat))
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"))
## Form an all.diffs object and check its validity
TS.vcov <- vcov(TS.emm)
TS.diffs <- allDifferences(predictions = TS.preds, classify = "Sources:Type",
vcov = TS.vcov, tdf = den.df)
validAlldiffs(TS.diffs)
}
## Plot p-values for predictions obtained using asreml or lmerTest
if (exists("TS.diffs"))
{
##Explore the LSD values for predictions obtained using asreml or lmerTest
LSDstat <- exploreLSDs(TS.diffs, LSDtype = "factor.combinations",
LSDby = "Sources")
}
Combines several factors into one in the components of an alldiffs.object
Description
Combines several factors, in the prediction component
of object, into one whose levels are the combinations of the
used levels of the individual factors. The matching
changes are made to the other components and the attributes of the
alldiffs.object. If any of the factors to be combined are in
LSDby, they are removed from the LSDby, unless the factors to
be combined are exactly those in the LSDby.
The levels of the factors are combined using fac.combine
from the dae package.
Usage
## S3 method for class 'alldiffs'
facCombine(object, factors, order="standard",
combine.levels=TRUE, sep="_", level.length = NA, ...)
Arguments
object |
An |
factors |
A |
order |
Either |
combine.levels |
A |
sep |
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. |
... |
Further arguments passed to |
Value
A modified alldiffs.object.
Author(s)
Chris Brien
See Also
as.alldiffs, allDifferences.data.frame,
print.alldiffs, sort.alldiffs,
renewClassify.alldiffs; fac.combine in package dae.
Examples
data("Ladybird.dat")
## Use asreml to get predictions and associated statistics
## Not run:
m1.asr <- asreml(logitP ~ Host*Cadavers*Ladybird,
random = ~ Run,
data = Ladybird.dat)
current.asrt <- as.asrtests(m1.asr)
HCL.pred <- asreml::predict.asreml(m1.asr, classify="Host:Cadavers:Ladybird",
sed=TRUE)
HCL.preds <- HCL.pred$pvals
HCL.sed <- HCL.pred$sed
HCL.vcov <- NULL
wald.tab <- current.asrt$wald.tab
den.df <- wald.tab[match("Host:Cadavers:Ladybird", rownames(wald.tab)), "denDF"]
## 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(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"))
HCL.vcov <- vcov(HCL.emm)
HCL.sed <- NULL
}
## Use the predictions obtained with either asreml or lmerTest
if (exists("HCL.preds"))
{
## Form an all.diffs object
HCL.diffs <- as.alldiffs(predictions = HCL.preds, classify = "Host:Cadavers:Ladybird",
sed = HCL.sed, vcov = HCL.vcov, tdf = den.df)
## Check the class and validity of the alldiffs object
is.alldiffs(HCL.diffs)
validAlldiffs(HCL.diffs)
## Combine Cadavers and Ladybird
HCL.diffs <- facCombine(HCL.diffs, factors = c("Cadavers","Ladybird"))
## Check the validity of HCL.diffs
validAlldiffs(HCL.diffs)
}
Reorders and/or revises the factor levels using the order of old levels in levels.order and the new labels for the levels given in newlabels. The values in levels.order must be unique.
Description
Reorders and revises the levels and labels of a factor, in the prediction
component of an alldiffs.object. The values in the
levels.order vector should be the same as the levels in the existing factor,
but the order can be changed. To revise the levels, specify the new levels in the
newlabels vector and these will replace the corresponding value in the
levels.order vector. The matching
changes are made to the other components and attributes of the alldiffs.object.
Usage
## S3 method for class 'alldiffs'
facRecast(object, factor, levels.order = NULL, newlabels = NULL, ...)
Arguments
object |
An |
factor |
A |
levels.order |
A |
newlabels |
A |
... |
Further arguments passed to the |
Value
A modified alldiffs.object.
Author(s)
Chris Brien
See Also
as.alldiffs, allDifferences.data.frame,
print.alldiffs, sort.alldiffs,
facCombine.alldiffs, facRename.alldiffs,
renewClassify.alldiffs;
fac.recast in package dae.
Examples
data("Ladybird.dat")
## Use asreml to get predictions and associated statistics
## Not run:
m1.asr <- asreml(logitP ~ Host*Cadavers*Ladybird,
random = ~ Run,
data = Ladybird.dat)
current.asrt <- as.asrtests(m1.asr)
HCL.pred <- asreml::predict.asreml(m1.asr, classify="Host:Cadavers:Ladybird",
sed=TRUE)
HCL.preds <- HCL.pred$pvals
HCL.sed <- HCL.pred$sed
HCL.vcov <- NULL
wald.tab <- current.asrt$wald.tab
den.df <- wald.tab[match("Host:Cadavers:Ladybird", rownames(wald.tab)), "denDF"]
## 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(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"))
HCL.vcov <- vcov(HCL.emm)
HCL.sed <- NULL
}
## Use the predictions obtained with either asreml or lmerTest
if (exists("HCL.preds"))
{
## Form an all.diffs object
HCL.diffs <- allDifferences(predictions = HCL.preds, classify = "Host:Cadavers:Ladybird",
sed = HCL.sed, vcov = HCL.vcov, tdf = den.df)
## Check the class and validity of the alldiffs object
is.alldiffs(HCL.diffs)
validAlldiffs(HCL.diffs)
## Recast the Ladybird and Host factors
HCL.diffs <- facRecast(HCL.diffs, factor = "Ladybird",
newlabels = c("none", "present"))
HCL.diffs <- facRecast(HCL.diffs, factor = "Ladybird",
levels.order = c("present", "none"),
newlabels = c("yes","no"))
HCL.diffs <- facRecast.alldiffs(HCL.diffs, factor = "Host",
levels.order = c("trefoil", "bean"))
## Check the validity of HCL.diffs
validAlldiffs(HCL.diffs)
}
Renames factors in the prediction component of an
alldiffs.object.
Description
Renames factors in the prediction component of an
alldiffs.object. These changes are propagated to the other
components and attributes of the alldiffs.object.
Usage
## S3 method for class 'alldiffs'
facRename(object, factor.names, newnames, ...)
Arguments
object |
An |
factor.names |
A |
newnames |
A |
... |
Provision for passing arguments to functions called internally - not used at present. |
Value
A modified alldiffs.object.
Author(s)
Chris Brien
See Also
as.alldiffs, allDifferences.data.frame,
print.alldiffs, sort.alldiffs,
facCombine.alldiffs, facRecast.alldiffs,
renewClassify.alldiffs;
fac.recast in package dae.
Examples
data("Ladybird.dat")
## Use asreml to get predictions and associated statistics
## Not run:
m1.asr <- asreml(logitP ~ Host*Cadavers*Ladybird,
random = ~ Run,
data = Ladybird.dat)
current.asrt <- as.asrtests(m1.asr)
HCL.pred <- asreml::predict.asreml(m1.asr, classify="Host:Cadavers:Ladybird",
sed=TRUE)
HCL.preds <- HCL.pred$pvals
HCL.sed <- HCL.pred$sed
HCL.vcov <- NULL
wald.tab <- current.asrt$wald.tab
den.df <- wald.tab[match("Host:Cadavers:Ladybird", rownames(wald.tab)), "denDF"]
## 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(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"))
HCL.vcov <- vcov(HCL.emm)
HCL.sed <- NULL
}
## Use the predictions obtained with either asreml or lmerTest
if (exists("HCL.preds"))
{
## Form an all.diffs object
HCL.diffs <- allDifferences(predictions = HCL.preds,
classify = "Host:Cadavers:Ladybird",
sed = HCL.sed, vcov = HCL.vcov, tdf = den.df)
## Check the class and validity of the alldiffs object
is.alldiffs(HCL.diffs)
validAlldiffs(HCL.diffs)
## Rename Cadavers
HCL.diffs <- facRename(HCL.diffs, factor.names = "Cadavers", newnames = "Cadaver.nos")
## Check the validity of HCL.diffs
validAlldiffs(HCL.diffs)
}
Find LSD values that minimize the number of errors in pairwise comparisons of predictions.
Description
Given an alldiffs.object with an sed component,
a search is made of a set of equally spaced values between the minimum and
maximum values of the LSDs, calculated from the sed component of the
alldiffs.object, to identify LSD values that minimize the number
of errors made in deciding on the significance of pairs of predicted values stored
in the alldiffs.object. If LSDtype is set to overall,
a search is made over the range of LSD values for all pairwise comparisons for a
single LSD value; if LSDtype is set to factor.combinations,
a separate search is made over the LSD values for the set of pairwise comparisons
for each factor.combination in order to identify a single value for each set.
The number of values used in the search is controlled by the argument nvalues.
For each value in the search, the numbers of false positives and false negatives
resulting from employing it as the LSD for each set of pairwise comparisons is calculated.
A criterion that combines the false positives and negative is calculated using the
false.pos.wt, the criterion being the number of false postives times the
false.pos.wt plus the number of false negatives. The value chosen for the LSD
is the smallest value from amongst those with the minimum value of the criterion and
the least number of false positives. A secondary search with 10 equally spaced values
is made of the interval below the chosen value and the search value immediately below
it to check whether the chosen grid value can be further reduced without changing the
value of either its criterion or the number of false positives.
The primary options for changing the numbers of errors associated with the values
resulting from the searching is to manipulate the LSDby and/or
false.pos.wt arguments.
Usage
## S3 method for class 'alldiffs'
findLSDminerrors(alldiffs.obj,
LSDtype = "overall", LSDby = NULL,
alpha = 0.05,
false.pos.wt = 10, nvalues = 100,
retain.zeroLSDs = FALSE,
zero.tolerance = .Machine$double.eps ^ 0.5,
trace = FALSE, ...)
Arguments
alldiffs.obj |
An |
LSDtype |
A |
LSDby |
A |
alpha |
A |
false.pos.wt |
A The default of 10 for |
nvalues |
A |
retain.zeroLSDs |
A |
zero.tolerance |
A |
trace |
A |
... |
Provision for passing arguments to functions called internally - not used at present. |
Value
A data.frame containing the chosen LSD(s), its(their) numbers of false positives
and negatives and the value(s) of the false criterion.
Author(s)
Chris Brien
See Also
asremlPlus-package, exploreLSDs.alldiffs plotLSDs.data.frame,
plotLSDs.alldiffs,
plotLSDerrors.alldiffs, plotLSDerrors.data.frame, recalcLSD.alldiffs,
redoErrorIntervals.alldiffs
Examples
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)
TS.diffs <- predictPlus(classify = "Sources:Type",
asreml.obj = current.asr,
wald.tab = current.asrt$wald.tab,
present = c("Sources", "Type", "Species"))
## 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 * (Type + Species)) +
(1|Benches:MainPlots),
data=na.omit(WaterRunoff.dat))
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"))
## Form an all.diffs object and check its validity
TS.vcov <- vcov(TS.emm)
TS.diffs <- allDifferences(predictions = TS.preds, classify = "Sources:Type",
vcov = TS.vcov, tdf = den.df)
validAlldiffs(TS.diffs)
}
## Choose LSD values with the minimum mumber of error for pairwise comparisons of
## the predictions obtained using asreml or lmerTest
if (exists("TS.diffs"))
{
##Pick the LSD values for predictions obtained using asreml or lmerTest
minLSD <- findLSDminerrors(TS.diffs)
TS.diffs <- redoErrorIntervals(TS.diffs, LSDtype = "supplied", LSDsupplied = minLSD["LSD"])
TS.diffs$LSD
minLSDs <- findLSDminerrors(TS.diffs, LSDtype = "factor.combinations",
LSDby = "Sources")
TS.diffs <- redoErrorIntervals(TS.diffs, LSDtype = "supplied",
LSDby = "Sources", LSDsupplied = minLSDs["LSD"])
TS.diffs$LSD
}
Finds the version of asreml that is loaded and returns the initial characters in version.
Description
Checks that asreml is loaded and, if it is, returns the first nchar characters of the version that is loaded.
Usage
getASRemlVersionLoaded(nchar = NULL, notloaded.fault = FALSE)
Arguments
nchar |
The number of characters in the asreml version to get. |
notloaded.fault |
A |
Value
A character, being the first nchar characters of the version of asreml
that is loaded.
Author(s)
Chris Brien
See Also
Examples
## Not run:
getASRemlVersionLoaded()
## End(Not run)
Gets the formulae from an asreml object.
Description
Gets the formulae nominated in the which argument from the call stored in an asreml object.
Usage
## S3 method for class 'asreml'
getFormulae(asreml.obj, which = c("fixed", "random", "residual"),
expanded = FALSE, envir = parent.frame(), ...)
Arguments
asreml.obj |
An object resulting from the fitting of
a model using |
which |
A |
expanded |
A |
envir |
The environment in which the |
... |
Arguments passed on to |
Value
A list containing a component with each of the extracted
formula(e), the name of a component being the formula
that it contains.
Author(s)
Chris Brien
See Also
Examples
## Not run:
data(Wheat.dat)
current.asr <- asreml(yield ~ Rep + WithinColPairs + Variety,
random = ~ Row + Column + units,
residual = ~ ar1(Row):ar1(Column),
data=Wheat.dat)
getFormulae(current.asr)
## End(Not run)
Gets the entry for a test recorded in the test.summary data.frame of an asrtests.object
Description
Matches the label in the term column of the test.summary data.frame
in the supplied asrtests.object and extracts the line for it. It only matches
the last occurrence of label.
Usage
## S3 method for class 'asrtests'
getTestEntry(asrtests.obj, label, error.absent = TRUE, ...)
Arguments
asrtests.obj |
An |
label |
A |
error.absent |
A |
... |
provision for passing arguments to functions called internally - not used at present. |
Value
A one-line data.frame containing the entry or, error.absent is NULL, NULL.
Author(s)
Chris Brien
See Also
getTestPvalue.asrtests, as.asrtests,
testranfix.asrtests,
testswapran.asrtests, testresidual.asrtests,
changeModelOnIC.asrtests, changeTerms.asrtests,
chooseModel.asrtests
Examples
## Not run:
data(Wheat.dat)
current.asr <- asreml(yield ~ Rep + WithinColPairs + Variety,
random = ~ Row + Column + units,
residual = ~ ar1(Row):ar1(Column),
data=Wheat.dat)
current.asrt <- as.asrtests(current.asr, NULL, NULL)
current.asrt <- rmboundary(current.asrt)
# Test nugget term
current.asrt <- testranfix(current.asrt, "units", positive=TRUE)
getTestEntry(current.asrt, label = "units")
## End(Not run)
Gets the p-value for a test recorded in the test.summary data.frame of an asrtests.object
Description
Matches the label in the term column of the test.summary data.frame
in the supplied asrtests.object and extracts its p-value. It only matches
the last occurrence of label.
Usage
## S3 method for class 'asrtests'
getTestPvalue(asrtests.obj, label, ...)
Arguments
asrtests.obj |
An |
label |
A |
... |
provision for passing arguments to functions called internally - not used at present. |
Value
An numeric containing the p-value. It can be NA, for example when a p-value could not be calculated.
Author(s)
Chris Brien
See Also
getTestEntry.asrtests, as.asrtests,
testranfix.asrtests,
testswapran.asrtests, testresidual.asrtests,
changeTerms.asrtests, chooseModel.asrtests
Examples
## Not run:
data(Wheat.dat)
current.asr <- asreml(yield ~ Rep + WithinColPairs + Variety,
random = ~ Row + Column + units,
residual = ~ ar1(Row):ar1(Column),
data=Wheat.dat)
current.asrt <- as.asrtests(current.asr, NULL, NULL)
current.asrt <- rmboundary(current.asrt)
# Test nugget term
current.asrt <- testranfix(current.asrt, "units", positive=TRUE)
getTestPvalue(current.asrt, label = "units")
## End(Not run)
Computes AIC and BIC for models.
Description
Computes Akiake and Bayesian (Schwarz) Information Criteria for models.
Either the Restricted Maximum likelihood (REML) or the full likelihood
(full) can be used. The full likelihood, evaluated using REML estimates
is used when it is desired to compare models that differ in their fixed models.
Usage
## S3 method for class 'asreml'
infoCriteria(object, DF = NULL,
bound.exclusions = c("F","B","S","C"),
IClikelihood = "REML", fixedDF = NULL, varDF = NULL, ...)
## S3 method for class 'list'
infoCriteria(object, bound.exclusions = c("F","B","S","C"),
IClikelihood = "REML", fixedDF = NULL, varDF = NULL, ...)
Arguments
object |
An |
DF |
A |
bound.exclusions |
A |
IClikelihood |
A |
fixedDF |
A |
varDF |
A |
... |
Provision for passing arguments to functions called internally - not used at present. |
Details
The variance degrees of freedom (varDF) are the number of number of variance parameters that
have been estimated, excluding those whose estimates have a code for bound
specified in bound.exclusions. If varDF is not NULL, the supplied value
is used. Otherwise varDF is determined from the information in object,
i.e. if object is an asreml object then from it, or if object is a
list then from each asreml object in the list.
Similarly, the fixed degrees of freedom (fixedDF) are the number of number of fixed parameters
that have been estimated, any coefficients that have the value NA being excluded.
If fixedDF is not NULL, the supplied value is used. Otherwise fixedDF
is determined from the information in object.
If ASReml-R version 4 is being used then the codes specified in bound.exclusions are
not restricted to a subset of the default codes, but a warning is issued if a code other
than these is specified.
For ASReml-R version 3, only a subset of the default codes are allowed:
F (Fixed), B (Boundary), C (Constrained) and
S (Singular).
The calculation of the information criteria is an adaptation of the code supplied in File S1
of Verbyla (2019). The log-likelihood is calculated as
loglik = log(REML) - log(|C|)/2,
where C is the inverse coefficient matrix; the term involving C is omitted for REML.
The AIC is calculated as - 2 * loglik + 2 * (varDF + fixedDF)
and the BIC as - 2 * loglik + (fixedDF + varDF) * log(n - r + fixedDF),
where n is the number of observations and r is the rank of the fixed effects
design matrix. For REML, fixedDF = 0.
Value
A data.frame containing the numbers of estimated fixed (fixedDF) and variance (varDF)
parameters, the number of bound parameters (NBound), AIC, BIC and the value of the
log-likelihood (loglik). All elements of the data.frame will be set to NA
for the invalid combinations of family and dispersion as noted in the IClikelihood argument.
If object is a list and its components are named, then those names will be used to
set the rownames of the data.frame.
Author(s)
Chris Brien
References
Verbyla, A. P. (2019). A note on model selection using information criteria for general linear models estimated using REML. Australian & New Zealand Journal of Statistics, 61, 39–50. doi:10.1111/anzs.12254.
See Also
REMLRT.asreml, changeTerms.asrtests, changeModelOnIC.asrtests
Examples
## Not run:
data(Wheat.dat)
## Fit several models to the wheat data and calculate their ICs
# Fit initial model
m.max <- asreml(yield ~ Rep + WithinColPairs + Variety,
random = ~ Row + Column + units,
residual = ~ ar1(Row):ar1(Column),
data=Wheat.dat)
infoCriteria(m.max.asr, IClikelihood = "full")
#Drop term for within Column pairs
m1 <- asreml(yield ~ Rep + Variety,
random = ~ Row + Column + units,
residual = ~ ar1(Row):ar1(Column),
data=Wheat.dat)
#Drop nugget term
m2 <- asreml(yield ~ Rep + WithinColPairs + Variety,
random = ~ Row + Column,
residual = ~ ar1(Row):ar1(Column),
data=Wheat.dat)
#Drop Row autocorrelation
m3 <- asreml(yield ~ Rep + WithinColPairs + Variety,
random = ~ Row + Column + units,
residual = ~ Row:ar1(Column),
data=Wheat.dat)
#Drop Col autocorrelation
m4 <- asreml(yield ~ Rep + WithinColPairs + Variety,
random = ~ Row + Column + units,
residual = ~ ar1(Row):Column,
data=Wheat.dat)
mods.asr <- list(m.max, m1, m2, m3, m4)
infoCriteria(mods.asr, IClikelihood = "full")
## End(Not run)
Tests whether an object is of class alldiffs
Description
A single-line function that tests whether an object is of class alldiffs.
Usage
is.alldiffs(object)
Arguments
object |
An |
Value
A logical.
Author(s)
Chris Brien
See Also
asremlPlus-package, alldiffs.object, is.alldiffs, as.alldiffs
Examples
data(Oats.dat)
## 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
## Form an all.diffs object
Var.diffs <- as.alldiffs(predictions = Var.preds, classify = "Nitrogen:Variety",
sed = Var.sed, vcov = Var.vcov, tdf = den.df)
## check the class of Var.diffs
is.alldiffs(Var.diffs)
}
Tests whether an object is of class asrtests
Description
A single-line function that tests whether an object is of class asrtests.
Usage
is.asrtests(object)
Arguments
object |
An |
Value
A logical.
Author(s)
Chris Brien
See Also
asremlPlus-package, asrtests.object, is.asrtests, as.asrtests
Examples
## Not run:
library(dae)
library(asreml)
library(asremlPlus)
## use ?Wheat.dat for data set details
data(Wheat.dat)
# Fit initial model
current.asr <- asreml(yield ~ Rep + WithinColPairs + Variety,
random = ~ Row + Column + units,
residual = ~ ar1(Row):ar1(Column),
data=Wheat.dat)
# Load current fit into an asrtests object
current.asrt <- as.asrtests(current.asr, NULL, NULL)
# check the class of current.asrt
is.asrtests(current.asrt)
## End(Not run)
Tests whether an object is of class predictions.frame
Description
A single-line function that tests whether an object is of class predictions.frame.
Usage
is.predictions.frame(object)
Arguments
object |
An |
Value
A logical.
Author(s)
Chris Brien
See Also
asremlPlus-package, predictions.frame, validPredictionsFrame, as.predictions.frame
Examples
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 <- as.predictions.frame(Var.pred$pvals, se = "std.error",
est.status = "status")
## End(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)
Var.preds <- as.predictions.frame(Var.preds, predictions = "emmean",
se = "SE", interval.type = "CI",
interval.names = c("lower.CL", "upper.CL"))
}
if (exists("Var.preds"))
{
## Check the class and validity of the alldiffs object
is.predictions.frame(Var.preds)
}
Tests whether an object of class matrix is compound symmetric
Description
Tests whether an object of class matrix is compound symmetric by checking whether all diagonal elements are equal and all off-diagonal elements are equal.
Usage
## S3 method for class 'matrix'
isCompoundSymmetric(object, tol = 100 * .Machine$double.eps, ...)
Arguments
object |
An |
tol |
a |
... |
Provision for passing arguments to functions called internally - not used at present. |
Value
A logical.
Author(s)
Chris Brien
See Also
Examples
data(Oats.dat)
## Not run:
## Use asreml to get the variance matrix of a set of predictions
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",
vcov = TRUE)
est.status = "status")
isCompoundSymmetrix(Var.pred$vcov)
## End(Not run)
## Use lmerTest and emmmeans to get the variance matrix of a set of predictions
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.vcov <- vcov(Var.emm)
}
if (exists("Var.vcov"))
{
## Check the variance matrix of the predictions is compound symmetric
isCompoundSymmetric(Var.vcov)
}
Subject the fitted asreml.obj stored in an asrtests.object
to further iterations of the fitting process.
Description
In an effort to improve convergence, subject the fitted asreml.obj stored
in an asrtests.object to further iterations of the fitting process;
the model specification is not changed. While no change is made to the
test.summary, the wald.tab is updated.
Usage
## S3 method for class 'asrtests'
iterate(asrtests.obj, denDF="numeric", trace = FALSE, ...)
Arguments
asrtests.obj |
an |
denDF |
Specifies the method to use in computing approximate denominator
degrees of freedom when |
trace |
If TRUE then partial iteration details are displayed when ASReml-R functions are invoked; if FALSE then no output is displayed. |
... |
further arguments passed to |
Value
An object of S3-class asrtests.
Author(s)
Chris Brien
References
Kenward, M. G., & Roger, J. H. (1997). Small sample inference for fixed effects from restricted maximum likelihood. Biometrics, 53, 983-997.
See Also
as.asrtests, asrtests.object, newfit.asreml
Examples
## Not run:
current.asrt <- iterate(current.asrt)
## End(Not run)
Calculates a linear transformation of the predictions stored in an
alldiffs.object.
Description
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.
Usage
## 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, ...)
Arguments
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 |
Details
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".
Value
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.
Author(s)
Chris Brien
See Also
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
Examples
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")
}
Ensures that a specific version of asreml is loaded.
Description
Loads the specified version of asreml, provided that it is not already loaded. If the version of asreml is not the required version, then the loaded version is unloaded first.
Usage
loadASRemlVersion(version = 4, ...)
Arguments
version |
The |
... |
Other library/require arguments that are needed to load the specified |
Value
A character, being all characters in the version of asreml that is loaded on exit from the function.
Author(s)
Chris Brien
See Also
Examples
## Not run:
loadASRemlVersion(3, lib.loc = "D:\Analyses\R asreml3")
## End(Not run)
Make the spline basis matrices and data needed to fit Tensor Product P-splines.
Description
Prepares the fixed and random P-spline basis matrices, and associated
information, that are needed for fitting of Tensor Product P-splines (TPPS)
as described by Rodriguez-Alvarez et al. (2018). This function is called
internally by addSpatialModelOnIC.asrtests,
addSpatialModelOnIC.asrtests and
chooseSpatialModelOnIC.asrtests when fitting TPPS models
for local spatial variation. There are two methods available, controlled by
asreml.option for creating and storing the basis functions.
This function is most likely to be called directly when mbf has been used
in creating an asreml.object and it is desired to use the object in a
session subsequent to the session in which the object was created.
Usage
## S3 method for class 'data.frame'
makeTPPSplineMats(data, sections = NULL,
row.covar, col.covar,
nsegs = NULL, nestorder = c(1,1),
degree = c(3,3), difforder = c(2,2),
rotateX = FALSE, theta = c(0,0),
asreml.option = "grp", mbf.env = sys.frame(),
...)
Arguments
data |
An |
sections |
A single |
row.covar |
A single |
col.covar |
A single |
nsegs |
A pair of |
nestorder |
A |
degree |
A |
difforder |
A |
rotateX |
A |
theta |
A |
asreml.option |
A single |
mbf.env |
A |
... |
Further arguments passed to |
Details
The objects are formed using the function tpsmmb from the R package TPSbits
authored by Sue Welham (2022). This function has been extended to allow for sections (see below)
and to allow rotation of the penalty matrix for the linear component of the interaction terms in
TPPCS models (for more information about rotation see Piepho, Boer and Williams, 2022).
Each combination of a row.covar and a col.covar does not have to specify a
single observation; for example, to fit a local spatial variation model to the main units
of a split-unit design, each combination would correspond to a main unit and all subunits
of the main unit would have the same combination.
The data for experiment can be divided sections and the spline bases and associated
data will be produced for each section. If there is more than one sections, then a
list is returned that has a component for each section. The component for
a section contains:
Value
A list of length equal to the number of sections is produced. Each of
these components is a list with 8 or 9 components. The component
named data.plus, being the input data.frame to which has been added
the columns required to fit the TPPS model (the data.frame stored
in the data component holds only the covariates from data).
List of length 8 or 9 (according to the asreml.option).
-
data= the input data frame augmented with structures required to fit tensor product splines inasreml-R. This data frame can be used to fit the TPS model.Added columns:
-
TP.col,TP.row= column and row coordinates -
TP.CxR= combined index for use with smooth x smooth term -
TP.C.nfor n=1:diff.c = X parts of column spline for use in random model (where diff.c is the order of column differencing) -
TP.R.nfor n=1:diff.r = X parts of row spline for use in random model (where diff.r is the order of row differencing) -
TP.CR.nfor n=1:(diff.c*diff.r) = interaction between the two X parts for use in fixed model. The first variate is a constant term which should be omitted from the model when the constant (1) is present. If all elements are included in the model then the constant term should be omitted,eg.y ~ -1 + TP.CR.1 + TP.CR.2 + TP.CR.3 + TP.CR.4 + other terms... when
asreml="grp"or"sepgrp", the spline basis functions are also added into the data frame. Column numbers for each term are given in thegrplist structure.
-
-
mbflist= list that can be used in call to asreml (so long as Z matrix data frames extracted with right names, eg BcZ<stub>.df) -
BcZ.df= mbf data frame mapping onto smooth part of column spline, last column (labelledTP.col) gives column index -
BrZ.df= mbf data frame mapping onto smooth part of row spline, last column (labelledTP.row) gives row index -
BcrZ.df= mbf data frame mapping onto smooth x smooth term, last column (labelledTP.CxR) maps onto col x row combined index -
dim= list structure, holding dimension values relating to the model:-
"diff.c"= order of differencing used in column dimension -
"nbc"= number of random basis functions in column dimension -
"nbcn"= number of nested random basis functions in column dimension used in smooth x smooth term -
"diff.r"= order of differencing used in column dimension -
"nbr"= number of random basis functions in column dimension -
"nbrn"= number of nested random basis functions in column dimension used in smooth x smooth term
-
-
trace= list of trace values for ZGZ' for the random TPspline terms, where Z is the design matrix and G is the known diagonal variance matrix derived from eigenvalues. This can be used to rescale the spline design matrix (or equivalently variance components). -
grp= list structure, only added for settingasreml="grp". Forasreml="grp", provides column indexes for each of the 5 random components of the 2D splines indata.plus. Dimensions of the components can be derived from the values in thedimitem. -
data.plus= the inputdata.frameto which has been added the columns required to fit tensor product splines inasreml-R. Thisdata.framecan be used to fit the TPS model. FOr multiplesections, thisdata.framewill occur in the component for each section. Ifasreml.optionis set tombf, then this component will have theattributembf.envthat specifies the environment to which thedata.framescontaining the spline bases have been assigned.
Author(s)
Chris Brien
References
Piepho, H-P, Boer, M. P. & Williams, E. R. (2022) Two-dimensional P-spline smoothing for spatial analysis of plant breeding trials. Biometrical Journal, 64, 835-857.)
Rodriguez-Alvarez, M. X., Boer, M. P., van Eeuwijk, F. A., & Eilers, P. H. C. (2018). Correcting for spatial heterogeneity in plant breeding experiments with P-splines. Spatial Statistics, 23, 52-71.
Welham, S. J. (2022) TPSbits: Creates Structures to Enable Fitting and Examination of 2D Tensor-Product Splines using ASReml-R. Version 1.0.0 https://mmade.org/tpsbits/
See Also
addSpatialModel.asrtests, addSpatialModelOnIC.asrtests,
chooseSpatialModelOnIC.asrtests, tpsmmb from TPSbits
Examples
## Not run:
data(Wheat.dat)
#Add row and column covariates
Wheat.dat <- within(Wheat.dat,
{
cColumn <- dae::as.numfac(Column)
cColumn <- cColumn - mean(unique(cColumn))
cRow <- dae::as.numfac(Row)
cRow <- cRow - mean(unique(cRow))
})
#Set up the matrices
tps.XZmat <- makeTPPSplineMats(wheat.dat,
row.covar = "cRow", col.covar = "cColumn")
## End(Not run)
Refits an asreml model with changed arguments by extracting, modifying
and evaluating its call - an alternate to update.asreml.
Description
Extracts the call from the asreml.obj and evaluates that call,
replacing supplied asreml arguments with changed values.
If update is TRUE and set.terms is NULL,
the call is evaluated using the variance parameter estimates
from the call stored in asreml.obj; if some
variance terms in the newly fitted model are singular (S) or
bound (B), a refit of the model will be tried in which the
variance parameter estimates in asreml.obj are not used
and will become the fitted model if its boundary terms are a
subset of those in the fitted model stored in asreml.obj.
If update is FALSE or set.terms is not
NULL, the previous values of the variance parameters
are not used as initial values for fitting the new model;
G.param and R.param are set to NULL or
to values as specified for set.terms. The ...
argument can be used to pass G.param and/or
R.param, provided update is FALSE and
set.terms is NULL.
Irrespective of whether set.terms is NULL,
variance parameter names, bounds and initial.values stored in
the setvparameters data.frame located in the
call component of the asreml.obj are added to any
set.terms supplied in the current call. except for those
in setvparameters that are specified in the
set.terms argument. In the process of fitting the model,
the setvparameters data.frame stored in the
supplied asreml.obj is updated to include the prior and
current set.terms. Then, just before exiting
newfit.asreml, a search for changes in the bounds
of the stored terms is made. If any have changed, an attempt is
made to force the values back to their values on entry.
Usage
## S3 method for class 'asreml'
newfit(asreml.obj, fixed., random., sparse.,
residual., rcov., update = TRUE, trace = FALSE,
allow.unconverged = TRUE, allow.fixedcorrelation = TRUE,
keep.order = TRUE,
set.terms = NULL, ignore.suffices = TRUE,
bounds = "P", initial.values = NA, ...)
Arguments
asreml.obj |
A valid |
fixed. |
A character or formula specifying changes to the fixed
formula. This is a two-sided formula
where "." is substituted for existing components in the
fixed component of |
random. |
A character or formula specifying changes to the random
formula. This is a one-sided formula
where "." is substituted for existing components in the
random component of |
sparse. |
A character or formula specifying changes to the sparse
formula. This is a one-sided formula
where "." is substituted for existing components in the
sparse component of |
residual. |
A character or formula specifying changes to the error
formula, used when version 4 or later of ASReml-R is loaded.
This is a one-sided formula
where "." is substituted for existing components in the
residual component of |
rcov. |
A character or formula specifying changes to the error
formula, used when version 3 of ASReml-R is loaded.
This is a one-sided formula
where "." is substituted for existing components in the
residual component of |
update |
A logical indicating whether to use the variance parameter
estimates in fitting a new model using |
trace |
A |
allow.unconverged |
A |
allow.fixedcorrelation |
A |
keep.order |
A logical value indicating whether the terms should keep
their positions. If |
set.terms |
A character vector specifying the terms that are to have
bounds and/or initial values set prior to fitting.
The names must match those in the |
ignore.suffices |
A logical vector specifying whether the suffices of the
|
bounds |
A |
initial.values |
A character vector specifying the initial values for
the terms specified in |
... |
additional arguments to the call, or arguments with changed values. |
Value
An asreml object.
Author(s)
Chris Brien
References
Butler, D. G., Cullis, B. R., Gilmour, A. R., Gogel, B. J. and Thompson, R. (2023). ASReml-R Reference Manual Version 4.2. VSN International Ltd, https://asreml.kb.vsni.co.uk/.
See Also
convAsremlobj.asreml, update.asreml, setvarianceterms.call
Examples
## Not run:
m2.asreml <- newfit(m1.asreml, random. = "~ . - Blocks:Plots", maxiter=75)
## End(Not run)
Recodes the unique values of a vector using the values in a new vector.
Description
Recodes the unique values of a variate using the value in position
i of the new.values vector to replace the ith
sorted unique values of x. The new levels do
not have to be unique.
Usage
num.recode(x, new.values)
Arguments
x |
The |
new.values |
A |
Value
A vector.
Author(s)
Chris Brien
See Also
dae::fac.recast.
Examples
## set up a factor with labels
x <- rep(c(-42, -14, 14, 42), 4)
## recode x
b <- num.recode(x, c(0, 28, 56, 84))
Calculates the differences between nominated pairs of predictions stored in
an alldiffs.object.
Description
Predictions of differences and their error intervals are formed for two levels of
a factor, the pairs.factor. For each pair of a level of the
pairs.factor in numerator.levels with a level in
denominator.levels, an alldiffs.object is formed that
contains the differences between predictions with this pair of levels for all of
the combinations of the levels of the other factors in the classify of the
alldiffs.object. These prediction differences are obtained using
linTransform by forming a suitable contrast matrix to specify
the linear.transformation. This function has the advantage that the
factors indexing the differences are included in the components of the
alldiffs.objects.
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.
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.
Usage
## S3 method for class 'alldiffs'
pairdiffsTransform(alldiffs.obj, pairs.factor, first.levels, second.levels,
Vmatrix = FALSE, error.intervals = "Confidence",
avsed.tolerance = 0.25, accuracy.threshold = NA,
LSDtype = "overall", LSDsupplied = NULL, LSDby = NULL,
LSDstatistic = "mean", LSDaccuracy = "maxAbsDeviation",
response = NULL, response.title = NULL, tables = "all",
pairwise = TRUE, alpha = 0.05, ...)
Arguments
alldiffs.obj |
An |
pairs.factor |
A |
first.levels |
A |
second.levels |
A |
Vmatrix |
A |
error.intervals |
A |
avsed.tolerance |
A
|
accuracy.threshold |
A |
LSDtype |
A See |
LSDsupplied |
A |
LSDby |
A |
LSDstatistic |
A |
LSDaccuracy |
A |
response |
A |
response.title |
A |
tables |
A |
pairwise |
A |
alpha |
A |
... |
further arguments passed to |
Value
A list of alldiffs.objects with a component for each combination
of a first.levels with a second.levels. The name of a component will be
a level from first.levels combined with a level from second.levels,
separated by a comma. If the predictions in the supplied alldiffs.object
are based on a response that was transformed, each alldiffs.object
in the list will include a backtransforms component that contains
a column labelled backtransformed.predictions, along with the backtransforms of
the nominated error.intervals. The predictions and backtransforms
components in an alldiffs.object will be indexed by the variables in the
classify of alldiffs.obj, except that the pairs.factor is omitted.
If the transformation was the logarithmic transformation, these
backtransformed.predictions are predicted ratios of the untransformed response.
If sortFactor attribute is set and is not the
ratio.factor, the predictions and, if present, their backtransforms will be sorted using
the sortOrder attribute of the alldiffs.object,
and both sortFactor and sortOrder will be set as attributes to the object.
Author(s)
Chris Brien
See Also
linTransform, ratioTransform, 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
Examples
#### Form the differences for log(RGR) for Salinity
load(system.file("extdata", "testDiffs.rda", package = "asremlPlus", mustWork = TRUE))
#### For the ratios for Cl per WU Temperature - use backtransforms of log-predictions
Preds.ratio.ClUp <- pairdiffsTransform(diffs.ClUp,
pairs.factor = "Temperature",
first.levels = "Hot",
second.levels = "Cool",
error.intervals = "halfLeast",
tables = "backtransforms") #Backtransforms are ratios
#### Form the differences for Nitrogen compared to no Nitrogen
data("Oats.dat")
## Not run:
m1.asr <- asreml(Yield ~ Nitrogen*Variety,
random=~Blocks/Wplots,
data=Oats.dat)
current.asrt <- as.asrtests(m1.asr)
wald.tab <- current.asrt$wald.tab
Var.diffs <- predictPlus(m1.asr, classify="Nitrogen:Variety", pairwise = TRUE,
Vmatrix = TRUE, error.intervals = "halfLeast",
LSDtype = "factor", LSDby = "Variety",
wald.tab = wald.tab)
## End(Not run)
## Use lme4 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)
## Set up a wald.tab
int <- as.data.frame(rbind(rep(NA,4)))
rownames(int) <- "(Intercept)"
wald.tab <- anova(m1.lmer, ddf = "Kenward", type = 1)[,3:6]
names(wald.tab) <- names(int) <- c("Df", "denDF", "F.inc", "Pr")
wald.tab <- rbind(int, wald.tab)
#Get predictions
Var.emm <- emmeans::emmeans(m1.lmer, specs = ~ Nitrogen:Variety)
Var.preds <- summary(Var.emm)
## 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
den.df <- wald.tab[match("Variety", rownames(wald.tab)), "denDF"]
#Create alldiffs object
Var.diffs <- as.alldiffs(predictions = Var.preds,
sed = Var.sed, vcov = Var.vcov,
classify = "Nitrogen:Variety", response = "Yield", tdf = den.df)
}
if (exists("Var.diffs"))
Preds.diffs.OatsN <- pairdiffsTransform(alldiffs.obj = Var.diffs,
pairs.factor = "Nitrogen",
first.levels = c("0.2","0.4","0.6"),
second.levels = "0", error.intervals = "halfLeast",
tables = "none")
Permutes the rows and columns of a square matrix.
Description
Permutes the rows and columns of a square matrix.
Usage
permute.square(x, permutation)
Arguments
x |
A square matrix. |
permutation |
A vector specifying the new order of rows and columns. |
Value
A square matrix.
Author(s)
Chris Brien
See Also
Examples
terms.marginality <- matrix(c(1,0,0,0,0, 0,1,0,0,0, 0,1,1,0,0,
1,1,1,1,0, 1,1,1,1,1), nrow=5)
permtn <- c(1,3,2,4,5)
terms.marginality <- permute.square(terms.marginality, permtn)
Permutes a square matrix until all the lower triangular elements are zero.
Description
Permutes a square matrix until all the lower triangular elements are zero.
Usage
permute.to.zero.lowertri(x)
Arguments
x |
A square matrix of order n with at least n*(n-1)/2 zero elements. |
Value
A square matrix.
Author(s)
Chris Brien
See Also
Examples
terms.marginality <- matrix(c(1,0,0,0,0, 0,1,0,0,0, 0,1,1,0,0,
1,1,1,1,0, 1,1,1,1,1), nrow=5)
terms.marginality <- permute.to.zero.lowertri(terms.marginality)
Pick LSDstatistics whose values minimize the number of errors in pairwise comparisons of predictions.
Description
Given an alldiffs.object with an sed component,
exploreLSDs.alldiffs is used to calculate the LSD values for each set of
prediction comparisons specified by LSDtype and LSDby using each of the
statistics minimum, q10, q25, mean, median, q75,
q90 and maximum. Then the numbers of false positives and
false negatives resulting from employing each of the calculated LSDs is obtained. For
each set of comparisons, the LSD value(s) with the lowest number of false positives are
identified and, from these, the smallest value with the lowest number of false negatives.
That is, a conservative approach is taken to picking LSD values by putting the priority on
avoiding false positives. Before using the LSDstatistics that this function suggests, the number
of false positives and negatives generated by them should be checked. For example, it may be
that there are too many false negatives and a better balance between the numbers of false
positives and negatives can be identified using exploreLSDs.alldiffs,
Usage
## S3 method for class 'alldiffs'
pickLSDstatistics(alldiffs.obj,
LSDtype = "overall", LSDby = NULL,
alpha = 0.05, digits = 3,
false.pos.wt = NULL, retain.zeroLSDs = FALSE,
zero.tolerance = .Machine$double.eps ^ 0.5,
...)
Arguments
alldiffs.obj |
An |
LSDtype |
A See |
LSDby |
A |
alpha |
A |
digits |
A |
false.pos.wt |
When it is not If, amongst the LSD statistices, the least number of false negatives that occurs is m,
then for a particular statistic with p the number of false positives, n the number
of false negatives and w the value of |
retain.zeroLSDs |
A |
zero.tolerance |
A |
... |
Provision for passing arguments to functions called internally - not used at present. |
Value
A character of length one for LSDby set to overall or of length equal to the
number of observed combinations of the values of the factors and numerics
in LSDby. Each element of the returned character is one of minimum,
q10, q25, mean, median, q75, q90 or maximum,
reflecting the value(s) of the LSD from amongst those calculated that minimizes the number of false
positives; if there is more than one such value, then the element will be correspond to the value
of the LSD from amongst those with the minimum number of false positives that minimizes
the number of false negatives.
Author(s)
Chris Brien
See Also
asremlPlus-package, exploreLSDs.alldiffs plotLSDs.data.frame,
plotLSDs.alldiffs,
plotLSDerrors.alldiffs, plotLSDerrors.data.frame, recalcLSD.alldiffs,
redoErrorIntervals.alldiffs
Examples
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)
TS.diffs <- predictPlus(classify = "Sources:Type",
asreml.obj = current.asr,
wald.tab = current.asrt$wald.tab,
present = c("Sources", "Type", "Species"))
## 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 * (Type + Species)) +
(1|Benches:MainPlots),
data=na.omit(WaterRunoff.dat))
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"))
## Form an all.diffs object and check its validity
TS.vcov <- vcov(TS.emm)
TS.diffs <- allDifferences(predictions = TS.preds, classify = "Sources:Type",
vcov = TS.vcov, tdf = den.df)
validAlldiffs(TS.diffs)
}
## Pick LSD statistics for calculating LSD values for pairwise comparisons of
## the predictions obtained using asreml or lmerTest
if (exists("TS.diffs"))
{
##Pick the LSD values for predictions obtained using asreml or lmerTest
LSDstat <- pickLSDstatistics(TS.diffs)
TS.diffs <- redoErrorIntervals(TS.diffs, LSDstatistic = LSDstat)
TS.diffs$LSD
LSDstat <- pickLSDstatistics(TS.diffs, LSDtype = "factor.combinations",
LSDby = "Sources")
TS.diffs <- redoErrorIntervals(TS.diffs, LSDtype = "factor.combinations",
LSDby = "Sources", LSDstatistic = LSDstat)
TS.diffs$LSD
}
Plots a map of the errors that occur in using the computed LSD values for pairwise differences between predictions.
Description
Produces a plot of the errors that occur in using the computed LSD values for
pairwise differences predictions by comparing the result obtained from using the
LSDs stored in the assignedLSD column of the LSD component of
the alldiffs.object with those computed from the sed
component using the t-value for the df stored in the tdf
attribute of the alldiffs.object.
The sed component is generally a matrix whose rows and columns
are labelled by the levels of one or more factors, the set of labels being
the same for rows and columns. The sections argument allows multiple
plots to be produced, one for each combination of the levels of the factors
listed in sections. Otherwise, a single plot is produced for all
observed combinations of the levels of the factors in the classify
attribute for the alldiffs.object. The plots are produced using
plotLSDerrors.data.frame. The order of plotting the levels of
one of the factors indexing the predictions can be modified using
sort.alldiffs.
Usage
plotLSDerrors(object, ...)
## S3 method for class 'alldiffs'
plotLSDerrors(object, alpha = 0.05, useIntervals = FALSE,
sections = NULL, gridspacing = 0, factors.per.grid = 0,
triangles = "both", title = NULL,
axis.labels = TRUE, axis.text.size = 12,
sep=",", colours = c("white","blue","red","grey"),
ggplotFuncs = NULL, printPlot = TRUE,
sortFactor = NULL, sortParallelToCombo = NULL,
sortNestingFactor = NULL, sortOrder = NULL,
decreasing = FALSE, ...)
Arguments
object |
An |
alpha |
A |
useIntervals |
A |
sections |
A |
gridspacing |
A |
factors.per.grid |
A |
triangles |
A |
title |
A |
axis.labels |
A |
axis.text.size |
A |
sep |
A |
colours |
A vector of colours to be passed to the |
ggplotFuncs |
A |
printPlot |
A |
sortFactor |
A |
sortParallelToCombo |
A |
sortNestingFactor |
A |
sortOrder |
A The following creates a |
decreasing |
A |
... |
Provision for passsing arguments to functions called internally - not used at present. |
Value
A list with components named LSDresults and plots.
The LSDresults component contains the data.frame with the columns Rows,
Columns, LSDresults, sections1 and sections2. This data.frame
is formed using the LSD and sed components of object and is used
by plotLSDerrors.data.frame in producng the plots. The plots
component contains a list of ggplot objects, one for each plot produced.
Multiple plots are stored in the plots component if the sections argument
is set and the plots are are named for the levels combinations of the sections.
Author(s)
Chris Brien
See Also
plotLSDerrors.alldiffs, plotLSDerrors.data.frame,
plotLSDs.data.frame,
exploreLSDs, sort.alldiffs, subset.alldiffs,
ggplot
Examples
##Subset WaterRunoff data to reduce time to execute
data(WaterRunoff.dat)
tmp <- subset(WaterRunoff.dat, Date == "05-18" & Benches != "3")
##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= tmp)
current.asrt <- as.asrtests(current.asr, NULL, NULL)
TS.diffs <- predictPlus.asreml(classify = "Sources:Type",
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 * (Type + Species)) +
(1|Benches:MainPlots),
data=na.omit(WaterRunoff.dat))
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"))
## Form an all.diffs object and check its validity
TS.vcov <- vcov(TS.emm)
TS.diffs <- allDifferences(predictions = TS.preds, classify = "Sources:Type",
vcov = TS.vcov, tdf = den.df)
validAlldiffs(TS.diffs)
}
## Plot LSD values for predictions obtained using asreml or lmerTest
if (exists("TS.diffs"))
{
plotLSDerrors(TS.diffs, gridspacing = rep(c(3,4), c(4,2)))
plotLSDerrors(TS.diffs, sections = "Sources", axis.labels = TRUE)
}
Plots a map of the supplied errors that occur in using the computed LSD values for pairwise differences between predictions.
Description
Produces a plot of the errors that have been supplied in a data.frame.
The data.frame includes two factors whose levels specify,
for each LSD result, which combinations of factor levels are being compared. The function
plotLSDerrors.alldiffs produces such data.frames.
Usage
## S3 method for class 'data.frame'
plotLSDerrors(object, LSDresults = "LSDresults", x, y,
alpha = 0.05, triangles = "both",
gridspacing = 0, title = NULL,
axis.labels = NULL, axis.text.size = 12,
colours = c("white","blue","red","grey"),
ggplotFuncs = NULL, printPlot = TRUE, ...)
Arguments
object |
A |
LSDresults |
A |
x |
A |
y |
A |
alpha |
A |
triangles |
A |
gridspacing |
A |
title |
A |
axis.labels |
A |
axis.text.size |
A |
colours |
A vector of colours to be passed to the |
ggplotFuncs |
A |
printPlot |
A |
... |
Provision for passing arguments to functions called internally - not used at present. |
Value
An object of class "ggplot", which can be plotted using print or otherwise manipulated.
Author(s)
Chris Brien
See Also
plotLSDs.data.frame, plotLSDs.alldiffs,
exploreLSDs, ggplot
Examples
##Subset 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:
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= tmp))
current.asrt <- as.asrtests(current.asr, NULL, NULL)
TS.diffs <- predictPlus.asreml(classify = "Sources:Type",
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 * (Type + Species)) +
(1|Benches:MainPlots),
data=na.omit(WaterRunoff.dat))
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"))
## Form an all.diffs object and check its validity
TS.vcov <- vcov(TS.emm)
TS.diffs <- allDifferences(predictions = TS.preds, classify = "Sources:Type",
vcov = TS.vcov, tdf = den.df)
validAlldiffs(TS.diffs)
}
## Plot LSD values for predictions obtained using asreml or lmerTest
if (exists("TS.diffs"))
{
LSDresults <- within(reshape2::melt(TS.diffs$p.differences),
{
Var1 <- factor(Var1, levels=dimnames(TS.diffs$p.differences)[[1]])
Var2 <- factor(Var2, levels=levels(Var1))
})
names(LSDresults) <- c("Rows","Columns","LSDresults")
plotLSDerrors(LSDresults, x = "Rows", y = "Columns", gridspacing = rep(c(3,4), c(4,2)))
}
Plots a heat map of computed LSD values for pairwise differences between predictions.
Description
Produces a heat-map plot of the computed LSD values for pairwise differences between
predictions by multiplying the values stored in the sed component of an
alldiffs object by the t-value for the df stored in the
tdf attribute of the object.
This component is generally a matrix whose rows and columns
are labelled by the levels of one or more factors, the set of labels being
the same for rows and columns. The sections argument allows multiple
plots to be produced, one for each combination of the levels of the factors
listed in sections. Otherwise, a single plot is produced for all
observed combinations of the levels of the factors in the classify
attribute for the alldiffs.object. The plots are produced using
plotLSDs.data.frame. The order of plotting the levels of
one of the factors indexing the predictions can be modified using
sort.alldiffs.
Usage
plotLSDs(object, ...)
## S3 method for class 'alldiffs'
plotLSDs(object, alpha = 0.05,
sections = NULL, gridspacing = 0, factors.per.grid = 0,
triangles = "both",
title = NULL, axis.labels = TRUE, axis.text.size = 12,
sep=",", colours = RColorBrewer::brewer.pal(3, "Set2"),
ggplotFuncs = NULL, printPlot = TRUE,
sortFactor = NULL, sortParallelToCombo = NULL,
sortNestingFactor = NULL, sortOrder = NULL,
decreasing = FALSE, ...)
Arguments
object |
An |
alpha |
A |
sections |
A |
gridspacing |
A |
factors.per.grid |
A |
triangles |
A |
title |
A |
axis.labels |
A |
axis.text.size |
A |
sep |
A |
colours |
A vector of colours to be passed to the |
ggplotFuncs |
A |
printPlot |
A |
sortFactor |
A |
sortParallelToCombo |
A |
sortNestingFactor |
A |
sortOrder |
A The following creates a |
decreasing |
A |
... |
Provision for passsing arguments to functions called internally - not used at present. |
Value
A list with components named LSDs and plots.
The LSDs component contains the data.frame with the columns Rows,
Columns, LSDs, sections1 and sections2. This data.frame is
formed using the sed component of object and is used by
plotLSDs.data.frame in producng the plot. The plots
component contains a list of ggplot objects, one for each plot produced.
Multiple plots are stored in the plots component if the sections argument
is set and the plots are are named for the levels combinations of the sections.
Author(s)
Chris Brien
See Also
plotLSDs.data.frame, exploreLSDs, sort.alldiffs, subset.alldiffs,
ggplot
Examples
##Subset WaterRunoff data to reduce time to execute
data(WaterRunoff.dat)
tmp <- subset(WaterRunoff.dat, Date == "05-18" & Benches != "3")
##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= tmp)
current.asrt <- as.asrtests(current.asr, NULL, NULL)
TS.diffs <- predictPlus.asreml(classify = "Sources:Type",
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 * (Type + Species)) +
(1|Benches:MainPlots),
data=na.omit(WaterRunoff.dat))
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"))
## Form an all.diffs object and check its validity
TS.vcov <- vcov(TS.emm)
TS.diffs <- allDifferences(predictions = TS.preds, classify = "Sources:Type",
vcov = TS.vcov, tdf = den.df)
validAlldiffs(TS.diffs)
}
## Plot LSD values for predictions obtained using asreml or lmerTest
if (exists("TS.diffs"))
{
plotLSDs(TS.diffs, gridspacing = rep(c(3,4), c(4,2)))
plotLSDs(TS.diffs, sections = "Sources", axis.labels = TRUE)
}
Plots a heat map of computed LSD-values for pairwise differences between predictions.
Description
Produces a heat-map plot of the computed LSD values for pairwise differences between
predictions that are stored in a data.frame. The data.frame includes
two factors whose levels specify, for each LSD value, which combinations of factor
levels are being compared.
Usage
## S3 method for class 'data.frame'
plotLSDs(object, LSD = "LSDs", x, y, alpha = 0.05,
triangles = "both", gridspacing = 0,
title = NULL, axis.labels = NULL, axis.text.size = 12,
colours = RColorBrewer::brewer.pal(3, "Set2"),
ggplotFuncs = NULL, printPlot = TRUE, ...)
Arguments
object |
A |
LSD |
A |
x |
A |
y |
A |
alpha |
A |
triangles |
A |
gridspacing |
A |
title |
A |
axis.labels |
A |
axis.text.size |
A |
colours |
A vector of colours to be passed to the |
ggplotFuncs |
A |
printPlot |
A |
... |
Provision for passing arguments to functions called internally - not used at present. |
Value
An object of class "ggplot", which can be plotted using print or otherwise manipulated.
Author(s)
Chris Brien
See Also
plotLSDs.alldiffs, plotLSDerrors.alldiffs, plotLSDerrors.data.frame,
exploreLSDs, ggplot
Examples
##Subset 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:
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= tmp))
current.asrt <- as.asrtests(current.asr, NULL, NULL)
TS.diffs <- predictPlus.asreml(classify = "Sources:Type",
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 * (Type + Species)) +
(1|Benches:MainPlots),
data=na.omit(WaterRunoff.dat))
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"))
## Form an all.diffs object and check its validity
TS.vcov <- vcov(TS.emm)
TS.diffs <- allDifferences(predictions = TS.preds, classify = "Sources:Type",
vcov = TS.vcov, tdf = den.df)
validAlldiffs(TS.diffs)
}
## Plot LSD values for predictions obtained using asreml or lmerTest
if (exists("TS.diffs"))
{
LSD <- within(reshape2::melt(TS.diffs$p.differences),
{
Var1 <- factor(Var1, levels=dimnames(TS.diffs$p.differences)[[1]])
Var2 <- factor(Var2, levels=levels(Var1))
})
names(LSD) <- c("Rows","Columns","LSDs")
plotLSDs(LSD, x = "Rows", y = "Columns", gridspacing = rep(c(3,4), c(4,2)))
}
Plots the predictions for a term, possibly with error bars.
Description
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.
Usage
## 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, ...)
Arguments
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 |
Value
An object of class ggplot, which can be plotted using print or otherwise manipulated.
Author(s)
Chris Brien
See Also
allDifferences.data.frame, predictPresent.asreml,
redoErrorIntervals.alldiffs,
recalcLSD.alldiffs, ggplot, Devices
Examples
## 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")
}
Plots a heat map of p-values for pairwise differences between predictions.
Description
Produces a heat-map plot of the p-values for pairwise differences between
predictions that is stored in the p.differences component of an
all.diffs object. This is generally a matrix whose rows and columns
are labelled by the levels of one or more factors, the set of labels being
the same for rows and columns. The sections argument allows multiple
plots to be produced, one for each combination of the levels of the factors
listed in sections. Otherwise, a single plot is produced for all
observed combinations of the levels of the factors in the classify
for the alldiffs.object. The plots are produced using
plotPvalues.data.frame. The order of plotting the levels of
one of the factors indexing the predictions can be modified using
sort.alldiffs.
Usage
plotPvalues(object, ...)
## S3 method for class 'alldiffs'
plotPvalues(object, sections = NULL,
gridspacing = 0, factors.per.grid = 0,
show.sig = FALSE, alpha = 0.10,
sig.size = 3, sig.colour = "black",
sig.face = "plain", sig.family = "",
triangles = "both",
title = NULL, axis.labels = TRUE, axis.text.size = 12,
sep=",", colours = RColorBrewer::brewer.pal(3, "Set2"),
ggplotFuncs = NULL, printPlot = TRUE,
sortFactor = NULL, sortParallelToCombo = NULL,
sortNestingFactor = NULL, sortOrder = NULL,
decreasing = FALSE, ...)
Arguments
object |
An |
sections |
A |
gridspacing |
A |
factors.per.grid |
A |
show.sig |
A |
alpha |
A |
sig.size |
A |
sig.colour |
A |
sig.face |
A |
sig.family |
A |
triangles |
A |
title |
A |
axis.labels |
A |
axis.text.size |
A |
sep |
A |
colours |
A vector of of colours to be passed to the |
ggplotFuncs |
A |
printPlot |
A |
sortFactor |
A |
sortParallelToCombo |
A |
sortNestingFactor |
A |
sortOrder |
A The following creates a |
decreasing |
A |
... |
Provision for passsing arguments to functions called internally - not used at present. |
Value
A list with components named pvalues and plots.
The pvalues component contains the data.frame with the columns Rows,
Columns, p, sections1 and sections2. This data.frame is
formed using the sed component of object and is used by
plotPvalues.data.frame in producng the plot. The plots
component contains a list of ggplot objects, one for each plot produced.
Multiple plots are stored in the plots component if the sections argument
is set and the plots are are named for the levels combinations of the sections.
Author(s)
Chris Brien
See Also
plotPvalues.data.frame, allDifferences.data.frame,
sort.alldiffs, subset.alldiffs, ggplot
Examples
##Subset WaterRunoff data to reduce time to execute
data(WaterRunoff.dat)
tmp <- subset(WaterRunoff.dat, Date == "05-18" & Benches != "3")
##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= tmp)
current.asrt <- as.asrtests(current.asr, NULL, NULL)
TS.diffs <- predictPlus.asreml(classify = "Sources:Type",
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 * (Type + Species)) +
(1|Benches:MainPlots),
data=na.omit(WaterRunoff.dat))
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"))
## Form an all.diffs object and check its validity
TS.vcov <- vcov(TS.emm)
TS.diffs <- allDifferences(predictions = TS.preds, classify = "Sources:Type",
vcov = TS.vcov, tdf = den.df)
validAlldiffs(TS.diffs)
}
## Plot p-values for predictions obtained using asreml or lmerTest
if (exists("TS.diffs"))
{
plotPvalues(TS.diffs, gridspacing = rep(c(3,4), c(4,2)), show.sig = TRUE)
plotPvalues(TS.diffs, sections = "Sources", show.sig = TRUE, axis.labels = TRUE)
}
Plots a heat map of p-values for pairwise differences between predictions.
Description
Produces a heat-map plot of the p-values for pairwise differences between
predictions that is in a data.frame. The data.frame includes
two factors whose levels specify, for each p-value, which factor levels are
being compared.
Usage
## S3 method for class 'data.frame'
plotPvalues(object, p = "p", x, y,
gridspacing = 0, show.sig = FALSE, alpha = 0.10,
sig.size = 3, sig.colour = "black",
sig.face = "plain", sig.family = "",
triangles = "both",
title = NULL, axis.labels = NULL, axis.text.size = 12,
colours = RColorBrewer::brewer.pal(3, "Set2"),
ggplotFuncs = NULL, printPlot = TRUE, ...)
Arguments
object |
A |
p |
A |
x |
A |
y |
A |
gridspacing |
A |
show.sig |
A |
alpha |
A |
sig.size |
A |
sig.colour |
A |
sig.face |
A |
sig.family |
A |
triangles |
A |
title |
A |
axis.labels |
A |
axis.text.size |
A |
colours |
A vector of of colours to be passed to the |
ggplotFuncs |
A |
printPlot |
A |
... |
Provision for passsing arguments to functions called internally - not used at present. |
Value
An object of class "ggplot", which can be plotted using print or otherwise manipulated.
Author(s)
Chris Brien
See Also
plotPvalues.alldiffs, allDifferences.data.frame, ggplot
Examples
##Subset 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:
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= tmp))
current.asrt <- as.asrtests(current.asr, NULL, NULL)
SS.diffs <- predictPlus.asreml(classify = "Sources:Type",
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 * (Type + Species)) +
(1|Benches:MainPlots),
data=na.omit(WaterRunoff.dat))
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"))
## Form an all.diffs object and check its validity
TS.vcov <- vcov(TS.emm)
TS.diffs <- allDifferences(predictions = TS.preds, classify = "Sources:Type",
vcov = TS.vcov, tdf = den.df)
validAlldiffs(TS.diffs)
}
## Plot p-values for predictions obtained using asreml or lmerTest
if (exists("TS.diffs"))
{
p <- within(reshape2::melt(TS.diffs$p.differences),
{
Var1 <- factor(Var1, levels=dimnames(TS.diffs$p.differences)[[1]])
Var2 <- factor(Var2, levels=levels(Var1))
})
names(p) <- c("Rows","Columns","p")
plotPvalues(p, x = "Rows", y = "Columns",
gridspacing = rep(c(3,4), c(4,2)), show.sig = TRUE)
}
Plots empirical variogram faces, including envelopes, from supplied residuals as described by Stefanova, Smith & Cullis (2009).
Description
Produces a plot for each face of an empirical 2D
variogram based on supplied residuals from both an observed data set
and simulated data sets. Those from simulated data sets are used to
produce confidence envelopes If the data consists of sections, such as separate
experiments, the two variogram faces are produced for each section. This
function is less efficient in storage terms than variofaces.asreml,
because here the residuals from all simulated data sets must be saved, in
addition to the values for the variogram faces; in
variofaces.asreml, the residuals for each simulated data set are
discarded after the variogram has been calculated. On the other hand, the
present function is more flexible, because there is no restriction on how the
residuals are obtained.
Usage
## S3 method for class 'data.frame'
plotVariofaces(data, residuals, restype="Residuals", ...)
Arguments
data |
A |
residuals |
A |
restype |
A |
... |
Other arguments that are passed down to the function |
Details
For each set of residuals, asreml.variogram is used to obtain the empirical
variogram, from which the values for its faces are obtained. Plots are produced for
each face and include the observed residuals and the 2.5%, 50% & 97.5% quantiles.
Value
A list with the following components:
face1: a
data.framecontaining the variogram values on which the plot for the first dimension is based.face2: a
data.framecontaining the variogram values on which the plot for the second dimension is based.
Author(s)
Chris Brien
References
Stefanova, K. T., Smith, A. B. & Cullis, B. R. (2009) Enhanced diagnostics for the spatial analysis of field trials. Journal of Agricultural, Biological, and Environmental Statistics, 14, 392–410.
See Also
asremlPlus-package, asreml, asreml.variogram,
variofaces.asreml, simulate.asreml.
Examples
## Not run:
data(Wheat.dat)
current.asr <- asreml(yield ~ Rep + WithinColPairs + Variety,
random = ~ Row + Column + units,
residual = ~ ar1(Row):ar1(Column),
data=Wheat.dat)
current.asrt <- as.asrtests(current.asr, NULL, NULL)
current.asrt <- rmboundary.asrtests(current.asrt)
# Form variance matrix based on estimated variance parameters
s2 <- current.asr$sigma2
gamma.Row <- current.asr$gammas[1]
gamma.unit <- current.asr$gammas[2]
rho.r <- current.asr$gammas[4]
rho.c <- current.asr$gammas[5]
row.ar1 <- mat.ar1(order=10, rho=rho.r)
col.ar1 <- mat.ar1(order=15, rho=rho.c)
V <- gamma.Row * fac.sumop(Wheat.dat$Row) +
gamma.unit * diag(1, nrow=150, ncol=150) +
mat.dirprod(col.ar1, row.ar1)
V <- s2*V
#Produce variogram faces plot (Stefanaova et al, 2009)
resid <- simulate(current.asr, V=V, which="residuals")
resid$residuals <- cbind(resid$observed[c("Row","Column")],
resid$residuals)
plotVariofaces(data=resid$observed[c("Row","Column","residuals")],
residuals=resid$residuals,
restype="Standardized conditional residuals")
## End(Not run)
Performs a combination of a linear and a power transformation on a variable. The
transformed variable is stored in the data.frame data.
Description
Perform a combination of a linear and a power transformation on a variable
whose name is given as a character string in var.name. The transformed
variable is stored in the data.frame data. The name of the transformed
variable is made by prepending to the original var.name a combination of
(i) .offset, if offset is nonzero,
(ii) neg., if scale is -1, or scaled., if abs(scale)
is other than one, and (iii) either log., sqrt., recip. or
power., if power is other than one.
No action is taken if there is no transformation (i.e. offset = 0,
scale = 1 and power = 1). Also, the titles list is
extended to include a component with a generated title for the
transformed variable with text indicating the transformation prepended
to the title for the var.name obtained from the
titles list. For nonzero offset, ‘Offset ’ is prepended,
For scaled not equal to one, the possible prepends are ‘Negative of ’
and ‘Scaled ’. The possible prepended texts for power not equal to one
are ‘Logarithm of’, ‘Square root of ’, ‘Reciprocal of ’ and ‘Power nnnn of ’,
where nnn is the power used.
Usage
powerTransform(var.name, power = 1, offset = 0, scale = 1, titles = NULL, data)
Arguments
var.name |
A |
power |
A number specifying the power to be used in the transformation.
If equal to 1, the default, no power transformation is applied.
Otherwise, the variable is raised to the specified |
offset |
A number to be added to each value of the variable, after any scaling and before applying any power transformation. |
scale |
A number to multiply each value of the variable, before adding any offset and applying any power transformation. |
titles |
A |
data |
A |
Value
A list with a component named data that is the data.frame containing the
transformed variable, a component named tvar.name that is a character string
that is the name of the transformed variable in data, and a component named
titles that extends the list supplied in the titles argument to
include a generated title for the transformed title, the name of the new component being
tvar.name.
Author(s)
Chris Brien
See Also
Examples
## set up a factor with labels
x.dat <- data.frame(y = c(14, 42, 120, 150))
## transform y to logarithms
trans <- powerTransform("y", power = 0, titles=list(y = "Length (cm)"), data = x.dat)
x.dat <- trans$data
tvar.name <- trans$tvar.name
## transform y to logarithms after multiplying by -1 and adding 1.
z.dat <- data.frame( y = c(-5.25, -4.29, -1.22, 0.05))
trans <- powerTransform("y", power = 0, scale = -1, offset = 1 ,
titles=list(y = "Potential"), data = z.dat)
z.dat <- trans$data
tvar.name <- trans$tvar.name
Forms the predictions for a term, their pairwise differences and associated statistics. A factor having parallel values may occur in the model and a linear transformation of the predictions can be specified. It results in an object of class alldifffs.
Description
This function forms the predictions for term using
classify and the supplied asreml object and stores
them in an alldiffs.object. If x.num is
supplied, the predictions will be obtained for the values supplied
in x.pred.values and, if supplied, x.plot.values will
replace them in the alldiffs.object that is returned.
If x.fac, but not x.num, is specified, predictions
will involve it and, if supplied, x.plot.values will replace
the levels of x.fac in the alldiffs.object
that is returned. In order to get the correct predictions you may
need to supply additional arguments to predict.asreml
through ... e.g. present, parallel, levels.
Any aliased predictions will be removed, as
will any standard error of pairwise differences involving them.
Also calculated are the approximate degrees of freedom of the
standard errors of the predictions. If the denominator degrees of
freedom for term are available in wald.tab, they are
used. Otherwise the residual degrees of freedom or the maximum of
the denominator degrees in wald.tab, excluding the
Intercept, are used. Which is used depends on the setting of
dDF.fault. These degrees of freedom are used for the
t-distribution on which p-values and confidence intervals are
based. It is stored as an attribute to the alldiffs.object.
The degrees of freedom are also used in calculating the minimum,
mean and maximum LSD for comparing pairs of predictions, which are
also stored in the alldiffs.object.
If pairwise = TRUE, all pairwise differences between the
predictions, their standard errors, p-values and LSD
statistics are computed using allDifferences.data.frame.
This adds them to the alldiffs.object as additional
list components named differences, sed,
p.differences and LSD.
If a linear transformation of the predictions is specified then the values of this linear transformation are returned, instead of the original predictions, along with their standard errors and the pairwise differences and associated statistics.
If a transformation has been applied in the analysis (any one of
transform.power is not one, scale is not one and
offset is nonzero), the backtransforms of the transformed
values and their lower and upper error intervals are added
to a data.frame that is consistent with the predictions
data.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.
Usage
## S3 method for class 'asreml'
predictPlus(asreml.obj, classify, term = NULL,
inestimable.rm = TRUE,
linear.transformation = NULL, EGLS.linTransform = TRUE,
error.intervals = "Confidence", alpha = 0.05,
wald.tab = NULL, dDF.fault = "residual", dDF.values = NULL,
pairwise = TRUE, Vmatrix = FALSE,
avsed.tolerance = 0.25, accuracy.threshold = NA,
LSDtype = "overall", LSDsupplied = NULL, LSDby = NULL,
LSDstatistic = "mean", LSDaccuracy = "maxAbsDeviation",
x.num = NULL, x.fac = NULL,
x.pred.values = NULL, x.plot.values = NULL,
titles = NULL, tables = "all" , level.length = NA,
transform.power = 1, offset = 0, scale = 1,
transform.function = "identity",
sortFactor = NULL, sortParallelToCombo = NULL,
sortNestingFactor = NULL, sortOrder = NULL,
decreasing = FALSE, trace = FALSE, ...)
Arguments
asreml.obj |
|
classify |
A |
term |
A |
inestimable.rm |
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 |
error.intervals |
A |
alpha |
A |
wald.tab |
A |
dDF.fault |
A |
dDF.values |
A |
pairwise |
A |
Vmatrix |
A |
avsed.tolerance |
A
|
accuracy.threshold |
A |
LSDtype |
A See |
LSDsupplied |
A |
LSDby |
A |
LSDstatistic |
A |
LSDaccuracy |
A |
titles |
A |
tables |
A |
x.num |
A |
x.fac |
A |
x.pred.values |
The values of |
x.plot.values |
The actual values to be plotted on the x axis. They are
needed when values different to those in |
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. |
transform.power |
A |
offset |
A |
scale |
A |
transform.function |
A |
sortFactor |
A |
sortParallelToCombo |
A |
sortNestingFactor |
A |
sortOrder |
A The following creates a |
decreasing |
A |
trace |
A |
... |
further arguments passed to |
Value
For linear.transformations set to NULL, an S3-class
alldiffs.object with predictions and their standard
errors and, depending on the settings of the arguments, all pairwise
differences between predictions, their standard errors and p-values
and LSD statistics. Also, unless the sortFactor or sortOrder
arguments are invoked, 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.
In addition, if necessary, the order of the columns of the variables in the
predictions component are changed to match their order in the classify.
If transform.power or scale is not one or offset
is not zero, it will contain a data.frame 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 name of the response, the response.title,
the term, the classify, tdf, 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.
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.objects stores a linear transformation of predictions.
For linear.transformations set to other than NULL,
an alldiffs.object with the linear.transformation
applied to the predictions and their standard errors and,
depending on the settings of the arguments, all pairwise
differences between the linearly transformed predictions, their
standard errors and p-values and LSD statistics.
(See also linTransform.alldiffs.)
Author(s)
Chris Brien
See Also
alldiffs.object, as.alldiffs, print.alldiffs,
linTransform.alldiffs, sort.alldiffs,
subset.alldiffs, allDifferences.data.frame,
redoErrorIntervals.alldiffs,
recalcLSD.alldiffs, exploreLSDs.alldiffs,
pickLSDstatistics.alldiffs,
predictPresent.asreml,
plotPredictions.data.frame, as.Date, predict.asreml
Examples
## Not run:
data(WaterRunoff.dat)
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)
diffs <- predictPlus(classify = "Sources:Type",
asreml.obj = current.asr,
wald.tab = current.asrt$wald.tab,
present = c("Sources", "Type", "Species"))
## End(Not run)
Forms the predictions for each of one or more terms and presents them in tables and/or graphs.
Description
This function forms the predictions for each term in terms
using a supplied asreml object and
predictPlus.asreml.
Tables are produced using predictPlus.asreml,
in conjunction with
allDifferences.data.frame,
with the argument tables specifying which tables are printed.
The argument plots, along with transform.power,
controls which plots are produced. The plots are
produced using plotPredictions.data.frame, with
line plots produced when variables involving x.num or x.fac
are involved in classify for the predictions and bar charts
otherwise.
In order to get the correct predictions you may
need to supply additional arguments to predict.asreml
through ... e.g. present, parallel, levels.
The order of plotting the levels of
one of the factors indexing the predictions can be modified and is achieved
using sort.alldiffs.
Usage
## S3 method for class 'asreml'
predictPresent(asreml.obj, terms, inestimable.rm = TRUE,
linear.transformation = NULL, EGLS.linTransform,
error.intervals = "Confidence", alpha = 0.05,
wald.tab = NULL, dDF.fault = "residual", dDF.values = NULL,
pairwise = TRUE, Vmatrix = FALSE,
avsed.tolerance = 0.25, accuracy.threshold = NA,
LSDtype = "overall", LSDsupplied = NULL, LSDby = NULL,
LSDstatistic = "mean", LSDaccuracy = "maxAbsDeviation",
x.num = NULL, x.fac = NULL, nonx.fac.order = NULL,
x.pred.values = NULL, x.plot.values = NULL,
plots = "predictions", panels = "multiple",
graphics.device = NULL, interval.annotate = TRUE,
titles = NULL, colour.scheme = "colour", save.plots = FALSE,
transform.power = 1, offset = 0, scale = 1,
transform.function = "identity",
tables = "all", level.length = NA,
sortFactor = NULL, sortParallelToCombo = NULL,
sortNestingFactor = NULL, sortOrder = NULL,
decreasing = FALSE,
trace = FALSE, ggplotFuncs = NULL, ...)
Arguments
asreml.obj |
|
terms |
A |
inestimable.rm |
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 in the |
EGLS.linTransform |
A |
error.intervals |
A |
alpha |
A |
wald.tab |
A |
dDF.fault |
A |
dDF.values |
A |
pairwise |
A logical indicating whether all pairwise differences of the
|
Vmatrix |
A |
avsed.tolerance |
A
|
accuracy.threshold |
A |
LSDtype |
A See |
LSDsupplied |
A |
LSDby |
A |
LSDstatistic |
A |
LSDaccuracy |
A |
x.num |
A |
x.fac |
A |
nonx.fac.order |
A |
x.pred.values |
The values of |
x.plot.values |
The actual values to be plotted on the x axis or in the labels of
tables. They are
needed when values different to those in |
plots |
Possible values are |
panels |
Possible values are |
graphics.device |
A |
interval.annotate |
A |
titles |
A |
colour.scheme |
A character string specifying the colour scheme for the plots.
The default is |
save.plots |
A |
transform.power |
A |
offset |
A number that has been added to each value of the response after any scaling
and before applying any power transformation. Unless it is equal to 0, the
default, back-transforms of the predictions will be obtained and stored in
the |
scale |
A number by which each value of the response has been multiply before adding
any offset and applying any power transformation. Unless it is equal to 1, the
default, back-transforms of the predictions will be obtained and stored in
the |
transform.function |
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 produced by
|
sortFactor |
A |
sortParallelToCombo |
A |
sortNestingFactor |
A |
sortOrder |
A The following creates a |
decreasing |
A |
trace |
If TRUE then partial iteration details are displayed when ASReml-R functions are invoked; if FALSE then no output is displayed. |
ggplotFuncs |
A |
... |
further arguments passed to |
Value
A list containing an alldiffs.object for each term for
which tables are produced. The names of the components of this list are
the terms with full-stops (.) replacing colons (:).
Plots are also preduced depending on the setting of the plot
argument.
Author(s)
Chris Brien
See Also
predictPlus.asreml, allDifferences.data.frame,
sort.alldiffs, subset.alldiffs,
redoErrorIntervals.alldiffs, recalcLSD.alldiffs,
pickLSDstatistics.alldiffs,
plotPredictions.data.frame,
print.alldiffs, as.Date, Devices
Examples
## Not run:
data(WaterRunoff.dat)
titles <- list("Days since first observation", "Days since first observation",
"pH", "Turbidity (NTU)")
names(titles) <- names(WaterRunoff.dat)[c(5,7,11:12)]
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:Species:xDay +
Sources: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("Sources","Species","Date","xDay")
levs <- as.data.frame(table(WaterRunoff.dat[class.facs]))
levs <- levs[do.call(order, levs), ]
levs <- as.list(levs[levs$Freq != 0, class.facs])
levs$xDay <- as.numfac(levs$xDay)
#### parallel and levels are arguments from predict.asreml
diff.list <- predictPresent.asreml(asreml.obj = current.asrt$asreml.obj,
terms = "Date:Sources:Species:xDay",
x.num = "xDay", x.fac = "Date",
parallel = TRUE, levels = levs,
wald.tab = current.asrt$wald.tab,
plots = "predictions",
error.intervals = "StandardError",
titles = titles,
transform.power = 0,
present = c("Type","Species","Sources"),
tables = "none",
level.length = 6)
## End(Not run)
Description of a predictions object
Description
A data.frame of S3-class predictions.frame that stores the
predictions for a fitted model.
as.predictions.frame is function that converts a
data.frame to an object of this class.
is.predictions.frame is the membership function for this class; it tests
that an object has class predictions.frame.
validPredictionsFrame can be used to test the validity of a
predictions.frame.
Value
A data.frame that begins with the variables classifying the predictions,
in the same order as in the classify, followed by a column of
predictions that is named either predicted.value or
backtransformed.predictions; it also contains columns named
standard.error and est.status.
The number of rows should equal the number of unique combinations
of the classifying variables. While such a data.frame
can be constructed from the beginning, the pvals component
of the value produced by predict.asreml is a suitable value to
supply for this argument. 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.
The data.frame may also include columns for the lower and upper
values of error intervals, either standard error, confidence or half-LSD
intervals. 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.
IF accuracy.threshold is set to a numeric value at the time the
prediction.frame is formed, it will also include a column logical values
named LSDwarning.
When halfLeastSignificant limits have been included in a predictions.frame,
its attributes will include those that are not NULL of LSDtype,
LSDby, LSDstatistic, LSDaccuracy and LSDvalues. LSDvalues are
the LSD values used to calculate the halfLeastSignificant error.intervals
and are an expanded version of the values stored in the assignedLSD column of the
LSD.frame.
See predictPlus.asreml for more information.
Author(s)
Chris Brien
See Also
predictPlus.asreml, is.predictions.frame,
as.predictions.frame, validPredictionsFrame
Examples
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 <- as.predictions.frame(Var.pred$pvals, se = "std.error",
est.status = "status")
## End(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)
Var.preds <- as.predictions.frame(Var.preds, predictions = "emmean",
se = "SE", interval.type = "CI",
interval.names = c("lower.CL", "upper.CL"))
}
if (exists("Var.preds"))
{
## Check the class and validity of the alldiffs object
is.predictions.frame(Var.preds)
validPredictionsFrame(Var.preds)
}
Prints the components of a list containing data on the LSDs for all pairwise differences of predictions.
Description
Prints the components of an LSDdata list created by exploreLSDs,
that contains data on the LSDs for all pairwise differences of predictions stored in an
alldiffs.object.
Usage
## S3 method for class 'LSDdata'
print(x, which.print = c("statistics", "false.pos", "false.neg"), ...)
Arguments
x |
An object that, ideally, is of class |
which.print |
Which components of the |
... |
further arguments passed to |
Value
No value is returned, but components of x are printed as specified in which.print.
Author(s)
Chris Brien
See Also
exploreLSDs.alldiffs, alldiffs.object
Examples
## Not run:
data(WaterRunoff.dat)
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)
diffs <- predictPlus(classify = "Sources:Type",
asreml.obj = current.asr,
wald.tab = current.asrt$wald.tab,
present = c("Sources", "Type", "Species"))
LSDdata <- exploreLSDs(diffs, LSDtype = "factor.combinations", LSDby = "Sources")
print(LSDdata)
## End(Not run)
Prints the values in an alldiffs.object in a nice format.
Description
Prints the predictions and standard errors from a fitted model,
including the attributes of the predictions.frame. Also prints out all
pairwise differences between the predictions to 2 significant figures,
along with their p-values and standard errors to 4 decimal places. If LSDs are
requested the mean, minimum and maximum LSDs will be printed.
Usage
## S3 method for class 'alldiffs'
print(x, which = "all", colourise = FALSE, ...)
Arguments
x |
An |
which |
A |
colourise |
A |
... |
further arguments passed to |
Value
No value is returned, but the components of x are printed.
Author(s)
Chris Brien
See Also
print.predictions.frame, as.alldiffs, allDifferences.data.frame
Examples
## Not run:
print.alldiffs(diffs, which = "predictions")
## End(Not run)
Prints the values in an asrtests.object
Description
Prints a summary of the asreml object, the pseudoanova and
the test.summary data.frame that are stored in the
asrtests.object.
Usage
## S3 method for class 'asrtests'
print(x, which = "key", colourise = FALSE, ...)
Arguments
x |
An |
which |
Which elements of the |
colourise |
A |
... |
further arguments passed to |
Value
No value is returned, but the elements of the list in x are
printed.
Author(s)
Chris Brien
See Also
print.wald.tab, as.asrtests, asremlPlus-package
Examples
## Not run:
data(Wheat.dat)
current.asr <- asreml(yield ~ Rep + WithinColPairs + Variety,
random = ~ Row + Column + units,
residual = ~ ar1(Row):ar1(Column),
data=Wheat.dat)
current.asrt <- as.asrtests(current.asr, NULL, NULL)
current.asrt <- rmboundary.asrtests(current.asrt)
# Test Row autocorrelation
current.asrt <- testresidual(current.asrt, , "~ Row:ar1(Column)",
label="Row autocorrelation", simpler=TRUE)
print(current.asrt)
## End(Not run)
Prints the values in a predictions.frame, with or without title and heading.
Description
Prints the predictions from a fitted model, along with their standard errors and, if present, their error intervals, with or without title and headings.
Usage
## S3 method for class 'predictions.frame'
print(x, title = NULL,
which.predictions = c("title", "heading", "table"),
colourise = FALSE, ...)
Arguments
x |
An object that, ideally, is of class |
title |
A |
which.predictions |
what Which elements of the |
colourise |
A |
... |
further arguments passed to |
Value
No value is returned, but the components of x are printed.
Author(s)
Chris Brien
See Also
print.alldiffs, as.alldiffs, allDifferences.data.frame
Examples
## Not run:
print.predictions.frame(diffs$predictions, which = "all")
## End(Not run)
Prints a data.frame containing a test.summary.
Description
Prints a test.summary (also a choose.summary) with or without a title and with p-values limited to 4-digits.
Usage
## S3 method for class 'test.summary'
print(x, which.print = c("title", "table"),
omit.columns = NULL, response = NULL, ...)
Arguments
x |
A object that, ideally, is of class |
which.print |
A |
omit.columns |
A |
response |
A |
... |
further arguments passed to |
Value
No value is returned, but x is printed, possibly with a title.
Author(s)
Chris Brien
See Also
print.wald.tab, print.asrtests, as.asrtests, asremlPlus-package
Examples
## Not run:
data(Wheat.dat)
current.asr <- asreml(yield ~ Rep + WithinColPairs + Variety,
random = ~ Row + Column + units,
residual = ~ ar1(Row):ar1(Column),
data=Wheat.dat)
current.asrt <- as.asrtests(current.asr, NULL, NULL)
current.asrt <- rmboundary.asrtests(current.asrt)
# Test Row autocorrelation
current.asrt <- testresidual(current.asrt, "~ Row:ar1(Column)",
label="Row autocorrelation", simpler=TRUE)
print(current.asrt$test.summary)
## End(Not run)
Prints a data.frame containing a Wald or pseudoanova table.
Description
Prints a wald.tab with or without title and/or heading.
The printing of the p-values is limited to 4 digits.
Usage
## S3 method for class 'wald.tab'
print(x, which.wald = c("title", "heading", "table"),
colourise = FALSE, ...)
Arguments
x |
An object that, ideally, is of class |
which.wald |
Which elements of the |
colourise |
A |
... |
further arguments passed to |
Value
No value is returned, but x is printed as specified in which.wald.
Author(s)
Chris Brien
See Also
print.test.summary, print.asrtests, as.asrtests, asremlPlus-package
Examples
## Not run:
data(Wheat.dat)
current.asr <- asreml(yield ~ Rep + WithinColPairs + Variety,
random = ~ Row + Column + units,
residual = ~ ar1(Row):ar1(Column),
data=Wheat.dat)
current.asrt <- as.asrtests(current.asr, NULL, NULL)
current.asrt <- rmboundary.asrtests(current.asrt)
# Test Row autocorrelation
current.asrt <- testresidual(current.asrt, "~ Row:ar1(Column)",
label="Row autocorrelation", simpler=TRUE)
print(current.asrt$wald.tab)
## End(Not run)
Prints the formulae from an asreml object.
Description
Prints the formulae nominated in the which argument from the call stored in an asreml object.
Usage
## S3 method for class 'asreml'
printFormulae(asreml.obj, which = c("fixed", "random", "residual"),
expanded = FALSE, envir = parent.frame(), ...)
Arguments
asreml.obj |
An |
which |
A |
expanded |
A |
envir |
The environment in which the |
... |
Arguments passed on to |
Value
Invisibly returns a character, each element of which contains one of the extracted
formulae.
Author(s)
Chris Brien
See Also
Examples
## Not run:
data(Wheat.dat)
current.asr <- asreml(yield ~ Rep + WithinColPairs + Variety,
random = ~ Row + Column + units,
residual = ~ ar1(Row):ar1(Column),
data=Wheat.dat)
printFormulae(current.asr)
## End(Not run)
Calculates the ratios of nominated pairs of predictions stored in an alldiffs.object.
Description
Ratio predictions and error intervals are formed for two levels of a factor,
the ratio.factor. For each pair of a level of the ratio.factor
in numerator.levels with a level in denominator.levels,
the ratio predictions are formed from all combinations of the other factors
as the ratio of the two predictions for each combination, along with confidence
intervals for the ratio predictions computed using the Fieller (1954) method.
The printing of the components produced is controlled by the
tables argument.
Usage
## S3 method for class 'alldiffs'
ratioTransform(alldiffs.obj, ratio.factor,
numerator.levels, denominator.levels,
method = "Fieller", alpha = 0.05,
response = NULL, response.title = NULL,
tables = "predictions", ...)
Arguments
alldiffs.obj |
An |
ratio.factor |
A |
numerator.levels |
A |
denominator.levels |
A |
method |
A |
alpha |
A |
response |
A |
response.title |
A |
tables |
A |
... |
further arguments passed to |
Value
A list of predictions.frames, each containing the ratio predictions
and their confidence limits for a combination of the numerator.levels with the
denominator.levels. It will also contain the values of the variables in the
classify of alldiffs.obj that index the ratio predictions, except that
the ratio.factor is omitted.
If sortFactor attribute of the alldiffs.object is set and is not the
ratio.factor, the predictions and their backtransforms will be sorted using
the sortOrder attribute of the alldiffs.object.
Author(s)
Chris Brien
References
Fieller, E. C. (1954). Some Problems in Interval Estimation. Journal of the Royal Statistical Society.Series B (Methodological), 16, 175-185.
See Also
pairdiffsTransform, linTransform, predictPlus.asreml,
as.alldiffs,
print.alldiffs, sort.alldiffs, subset.alldiffs,
allDifferences.data.frame,
redoErrorIntervals.alldiffs,
recalcLSD.alldiffs, predictPresent.asreml,
plotPredictions.data.frame,
as.Date, predict.asreml
Examples
#### Form the ratios and Fieller CIs for RGR Salinity
load(system.file("extdata", "testDiffs.rda", package = "asremlPlus", mustWork = TRUE))
Preds.ratio.RGR <- ratioTransform(diffs.RGR,
ratio.factor = "Salinity",
numerator.levels = "Salt",
denominator.levels = "Control")
#### Form the ratios and Fieller CIs for Nitrogen compared to no Nitrogen
data("Oats.dat")
## Not run:
m1.asr <- asreml(Yield ~ Nitrogen*Variety,
random=~Blocks/Wplots,
data=Oats.dat)
current.asrt <- as.asrtests(m1.asr)
wald.tab <- current.asrt$wald.tab
Var.diffs <- predictPlus(m1.asr, classify="Nitrogen:Variety", pairwise = TRUE,
Vmatrix = TRUE, error.intervals = "halfLeast",
LSDtype = "factor", LSDby = "Variety",
wald.tab = wald.tab)
## End(Not run)
## Use lme4 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)
## Set up a wald.tab
int <- as.data.frame(rbind(rep(NA,4)))
rownames(int) <- "(Intercept)"
wald.tab <- anova(m1.lmer, ddf = "Kenward", type = 1)[,3:6]
names(wald.tab) <- names(int) <- c("Df", "denDF", "F.inc", "Pr")
wald.tab <- rbind(int, wald.tab)
#Get predictions
Var.emm <- emmeans::emmeans(m1.lmer, specs = ~ Nitrogen:Variety)
Var.preds <- summary(Var.emm)
## 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
den.df <- wald.tab[match("Variety", rownames(wald.tab)), "denDF"]
#Create alldiffs object
Var.diffs <- as.alldiffs(predictions = Var.preds,
sed = Var.sed, vcov = Var.vcov,
classify = "Nitrogen:Variety", response = "Yield", tdf = den.df)
}
if (exists("Var.diffs"))
Preds.ratio.OatsN <- ratioTransform(alldiffs.obj = Var.diffs,
ratio.factor = "Nitrogen",
numerator.levels = c("0.2","0.4","0.6"),
denominator.levels = "0.2")
Adds or recalculates the LSD.frame that is a component of an
alldiffs.object.
Description
Given an alldiffs.object, adds or recalculate its LSD.frame.
N.B. No changes are made to the error.intervals — use redoErrorIntervals.alldiffs
to modify both the error.intervals and the LSD.frame.
Usage
## S3 method for class 'alldiffs'
recalcLSD(alldiffs.obj, LSDtype = "overall", LSDsupplied = NULL,
LSDby = NULL, LSDstatistic = "mean", LSDaccuracy = "maxAbsDeviation",
alpha = 0.05, ...)
Arguments
alldiffs.obj |
An |
LSDtype |
A See |
LSDsupplied |
A |
LSDby |
A |
LSDstatistic |
A |
LSDaccuracy |
A |
alpha |
The significance level for an LSD to compare a pair of predictions.
It is stored as an attribute to the |
... |
further arguments passed to |
Value
An alldiffs.object with components
predictions, vcov, differences, p.differences
sed, LSD and, if present in alldiffs.obj, backtransforms.
Author(s)
Chris Brien
See Also
asremlPlus-package, as.alldiffs, sort.alldiffs,
subset.alldiffs, print.alldiffs,
renewClassify.alldiffs, exploreLSDs.alldiffs,
pickLSDstatistics.alldiffs,
redoErrorIntervals.alldiffs,
plotPredictions.data.frame,
predictPlus.asreml,
predictPresent.asreml
Examples
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)
TS.diffs <- predictPlus(classify = "Sources:Type",
asreml.obj = current.asr,
wald.tab = current.asrt$wald.tab,
present = c("Sources", "Type", "Species"))
## 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 * (Type + Species)) +
(1|Benches:MainPlots),
data=na.omit(WaterRunoff.dat))
TS.emm <- emmeans::emmeans(m1.lmer, specs = ~ Sources:Species)
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"))
## Form an all.diffs object and check its validity
TS.vcov <- vcov(TS.emm)
TS.diffs <- allDifferences(predictions = TS.preds, classify = "Sources:Species",
vcov = TS.vcov, tdf = den.df)
validAlldiffs(TS.diffs)
}
## Plot p-values for predictions obtained using asreml or lmerTest
if (exists("TS.diffs"))
{
##Recalculate the LSD values for predictions obtained using asreml or lmerTest
TS.diffs <- recalcLSD.alldiffs(TS.diffs, LSDtype = "factor.combinations",
LSDby = "Sources")
}
Recalculates the denDF, F.inc and P values for a table of Wald test statistics obtained
using wald.asreml
Description
If some or all denDF are not available, either because they are NA or because
F.inc values were not calculated, this function allows the user to specify how
approximate denDF values are to be obtained. This is done through the dDF.fault and
dDF.values arguments. Note that if denDF values are available in the Wald table then
only those that are NA will be replaced. The P values are recalculated using F.con,
if present in the wald.tab, otherwise F.inc is used. It is noted that, as of asreml version 4,
wald.asreml has a kenadj argument.
Usage
## S3 method for class 'asrtests'
recalcWaldTab(asrtests.obj, recalc.wald = FALSE,
denDF="numeric", dDF.fault = "none",
dDF.values = NULL, trace = FALSE, ...)
Arguments
asrtests.obj |
an |
recalc.wald |
A |
denDF |
Specifies the method to use in computing approximate denominator
degrees of freedom when |
dDF.fault |
A |
dDF.values |
A |
trace |
If TRUE then partial iteration details are displayed when ASReml-R functions are invoked; if FALSE then no output is displayed. |
... |
further arguments passed to |
Value
A wald.tab: a 4- or 6-column data.frame containing a
pseudo-anova table for the fixed terms produced by wald.asreml.
Author(s)
Chris Brien
References
Kenward, M. G., & Roger, J. H. (1997). Small sample inference for fixed effects from restricted maximum likelihood. Biometrics, 53, 983-997.
See Also
as.asrtests, testranfix.asrtests
Examples
## Not run:
wald.tab <- recalcWaldTab(current.asrt,
dDF.fault = "supplied",
dDF.values = c(NA,rep(c(330,346), c(4,3))))
## End(Not run)
Adds or replaces the error intervals stored in a prediction component
of an alldiffs.object.
Description
Given an alldiffs.object, adds or replaces error.intervals
for its prediction component. If the backtransforms component is
present, the transform.power, offset and scale will be
retrieved from the backtransforms attributes, ignoring the values for the
function's arguments, and the backtransformed
error.intervals will also be calculated.
Usage
## S3 method for class 'alldiffs'
redoErrorIntervals(alldiffs.obj, error.intervals = "Confidence",
alpha = 0.05,
avsed.tolerance = 0.25, accuracy.threshold = NA,
LSDtype = NULL, LSDsupplied = NULL,
LSDby = NULL, LSDstatistic = "mean",
LSDaccuracy = "maxAbsDeviation",
retain.zeroLSDs = FALSE,
zero.tolerance = .Machine$double.eps ^ 0.5, ...)
Arguments
alldiffs.obj |
An |
error.intervals |
A |
alpha |
A |
avsed.tolerance |
A
|
accuracy.threshold |
A |
LSDtype |
A If See |
LSDsupplied |
A |
LSDby |
A |
LSDstatistic |
A |
LSDaccuracy |
A |
retain.zeroLSDs |
A |
zero.tolerance |
A |
... |
further arguments passed to |
Value
An alldiffs.object with components
predictions, vcov, differences, p.differences
sed, LSD and, if present in alldiffs.obj, backtransforms.
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 term, the classify and
tdf, as well as the degrees of freedom of the standard error, 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.
Author(s)
Chris Brien
See Also
recalcLSD.alldiffs, exploreLSDs.alldiffs,
pickLSDstatistics.alldiffs,
predictPresent.asreml, plotPredictions.data.frame,
allDifferences.data.frame,
as.alldiffs, print.alldiffs, sort.alldiffs,
subset.alldiffs,
as.Date, predict.asreml
Examples
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)
TS.diffs <- predictPlus(classify = "Sources:Type",
asreml.obj = current.asr,
wald.tab = current.asrt$wald.tab,
present = c("Sources", "Type", "Species"))
## 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 * (Type + Species)) +
(1|Benches:MainPlots),
data=na.omit(WaterRunoff.dat))
TS.emm <- emmeans::emmeans(m1.lmer, specs = ~ Sources:Species)
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"))
## Form an all.diffs object and check its validity
TS.vcov <- vcov(TS.emm)
TS.diffs <- allDifferences(predictions = TS.preds,
classify = "Sources:Species",
vcov = TS.vcov, tdf = den.df)
validAlldiffs(TS.diffs)
}
## Plot p-values for predictions obtained using asreml or lmerTest
if (exists("TS.diffs"))
{
##Recalculate the LSD values for predictions obtained using asreml or lmerTest
TS.diffs <- redoErrorIntervals.alldiffs(TS.diffs,
error.intervals = "halfLeastSignificant")
}
Renews the components in an alldiffs.object according to a new classify.
Description
The classify is an attribute of an alldiffs.object and determines
the order within the components of an unsorted alldiffs.object.
This function resets the classify attribute and re-orders the components of
alldiffs.object to be in standard order for the variables in a
newclassify, using allDifferences.data.frame. The newclassify
may be just a re-ordering of the variable names in the previous classify, or be
based on a new set of variable names. The latter is particularly useful when
linTransform.alldiffs has been used with a matrix and it
is desired to replace the resulting Combination classify with a
newclassify comprised of a more meaningful set of variables; first replace
Combination in the predictions component with the new set of variables
and then call renewClassify.
Usage
## S3 method for class 'alldiffs'
renewClassify(alldiffs.obj, newclassify,
sortFactor = NULL, sortParallelToCombo = NULL,
sortNestingFactor = NULL, sortOrder = NULL, decreasing = FALSE, ...)
Arguments
alldiffs.obj |
An |
newclassify |
A |
sortFactor |
A |
sortParallelToCombo |
A |
sortNestingFactor |
A |
sortOrder |
A The following creates a |
decreasing |
A |
... |
further arguments passed to |
Details
First, the components of the alldiffs.object is arranged in standard order for
the newclassify. Then predictions are reordered according to the settings of
sortFactor, sortParallelToCombo, sortOrder and decreasing (see
sort.alldiffs for details).
Value
The alldiffs.object supplied with the following components,
if present, sorted: predictions, vcov, backtransforms, differences,
p.differences and sed. Also, the sortFactor and sortOrder
attributes are set.
Author(s)
Chris Brien
See Also
as.alldiffs, allDifferences.data.frame,
print.alldiffs, sort.alldiffs,
redoErrorIntervals.alldiffs, recalcLSD.alldiffs,
predictPlus.asreml, predictPresent.asreml
Examples
data(WaterRunoff.dat)
##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= WaterRunoff.dat)
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"))
## 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(WaterRunoff.dat))
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"))
## Form an all.diffs object and check its validity
TS.vcov <- vcov(TS.emm)
TS.diffs <- allDifferences(predictions = TS.preds,
classify = "Sources:Type",
vcov = TS.vcov, tdf = den.df)
validAlldiffs(TS.diffs)
}
#Re-order predictions from asreml or lmerTest so all Sources for the same Type are together
#for each combination of A and B
if (exists("TS.diffs"))
{
TS.diffs.reord <- renewClassify(TS.diffs, newclassify = "Type:Sources")
validAlldiffs(TS.diffs.reord)
}
Reparamterizes each random (deviations) term involving
devn.fac to a fixed term and ensures that the same term, with
trend.num replacing devn.fac, is included if any
other term with trend.num is included in terms.
Description
This function reparamterizes each random (deviations) term involving
devn.fac to a fixed term and ensures that the same term with
trend.num replacing devn.fac is included if any
other term with trend.num is included in terms. It also
ansures that any term with spl{trend.num} replacing
devn.fac in a term being reparameterized is removed from the model.
Usage
## S3 method for class 'asrtests'
reparamSigDevn(asrtests.obj,terms = NULL,
trend.num = NULL, devn.fac = NULL,
allow.unconverged = TRUE, allow.fixedcorrelation = TRUE,
checkboundaryonly = FALSE,
denDF = "numeric", IClikelihood = "none",
trace = FALSE, update = TRUE,
set.terms = NULL, ignore.suffices = TRUE,
bounds = "P", initial.values = NA,...)
Arguments
asrtests.obj |
an |
terms |
A character string vector giving the random terms that are to be reparameterized. |
trend.num |
A character string giving the name of the numeric covariate that
corresponds to |
devn.fac |
A character string giving the name of the factor that corresponds to
|
allow.unconverged |
A |
allow.fixedcorrelation |
A |
checkboundaryonly |
If |
denDF |
Specifies the method to use in computing approximate denominator
degrees of freedom when |
IClikelihood |
A |
trace |
If TRUE then partial iteration details are displayed when ASReml-R functions are invoked; if FALSE then no output is displayed. |
update |
If |
set.terms |
A character vector specifying the terms that are to have bounds and/or initial values set prior to fitting. |
ignore.suffices |
A logical vector specifying whether the suffices of the
|
bounds |
A |
initial.values |
A character vector specifying the initial values for
the terms specified in |
... |
further arguments passed to |
Value
An asrtests.object containing the components (i) asreml.obj,
(ii) wald.tab, and (iii) test.summary.
Author(s)
Chris Brien
References
Kenward, M. G., & Roger, J. H. (1997). Small sample inference for fixed effects from restricted maximum likelihood. Biometrics, 53, 983-997.
See Also
as.asrtests, changeTerms.asrtests,
testranfix.asrtests, testresidual.asrtests,
newfit.asreml, chooseModel.asrtests
Examples
## 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:Species:xDay +
Sources:Species:Date,
data = WaterRunoff.dat, keep.order = TRUE)
current.asrt <- as.asrtests(current.asr, NULL, NULL)
#Examine terms that describe just the interactions of Date and the treatment factors
terms.treat <- c("Sources", "Type", "Species", "Sources:Type", "Sources:Species")
date.terms <- sapply(terms.treat,
FUN=function(term){paste("Date:",term,sep="")},
simplify=TRUE)
date.terms <- c("Date", date.terms)
date.terms <- unname(date.terms)
treat.marginality <- matrix(c(1,0,0,0,0,0, 1,1,0,0,0,0, 1,0,1,0,0,0,
1,0,1,1,0,0, 1,1,1,0,1,0, 1,1,1,1,1,1), nrow=6)
rownames(treat.marginality) <- date.terms
colnames(treat.marginality) <- date.terms
choose <- chooseModel(current.asrt, treat.marginality, denDF="algebraic")
current.asrt <- choose$asrtests.obj
current.asr <- current.asrt$asreml.obj
sig.date.terms <- choose$sig.terms
#Remove all Date terms left in the fixed model
terms <- "(Date/(Sources * (Type + Species)))"
current.asrt <- changeTerms(current.asrt, dropFixed = terms)
#if there are significant date terms, reparameterize to xDays + spl(xDays) + Date
if (length(sig.date.terms) != 0)
{ #add lin + spl + devn for each to fixed and random models
trend.date.terms <- sapply(sig.date.terms,
FUN=function(term){sub("Date","xDay",term)},
simplify=TRUE)
trend.date.terms <- paste(trend.date.terms, collapse=" + ")
current.asrt <- changeTerms(current.asrt, addFixed=trend.date.terms)
trend.date.terms <- sapply(sig.date.terms,
FUN=function(term){sub("Date","spl(xDay)",term)},
simplify=TRUE)
trend.date.terms <- c(trend.date.terms, sig.date.terms)
trend.date.terms <- paste(trend.date.terms, collapse=" + ")
current.asrt <- changeTerms(current.asrt, addRandom = trend.date.terms)
current.asrt <- rmboundary(current.asrt)
}
#Now test terms for sig date terms
spl.terms <- sapply(terms.treat,
FUN=function(term){paste("spl(xDay):",term,sep="")},
simplify=TRUE)
spl.terms <- c("spl(xDay)",spl.terms)
lin.terms <- sapply(terms.treat,
FUN=function(term){paste(term,":xDay",sep="")},
simplify=TRUE)
lin.terms <- c("xDay",lin.terms)
systematic.terms <- c(terms.treat, lin.terms, spl.terms, date.terms)
systematic.terms <- unname(systematic.terms)
treat.marginality <- matrix(c(1,0,0,0,0,0, 1,1,0,0,0,0, 1,0,1,0,0,0,
1,0,1,1,0,0, 1,1,1,1,1,0, 1,1,1,1,1,1), nrow=6)
systematic.marginality <- kronecker(matrix(c(1,0,0,0, 1,1,0,0,
1,1,1,0, 1,1,1,1), nrow=4),
treat.marginality)
systematic.marginality <- systematic.marginality[-1, -1]
rownames(systematic.marginality) <- systematic.terms
colnames(systematic.marginality) <- systematic.terms
choose <- chooseModel(current.asrt, systematic.marginality,
denDF="algebraic", pos=TRUE)
current.asrt <- choose$asrtests.obj
#Check if any deviations are significant and, for those that are, go back to
#fixed dates
current.asrt <- reparamSigDevn(current.asrt, choose$sig.terms,
trend.num = "xDay", devn.fac = "Date",
denDF = "algebraic")
## End(Not run)
Removes any boundary or singular variance components from the fit stored in
asrtests.obj and records their removal in an asrtests.object.
Description
Any terms specified in the random model that are
estimated on the boundary or are singular and can be removed are removed from the fit
stored in the asreml object stored in the asrtests.object.
Terms that specify multiple parameters in the random model cannot be removed
(e.g. terms specified using the at function with more than one level of the
factor) and terms in residual model are not removed. Terms that can be removed
are selected for removal in the following order based on whether they involve:
(i) a dev function, (ii) only factors, (iii) an spl function,
(iv) a pol function and (v) a lin function or a variable that
is an integer or a numeric. It should be noted that this order of removal
presumes that random deviation terms are specified via the dev function
rather than via a random factor. Once the earliest of the above classes
with a boundary term is identified, a term within this class is selected for
removal. For all classes, except for factor-only terms, the smallest term
with the largest number of variables/factors is removed.
Amongst factor-only terms, the smallest term with the smallest number of
variables/factors is removed. After each
variance component is removed, a row for it is added to the
test.summary data.frame and the model refitted. If there are further
boundary or singular terms, one is removed using the above strategy.
This process continues until there are no further boundary or singular
variance components that are removable. Other types of boundary or singular terms,
which cannot be removed, are reported in warning messages.
Usage
## S3 method for class 'asrtests'
rmboundary(asrtests.obj, checkboundaryonly = FALSE,
IClikelihood = "none", trace = FALSE, update = TRUE,
set.terms = NULL, ignore.suffices = TRUE,
bounds = "P", initial.values = NA, ...)
Arguments
asrtests.obj |
an |
checkboundaryonly |
If |
IClikelihood |
A |
trace |
If |
update |
If |
set.terms |
A character vector specifying the terms that are to have
bounds and/or initial values set prior to fitting.
The names must match those in the |
ignore.suffices |
A logical vector specifying whether the suffices of the
|
bounds |
A |
initial.values |
A character vector specifying the initial values for
the terms specified in |
... |
Further arguments, including |
Value
An asrtests.object containing the components (i) asreml.obj,
(ii) wald.tab, and (iii) test.summary.
Author(s)
Chris Brien
See Also
as.asrtests, changeTerms.asrtests,
testranfix.asrtests, testresidual.asrtests,
newfit.asreml, reparamSigDevn.asrtests,
chooseModel.asrtests
Examples
## Not run:
current.asrt <- rmboundary(current.asrt)
## End(Not run)
allows the setting of bounds and initial values for terms in the
random and residual arguments of an asreml call, with
the resulting call being evaluated.
Description
Takes an unevaluated call and evaluates the call
after setting the bounds and initial values for the terms
specified in terms. The elements of terms are matched
with those generated by asreml and used, for example, in the
varcomp component of a summary.asreml object.
These names generally include descriptive suffices. To match an
element of terms that includes such a suffix, set
ignore.suffices to FALSE so that a literal match
between the element and the assigned names is sought.
Note that the terms, bounds and initial.values
are stored on entry in a data.frame, named setvparameters,
as a component in call that is itself a component of the asreml.obj
that is returned. The data.frame setvparameters contains all of
the values of terms, ignore.suffices, bounds
and initial.values that have been set in this and previous calls to
setvarianceterms.call and other model modification and selection functions in
asremlPlus, for example changeModelOnIC.asrtests,
testranfix.asrtests and changeTerms.asrtests. It is used in subsequent calls to
model modification and selection functions to ensure that the bounds and initial
values that have been set are retained in new model fits.
Usage
## S3 method for class 'call'
setvarianceterms(call, terms, ignore.suffices = TRUE,
bounds = "P", initial.values = NA, ...)
Arguments
call |
an unevaluated |
terms |
A character vector specifying the terms
that are to have bounds and/or initial values specified.
The names must match those in the |
ignore.suffices |
A logical vector specifying whether the suffices of the
|
bounds |
A The codes used by ASReml are:
|
initial.values |
A character vector specifying the initial values for
the terms specified in |
... |
additional arguments to be added to the asreml call, or arguments in the asreml call with changed values. |
Value
An asreml object, with the updated setvparameters data.frame,
stored in the call component of the asreml object.
Author(s)
Chris Brien
References
Butler, D. G., Cullis, B. R., Gilmour, A. R., Gogel, B. J. and Thompson, R. (2023). ASReml-R Reference Manual Version 4.2. VSN International Ltd, https://asreml.kb.vsni.co.uk/.
See Also
newfit.asreml, update.asreml
Examples
## Not run:
m1.call <- call("asreml",
fixed = Height ~ (Block + Irrig)*csDay.num,
random= ~ spl(csDay.num)/(Irrig+Block)
+ dev(csDay.num)
+ str(~Block:Plot/csDay.num, ~us(2):id(20))
+ Block:Plot:spl(csDay.num),
data=quote(dat)) ##use quote to stop evaluation of dat here
terms <- c("Block:Plot+Block:Plot:csDay.num!us(2).2:1", "R!variance")
m1.asreml <- setvarianceterms(m1.call, terms, bounds=c("U","P"),
initial=c(NA,3), ignore.suffices=c(FALSE,TRUE))
summary(m1.asreml)
## End(Not run)
Produce sets of simulated data from a multivariate normal distribution and save quantities related to the simulated data
Description
Produce in parallel sets of simulated data corresponding to an asreml model,
along with its fitted values and residuals. A variance matrix V,
corresponding to the random and residual models must be
supplied. What to save is specified by the which argument.
Usage
## S3 method for class 'asreml'
simulate(object, nsim=100, seed = NULL, means=NULL, V, tolerance = 1E-10,
update = TRUE, trace = FALSE, which="data", units = "ignore",
ncores = 2, ...)
Arguments
object |
An |
means |
The |
V |
The fitted variance |
nsim |
The number of data sets to be simulated. |
seed |
A single value, interpreted as an integer, that specifies the
starting value of the random number generator. The "L'Ecuyer-CMRG" random
generator is used and |
tolerance |
The value such that eigenvalues less than it are considered to be zero. |
update |
If |
trace |
If |
which |
The quantities from the simulated data set to be stored. Any combination of
|
units |
A |
ncores |
A |
... |
Other arguments that are passed down to the function asreml. Changes to the models are not allowed. Other changes are dangerous and generally should be avoided. |
Details
Generate nsim sets of data and analyse them using asreml
using the model in object, performing the generation and analysis of several
sets in parallel. Note, if the analysis for a data set does
not converge in maxiter iterations, it is discarded and
a replacement data set generated. The value of maxiter can be specified
in the call to simulate.asreml. The fitted values and residuals are extracted
as required. If aom = TRUE when the simulated data are analysed, standardised
conditional residuals are stored. If which includes residuals or
fitted, the specified quantities for the observed data are added to the
data.frame on which the fit in object is based.
Value
A list with the following components whose presence depends on the setting of
which:
observed: present if
whichincludesresidualsorfitted, in which case it will be thedata.frameon which the fit inobjectis based, withresidualsand/orfitted.data: present if
whichincludesdata, adata.framecontaining the simulated data sets.fitted: present if
whichincludesfitted, adata.framecontaining the fitted values from the analyses of the simulated data sets.residuals: present if
whichincludesresiduals, adata.framecontaining the residuals from the analyses of the simulated data sets.
Author(s)
Chris Brien
See Also
asreml, newfit.asreml, variofaces.asreml, plotVariofaces.data.frame,
set.seed.
Examples
## Not run:
data(Wheat.dat)
current.asr <- asreml(yield ~ Rep + WithinColPairs + Variety,
random = ~ Row + Column + units,
residual = ~ ar1(Row):ar1(Column),
data=Wheat.dat)
current.asrt <- as.asrtests(current.asr, NULL, NULL)
current.asrt <- rmboundary.asrtests(current.asrt)
# Form variance matrix based on estimated variance parameters
s2 <- current.asr$sigma2
gamma.Row <- current.asr$gammas[1]
gamma.unit <- current.asr$gammas[2]
rho.r <- current.asr$gammas[4]
rho.c <- current.asr$gammas[5]
row.ar1 <- mat.ar1(order=10, rho=rho.r)
col.ar1 <- mat.ar1(order=15, rho=rho.c)
V <- gamma.Row * fac.sumop(Wheat.dat$Row) +
gamma.unit * diag(1, nrow=150, ncol=150) +
mat.dirprod(col.ar1, row.ar1)
V <- s2*V
#Produce residuals from 100 simulated data sets
resid <- simulate(current.asr, V=V, which="residuals", ncores = parallel::detectCores())
## End(Not run)
Sorts the components in an alldiffs.object according to the predicted values
associated with a factor.
Description
Sorts the rows of the components in an alldiffs.object
(see as.alldiffs) that are data.frames and the rows and columns
of those that are matrices according to the predicted values in the
predictions component. 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 all components are sorted
according to the order of the complete set of predictions.
Note that renewClassify.alldiffs is called after sorting to ensure that
the order of the rows and columns of the components is in standard order for the new
variable order.
Usage
## S3 method for class 'alldiffs'
sort(x, decreasing = FALSE, classify = NULL, sortFactor = NULL,
sortParallelToCombo = NULL, sortNestingFactor = NULL,
sortOrder = NULL, ...)
Arguments
x |
An |
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 and, if present, backtransforms components 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 alldiffs.object supplied with the following components,
if present, sorted: predictions, vcov, backtransforms, differences,
p.differences and sed. Also, the sortFactor and sortOrder
attributes are set.
Author(s)
Chris Brien
See Also
as.alldiffs, allDifferences.data.frame,
print.alldiffs,
sort.predictions.frame, renewClassify.alldiffs,
redoErrorIntervals.alldiffs,
recalcLSD.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.alldiffs and save order for use with other response variables
TS.diffs.sort <- sort(TS.diffs, sortFactor = "Sources",
sortParallelToCombo = list(Type = "Control"))
sort.order <- attr(TS.diffs.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
diffs2.sort <- predictPlus(m2.asr, classify = "Sources:Type",
pairwise = FALSE, error.intervals = "Stand",
tables = "none", present = c("Type","Species","Sources"),
sortFactor = "Sources",
sortOrder = 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"))
## Form an all.diffs object and check its validity
TS.vcov <- vcov(TS.emm)
TS.diffs <- allDifferences(predictions = TS.preds,
classify = "Sources:Type",
vcov = TS.vcov, tdf = den.df)
validAlldiffs(TS.diffs)
#Use sort.alldiffs and save order for use with other response variables
TS.diffs.sort <- sort(TS.diffs, sortFactor = "Sources",
sortParallelToCombo = list(Type = "Control"))
sort.order <- attr(TS.diffs.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"))
## Form an all.diffs object, sorting it using the pH sort.order and check its validity
TS.vcov <- vcov(TS.emm)
TS.diffs2.sort <- allDifferences(predictions = TS.preds,
classify = "Sources:Type",
vcov = TS.vcov, tdf = den.df,
sortFactor = "Sources",
sortOrder = sort.order)
validAlldiffs(TS.diffs2.sort)
}
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"))
}
Subsets the components in an alldiffs.object according to the supplied condition.
Description
Subsets each of the components of an alldiffs.object. The subset is
determined by applying the condition to the prediction component to
determine which of its rows are to be included in the subset. Then, if present,
this subset is applied to the rows of backtransforms and to the rows
and columns of differences, p.differences and sed
components. In addition, if sed is present, recalcLSD.alldiffs
is called to recalculate the values in the LSD.frame stored in the
LSD component, with any arguments supplied via the ...
argument passed ot it.
The select argument of subset is not implemented, but can be
achieved for variables in the classify using the rmClassifyVars
argument.
Usage
## S3 method for class 'alldiffs'
subset(x, subset = rep(TRUE, nrow(x$predictions)),
rmClassifyVars = NULL, ...)
Arguments
x |
An |
subset |
A |
rmClassifyVars |
A |
... |
further arguments passed to |
Value
An alldiffs.object with the following components of the supplied
alldiffs.object subsetted, if present in the original object:
predictions, vcov, backtransforms, differences,
p.differences and sed. In addition, if sed is present, the
LSD.frame in the LSD component will be recalculated.
Author(s)
Chris Brien
See Also
as.alldiffs, allDifferences.data.frame,
print.alldiffs, sort.alldiffs,
redoErrorIntervals.alldiffs, recalcLSD.alldiffs,
predictPlus.asreml, predictPresent.asreml
Examples
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)
TS.diffs <- predictPlus.asreml(classify = "Sources:Type",
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 * (Type + Species)) +
(1|Benches:MainPlots),
data=na.omit(WaterRunoff.dat))
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"))
## Form an all.diffs object and check its validity
TS.vcov <- vcov(TS.emm)
TS.diffs <- allDifferences(predictions = TS.preds, classify = "Sources:Type",
vcov = TS.vcov, tdf = den.df)
validAlldiffs(TS.diffs)
}
## Plot p-values for predictions obtained using asreml or lmerTest
if (exists("TS.diffs"))
{
##Use subset.alldiffs to select a subset of the alldiffs object
TS.diffs.subs <- subset(TS.diffs,
subset = grepl("R", Sources, fixed = TRUE) &
Type %in% c("Control","Medicinal"))
}
Forms a list that contains a subset of the components of the supplied
list.
Description
Select components of a list specified by a list of numbers or names,
or by a logical indicating for each component of the list whether or not it is to
be retained.
Usage
## S3 method for class 'list'
subset(x, select = 1:length(x), ...)
Arguments
x |
An |
select |
A |
... |
further arguments passed to or from other methods. Not used at present. |
Value
A list with just the subset of the components from x. If the
components of x are named, then these names are retained in the subset
list.
Author(s)
Chris Brien
See Also
Examples
x <- list(1:3,letters[1:3],LETTERS[1:3])
y <- subset.list(x, select = c(1,3))
y <- subset.list(x, select = c(TRUE,FALSE,TRUE))
names(x) <- LETTERS[1:3]
y <- subset.list(x, select = c(1,3))
z <- subset.list(x, select = LETTERS[c(1,3)])
x <- list(1:3,letters[1:3],LETTERS[1:3])
names(x)[c(1,3)] <- LETTERS[c(1,3)]
z <- subset.list(x, select = c(1,2))
v <- subset.list(x)
Tests for a single fixed or random term in model fitted using asreml
and records the result in an asrtests.object.
Description
Tests for a single term, using a REML ratio test (REMLRT) for a random term or based
on Wald statistics for a fixed term. The term must be in the fitted model.
A random term is removed from the model fit and a REMLRT is
performed using REMLRT.asreml. It compares the fit of the model in
asreml.obj and the newly fitted model without the term.
If the newly fitted model is retained, any boundary terms are then removed
using rmboundary.asrtests.
For a fixed term, the probability of the Wald
statistics is extracted from the pseudo-anova table produced by
wald.asreml. If this is available in the asrtests.object, it is
used; otherwise wald.asreml is called to add it to the
asrtests.object. Whether nonsignificant terms are dropped is controlled
by drop.ran.ns for random terms and drop.fix.ns for fixed terms. A row is
added to the test.summary data.frame for the term that is tested.
Usage
## S3 method for class 'asrtests'
testranfix(asrtests.obj, term=NULL, alpha = 0.05,
allow.unconverged = TRUE, allow.fixedcorrelation = TRUE,
checkboundaryonly = FALSE,
drop.ran.ns = TRUE, positive.zero = FALSE,
bound.test.parameters = "none",
bound.exclusions = c("F","B","S","C"), REMLDF = NULL,
drop.fix.ns = FALSE, denDF="numeric", dDF.fault = "none",
dDF.values = NULL, IClikelihood = "none",
trace = FALSE, update = TRUE,
set.terms = NULL, ignore.suffices = TRUE,
bounds = "P", initial.values = NA, ...)
Arguments
asrtests.obj |
An |
term |
A single model term that is valid in |
alpha |
The significance level for the test. |
allow.unconverged |
A |
allow.fixedcorrelation |
A |
checkboundaryonly |
If |
drop.ran.ns |
A |
positive.zero |
Indicates whether the hypothesized values for the
variance components being tested are on the boundary
of the parameter space. For example, this is true
for positively-constrained variance components that,
under the reduced model, are zero. This argument does
not need to be set if |
bound.test.parameters |
Indicates whether for the variance components
being tested, at least some of the hypothesized values
are on the boundary of the parameter space.
The possibilities are |
bound.exclusions |
A |
REMLDF |
A |
drop.fix.ns |
A |
denDF |
Specifies the method to use in computing approximate denominator
degrees of freedom when |
dDF.fault |
A |
dDF.values |
A |
IClikelihood |
A |
trace |
If TRUE then partial iteration details are displayed when ASReml-R functions are invoked; if FALSE then no output is displayed. |
update |
If |
set.terms |
A character vector specifying the terms that are to have
bounds and/or initial values set prior to fitting.
The names must match those in the |
ignore.suffices |
A logical vector specifying whether the suffices of the
|
bounds |
A |
initial.values |
A character vector specifying the initial values for
the terms specified in |
... |
Further arguments passed to |
Value
An asrtests.object containing the components (i) asreml.obj,
(ii) wald.tab, and (iii) test.summary.
If the term is not in the model, then the supplied asreml
object will be returned. Also, reml.test will have the likelihood
ratio and the p-value set to NA and the degrees of freedom to zero.
Similarly, the row of test.summary for the term will have
its name, DF set to NA, p-value set to NA, and action set to Absent.
Author(s)
Chris Brien
References
Kenward, M. G., & Roger, J. H. (1997). Small sample inference for fixed effects from restricted maximum likelihood. Biometrics, 53, 983-997.
See Also
asremlPlus-package, as.asrtests,
chooseModel.asrtests, REMLRT.asreml,
rmboundary.asrtests,
newfit.asreml, changeModelOnIC.asrtests,
changeTerms.asrtests, reparamSigDevn.asrtests
Examples
## Not run:
data(Wheat.dat)
current.asr <- asreml(yield ~ Rep + WithinColPairs + Variety,
random = ~ Row + Column + units,
residual = ~ ar1(Row):ar1(Column),
data=Wheat.dat)
current.asrt <- as.asrtests(current.asr, NULL, NULL)
current.asrt <- rmboundary(current.asrt)
# Test nugget term
current.asrt <- testranfix(current.asrt, "units", positive=TRUE)
## End(Not run)
Fits a new residual formula, tests whether the change
is significant and records the result in an asrtests.object.
Description
Fits a new residual formula using asreml-R4
(replaces the rcov formula of asreml-R3) and tests
whether the change is significant. If simpler = FALSE the model
to be fitted must be more complex than the one whose fit has been stored in
asrtests.obj. That is, the new model must have more parameters.
However, if simpler = TRUE the model to be fitted must be simpler
than the one whose fit has been stored in asrtests.obj in that it
must have fewer parameters. Any boundary terms are removed using
rmboundary.asrtests, which may mean that the models are not
nested. The test is a REML likelihood ratio test that is performed using
REMLRT.asreml, which is only valid if the models are nested.
It compares the newly fitted model with the fit of the model in
asrtest.obj. If the two models have the same number of variance
parameters, then no change is made to the residual. A row is added to the
test.summary data.frame using the supplied label.
Usage
## S3 method for class 'asrtests'
testresidual(asrtests.obj, terms=NULL, label = "R model",
simpler = FALSE, alpha = 0.05,
allow.unconverged = TRUE, allow.fixedcorrelation = TRUE,
checkboundaryonly = FALSE, positive.zero = FALSE,
bound.test.parameters = "none",
bound.exclusions = c("F","B","S","C"), REMLDF = NULL,
denDF="numeric", IClikelihood = "none",
update = TRUE, trace = FALSE,
set.terms = NULL, ignore.suffices = TRUE,
bounds = "P", initial.values = NA, ...)
Arguments
asrtests.obj |
an |
terms |
A model for the |
label |
A character string to use as the label in |
simpler |
A logical indicating whether the new model to be fitted is
simpler than the already fitted model whose fit is stored in
|
alpha |
The significance level for the test. |
allow.unconverged |
A |
allow.fixedcorrelation |
A |
checkboundaryonly |
If |
positive.zero |
Indicates whether the hypothesized values for the
variance components being tested are on the boundary
of the parameter space. For example, this is true
for positively-constrained variance components that,
under the reduced model, are zero. This argument does
not need to be set if |
bound.test.parameters |
Indicates whether for the variance components
being tested, at least some of the hypothesized values
are on the boundary of the parameter space.
The possibilities are |
bound.exclusions |
A |
REMLDF |
A |
denDF |
Specifies the method to use in computing approximate denominator
degrees of freedom when |
IClikelihood |
A |
update |
If |
trace |
If |
set.terms |
A |
ignore.suffices |
A |
bounds |
A |
initial.values |
A character vector specifying the initial values for
the terms specified in |
... |
Further arguments passed to |
Value
An asrtests.object containing the components (i) asreml.obj,
(ii) wald.tab, and (iii) test.summary.
If the term is not in the model, then the supplied asreml.obj
will be returned. Also, reml.test will have the likelihood
ratio and the p-value set to NA and the degrees of freedom to zero.
Similarly, the row of test.summary for the term will have
its name, a p-value set to NA, and action set to Absent.
Author(s)
Chris Brien
References
Kenward, M. G., & Roger, J. H. (1997). Small sample inference for fixed effects from restricted maximum likelihood. Biometrics, 53, 983-997.
See Also
asremlPlus-package, as.asrtests, changeTerms.asrtests,
chooseModel.asrtests,
REMLRT.asreml, rmboundary.asrtests,
newfit.asreml, testswapran.asrtests,
changeModelOnIC.asrtests,
changeTerms.asrtests, reparamSigDevn.asrtests
Examples
## Not run:
data(Wheat.dat)
current.asr <- asreml(yield ~ Rep + WithinColPairs + Variety,
random = ~ Row + Column + units,
residual = ~ ar1(Row):ar1(Column),
data=Wheat.dat)
current.asrt <- as.asrtests(current.asr, NULL, NULL)
current.asrt <- rmboundary(current.asrt)
# Test Row autocorrelation
current.asrt <- testresidual(current.asrt, "~ Row:ar1(Column)",
label="Row autocorrelation", simpler=TRUE)
print(current.asrt)
## End(Not run)
Tests, using a REMLRT, the significance of the difference between the current
random model and one in which oldterms are dropped and newterms are added.
The result is recorded in an asrtests.object.
Description
Fits a new random model using asreml by removing oldterms
and adding newterms. If simpler = FALSE the model to be fitted
must be more complex than the one whose fit has been stored in
asrtests.obj. That is, the new model must have more parameters.
However, if simpler = TRUE the model to be fitted must be simpler
than the one whose fit has been stored in asrtests.obj in that it
must have fewer parameters. The test is a REML ratio test that is performed using
REMLRT.asreml, which is only valid if the models are nested.
It compares the newly fitted model with the fit of the model in
asrtests.obj. A row is added to the test.summary
data.frame using the supplied label. If the newly fitted model
is retained, any boundary terms are then removed using
rmboundary.asrtests. If the models are not nested, then using
changeModelOnIC.asrtests may be the more appropriate approach
for comparing models.
Usage
## S3 method for class 'asrtests'
testswapran(asrtests.obj, oldterms = NULL, newterms = NULL,
label = "Swap in random model", simpler = FALSE, alpha = 0.05,
allow.unconverged = TRUE, allow.fixedcorrelation = TRUE,
checkboundaryonly = FALSE,
positive.zero = FALSE, bound.test.parameters = "none",
bound.exclusions = c("F","B","S","C"), REMLDF = NULL,
denDF="numeric", IClikelihood = "none",
trace = FALSE, update = TRUE,
set.terms = NULL, ignore.suffices = TRUE,
bounds = "P", initial.values = NA, ...)
Arguments
asrtests.obj |
an |
oldterms |
Terms, stored as a |
newterms |
Terms, stored as a |
simpler |
A logical indicating whether the new model to be fitted. after the
changes made as a result of swapping |
alpha |
The significance level for the test. |
allow.unconverged |
A |
allow.fixedcorrelation |
A |
checkboundaryonly |
If |
label |
A character string to use as the label in |
positive.zero |
Indicates whether the hypothesized values for the
variance components being tested are on the boundary
of the parameter space. For example, this is true
for positively-constrained variance components that,
under the reduced model, are zero. This argument does
not need to be set if |
bound.test.parameters |
Indicates whether for the variance components
being tested, at least some of the hypothesized values
are on the boundary of the parameter space.
The possibilities are |
bound.exclusions |
A |
REMLDF |
A |
denDF |
Specifies the method to use in computing approximate denominator
degrees of freedom when |
IClikelihood |
A |
trace |
If TRUE then partial iteration details are displayed when ASReml-R functions are invoked; if FALSE then no output is displayed. |
update |
If |
set.terms |
A character vector specifying the terms that are to have
bounds and/or initial values set prior to fitting.
The names must match those in the |
ignore.suffices |
A logical vector specifying whether the suffices of the
|
bounds |
A |
initial.values |
A character vector specifying the initial values for
the terms specified in |
... |
Further arguments passed to |
Value
An asrtests.object for a fitted model that is a list
containing the components (i) asreml.obj, (ii) wald.tab
(iii) test.summary.
If the term is not in the model, then the supplied asreml
object will be returned. Also, reml.test will have the likelihood
ratio and the p-value set to NA and the degrees of freedom to zero.
Similarly, the row of test.summary for the term will have
its name, a p-value set to NA, and action set to Absent.
Author(s)
Chris Brien
References
Kenward, M. G., & Roger, J. H. (1997). Small sample inference for fixed effects from restricted maximum likelihood. Biometrics, 53, 983-997.
See Also
as.asrtests, chooseModel.asrtests,
REMLRT.asreml, rmboundary.asrtests,
newfit.asreml, testresidual.asrtests,
changeModelOnIC.asrtests,
changeTerms.asrtests, reparamSigDevn.asrtests
Examples
## Not run:
current.asrt <- testswapran(current.asrt, oldterms = "str(~ Cart/xDays, ~us(2):id(184))",
newterms = "Cart/xDays", pos = FALSE,
label = "Intercept/Slope correlation",
simpler = TRUE)
print(current.asrt)
## End(Not run)
Checks that an object is a valid alldiffs object.
Description
Checks that an object is an alldiffs.object of S3-class
alldiffs containing the components asreml.obj,
wald.tab and test.summary.
Usage
validAlldiffs(object)
Arguments
object |
an |
Value
TRUE or a character describing why the object
is not a valid alldiffs.object.
Author(s)
Chris Brien
See Also
alldiffs.object, is.alldiffs, as.alldiffs,
validPredictionsFrame, validAsrtests
Examples
data(Oats.dat)
## 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
## Form an all.diffs object
Var.diffs <- as.alldiffs(predictions = Var.preds, classify = "Nitrogen:Variety",
sed = Var.sed, vcov = Var.vcov, tdf = den.df)
## check the validity of Var.diffs
validAlldiffs(Var.diffs)
}
Checks that an object is a valid asrtests object.
Description
Checks that an object is an asrtests.object of S3-class
asrtests containing the components asreml.obj,
wald.tab and test.summary.
Usage
validAsrtests(object)
Arguments
object |
an |
Value
TRUE or a character describing why the object
is not a valid asrtests.object.
Author(s)
Chris Brien
See Also
asrtests.object, is.asrtests, as.asrtests,
validPredictionsFrame, validAlldiffs
Examples
## Not run:
library(dae)
library(asreml)
library(asremlPlus)
## use ?Wheat.dat for data set details
data(Wheat.dat)
# Fit initial model
current.asr <- asreml(yield ~ Rep + WithinColPairs + Variety,
random = ~ Row + Column + units,
residual = ~ ar1(Row):ar1(Column),
data=Wheat.dat)
# Load current fit into an asrtests object
current.asrt <- as.asrtests(current.asr, NULL, NULL)
# check validity of current.asrt
validAsrtests(current.asrt)
## End(Not run)
Checks that an object is a valid predictions.frame.
Description
Checks that an object is a predictions.frame
of S3-class data.frame that contains the columns
predicted.value, standard.error and est.status.
Usage
validPredictionsFrame(object)
Arguments
object |
Value
TRUE or a character describing why the object
is not a valid predictions.frame.
Author(s)
Chris Brien
See Also
predictions.frame, is.predictions.frame,
as.predictions.frame,
validAsrtests, validAlldiffs
Examples
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 <- as.predictions.frame(Var.pred$pvals, se = "std.error",
est.status = "status")
## End(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)
Var.preds <- as.predictions.frame(Var.preds, predictions = "emmean",
se = "SE", interval.type = "CI",
interval.names = c("lower.CL", "upper.CL"))
}
if (exists("Var.preds"))
{
## Check the class and validity of the predictions.frame
is.predictions.frame(Var.preds)
validPredictionsFrame(Var.preds)
}
Plots empirical variogram faces, including envelopes, as described by Stefanova, Smith & Cullis (2009).
Description
A function that produces a plot for each face of an empirical 2D
variogram based on residuals produced after the fitting of a model
using the function asreml.
It also adds envelopes to the plot by simulating data sets in parallel
from a multivariate normal distribution with expectation equal to the
fitted values obtained from the fixed and spline terms and variance
matrix equal to the fitted variance matrix
(Stefanova, Smith & Cullis, 2009). The plot is controlled by the
residual model, which must consist of two factors corresponding to
the two physical dimensions underlying the data. It can also have a third
term involving the at or dsum function that defines sections
of the data, such as experiments in different environments.
In this case, the two variogram faces are produced for each section.
Usage
## S3 method for class 'asreml'
variofaces(asreml.obj, means=NULL, V=NULL,
sections = NULL, row.factor = NULL, col.factor = NULL,
nsim=100, seed = NULL,
extra.matrix = NULL, ignore.terms = NULL, fixed.spline.terms = NULL,
bound.exclusions = c("F","B","S","C"), tolerance=1E-10,
units = "ignore", update = TRUE, trace = FALSE,
graphics.device=NULL, ncores = 2, ...)
Arguments
asreml.obj |
An |
means |
The |
V |
The fitted variance |
sections |
A single |
row.factor |
A single |
col.factor |
A single |
nsim |
The number of data sets to be simulated in obtaining the envelopes. |
seed |
A single value, interpreted as an integer, that specifies the
starting value of the random number generator. The "L'Ecuyer-CMRG" random
generator is used and |
extra.matrix |
A |
ignore.terms |
A |
fixed.spline.terms |
A |
bound.exclusions |
A |
tolerance |
The value such that eigenvalues less than it are considered to be zero. |
units |
A |
update |
If |
trace |
If TRUE then partial iteration details are displayed when ASReml-R functions are invoked; if FALSE then no output is displayed. |
graphics.device |
A |
ncores |
A |
... |
Other arguments that are passed down to the function |
Details
The residual model is scanned to ensure that it involves only two factors
not included in the at function, and to see if it has a third factor in
an at function. If so, the faces of the 2D variogram, each based on one
of the two non-at factors, are derived from the residuals in the
supplied asreml object using asreml.variogram, this yielding the observed
variogram faces. If aom was set to TRUE for the asreml
object, the standardized conditional residuals are used.
Then nsim data sets are generated by
adding the fitted.values, extracted from the asreml object,
to a vector of values randomly generated from a normal distribution with
expectation zero and variance matrix V. Each data set is analyzed
using the model in object and several sets are generated and analyzed
in parallel. The variogram values for the faces are
obtained using asreml.variogram stored. Note, if the analysis for a
data set does not converge in maxiter iterations, it is discarded and
a replacement data set generated. The value of maxiter can be specified
in the call to variofaces.asreml. Plots are produced for each face and
include the observed values and the 2.5%, 50% & 97.5% quantiles.
Value
A list with the following components:
face1: a
data.framecontaining the variogram values on which the plot for the first dimension is based.face2: a
data.framecontaining the variogram values on which the plot for the second dimension is based.
Author(s)
Chris Brien
References
Stefanova, K. T., Smith, A. B. & Cullis, B. R. (2009) Enhanced diagnostics for the spatial analysis of field trials. Journal of Agricultural, Biological, and Environmental Statistics, 14, 392–410.
See Also
asremlPlus-package, asreml, newfit.asreml,
plotVariofaces.data.frame, simulate.asreml, set.seed.
Examples
## Not run:
data(Wheat.dat)
current.asr <- asreml(yield ~ Rep + WithinColPairs + Variety,
random = ~ Row + Column + units,
residual = ~ ar1(Row):ar1(Column),
data=Wheat.dat)
current.asrt <- as.asrtests(current.asr, NULL, NULL)
current.asrt <- rmboundary.asrtests(current.asrt)
# Form variance matrix based on estimated variance parameters
s2 <- current.asr$sigma2
gamma.Row <- current.asr$gammas[1]
gamma.unit <- current.asr$gammas[2]
rho.r <- current.asr$gammas[4]
rho.c <- current.asr$gammas[5]
row.ar1 <- mat.ar1(order=10, rho=rho.r)
col.ar1 <- mat.ar1(order=15, rho=rho.c)
V <- gamma.Row * fac.sumop(Wheat.dat$Row) +
gamma.unit * diag(1, nrow=150, ncol=150) +
mat.dirprod(col.ar1, row.ar1)
V <- s2*V
#Produce variogram faces plot (Stefanaova et al, 2009)
variofaces(current.asr, V=V, ncores = parallel::detectCores())
## End(Not run)