Multilevel modelling allows for analysis of data that have hierarchical or clustered structures.Source: Output generated by author using R.Note: Original article is available here.Multilevel modelling is particularly useful in the context of market research, whereby segmenting customers by category (e.g. demographics, purchasing habits) is important in understanding how a business can both attract new customers and improve customer loyalty among existing ones.The lme4 library in R is used to create multilevel models. One significant example of a multilevel modelling exercise within this library is that of the sleepstudy example, whereby a multilevel model was used to analyse how reaction times across sleep deprived individuals differed between participants given the number of days of sleep deprivation.How would we apply such a model to analysing customer data? Let’s take a look!An e-commerce site wishes to analyse some recent sales data that they have collected regarding activity on their site. Specifically, they wish to determine factors that influence spend per customer.They provide a dataset containing the following information: