Problem description: I have 14 faecal pellets from 6 bat individuals (3 females, 3 males). All pellets are approximately of equal size. Prey composition (3 types: A, B, C) has been determined by calculating percentage volume of prey item within pellet. My aim is to compare whereas females eat more/less of particular prey than males.
my.data <- data.frame(pellet = seq(1,14,1),
individual = rep(c(LETTERS[1:6]), times=c(3,2,4,2,1,2)),
group = rep(c("female","male"), times = c(9, 5)),
prey.A = c(10,20,40,0,0,20,0,10,80,20,40,40,20,10),
prey.B = c(0,0,10,0,0,20,0,0,0,30,30,0,10,0),
prey.C = c(90,80,50,100,100,60,100,90,20,50,30,60,70,90))
# --- custom function start--- #
error.bar <- function(x, y, upper, lower=upper, length=0.1,...){
if(length(x) != length(y) | length(y) !=length(lower) | length(lower) != length(upper))
stop("vectors must be same length")
arrows(x,y+upper, x, y-lower, angle=90, code=3, length=length, ...)
}
# --- custom function end--- #
# data handling
library(psych)
prey_female <- subset(my.data, group == "female")
prey_male <- subset(my.data, group == "male")
female_data <- c(prey_female$prey.A, prey_female$prey.B, prey_female$prey.C)
mtrx.female <- matrix(female_data,9,3)
female.means <- apply(mtrx.female,2,mean)
female.sd <- apply(mtrx.female,2,sd)
male_data <- c(prey_male$prey.A, prey_male$prey.B, prey_male$prey.C)
mtrx.male <- matrix(male_data,5,3)
male.means <- apply(mtrx.male,2,mean)
male.sd <- apply(mtrx.male,2,sd)
yy <- matrix(c(female.means,male.means),2,3,byrow=TRUE)
ee <- matrix(c(female.sd,male.sd),2,3,byrow=TRUE)*1.96/10
# plot creation
barx <- barplot(yy, beside=TRUE,col=c("palevioletred","lightskyblue2"), ylim=c(0,100),
names.arg=LETTERS[1:3], axis.lty=1, xlab="prey", ylab="percetage volume (%)")
error.bar(barx,yy,ee)
I have two solutions - but I can not decide which is more appropriate.
First solution is to use Wilcoxon-Mann-Whitney Test to compare medians of both groups. Here is test which compares females and males with respect to prey item A.
library(coin)
wilcox_test(c(prey_female$prey.A,prey_male$prey.A) ~ as.factor(c(prey_female$group, prey_male$group)))
# Asymptotic Wilcoxon-Mann-Whitney Test
# data: c(prey_female$prey.A, prey_male$prey.A) by
# as.factor(c(prey_female$group, prey_male$group)) (1, 2)
# Z = -1.1618, p-value = 0.2453
# alternative hypothesis: true mu is not equal to 0
Second solution is to do Chi-squared test.
chisq.test(c(mean(prey_female$prey.A),mean(prey_male$prey.A)), p = c(1/2,1/2), correct = TRUE)
# Chi-squared test for given probabilities
# data: c(mean(prey_female$prey.A), mean(prey_male$prey.A))
# X-squared = 0.78261, df = 1, p-value = 0.3763
Data are fabricated, original dataset is much larger. How to make the comparison rigorously? It seems to me that both tests answer the same question.