1. Home
  2. Basic usage

Basic usage

The R system is modular, so when it loads only core functionality is available. Mixed models are made available by additional ‘packages’, which are loaded using the libary function. The most common mixed model packages in R are nlme (which is part of the default R installation) and the somewhat newer lme4. Both of them are free and open source, and have some pros and cons compared to ASReml-R, which is a commercial and closed source package.

library(asreml)
fm <- asreml(response ~ fixed.factors, random = more.factors,
             data = my data)
summary(fm)

The first line of the example loads the ASReml-R package and makes available all its functionality to the R environment. The second line calls the function asreml() with a model equation using fixed and random factors, taking all the variable names from a data frame called mydata. We need to load the package only once during our session.

Let us say that we have a data frame containing the following variables (columns): Replicate, Family and height, which refer to a randomized complete block design with, say 30 replicates, 100 families, plots with 5 plants per family in each replicate and plants assessed for total height. All these variables are stored in a data frame called trial1. Please note that the notation convention in these pages is to use capitalized names for factors and lowercase names for covariates. We could fit this example using:

library(asreml)
fm <- asreml(height ~ 1, random = ~ Replicate*Family,
             data = trial1)

# or, equivalently,

fm <- asreml(height ~ 1, random = ~ Replicate + Family + Replicate:Family,
             data = trial1)

The call to ASReml uses height as the response variable (to the left of the tilde symbol ~) and fits the overall mean (the 1 used to the right of the ~) as a fixed effect. Additionally, the call fits Replicate, Family and their interaction as random effects. All the variables are contained in trial1, but note that they need to be specified as factors. Both calls are equivalent because in R Replicate*Family expands to Replicate + Family + Replicate:Family.

The whole ASReml-R run is assigned to objectfm (meaning fitted model in our example) using the <- operator. It can then be further manipulated and interrogated. If you come from nlme or lme4, you could be tempted to use summary(fm) to get summary results for the model fit. This would not be a good idea when using ASReml-R, because it would print all parts of the model. Thus, instead of getting a nice summary of the results, you will get the whole shebang; that is, predicted values, residuals, variance components, etc. This means that if you ran a large analysis you will get several screens of output.

Instead, one usually accesses different parts of the output using the typical R notation object$name applied to summary(), which in this case would look like:

# or you could assign it to a variable for further
# manipulation as:
luis <- summary(fm)$varcomp

Copyright (1997–2021) by Luis Apiolaza, some rights are reserved.

Updated on September 22, 2021

Was this article helpful?