I have some data like this:
id pop var
1 593 51
2 592 31
3 346 20
4 1214 70
5 1063 66
6 1370 71
each id
represents a school. There are around 1847 of them, of which 1833 are unique . pop
is the number of pupils in the school. var
is the number of pupils with a particular trait. Interest in centered on the ratio of var/pop
. I have used a binomial regression:
fit.bn <- glm(cbind(var,pop-var)~1, data=dt, family=binomial(link=logit))
which produced the results:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -2.748516 0.003295 -834.2 <2e-16 ***
And to get the estimate for the proportion and it's confidence interval I used:
invlogit(coef(fit.bn))
invlogit(confint(fit.bn,level = 0.95))
where
invlogit <- function (x) { return(exp(x)/(1+exp(x))) }
which produced:
(Intercept)
0.06017054
2.5 % 97.5 %
0.05980603 0.06053643
Is this a valid confidence interval for these data ? I was surprised that it was so narrow, but I guess this is because the total number observations is high (altogether, sum(var)= 98008
and sum(pop)=1628981
). Nevertheless, I am still unsure about this, due to:
sd(var/pop)
0.01373888
In other words the standard deviation of these proportions is around 20 times larger than their confidence interval.
Am I doing something stupid ? It just doesn't seem quite right.
I wondered about using a variance components model to try to account for variability between schools and within schools. I did this with
require(lme4)
fit.lme4 <- glmer(cbind(cbind(var,pop-var)~1+(1|id), data=dt, family=binomial(link=logit))
This produced:
Random effects:
Groups Name Variance Std.Dev.
id (Intercept) 0.024125 0.15532
Number of obs: 1847, groups: id, 1814
Fixed effects:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -1.776882 0.005423 -327.7 <2e-16 ***
So I computed another confidence interval by:
invlogit(-1.776882 + (c(-1.96,1.96)* 0.005423))
0.1433781 0.1460089
which is wider than the first one, but the estimate is very different. Is this a valid procedure ? How do I interpret this estimate and confidence interval as compared to the first one ? And how do I interpret the variance of the random effects ? Am I barking up the wrong tree ?
Update:
Here is a histogram of var/pop
var
andpop
per school.......... $\endgroup$