I would like to do a piecewise growth regression with my data, based on Raudenbush/Bryk(1992/2002), Hierarchical Linear Models, p178 - 179.
I will have to apply a Multi level Model to do this.
I is the lme4-package I will need to use.
My data contains sales revenues over time per ID. I have two breakpoints: sales>10 and sales>25. I want to analyse the growth in sales before and after the breakpoints.
I have two variables for every ID: var1: 123455555555 (when the salesrevenue exceeds 10 (breakpoint1), the variable stays constant) var2: 000000006789 (when the sales revenue exceeds 25(for breakpoint2), the variable is increasing, before 25 it is 0)
df = data.frame (
ID = c(1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2),
sales = c(1,4,10,12,20,26,28,2,5,9,12,13,18,26,29,35),
var1 = c(1,2,3,3,3,3,3,1,2,3,4,4,4,4,4,4),
var2 = c(0,0,0,0,0,1,2,0,0,0,0,0,0,1,2,3))
My Multi-Level Model has the form:
Y= b0i + b1i*a1ti + b2i*a2ti + eti
(sorry, I m not allow to post images and formulas :( )
a1ti and a2ti are my the coded variables (var1 and var2) which specify the pieces.
Level 1: repeated-observation for each individual level
Level 2: between-subjects level
Could maybe somebody explain me where I have to specify the Level 1 and Level 2 in my lmer()-Code and how I will get the two slopes of my two pieces? Do I have to add specifications between my brackets as O + ..., or 1 + ... to get only the intercept, etc.?
I guess my Code will look something like this:
test <- (lmer(sales ~ ID*var1 + (1|var1) + (1|ID), df))
or this:
test <- (lmer(sales ~ var1 + var2 + (1|var1) + (1|var2), df))
Thank you!
Best wishes Alexa