The setup is like this:

  • each individual is measured in each of two situations
  • a measurement can yield zero or more usable results

I want to answer the question: "Does the situation affect the behavior of the members of this population (all of them in a similar manner)?" How should I approach this problem, so that I correctly disregard differences between individuals and unequal number of results for each of them, but emphasize the difference between situations?

To give you some more concrete context: I record cats' calls. From each recording I extract some parameters and it's these parameters that I want to compare - say, a length of a meow. Do cats produce statistically longer meows in one situation than in the other?

I don't want to take inter-individual differences into account. E.g. one cat may usually produce longer calls than the other, but I am only interested in a difference between situations, not between cats. To account for that, I want to center each individual's data by subtracting mean from their measurements.

But the biggest challenge for me is how to deal with the fact that some individuals have more measurements than others (some cats just meow more often). This is not a difference that I am interested in, but it will affect any test I could perform. And because of that difference I can't use paired tests.
Here are my thoughts on this:

  • If I treat all recordings from one situation as one group, and all the recordings from the other situation as another group, then the difference (or lack thereof) present in cats which produce less calls, will be underrepresented in my sample. The fact that a cat meows less frequently shouldn't affect the significance of the difference observed in this cat.
  • I could group the recordings by [cat, situation] and compute an average in each of such groups. Then treat these averages as my measurements and compare them between situations. This way each cat will be equally significant.
    However I see two problems with this approach:
    • firstly, I will have much less measurements so my test will be less powerful*;
    • secondly, an average computed from smaller number of recordings is less accurate than the one computed from larger number of recordings, so this should be probably also taken into account.

I looked into weighted t-tests and thought that maybe I could weigh recordings of each cat by a reciprocal of a number of calls the cat produced, but I'm far from sure that it's the correct way.

I am using Python for my calculations. So far I've used scipy.stats; today I also discovered statmodels which offer weighted tests, but their docs say that weighting is equivalent to repeating the measurements (frequency weighting), which I am not convinced is a correct way here.

Could you please guide me on how to approach this problem?

*I am not a statistician, I don't have much experience in this field. Quite probably I have used some terms incorrectly here - sorry if that's the case. Just trying to conduct the analysis in a most correct way I am capable of. :)

--- EDIT ---

Adding some plots to visualize the problem.

Here are values of one of the parameters (it's not length of a meow, let's call this parameter F). Here one might hypothesize that F is usually higher for each cat in blue situation. I would like to (dis)prove it.

One dot represents one call. Color represents situation (we have two situations: blue and orange). Cats are on x axis. In parentheses a number of recording per cat is given. not centered, swarm

Same data on a box plot: not centered, box

And the same data after removing mean from each cat: centered, box


1 Answer 1


It is not clear to me if a length of a meow of a cat is just an example or the real context, but will treat it as the last. You cannot just say that you are not interested in the variation between cats (even if that is not the inferential interest), since that contributes to the variability, creates dependence in the data. So just ignoring it could invalidate results.

I would propose a mixed-effects model (as I am not using Python, I cannot comment of Python software. But Python must have some analog of lme4 in R.) Different number of meow's per cat is not a problem. A simple linear mixed-effects model is $$ y_{ijt}=\mu + \alpha_i + \gamma_t + \epsilon_{ijt} $$ where $y_{ijt}$ is response $j$ from cat $i$ with treatment $t$, the random effect is $\alpha_i$ for cat $i$ and $\gamma_t$ is treatment effect. This is a model with normal errors $\epsilon_{ijt}$, constant variance. So it is a natural starting point. If your situation is not covered by this assumption, you can replace it with a generalized linear mixed effects model. At least it is a starting point. If the treatment effects could vary between cats, maybe a random effect $\gamma_{it}$ is necessary.

Could you show us some plots, or even share (a link to) the data?

  • 1
    $\begingroup$ Thank you very much for your answer! I will certainly explore mixed-effect models. I added some plots to the question. Unfortunately I cannot share the data, surely not now. $\endgroup$ Commented Oct 24, 2020 at 17:05

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.