Estimating AIC for data subsets When modelling data that contain groups, I want to test whether the groups are different and therefore should be modeled with different parameters. If a simple model for the whole dataset is y ~ x, and the groups are denoted by parameter z, a model that allows the groups to differ is y ~ x*z. It is straightforward to use AIC to compare this group model with y ~ x. If there are 2 groups, the parameter estimates from the group model can also be obtained by splitting the dataset by z, and fitting a model to each data subset: 
model a: y[z=0] ~ x[z=0] 
model b: y[z=1] ~ x[z=1] 

However, when fitted in R, the AIC(group model: a,b) is not equal to AIC(model a) + AIC(model b). See the code below. I checked with both glm and gam (mgcv). 
I expected that the AIC(group model) would be the same as AIC(model a) + AIC(model b), because the same data are being used on both sides, the parameter estimates are the same on both sides, and the numbers of parameters are the same on both sides. But the AICs on the two sides are different. Since AIC = 2k - 2 x ln(L), this must mean that the likelihood estimates are different, but I don't understand why. 
Could someone please explain why they differ? 
x=1:10
y=x+rnorm(10)
z = rep(c(F,T),5)
dat <- data.frame(x,y,z)
mod2 <- glm(y ~ x,data=dat[dat$z,])
mod3 <- glm(y ~ x,data=dat[!dat$z,])
mod4 <- glm(y ~ x*z,data=dat)
AIC(mod4) # the combined group model 
# [1] 38.10184

AIC(mod2) + AIC(mod3) # a separate model for each group
# [1] 40.08271 # in 10000 trials, this number was larger than AIC(mod4) 84% of the time

sum(dnorm(mod4$residuals))
# [1] 2.725178
sum(dnorm(mod2$residuals)) + sum(dnorm(mod3$residuals))
# [1] 2.725178

pred1 <- predict(mod1,newdata=dat)
pred2 <- predict(mod2,newdata=dat)
pred3 <- predict(mod3,newdata=dat)
pred4 <- predict(mod4,newdata=dat)

windows();
plot(dat$x,pred1,type="l",xlim=c(0,11),ylim=c(0,11))
lines(dat$x,pred2,col=2)
lines(dat$x,pred3,col=3)
points(dat$x,pred4)

 A: AIC, as it turns out, is related to the Shannon entropy of a single dataset, which is a measure of self-information. Entropy is not relative information content and is not a comparative measure between datasets. It has none of the properties of, for example, temperature difference, which would indicate in which direction information would flow. Self-information does not have nice properties and can only be used for comparing differing models fit to the same dataset. 
Different subsets have differing entropies and cannot be compared using AIC.
A: When the dataset is split into parts, the sum of the likelihoods (and therefore the AIC's) won't be the same as the likelihood of the group model, because the variances in the likelihood equations differ. The variance estimate in each part uses a subset of the data, while the variance estimate in the group analysis uses all of the data. 
Running the model in the question 10000 times, the sum of AIC(mod2) and AIC(mod3) is about one unit larger than AIC(mod4), the group AIC, on average. The difference in each run is random (variance is fairly unstable) and in 16% of runs the group AIC is larger. 
