I'll start by saying that I'm not sure whether to use Multilevel Modeling or Vector Autoregression for this problem. I have panel data, which tracks users who log into my website over time. I record purchase behavior, time of purchase, user ID, and location of user. Data are aggregated on a per-day basis. So for any given day, I have recorded the number of purchases for a user, the country they are in when they logged into the site, and the total number of purchases for the day.

These data are also not sampled. I have the whole shebang.

user_id = User ID
time = Time user logged in
user_location = User location (0: USA, 1: France, 2: Germany)
purchase_volume = Number of purchases


I want to understand the differences in purchasing volume over time for my users (are users in Germany buying at a faster rate than users in France?). It's the issue of RATE here that confuses me in terms of how I approach this problem. From what I've learned, I need a multilevel model, which should be able to describe how my customers grow in their purchasing volume at separate rates in different countries.

So I use mixedlm in statsmodels and use the following code. I include a random intercept for user, and I allow those intercepts to vary randomly as a function of time.

md = smf.mixedlm("purchase_volume ~ time * C(country)", 
mdf = md.fit(method=["lbfgs"])

Mixed Linear Model Regression Results
Model:              MixedLM Dependent Variable: purchase_volume
No. Observations:   861     Method:             REML           
No. Groups:         72      Scale:              5.9993         
Min. group size:    11      Likelihood:         -2217.5256     
Max. group size:    12      Converged:          Yes            
Mean group size:    12.0                                       
                     Coef.  Std.Err.   z    P>|z| [0.025 0.975]
Intercept            15.872    0.613 25.884 0.000 14.671 17.074
C(country)[T.1]       0.433    0.480  0.903 0.366 -0.507  1.374
C(country)[T.2]      -0.880    0.479 -1.836 0.066 -1.819  0.060
time                  6.929    0.089 78.071 0.000  6.755  7.103
time:C(country)[T.1] -0.081    0.066 -1.212 0.226 -0.211  0.050
time:C(country)[T.2]  0.116    0.067  1.738 0.082 -0.015  0.247
user_id Var          19.377    1.556                           
user_id x time Cov    0.298    0.152                           
time Var              0.415    0.033                           


Now I can see that I have an overall effect of time, and no real effect of country or interaction of country with time. However, the variances are still a mystery to me: How do these values help me understand how my users grow at different rates? What extra analysis do I need to do to determine this specific piece? My initial thoughts were to do some sort of post hoc within subjects ANOVA, but that feels wrong. I mean, why not just make this an ANOVA to begin with then?

With that being said, I'm also confused whether I should use a VAR model instead for this problem. Thanks for your help.


1 Answer 1


IIUC, you have 72 users who made a total of 861 purchases, and the number of purchases per user is extremely consistent, ranging only from 11 to 12.

Ideally, time should be translated so that time=0 is meaningful.

The purchase sizes are getting larger over time. There are no detectable differences between countries, either in their starting levels (at time=0), or in their rate of change over time.

The variances describe differences in behavior between individual users. The user intercept has an SD of sqrt(19.4) ~ 4, so a typical user consistently purchases 4-8 units more volume or less volume (1-2 SD) than the mean. The individual time slope has SD sqrt(0.4) ~ 0.6. So the common slope (6.3) is modulated by around +/- 1.2 (2 SD) between individuals.


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.