# Animal density and locomotion: analysis given missing data

I want to see whether the number of animals in a paddock has any effect on distance walked per day by the animals.

I have data on the distance an animal walks (per day) against the number of animals in a paddock.

[The distances are not independent (i.e how far one animal walks significantly affects how far all the others walk as they usually live in herds) therefore, although I have the original data I'm fairly sure that I cannot use per/animal results, I think I need to take the average over all the animals in the paddock.]

There were 3 trials, these are as follows:

In the first one there were two control groups, 30 animals in two separate paddocks. This was repeated 3 days in a row. The distance each animal walked was recorded.

In the second trial there was one control group (30 animals in the paddock) and one treatment (20 animals in another paddock). This was repeated 3 days in a row.

In the third trial there was one control group (30 animals in one paddock) and one treatment (10 animals in another paddock). This was repeated 3 days in a row.

We were measuring using GPS which was not 100% reliable, therefore I don't have results for all animals on all days. This means I also can't just take results over the entire 3 days non-stop, as there were some treatments where only 2 collars worked for the entire time. I need to divide the results into separate days as some collars worked on some days and some collars on other days, (that way I can have, for example, 4 results per day, rather than just use the two collars that worked for the entire time. Using just 2 results could cause bias as some collars record slightly higher results than others and some animals walk further than others).

Would someone be able to give me advice on which statistical test to use to suit the experimental design and cases of missing data?

• At a brief look at your question, you could consider a mixed effects model. The advantages here are 1) that only the time points/cases of missing data will be dropped, and 2) you take your experimental design into account. Apr 24 '17 at 3:23
• What is the extent of missingness? Is it random? Also, do you control for external factors in your experiment? ie. pasture quality, temperature, precipitation, status of the animal (pregnant, age etc.). Apr 24 '17 at 3:26
• Hi, thanks for your help, the missingness is due to some collars tending to work better than others, e.g. better soldering, better fit so that antenna didn't move round underneath the animal's neck accidentally etc. So it is related to collar quality rather than something external which might affect the distance walked. Some collars would work for an hour or so, stop then start again, these have already been deleted as I only use collars with >90% data. The ones remaining are those that tended to work for a day then stop for an hour etc. (perhaps antenna was obscured or something).
– S.H.
Apr 24 '17 at 4:49
• Yes, all those things were kept similar. Also there was a control along with each treatment in a nearby paddock.
– S.H.
Apr 24 '17 at 4:50

Let's say that this data simulated in R reflects your data (assuming no animals are used repeatedly across experiments).

#Add function to simulate missing data -
insert_nas <- function(x) {
len <- length(x)
n <- sample(1:floor(0.2*len), 1)
i <- sample(1:len, n)
x[i] <- NA
x
}

#Create base simulated data
set.seed(1203030)
animalControl <- data.frame(time1 = rnorm(120, mean = 5, sd = 1),
time2 = rnorm(120, mean = 4, sd = 1),
time3 = rnorm(120, mean = 6, sd = 1)
)

animal20 <- data.frame(time1 = rnorm(30, mean = 6, sd = 1),
time2 = rnorm(30, mean = 7, sd = 1),
time3 = rnorm(30, mean = 6, sd = 1)
)

animal10 <- data.frame(time1 = rnorm(30, mean = 10, sd = 1),
time2 = rnorm(30, mean = 9, sd = 1),
time3 = rnorm(30, mean = 11, sd = 1)
)

#Apply missingness and add other variables
animalControl <- cbind(animalId = seq(1:120), sapply(animalControl, insert_nas), group = "Control", exper = c(rep(1, 60), rep(2,30), rep(3, 30)), herd = c(rep(1, 30), rep(2,30), rep(3, 30), rep(4, 30)))
animal20 <- cbind(animalId = seq(121, 150, by = 1), animal20$animalId, sapply(animal20, insert_nas), group = "Treat20", exper = rep(2, 30), herd = rep(5, 30)) animal10 <- cbind(animalId = seq(151, 180, by = 1), animal10$animalId, sapply(animal10, insert_nas), group = "Treat10", exper = rep(3, 30), herd = rep(6, 30))

df <- data.frame(rbind(animalControl, animal20, animal10))
animalId            time1            time2            time3   group exper herd
1        1  4.5683686649673 6.84218504440714 5.63669812247394 Control     1    1
2        2 5.16742386265328 5.58724225879838 5.84898870042538 Control     1    1
3        3 5.68519677097074 4.33549563763083 6.12578675349171 Control     1    1
4        4 5.62363505382805 5.19776974967204 4.29196504220035 Control     1    1
5        5             <NA> 5.18210699347768 4.60001664866427 Control     1    1
6        6 4.25563560046411 3.48043514234613 6.18680692338524 Control     1    1


An example of restructuring your data and conducting a multi-level/mixed effects model with observations nested under animals which are in turn nested in herds is as follows (again in R):

#Transform to long form
library(tidyr)
dfGathered <- gather(df, time, distance, c(time1, time2, time3))

library(lme4)
animalDistMod <- lmer(as.numeric(distance) ~ group + (1 | herd/animalId), data = dfGathered)
summary(animalDistMod)
...


Note, this model is simply an example. Your particular case will need a different specification. There are many resources on mixed effects modeling on the internet and Crossvalidated - both for specification and interpretation.

• Thank you very much!! I don't have much background statistical knowledge so I will have to research this a bit to understand it. Some of the animals were reused, does that matter? For example some of the same animals in the first trial (control and treatment) would have been reused in the second and third trials. Which animals were reused or not reused was random.
– S.H.
Apr 24 '17 at 8:41
• If you have a unique ID for an animal then I believe it will be fine. Post a more specific question once you've read a bit more. Try and include a simulated dataset in your next question. Apr 24 '17 at 9:33