Hello,I am trying to calculate the rolling **Beta.distr** in column ~K and rolling ~Gamma.dist. in column ~b .

What do I have incorrect in my code?Could anyone help me with this?

**in put code as follows:**

read_file(sales1)

library(tidyverse)

library(psy)

library(lm.beta)

library(invgamma)

#Number of rows before to take into account

rolling = 2

sales1 <- sales::sales( ~date, ~sales,~K,~b,~s,~a,)

#Lag

sales1 = sales1 %>% mutate(lagsales = lag(sales))

#Aquire 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

})

)

#Aquire rolling beta

sales1$beta = c(rep(NA, rolling),

map_lgl((rolling + 1):nrow(sales1), function(x){lm.beta(sales1 %>% select(sales, lagsales) %>% slice((x-rolling):x))$lm.beta

})

)

#Aquire rolling gamma

sales1$invgamma = c(rep(NA, rolling),

map_dbl((rolling + 1):nrow(sales1), function(x){rinvgamma(sales1 %>% select(sales, lagsales) %>% slice((x-rolling):x))$rinvgamma

})

)

sales1

**out put is as follows: Including errors**

library(tidyverse)

library(psy)

library(lm.beta)

library(invgamma)#Number of rows before to take into account

rolling = 2sales1 <- sales::sales( ~date, ~sales,~K,~b,~s,~a,)

Error in loadNamespace(name) : there is no package called ‘sales’

#Lag

sales1 = sales1 %>% mutate(lagsales = lag(sales))#Aquire 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

- })
- )

#Aquire rolling beta

sales1$beta = c(rep(NA, rolling),

- map_lgl((rolling + 1):nrow(sales1), function(x){lm.beta(sales1 %>% select(sales, lagsales) %>% slice((x-rolling):x))$lm.beta
- })
- )

Error in lm.beta(sales1 %>% select(sales, lagsales) %>% slice((x - rolling):x)) :

object has to be of class lm

Called from: lm.beta(sales1 %>% select(sales, lagsales) %>% slice((x - rolling):x))

Browse[1]>

#Aquire rolling gamma

sales1$invgamma = c(rep(NA, rolling),

- map_dbl((rolling + 1):nrow(sales1), function(x){rinvgamma(sales1 %>% select(sales, lagsales) %>% slice((x-rolling):x))$rinvgamma
- })
- )

Error in rgamma(n, shape, rate) :

argument "shape" is missing, with no default

Called from: rgamma(n, shape, rate)

Browse[1]>

sales1

# A tibble: 341 x 8

Date sales K b s a lagsales alpha

1 03-0~ 40 NA NA NA NA NA NA

2 04-0~ 2 NA NA NA NA 40 NA

3 05-0~ 2 NA NA NA NA 2 0

4 06-0~ 2 NA NA NA NA 2 0

5 07-0~ 30 NA NA NA NA 2 0

6 08-0~ 2 NA NA NA NA 30 -2

7 01-0~ 9 NA NA NA NA 2 -4.44

8 02-0~ 5 NA NA NA NA 9 -1.48

9 03-0~ 65 NA NA NA NA 5 -0.0604

10 04-0~ 3 NA NA NA NA 65 -2.69