2
$\begingroup$

I have a large population of books. Each book is either a hardback or softback (thus hardback and softback books are paired with one another by title), and can fall into two categorical genres - Action or Thriller. For each book, the sales volume is measured annually (hence it is a repeated measures design). Importantly, some books have sales measurements over many years, whilst for some books it was only possible to measure sales for the first year or two years.

Data are structured as followed, just as an example. There are approximately 10,000 books in the sample (5,000 hardback, 5,000 softback).

Title    Type        Genre       SalesYear1   SalesYear2   SalesYear3   
AAA      Hardback    Action      100          150          180
AAA      Softback    Action      80           105          125
BBB      Hardback    Thriller    50           90           110
BBB      Softback    Thriller    20           45           80
CCC      Hardback    Action      120          200          --
CCC      Softback    Action      120          245          --
DDD      Hardback    Action      75           --           --
DDD      Softback    Action      95           --           --
...      ...         ...         ...          ...          ...

I want to conduct a regression analysis to determine whether hardback books have higher sales than softback books, taking into account other variables, i.e. genre of the book, as well as time.

For a single year, I could potentially do this with a linear regression model assuming sales were normally distributed, as follows (with R):

lm(formula = SalesYear1 ~ Type + Genre, data=data)

summary(lm)

However, this does not take into account the paired nature of the books, and ignores the repeated measures approach. How might I do this? I have read that the lmer function of the lme4 package would be suitable. In that case I would reorder my data into a long format, with a single column for Sales, and a column for Time, and then do something like:

lmer(Sales ~ Time + Type + Genre + (Type| Title), data = data)

This would seem to account for the nesting of Title in Type, but I don't know if another random effect is required for Time. Does this syntax look right? I'm very confused - any pointers to resources would be much appreciated.

$\endgroup$
  • $\begingroup$ I don't see why you can't do a paired T test. Each factor in your dataset is a between-cluster factor. If you calculate paired differences, you remove the influence of the factor. If you want to know about the ancillary factors, you can sum the sales values and use those in a regression model against year and genre. $\endgroup$ – AdamO Aug 15 '19 at 16:08
2
$\begingroup$

You have indeed a complex type of design and a rich dataset to explore it. A couple of considerations:

  • To explore the following (nested) structure, you will need to put the data in the long format with measurements over time in the same book and type put one underneath the other, and also create a time variable.
  • It would be expected that sales of the same book over time are correlated. To explore this, you will need to include random effects for the Title grouping factor.
  • Moreover, sales in the same type may be more correlated than measurements from different types. To explore this you will need to include a nested random effect for Type.
  • In the fixed effects if you only include the main effect of Type you postulate that the difference between types is constant over time. If you want to explore whether the difference between types changes over time, you will need to include the interaction of Type with Time.
  • Logically you would expect that the sales of a book over time would follow a nonlinear pattern. To explore this you could include splines of time.
  • Putting all these together, some potential models to consider are:

# Random intercepts & linear random slopes nested random effects fm_nested <- lmer(Sales ~ ns(Time, 3) * Type + Genre + (Time | Title) + (Time | Title:Type), data = data)

# Random intercepts and linear random slopes only for Time fm_title <- lmer(Sales ~ ns(Time, 3) * Type + Genre + (Time | Title), data = data)

#Likelihood Ratio Test between the two models anova(fm_titleRE, fm_nested)

Function ns() is from package splines and is used to model a potential nonlinear time effect using natural cubic splines.

  • You will also need to explore the residuals to see if the assumptions of the model are validated.
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.