# Help understand data structure and appropriate model (hierarchial data wtih repeated measures)

I have credit card transaction data, that I will describe with a relationship diagram. There are thousands of records, which are tied to a credit card, tied to a customer. Each customer can have 1-2 cards, on which there can be anywhere between 1-30 transactions (unbalanced repeated), ordered by date. Each transaction record also contains a boolean variable classifying if the transaction was tagged as fraud. The goal is to build a model that will be able to predict if a transaction from another set of test data is fraudulent or not.

The way I see it, this is hierarchial data, where [Transactions] are nested within [Credit card] nested within [Customer]. One source of my uncertainty is how to treat each level. I am studying variation in purchasing habits of customers to classify whether it was fraudulent, the results of which would be applicable to other customers, hence customer is a random effect. But the features pertaining to customers are their tier (always 3 levels), and age (20-70 range), so they are fixed effects? Would the credit limit/type and transaction value/sector variables also be fixed effects, since they are specific to each customer. Should I recode numeric variables of customer - age, credit card - limit, and transaction - value into ordered categories so I can treat them as fixed effects as well?

Would a Generalized Linear Mixed Model with transactions as unbalanced repeated measures be appropriate for modelling? What are the fixed and random effects?

Thanks to everyone who reads my question and any input you may have.

You could use a Generalized Linear Mixed Model with transactions nested in card and card nested in customer. Those will be the random effects. The other variables: customer age, credit card limit, and transaction value will be fixed effects - they don't need to be recoded.

In R using lme4 syntax this would be:

mod <- glmer(fraud ~ age + limit + value + (1 | customer/card), data = mydata, family="binomial"(link="logit"))


You might want to consider a model where the slope for value varies by customer by fitting random slopes, if the data supports such a model.

You might also want to allow for a nonlinear association of value with fraud by including nonlinear terms or splines.

• Thank you! I'll give it a shot next, so far I tried Random Forest and some density based classification methods, treating all records as independent observations, and all of which have given me zero discriminatory ability. Commented Jul 6, 2020 at 2:46
• Do you think I should treat transaction and credit card as fixed effects, since unlike randomly sampled customers, I have all the data on how many cards they own and all the transactions made on that card? Commented Jul 6, 2020 at 3:00
• @darsin I was going to suggest card as a fixed effect in case of convergence issues. I can see arguments for both. But ransactions are not random effects, those are the lower level which are repeated measures. Commented Jul 6, 2020 at 4:44