# Changes in overall mean as a consequence of group composition vs. group-wise mean shifts

The mean body size of an entire community might shift due to different mechanisms and as a consequence of e.g.

"changes in the relative abundances of different age-classes [...] within the population [of a species] (‘structure shift’) [...or...] through a shift in the relative abundances of differently sized species (‘composition shift’)" Ohlberger (2013)

For simplicity, let's assume a community formed of only two species (sp1 and sp2), with an abundance of N=50 for each species in community 1 (at Time1) and an average body sizes of L_Sp1 = 100 and L_Sp = 160 mm. The average community body size would then be 130 mm.

We could think now of scenarios where each both mentioned mechanisms (structural and compositional shift) causes a community level shift to a mean body size of 145 mm. In scenario 1 the species-specific body sizes changes but abundances remain; in scenario 2 the species-specific body sizes remain but abundances change. Here some code for illustration:

library(ggplot2)
library(tidyr)
library(dplyr)

df1 <- data.frame(sp = rep(c("sp1","sp2","sp1","sp2"),c(50,50,50,50)),
Time = rep(c("T1","T2"),c(100,100)),
L1 = rep(c(100,160,120,170),c(50,50,50,50)),
scenario = 1)
df2 <- data.frame(sp = rep(c("sp1","sp2","sp1","sp2"),c(50,50,50,150)),
Time = rep(c("T1","T2"),c(100,200)),
L1 = rep(c(100,160,100,160),c(50,50,50,150)),
scenario = 2)
df <- rbind(df1,df2)

df%>%
ggplot(aes(x=Time,y=L1,
group=Time,color=sp))+
geom_jitter(width=0.2)+
geom_violin(alpha=0.2,scale="width",width=0.4)+
stat_summary(fun=mean, geom="point", shape=20, size=14, color="red", fill="red")+
facet_grid(scenario~.)

df%>%
group_by(case,Time)%>%
summarise(mean=mean(L1))


So this is related to the weights of each of the groups (i.e. species) that form the community in combination with changes in group-wise means. I was wondering how could this be statistically differentiated e.g. when we compare the mean body size of communities (e.g. over time). How large/important is is the 'structural' and what the 'compositional' component for an observed pattern? Ohlberger J (2013) Climate warming and ectotherm body size - from individual physiology to community ecology. Functional Ecology 27(4): 991–1001, doi: 10.1111/1365-2435.12098