Add beta and gamma to Alpha calc in separate columns

The following code calculates the Alpha for a time series.Sales for product in this case.
Would the R code for calculating Beta and Gamma be in lm.beta package?

CODE:

read_file(sales1)
library(tidyverse)
library(psy)
library(lm.beta)

#Number of rows before to take into account
rolling = 2

sales1 <- sales::sales(
~date, ~sales,)
#Lag
sales1 = sales1 %>% mutate(lagsales = lag(sales))

#Get the rolling alpha
sales1$alpha = c(
rep(NA, rolling),
map_dbl((rolling + 1):nrow(sales1), function(x){cronbach(sales1 %>% select(sales, lagsales) %>% slice((x-rolling):x))$alpha
})
)
#Get the rolling beta
sales1$lm.beta = c(rep(NA, rolling),
map_dbl((rolling + 1):nrow(sales1), function(x){cronbach(sales1 %>% select(sales, lagsales) %>% slice((x-rolling):x))$lm.beta
})
)

#Get the rolling gamma
sales1$gamma = c(rep(NA, rolling),
map_dbl((rolling + 1):nrow(sales1), function(x){cronbach(sales1 %>% select(sales, lagsales) %>% slice((x-rolling):x))$gamma
})
)

sales1

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.