# How to analyse intra-individual difference between two situations, with unequal sample size for each individual?

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.

Same data on a box plot:

And the same data after removing mean from each cat:

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.