How to handle repeated measures when fitting a gamma model with log link I am not a statistician and wanted to see if anyone could help me with some statistical modeling. 
I have the total medical costs for thousands of patients (total yearly cost for each patient) along with some demographic information such as age, gender, geography etc). I have 5 years worth of data and some patients have data for a single year, some for two years, and some for more than two years. The cost per patient per year is always positive and extremely skewed with a small number of patients with very high costs. Most of what I have read suggests that I should be using a gamma model with log-link, but what I want to understand is how do I account for the repeated measures for (multiple years) for some patients?
Ultimately, I am trying to understand what variables (such as age, gender, geography, insurance type etc) drive healthcare costs. I am using R for building the model. Any suggestions on how to go about doing this? 
 A: You can fit a Gamma generalized linear mixed model GLMM with patient as a random-effects grouping variable, e.g.
library(lme4)
glmer(cost ~ age + gender + (1|patient), family=Gamma(link="log"),
      data= ...)



*

*Depending on how much and what kind of geographic information you have, you might want to include geographic areas (e.g. state or county) as a random-effects grouping variable as well.

*Depending on the size of your data set (larger is better), you might consider including random slopes for covariates that vary within groups, such as 


*

*(age|patient) (age varies within patients, although not very much, so you might be able to detect how much the age effect varies across patients) or 

*(age+gender|county) (age and gender vary within counties, so you can try to estimate how much their effects vary across counties.


*Log-normal linear mixed models (i.e. fit linear mixed models to the log-transformed cost data) might be faster and/or more robust than log-link Gamma models.

