Title: | Functions to Assist Design and Analysis of Agronomic Experiments |
---|---|
Description: | Provides functions to aid in the design and analysis of agronomic and agricultural experiments through easy access to documentation and helper functions, especially for users who are learning these concepts. While not required for most functionality, this package enhances the `asreml` package which provides a computationally efficient algorithm for fitting mixed models using Residual Maximum Likelihood. It is a commercial package that can be purchased as 'asreml-R' from 'VSNi' <https://vsni.co.uk/>, who will supply a zip file for local installation/updating (see <https://asreml.kb.vsni.co.uk/>). |
Authors: | Sharon Nielsen [aut], Sam Rogers [aut, cre], Annie Conway [aut], University of Adelaide [cph, fnd] (https://adelaide.edu.au/), Grains Research and Development Corporation [cph, fnd] (https://grdc.com.au/) |
Maintainer: | Sam Rogers <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.2.1 |
Built: | 2025-02-11 05:13:21 UTC |
Source: | https://github.com/biometryhub/biometryassist |
Generate automatic plots for objects generated in biometryassist
autoplot(object, ...) ## S3 method for class 'mct' autoplot( object, size = 4, label_height = 0.1, rotation = 0, axis_rotation = rotation, label_rotation = rotation, ... ) ## S3 method for class 'design' autoplot( object, rotation = 0, size = 4, margin = FALSE, palette = "default", buffer = NULL, row = NULL, column = NULL, block = NULL, treatments = NULL, ... )
autoplot(object, ...) ## S3 method for class 'mct' autoplot( object, size = 4, label_height = 0.1, rotation = 0, axis_rotation = rotation, label_rotation = rotation, ... ) ## S3 method for class 'design' autoplot( object, rotation = 0, size = 4, margin = FALSE, palette = "default", buffer = NULL, row = NULL, column = NULL, block = NULL, treatments = NULL, ... )
object |
An object to create a plot for. Currently objects from the |
... |
Arguments passed to methods. |
size |
Increase or decrease the text size within the plot for treatment labels. Numeric with default value of 4. |
label_height |
Height of the text labels above the upper error bar on the plot. Default is 0.1 (10%) of the difference between upper and lower error bars above the top error bar. Values > 1 are interpreted as the actual value above the upper error bar. |
rotation |
Rotate the x axis labels and the treatment group labels within the plot. Allows for easier reading of long axis or treatment labels. Number between 0 and 360 (inclusive) - default 0 |
axis_rotation |
Enables rotation of the x axis independently of the group labels within the plot. |
label_rotation |
Enables rotation of the treatment group labels independently of the x axis labels within the plot. |
margin |
Logical (default |
palette |
A string specifying the colour scheme to use for plotting. Default is equivalent to "Spectral". Colour blind friendly palettes can also be provided via options |
buffer |
A string specifying the buffer plots to include for plotting. Default is |
row |
A variable to plot a column from |
column |
A variable to plot a column from |
block |
A variable to plot a column from |
treatments |
A variable to plot a column from |
A ggplot2
object.
multiple_comparisons()
and design()
dat.aov <- aov(Petal.Width ~ Species, data = iris) output <- multiple_comparisons(dat.aov, classify = "Species") autoplot(output, label_height = 0.5) des.out <- design(type = "crd", treatments = c(1, 5, 10, 20), reps = 5, nrows = 4, ncols = 5, seed = 42, plot = FALSE) autoplot(des.out) # Colour blind friendly colours autoplot(des.out, palette = "colour-blind") # Alternative colour scheme autoplot(des.out, palette = "plasma")
dat.aov <- aov(Petal.Width ~ Species, data = iris) output <- multiple_comparisons(dat.aov, classify = "Species") autoplot(output, label_height = 0.5) des.out <- design(type = "crd", treatments = c(1, 5, 10, 20), reps = 5, nrows = 4, ncols = 5, seed = 42, plot = FALSE) autoplot(des.out) # Colour blind friendly colours autoplot(des.out, palette = "colour-blind") # Alternative colour scheme autoplot(des.out, palette = "plasma")
Produce a graph of design layout, skeletal ANOVA table and data frame with complete design
des_info( design.obj, nrows, ncols, brows = NA, bcols = NA, byrow = TRUE, fac.names = NULL, fac.sep = c("", " "), plot = TRUE, rotation = 0, size = 4, margin = FALSE, save = FALSE, savename = paste0(design.obj$parameters$design, "_design"), plottype = "pdf", return.seed = TRUE, quiet = FALSE, ... )
des_info( design.obj, nrows, ncols, brows = NA, bcols = NA, byrow = TRUE, fac.names = NULL, fac.sep = c("", " "), plot = TRUE, rotation = 0, size = 4, margin = FALSE, save = FALSE, savename = paste0(design.obj$parameters$design, "_design"), plottype = "pdf", return.seed = TRUE, quiet = FALSE, ... )
design.obj |
An |
nrows |
The number of rows in the design. |
ncols |
The number of columns in the design. |
brows |
For RCBD only. The number of rows in a block. |
bcols |
For RCBD only. The number of columns in a block. |
byrow |
For split-plot only. Logical (default: |
fac.names |
Allows renaming of the |
fac.sep |
The separator used by |
plot |
Logical (default |
rotation |
Rotate the text output as Treatments within the plot. Allows for easier reading of long treatment labels. Takes positive and negative values being number of degrees of rotation from horizontal. |
size |
Increase or decrease the text size within the plot for treatment labels. Numeric with default value of 4. |
margin |
Logical (default FALSE). Setting to |
save |
One of |
savename |
A filename for the design to be saved to. Default is the type of the design combined with "_design". |
plottype |
The type of file to save the plot as. Usually one of |
return.seed |
Logical (default TRUE). Output the seed used in the design? |
quiet |
Logical (default FALSE). Return the objects without printing output. |
... |
Additional parameters passed to |
If save = TRUE
(or "both"
), both the plot and the workbook will be saved to the current working directory, with filename given by savename
. If one of either "plot"
or "workbook"
is specified, only that output is saved. If save = FALSE
(the default, or equivalently "none"
), nothing will be output.
fac.names
can be supplied to provide more intuitive names for factors and their levels in factorial designs. They should be specified in a list format, for example fac.names = list(A_names = c("a", "b", "c"), B_names = c("x", "y", "z"))
. This will result a design output with a column named A_names
with levels a, b, c
and another named B_names
with levels x, y, z
. Only the first two elements of the list will be used.
If fac.sep
is a single element (e.g. ""), this is used to separate all factor labels (e.g. A_1_B_1). If it is two elements (e.g. c("", "")), the first element separates the factor names and their levels, and the second level separates the two factors (e.g. A1_B1).
...
allows extra arguments to be passed to ggsave for output of the plot. The details of possible arguments can be found in ggplot2::ggsave()
.
A list containing a data frame with the complete design, a ggplot object with plot layout, the seed (if return.seed = TRUE
), and the satab
object, allowing repeat output of the satab
table via cat(output$satab)
.
library(agricolae) # Completely Randomised Design trt <- c(1, 5, 10, 20) rep <- 5 outdesign <- design.crd(trt = trt, r = rep, seed = 42) des.out <- des_info(design.obj = outdesign, nrows = 4, ncols = 5) # Randomised Complete Block Design trt <- LETTERS[1:11] rep <- 4 outdesign <- design.rcbd(trt = trt, r = rep, seed = 42) des.out <- des_info( design.obj = outdesign, nrows = 11, ncols = 4, brows = 11, bcols = 1 ) # Latin Square Design trt <- c("S1", "S2", "S3", "S4") outdesign <- design.lsd(trt) des.out <- des_info(design.obj = outdesign, nrows = 4, ncols = 4) # Factorial Design (Crossed, Completely Randomised) trt <- c(3, 2) # Factorial 3 x 2 rep <- 3 outdesign <- design.ab(trt, r = rep, design = "crd") des.out <- des_info(design.obj = outdesign, nrows = 6, ncols = 3) # Factorial Design (Crossed, Completely Randomised), renaming factors trt <- c(3, 2) # Factorial 3 x 2 rep <- 3 outdesign <- design.ab(trt, r = rep, design = "crd") des.out <- des_info(design.obj = outdesign, nrows = 6, ncols = 3, fac.names = list(N = c(50, 100, 150), Water = c("Irrigated", "Rain-fed"))) # Factorial Design (Nested, Latin Square) trt <- c("A1", "A2", "A3", "A4", "B1", "B2", "B3") outdesign <- design.lsd(trt) des.out <- des_info(design.obj = outdesign, nrows = 7, ncols = 7) # Split plot design trt1 <- c("A", "B") trt2 <- 1:4 rep <- 4 outdesign <- design.split(trt1, trt2, r = rep) des.out <- des_info(design.obj = outdesign, nrows = 8, ncols = 4, brows = 4, bcols = 2)
library(agricolae) # Completely Randomised Design trt <- c(1, 5, 10, 20) rep <- 5 outdesign <- design.crd(trt = trt, r = rep, seed = 42) des.out <- des_info(design.obj = outdesign, nrows = 4, ncols = 5) # Randomised Complete Block Design trt <- LETTERS[1:11] rep <- 4 outdesign <- design.rcbd(trt = trt, r = rep, seed = 42) des.out <- des_info( design.obj = outdesign, nrows = 11, ncols = 4, brows = 11, bcols = 1 ) # Latin Square Design trt <- c("S1", "S2", "S3", "S4") outdesign <- design.lsd(trt) des.out <- des_info(design.obj = outdesign, nrows = 4, ncols = 4) # Factorial Design (Crossed, Completely Randomised) trt <- c(3, 2) # Factorial 3 x 2 rep <- 3 outdesign <- design.ab(trt, r = rep, design = "crd") des.out <- des_info(design.obj = outdesign, nrows = 6, ncols = 3) # Factorial Design (Crossed, Completely Randomised), renaming factors trt <- c(3, 2) # Factorial 3 x 2 rep <- 3 outdesign <- design.ab(trt, r = rep, design = "crd") des.out <- des_info(design.obj = outdesign, nrows = 6, ncols = 3, fac.names = list(N = c(50, 100, 150), Water = c("Irrigated", "Rain-fed"))) # Factorial Design (Nested, Latin Square) trt <- c("A1", "A2", "A3", "A4", "B1", "B2", "B3") outdesign <- design.lsd(trt) des.out <- des_info(design.obj = outdesign, nrows = 7, ncols = 7) # Split plot design trt1 <- c("A", "B") trt2 <- 1:4 rep <- 4 outdesign <- design.split(trt1, trt2, r = rep) des.out <- des_info(design.obj = outdesign, nrows = 8, ncols = 4, brows = 4, bcols = 2)
Create a complete experimental design with graph of design layout and skeletal ANOVA table
design( type, treatments, reps, nrows, ncols, brows = NA, bcols = NA, byrow = TRUE, sub_treatments = NULL, fac.names = NULL, fac.sep = c("", " "), plot = TRUE, rotation = 0, size = 4, margin = FALSE, save = FALSE, savename = paste0(type, "_design"), plottype = "pdf", seed = TRUE, quiet = FALSE, ... )
design( type, treatments, reps, nrows, ncols, brows = NA, bcols = NA, byrow = TRUE, sub_treatments = NULL, fac.names = NULL, fac.sep = c("", " "), plot = TRUE, rotation = 0, size = 4, margin = FALSE, save = FALSE, savename = paste0(type, "_design"), plottype = "pdf", seed = TRUE, quiet = FALSE, ... )
type |
The type of design. Supported design types are |
treatments |
A vector containing the treatment names or labels. |
reps |
The number of replicates. Ignored for Latin Square Designs. |
nrows |
The number of rows in the design. |
ncols |
The number of columns in the design. |
brows |
For RCBD and Split Plot designs. The number of rows in a block. |
bcols |
For RCBD and Split Plot designs. The number of columns in a block. |
byrow |
For split-plot only. Logical (default |
sub_treatments |
A vector of treatments for sub-plots in a split plot design. |
fac.names |
Allows renaming of the |
fac.sep |
The separator used by |
plot |
Logical (default |
rotation |
Rotate the text output as Treatments within the plot. Allows for easier reading of long treatment labels. Takes positive and negative values being number of degrees of rotation from horizontal. |
size |
Increase or decrease the text size within the plot for treatment labels. Numeric with default value of 4. |
margin |
Logical (default |
save |
One of |
savename |
A file name for the design to be saved to. Default is the type of the design combined with "_design". |
plottype |
The type of file to save the plot as. Usually one of |
seed |
Logical (default |
quiet |
Logical (default |
... |
Additional parameters passed to |
The designs currently supported by type
are Completely Randomised designs (crd
), Randomised Complete Block designs (rcbd
), Latin Square Designs (lsd
), Factorial with crossed structure (use crossed:<type>
where <type>
is one of the previous types e.g. crossed:crd
) and Split Plot designs (split
). Nested factorial designs are supported through manual setup, see Examples.
If save = TRUE
(or "both"
), both the plot and the workbook will be saved to the current working directory, with filename given by savename
. If one of either "plot"
or "workbook"
is specified, only that output is saved. If save = FALSE
(the default, or equivalently "none"
), nothing will be output.
fac.names
can be supplied to provide more intuitive names for factors and their levels in factorial and split plot designs. They can be specified in a list format, for example fac.names = list(A_names = c("a", "b", "c"), B_names = c("x", "y", "z"))
. This will result a design output with a column named A_names
with levels a, b, c
and another named B_names
with levels x, y, z
. Labels can also be supplied as a character vector (e.g. c("A", "B")
) which will result in only the treatment column names being renamed. Only the first two elements of the list will be used, except in the case of a 3-way factorial design.
...
allows extra arguments to be passed to ggsave()
for output of the plot. The details of possible arguments can be found in ggplot2::ggsave()
.
A list containing a data frame with the complete design ($design
), a ggplot object with plot layout ($plot.des
), the seed ($seed
, if return.seed = TRUE
), and the satab
object ($satab
), allowing repeat output of the satab
table via cat(output$satab)
.
# Completely Randomised Design des.out <- design(type = "crd", treatments = c(1, 5, 10, 20), reps = 5, nrows = 4, ncols = 5, seed = 42) # Randomised Complete Block Design des.out <- design("rcbd", treatments = LETTERS[1:11], reps = 4, nrows = 11, ncols = 4, brows = 11, bcols = 1, seed = 42) # Latin Square Design # Doesn't require reps argument des.out <- design(type = "lsd", c("S1", "S2", "S3", "S4"), nrows = 4, ncols = 4, seed = 42) # Factorial Design (Crossed, Completely Randomised) des.out <- design(type = "crossed:crd", treatments = c(3, 2), reps = 3, nrows = 6, ncols = 3, seed = 42) # Factorial Design (Crossed, Completely Randomised), renaming factors des.out <- design(type = "crossed:crd", treatments = c(3, 2), reps = 3, nrows = 6, ncols = 3, seed = 42, fac.names = list(N = c(50, 100, 150), Water = c("Irrigated", "Rain-fed"))) # Factorial Design (Crossed, Randomised Complete Block Design), # changing separation between factors des.out <- design(type = "crossed:rcbd", treatments = c(3, 2), reps = 3, nrows = 6, ncols = 3, brows = 6, bcols = 1, seed = 42, fac.sep = c(":", "_")) # Factorial Design (Nested, Latin Square) trt <- c("A1", "A2", "A3", "A4", "B1", "B2", "B3") des.out <- design(type = "lsd", treatments = trt, nrows = 7, ncols = 7, seed = 42) # Split plot design des.out <- design(type = "split", treatments = c("A", "B"), sub_treatments = 1:4, reps = 4, nrows = 8, ncols = 4, brows = 4, bcols = 2, seed = 42) # Alternative arrangement of the same design as above des.out <- design(type = "split", treatments = c("A", "B"), sub_treatments = 1:4, reps = 4, nrows = 8, ncols = 4, brows = 4, bcols = 2, byrow = FALSE, seed = 42)
# Completely Randomised Design des.out <- design(type = "crd", treatments = c(1, 5, 10, 20), reps = 5, nrows = 4, ncols = 5, seed = 42) # Randomised Complete Block Design des.out <- design("rcbd", treatments = LETTERS[1:11], reps = 4, nrows = 11, ncols = 4, brows = 11, bcols = 1, seed = 42) # Latin Square Design # Doesn't require reps argument des.out <- design(type = "lsd", c("S1", "S2", "S3", "S4"), nrows = 4, ncols = 4, seed = 42) # Factorial Design (Crossed, Completely Randomised) des.out <- design(type = "crossed:crd", treatments = c(3, 2), reps = 3, nrows = 6, ncols = 3, seed = 42) # Factorial Design (Crossed, Completely Randomised), renaming factors des.out <- design(type = "crossed:crd", treatments = c(3, 2), reps = 3, nrows = 6, ncols = 3, seed = 42, fac.names = list(N = c(50, 100, 150), Water = c("Irrigated", "Rain-fed"))) # Factorial Design (Crossed, Randomised Complete Block Design), # changing separation between factors des.out <- design(type = "crossed:rcbd", treatments = c(3, 2), reps = 3, nrows = 6, ncols = 3, brows = 6, bcols = 1, seed = 42, fac.sep = c(":", "_")) # Factorial Design (Nested, Latin Square) trt <- c("A1", "A2", "A3", "A4", "B1", "B2", "B3") des.out <- design(type = "lsd", treatments = trt, nrows = 7, ncols = 7, seed = 42) # Split plot design des.out <- design(type = "split", treatments = c("A", "B"), sub_treatments = 1:4, reps = 4, nrows = 8, ncols = 4, brows = 4, bcols = 2, seed = 42) # Alternative arrangement of the same design as above des.out <- design(type = "split", treatments = c("A", "B"), sub_treatments = 1:4, reps = 4, nrows = 8, ncols = 4, brows = 4, bcols = 2, byrow = FALSE, seed = 42)
This function plots a heatmap of variables in a grid layout, optionally grouping them.
heat_map( data, value, x_axis, y_axis, grouping = NULL, raster = TRUE, smooth = FALSE, palette = "default", ... )
heat_map( data, value, x_axis, y_axis, grouping = NULL, raster = TRUE, smooth = FALSE, palette = "default", ... )
data |
A data frame containing the data to be plotted. |
value |
A column of |
x_axis |
The column of |
y_axis |
The column of |
grouping |
An optional grouping variable to facet the plot by. |
raster |
Logical (default: |
smooth |
Logical (default: |
palette |
Colour palette to use. By default it will use the |
... |
Other arguments passed to |
A ggplot2
object.
set.seed(42) dat <- expand.grid(x = 1:5, y = 1:6) dat$value <- rnorm(30) dat$groups <- sample(rep(LETTERS[1:6], times = 5)) heat_map(dat, value, x, y) # Column names can be quoted, but don't need to be. heat_map(dat, "value", "x", "y", "groups") # Different palettes are available heat_map(dat, value, x, y, palette = "Spectral") # Arguments in ... are passed through to facet_wrap heat_map(dat, value, x, y, groups, labeller = ggplot2:::label_both) heat_map(dat, value, x, y, groups, scales = "free_y") heat_map(dat, value, x, y, groups, nrow = 1)
set.seed(42) dat <- expand.grid(x = 1:5, y = 1:6) dat$value <- rnorm(30) dat$groups <- sample(rep(LETTERS[1:6], times = 5)) heat_map(dat, value, x, y) # Column names can be quoted, but don't need to be. heat_map(dat, "value", "x", "y", "groups") # Different palettes are available heat_map(dat, value, x, y, palette = "Spectral") # Arguments in ... are passed through to facet_wrap heat_map(dat, value, x, y, groups, labeller = ggplot2:::label_both) heat_map(dat, value, x, y, groups, scales = "free_y") heat_map(dat, value, x, y, groups, nrow = 1)
Helper functions for installing or updating the ASReml-R package, intended to reduce the difficulty of finding the correct version for your operating system and R version.
install_asreml( library = .libPaths()[1], quiet = FALSE, force = FALSE, keep_file = FALSE ) update_asreml(...)
install_asreml( library = .libPaths()[1], quiet = FALSE, force = FALSE, keep_file = FALSE ) update_asreml(...)
library |
Library location to install ASReml-R. Uses first option in |
quiet |
Logical (default |
force |
Logical (default |
keep_file |
Should the downloaded asreml package file be kept? Default is |
... |
other arguments passed to |
The ASReml-R package file is downloaded from a shortlink, and if keep_file
is TRUE
, the package archive file will be saved in the current directory. If a valid path is provided in keep_file
, the file will be saved to that path, but all directories are assumed to exist and will not be created. If keep_file
does not specify an existing, valid path, an error will be shown after package installation.
Silently returns TRUE
if asreml
installed successfully or already present, FALSE
otherwise. Optionally prints a confirmation message on success.
## Not run: # Example 1: download and install asreml install_asreml() # Example 2: install asreml and save file for later install_asreml(keep_file = TRUE) ## End(Not run)
## Not run: # Example 1: download and install asreml install_asreml() # Example 2: install asreml and save file for later install_asreml(keep_file = TRUE) ## End(Not run)
Conduct a log-likelihood test for comparing terms in ASReml-R models
logl_test( model.obj, rand.terms = NULL, resid.terms = NULL, decimals = 3, numeric = FALSE, quiet = FALSE )
logl_test( model.obj, rand.terms = NULL, resid.terms = NULL, decimals = 3, numeric = FALSE, quiet = FALSE )
model.obj |
An ASReml-R model object |
rand.terms |
Random terms from the model. Default is NULL. |
resid.terms |
Residual terms from the model. Default is NULL. |
decimals |
Controls rounding of decimal places in output. Default is 3 decimal places. |
numeric |
Return p-values as numeric? Default is that they are characters, where very small values shown as less than a small number. See |
quiet |
Logical (default: |
Typically p-values cannot be 0, and are usually just below some threshold of accuracy in calculation of probability.
A dataframe containing the results of the test.
## Not run: library(asreml) dat <- asreml::oats dat <- dat[order(dat$Row, dat$Column),] #Fit ASReml Model model.asr <- asreml(yield ~ Nitrogen + Variety + Nitrogen:Variety, random = ~ Blocks + Blocks:Wplots, residual = ~ ar1(Row):ar1(Column), data = dat) oats.logl <- logl_test( model.obj = model.asr, rand.terms = c("Blocks", "Blocks:Wplots"), resid.terms = c("ar1(Row)", "ar1(Column)") ) oats.logl ## End(Not run)
## Not run: library(asreml) dat <- asreml::oats dat <- dat[order(dat$Row, dat$Column),] #Fit ASReml Model model.asr <- asreml(yield ~ Nitrogen + Variety + Nitrogen:Variety, random = ~ Blocks + Blocks:Wplots, residual = ~ ar1(Row):ar1(Column), data = dat) oats.logl <- logl_test( model.obj = model.asr, rand.terms = c("Blocks", "Blocks:Wplots"), resid.terms = c("ar1(Row)", "ar1(Column)") ) oats.logl ## End(Not run)
A function for comparing and ranking predicted means with Tukey's Honest Significant Difference (HSD) Test.
multiple_comparisons( model.obj, classify, sig = 0.05, int.type = "ci", trans = NA, offset = NA, power = NA, decimals = 2, descending = FALSE, plot = FALSE, label_height = 0.1, rotation = 0, save = FALSE, savename = "predicted_values", order, pred.obj, pred, ... )
multiple_comparisons( model.obj, classify, sig = 0.05, int.type = "ci", trans = NA, offset = NA, power = NA, decimals = 2, descending = FALSE, plot = FALSE, label_height = 0.1, rotation = 0, save = FALSE, savename = "predicted_values", order, pred.obj, pred, ... )
model.obj |
An ASReml-R or aov model object. Will likely also work with |
classify |
Name of predictor variable as string. |
sig |
The significance level, numeric between 0 and 1. Default is 0.05. |
int.type |
The type of confidence interval to calculate. One of |
trans |
Transformation that was applied to the response variable. One of |
offset |
Numeric offset applied to response variable prior to transformation. Default is |
power |
Numeric power applied to response variable with power transformation. Default is |
decimals |
Controls rounding of decimal places in output. Default is 2 decimal places. |
descending |
Logical (default |
plot |
Automatically produce a plot of the output of the multiple comparison test? Default is |
label_height |
Height of the text labels above the upper error bar on the plot. Default is 0.1 (10%) of the difference between upper and lower error bars above the top error bar. |
rotation |
Rotate the text output as Treatments within the plot. Allows for easier reading of long treatment labels. Number between 0 and 360 (inclusive) - default 0 |
save |
Logical (default |
savename |
A file name for the predicted values to be saved to. Default is |
order |
Deprecated. Use |
pred.obj |
Deprecated. Predicted values are calculated within the function from version 1.0.1 onwards. |
pred |
Deprecated. Use |
... |
Other arguments passed through to |
Some transformations require that data has a small offset applied, otherwise it will cause errors (for example taking a log of 0, or square root of negative values). In order to correctly reverse this offset, if the trans
argument is supplied, an offset value must also be supplied. If there was no offset required for a transformation, then use a value of 0 for the offset
argument.
A list containing a data frame with predicted means, standard errors, confidence interval upper and lower bounds, and significant group allocations (named predicted_values
), as well as a plot visually displaying the predicted values (named predicted_plot
). If some of the predicted values are aliased, a warning is printed, and the aliased treatment levels are returned in the output (named aliased
).
Jørgensen, E. & Pedersen, A. R. (1997). How to Obtain Those Nasty Standard Errors From Transformed Data - and Why They Should Not Be Used. https://pure.au.dk/portal/en/publications/how-to-obtain-those-nasty-standard-errors-from-transformed-data–and-why-they-should-not-be-used(d649ca20-d15f-11db-8e26-000ea68e967b).html
# Fit aov model model <- aov(Petal.Length ~ Species, data = iris) # Display the ANOVA table for the model anova(model) # Determine ranking and groups according to Tukey's Test pred.out <- multiple_comparisons(model, classify = "Species") # Display the predicted values table pred.out # Show the predicted values plot autoplot(pred.out, label_height = 0.5) ## Not run: # ASReml-R Example library(asreml) #Fit ASReml Model model.asr <- asreml(yield ~ Nitrogen + Variety + Nitrogen:Variety, random = ~ Blocks + Blocks:Wplots, residual = ~ units, data = asreml::oats) wald(model.asr) #Nitrogen main effect significant #Determine ranking and groups according to Tukey's Test pred.out <- multiple_comparisons(model.obj = model.asr, classify = "Nitrogen", descending = TRUE, decimals = 5) pred.out # Example using a box-cox transformation set.seed(42) # See the seed for reproducibility resp <- rnorm(n = 50, 5, 1)^3 trt <- as.factor(sample(rep(LETTERS[1:10], 5), 50)) block <- as.factor(rep(1:5, each = 10)) ex_data <- data.frame(resp, trt, block) # Change one treatment random values to get significant difference ex_data$resp[ex_data$trt=="A"] <- rnorm(n = 5, 7, 1)^3 model.asr <- asreml(resp ~ trt, random = ~ block, residual = ~ units, data = ex_data) resplot(model.asr) # Perform Box-Cox transformation and get maximum value out <- MASS::boxcox(ex_data$resp~ex_data$trt) out$x[which.max(out$y)] # 0.3838 # Fit cube root to the data model.asr <- asreml(resp^(1/3) ~ trt, random = ~ block, residual = ~ units, data = ex_data) resplot(model.asr) # residual plots look much better #Determine ranking and groups according to Tukey's Test pred.out <- multiple_comparisons(model.obj = model.asr, classify = "trt", trans = "power", power = (1/3)) pred.out autoplot(pred.out) ## End(Not run)
# Fit aov model model <- aov(Petal.Length ~ Species, data = iris) # Display the ANOVA table for the model anova(model) # Determine ranking and groups according to Tukey's Test pred.out <- multiple_comparisons(model, classify = "Species") # Display the predicted values table pred.out # Show the predicted values plot autoplot(pred.out, label_height = 0.5) ## Not run: # ASReml-R Example library(asreml) #Fit ASReml Model model.asr <- asreml(yield ~ Nitrogen + Variety + Nitrogen:Variety, random = ~ Blocks + Blocks:Wplots, residual = ~ units, data = asreml::oats) wald(model.asr) #Nitrogen main effect significant #Determine ranking and groups according to Tukey's Test pred.out <- multiple_comparisons(model.obj = model.asr, classify = "Nitrogen", descending = TRUE, decimals = 5) pred.out # Example using a box-cox transformation set.seed(42) # See the seed for reproducibility resp <- rnorm(n = 50, 5, 1)^3 trt <- as.factor(sample(rep(LETTERS[1:10], 5), 50)) block <- as.factor(rep(1:5, each = 10)) ex_data <- data.frame(resp, trt, block) # Change one treatment random values to get significant difference ex_data$resp[ex_data$trt=="A"] <- rnorm(n = 5, 7, 1)^3 model.asr <- asreml(resp ~ trt, random = ~ block, residual = ~ units, data = ex_data) resplot(model.asr) # Perform Box-Cox transformation and get maximum value out <- MASS::boxcox(ex_data$resp~ex_data$trt) out$x[which.max(out$y)] # 0.3838 # Fit cube root to the data model.asr <- asreml(resp^(1/3) ~ trt, random = ~ block, residual = ~ units, data = ex_data) resplot(model.asr) # residual plots look much better #Determine ranking and groups according to Tukey's Test pred.out <- multiple_comparisons(model.obj = model.asr, classify = "trt", trans = "power", power = (1/3)) pred.out autoplot(pred.out) ## End(Not run)
Print output of multiple_comparisons
## S3 method for class 'mct' print(x, ...)
## S3 method for class 'mct' print(x, ...)
x |
An mct object to print to the console. |
... |
Other arguments |
The original object invisibly.
dat.aov <- aov(Petal.Width ~ Species, data = iris) output <- multiple_comparisons(dat.aov, classify = "Species") print(output)
dat.aov <- aov(Petal.Width ~ Species, data = iris) output <- multiple_comparisons(dat.aov, classify = "Species") print(output)
Produces plots of residuals for assumption checking of linear (mixed) models.
resplot( model.obj, shapiro = TRUE, call = FALSE, label.size = 10, axes.size = 10, call.size = 9, mod.obj )
resplot( model.obj, shapiro = TRUE, call = FALSE, label.size = 10, axes.size = 10, call.size = 9, mod.obj )
model.obj |
An |
shapiro |
(Logical) Display the Shapiro-Wilks test of normality on the plot? |
call |
(Logical) Display the model call on the plot? |
label.size |
A numeric value for the size of the label (A,B,C) font point size. |
axes.size |
A numeric value for the size of the axes label font size in points. |
call.size |
A numeric value for the size of the model displayed on the plot. |
mod.obj |
Deprecated to be consistent with other functions. Please use |
A ggplot2 object containing the diagnostic plots.
dat.aov <- aov(Petal.Length ~ Petal.Width, data = iris) resplot(dat.aov) resplot(dat.aov, call = TRUE)
dat.aov <- aov(Petal.Length ~ Petal.Width, data = iris) resplot(dat.aov) resplot(dat.aov, call = TRUE)
Variables are plotted in different ways according to the number of explanatory variables provided as input.
summary_graph(data, response, exp_var, resp_units = "")
summary_graph(data, response, exp_var, resp_units = "")
data |
A data frame containing the variables to be plotted. |
response |
The response variable to plot. |
exp_var |
The explanatory (or grouping) variable(s) to plot. Up to three can be provided. |
resp_units |
A string providing units to display on the response variable (y) axis. Will use the empty string by default so axes will have no units by default. |
With a single explanatory variable, a boxplot grouped by exp_var
is produced.
With two explanatory variables, a dot-plot with lines connecting the mean of each
group is produced, with the first element of exp_var
used as the x axis variable,
and the second is used to colour the points. Three explanatory variables produces
the same as two, but with the third used to facet the plot.
A ggplot2 plot object
summary_graph(iris, "Petal.Length", "Species", "mm") # Multiple explanatory variables can be provided as a vector summary_graph(npk, "yield", c("N", "P"), "lb/plot") summary_graph(npk, "yield", c("N", "P", "K"), "lb/plot")
summary_graph(iris, "Petal.Length", "Species", "mm") # Multiple explanatory variables can be provided as a vector summary_graph(npk, "yield", c("N", "P"), "lb/plot") summary_graph(npk, "yield", c("N", "P", "K"), "lb/plot")
Produces variogram plots for checking spatial trends.
variogram( model.obj, row = NA, column = NA, horizontal = TRUE, palette = "default" )
variogram( model.obj, row = NA, column = NA, horizontal = TRUE, palette = "default" )
model.obj |
An |
row |
A row variable. |
column |
A column variable. |
horizontal |
Logical (default |
palette |
A string specifying the colour scheme to use for plotting. The default value ( |
A ggplot2
object.
S. P. Kaluzny, S. C. Vega, T. P. Cardoso, A. A. Shelly, "S+SpatialStats: User’s Manual for Windows® and UNIX®" Springer New York, 2013, p. 68, https://books.google.com.au/books?id=iADkBwvario_pointsQBAJ.
A. R. Gilmour, B. R. Cullis, A. P. Verbyla, "Accounting for Natural and Extraneous Variation in the Analysis of Field Experiments." Journal of Agricultural, Biological, and Environmental Statistics 2, no. 3, 1997, pp. 269–93, https://doi.org/10.2307/1400446.
## Not run: library(asreml) oats <- asreml::oats oats <- oats[order(oats$Row, oats$Column),] model.asr <- asreml(yield ~ Nitrogen + Variety + Nitrogen:Variety, random = ~ Blocks + Blocks:Wplots, residual = ~ ar1(Row):ar1(Column), data = oats) variogram(model.asr) ## End(Not run)
## Not run: library(asreml) oats <- asreml::oats oats <- oats[order(oats$Row, oats$Column),] model.asr <- asreml(yield ~ Nitrogen + Variety + Nitrogen:Variety, random = ~ Blocks + Blocks:Wplots, residual = ~ ar1(Row):ar1(Column), data = oats) variogram(model.asr) ## End(Not run)