How to do it...

In the following example, we will work with a mixed effects model, containing data for some clients. We have 100 observations with 50 subjects and several replications per subject. Each client is contacted each time by a salesman using a variety of communication strategies (this is the fixed effect we are interested in).

The target variable is the amount sold, and we want to understand whether there are differences that are attributable to the different communication strategies. If that is the case, we want to implement the best communication strategy as the main one for the entirety of the sales team:

  1. First, we need to load the necessary libraries and dataset, as follows:
library(lme4)
library(lmerTest)
library(lsmeans)
clients <- read.csv("./clients.csv")
  1. We will use the lmer function from the lme4 package. We want to model Sales in terms of Strategy, Client, and Salesman. The notation for this model will be different from a model where the effects are fixed. The (1|Client) term means that we want to add a random intercept (mean) effect for each client. This implies that all of the observations belonging to the same client will be correlated (they will share a common shock). We use the same approach for the Salesman effect:
E = lmer(Sales ~ Strategy + (1|Client) + (1|Salesman),data=clients)
summary(E)
Note that all of the fixed effects coefficients are statistically significative. Regarding the random effects, we can see that most of the variability of the model is explained by the salesman (it's almost as big as the combined client variability and the unexplained variability – residual).

The preceding code generates the following output of mixed effects model results:

  1. The ANOVA table can be obtained as usual, and obviously the fixed effect is highly significative: 
anova(E) 

The following screenshot shows ANOVA table:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.235.104