## Introduction

A major advance for the study of quantitative trait evolution in wild populations was precipitated by the adoption of the ‘animal model’, a mixed effects model with a long and proven history in the animal breeding sciences (Henderson 1984; Lynch & Walsh 1998; Kruuk 2004). Using the similarity among relatives to elucidate the underlying genetic basis of phenotypic variation at the population level, the method (1) enables researchers to control (or study in and of themselves) confounding factors because of environmental or other non-heritable sources of similarity between relatives, (2) simultaneously utilizes additional relationships beyond parent-offspring or half- and full siblings in the estimation of genetic parameters, thereby increasing the types of populations and organisms able to be studied and (3) is unbiased to selection within a population (Lynch & Walsh 1998; Kruuk 2004). Response variables in animal models may be univariate, multivariate, Gaussian or non-Gaussian. Further, solutions to the animal model may be obtained using Likelihood or Bayesian approaches (further information in the Supporting Information *Relatedness matrices in the animal model* section and detailed descriptions of the animal model can be found in Lynch & Walsh 1998; Sorensen & Gianola, 2002; Kruuk 2004; Mrode, 2005).

The phenotypic variance of a quantitative trait can be broken down into additive genetic, non-additive genetic and environmental sources of variation. The non-additive genetic variance can be further subdivided into dominance and epistatic variances. The additive, dominance and epistatic genetic variances are proportional to the probability that individuals share alleles identical by descent at the same locus, for both alleles at the same locus, or for alleles at different loci, respectively. If one knows all the relationships in a population (i.e. the pedigree) then the above genetic variances can be estimated in an animal model.

Non-additive genetic variances are seldom, if ever, estimated in ecological and evolutionary analyses (but see, Crnokrak & Roff 1995; Waldmann 2001), although the fields of animal and plant breeding have been estimating these genetic variances for over two decades (e.g. Hoeschele 1991; Tempelman & Burnside 1991). This could be, in part, because non-additive genetic effects are assumed to be of little importance in predicting the evolutionary trajectory of moderately sized wild populations (Fisher 1958). Also, studies of wild organisms typically have low numbers of individuals in a population, especially compared to the millions often handled in animal breeding. This is problematic, because datasets with too few individuals preclude the inclusion of too many random effects in an animal model (Kruuk 2004) and have been shown to be problematic for the estimation of dominance variance (Misztal 1997). However, if dominance genetic effects are present, but not included in an animal model, they can potentially bias the prediction of the additive genetic effects as well as the estimate of additive genetic variance (Lynch & Walsh 1998; Ovaskainen, Cano & Merilä 2008; Waldmann *et al.* 2008; but see Misztal, Lawlor & Fernando 1997). Additionally, non-additive effects are of central interest to a number of evolutionary hypotheses, for example: dominance and epistasis are expected to contribute substantially to variation in fitness (Wright 1929; Haldane 1932; Fisher 1958; Crnokrak & Roff 1995; Merilä & Sheldon 1999); non-additive variance may determine the extent to which additive genetic variance increases after bottlenecks (Cockerham & Tachida 1988; Goodnight 1988; Willis & Orr 1993; Barton & Turelli 2004); epistasis can shape additive genetic effects and variances during processes such as mutation and selection (Gavrilets 1993; Hermisson, Hansen & Wagner 2003; Carter, Hermisson & Hansen 2005) which has consequences for the evolution of sex and recombination (Charlesworth 1990); epistasis plays an integral part in speciation through the evolution of Dobzhansky-Muller incompatibilities (Crow & Kimura 1970; Orr 1995; Welch 2004); the sign of genetic correlations between fitness-related traits may depend on the amount of dominance variance (Curtsinger, Service & Prout 1994; Roff 1997; Merilä & Sheldon 1999); dominance potentially causes inbreeding depression or heterosis (Roff 1997) especially in small populations of conservation concern (Waldmann *et al.* 2008); and sex-linked dominance effects may play a role in the evolution of sexually dimorphic traits (Fairbairn & Roff 2006).

Aside from being unable to obtain meaningful estimates of non-additive variances as a result of the overall size of a population (see “Sampling covariances and confidence intervals” below), the next challenge to including dominance and epistasis in animal models is constructing the non-additive genetic relationship matrices (i.e. dominance matrix **D** and the three digenic epistatic matrices: additive by additive **AA**, additive by dominance **AD** and the dominance by dominance **DD**– where the additive genetic relationship matrix is represented by **A** and boldfaced, upper-case letters indicate a matrix). A further challenge is to obtain the inverses of these matrices, which is what is required to solve the system of equations in the animal model. Although the process of constructing the necessary matrix inverses has been worked out (e.g. Hoeschele & VanRaden 1991), only the creation of the additive inverse matrix has been incorporated into software used by most ecologists and evolutionary biologists: ASReml (Gilmour *et al.* 2009), **MCMCglmm** (Hadfield 2010) and WOMBAT (Meyer 2007). This study gives an overview of the software package **nadiv** (Non-Additive InVerses), implemented in the widely used statistical program R (R Development Core Team, 2011), which can be used to construct dominance and epistatic genetic relatedness matrices and their inverses. The inverses can subsequently be used in a variety of animal model software programs for univariate or multivariate analyses of quantitative traits. Below, examples briefly demonstrate the main functions using **nadiv**’s simulated data set warcolak.