11Analysis of Covariance (ANCOVA)
When we have a continuous response variable and a mix of continuous and categorical explanatory variables (at least one of each), we use a so‐called analysis of covariance model (ANCOVA). In R, this type of model can be implemented using the familiar lm
function. Let us explore this type of analysis with a dataset consisting of the growth rate (growth
, μm day−1) of three different pathogenic fungal species as a function of fungicide concentration (conc
, mg l−1). The data are stored in the provided dataset called pathfung
. As a ‘sanity check’, we first look at the structure (str
) and the summary (summary
) of the data.
## Read in data
> pathfung <- read.csv("pathogenic_fungi.csv")
## Check structure and summary
> str(pathfung)
'data.frame': 54 obs. of 3 variables:
$ conc : int 10 8 6 4 2 0 10 8 6 4 ...
$ growth : num 37.8 85.3 111.4 147.3 236.4 ...
$ species: chr "A" "A" "A" "A" ...
The str
output shows fungicide concentration as an integer and fungal growth as a numeric (continuous) variable, which is fine. However, species is currently coded as character but since it is a categorical variable (factor), it should be coded as a factor (see Box 1.4 in Chapter 1). We will do this right away.
## Recode species as factor
> pathfung$species <- as.factor(pathfung$species)
It is a good idea to rerun the str(pathfung)
command at this stage to ensure that species
is now a factor.
The summary of this dataset flags no issues. The concentration ranges ...
Get R-ticulate now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.