The data below are from a health testing centre over 8 years so there are different people being tested there each year. All I really want to show is that the amount of females being tested is different over the different years. The data look like this:

2002     50       7      57
2003    126      50     176
2004    339      68     407
2005    401     158     559
2006    639     328     967
2007    744     600    1344
2008    570     526    1096
2009    452     448     900
2010    561     372     933

I think these data are not actually repeated measures, because each year different individuals are being tested. Moreover, the data are counts in nature. So, I was just thinking of using Runs test to show if the amount of females being tested is different over the different years. Because Runs test is a test of randomness. The alternative hypothesis should be indicating some trend in the data.

Am I right that the data are not repeated measures? Moreover, is the concept of Runs test appropriate here?

What would the test be if I wanted to test "if the proportion of females being tested is different over the different years"? I think this is a more sensible test to do, but how can I do it?

I have several comparisons like this, so it would be good to know if I'm using the wrong test! Any suggestion regarding the test procedure will be greatly appreciated.

  • $\begingroup$ @PeterFlom, Sir may I ask for your suggestion? I guess if Runs test is appropriate, I can perform this for proportions too. But I am just getting a little bit confused! $\endgroup$
    – Blain Waan
    Commented Nov 28, 2012 at 4:58

1 Answer 1


You could just fit a flexible regression model and examine that instead. Since you don't know what the trend might be, but you think that the visits are independent people so the counts are binomially distributed, then you could do the following in R.

First we make the data and load a useful library

## make the data
dat <- data.frame(f=c(50, 126, 339, 401, 639, 744, 570, 452, 561),
                  m=c(7, 50, 68, 158, 328, 600, 526, 448, 372),
                  year=c(2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010))

## load the splines library

Then fit a flexible generalised linear model

## fit a model of the counts as a smooth (beta spline) function of year    
mod <- glm(cbind(f, m) ~ bs(year), data=dat, family=binomial)

## get the model predictions with standard errors
mod.pred <- predict(mod, type='response', se=TRUE)

Now plot the original data

## plot the data as proportions of females
with(dat, plot(f/(f+m) ~ year))

and put the model's predictions on top.

## plot them on top with rather approximate confidence intervals
with(mod.pred, lines(fit ~ dat$year))
with(mod.pred, lines(fit + se.fit*2 ~ dat$year))
with(mod.pred, lines(fit - se.fit*2 ~ dat$year))

fitted mean

That looks like evidence of a trend to me, albeit not a uniformly linear one.

If you were to assume the trend was linear (in the log ratios of females to males), then you might fit a simpler model, like

## just take out the spline
mod.lin <- glm(cbind(f, m) ~ year, data=dat, family=binomial)

This doesn't fit so well, but nevertheless still suggests that each year there are expected to have been exp(-0.16205) = 0.85 i.e. only 85% of the number of women each year compared to the year before - an effect that is, for what it's worth, significant.

  • $\begingroup$ Thank you so much. Your answer is very complete. But could you please explain a little more for me on why the counts are taken to be binomially distributed? Why we do not consider them as Poisson random variables? For testing the proportion of females would you please see if I can use the following link for my case? itl.nist.gov/div898/handbook/prc/section4/prc474.htm $\endgroup$
    – Blain Waan
    Commented Nov 28, 2012 at 17:21
  • 2
    $\begingroup$ If we assume that the counts of women and the counts of men in a year are Poisson distributed with different means (a reasonable assumption here) then at the end of the year we have a total number of people that arrived. Conditional on this total, the two counts must therefore, as a matter of mathematics, be Binomially distributed. That's just what happens when you condition two Poisson variables on their total. $\endgroup$ Commented Nov 28, 2012 at 20:53
  • 1
    $\begingroup$ You'll notice that in the link you provided there is a test of whether a set of proportions could actually all be the same, but the opposite of 'all the same' is not specified. In the answer above I am working with your specified alternative: that there is a time trend. Consequently I showed how to fit models that could find and represent such a trend if there was one to be found and could fail to see it if there was not. But that's really just a difference in perspective on your problem. $\endgroup$ Commented Nov 28, 2012 at 21:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.