I have the following code for the Alpha calculation:
df <- tibble::tribble(
~seq, ~date, ~sales,
1, "3/01/2017", 40,
2, "4/01/2017", 2,
3, "5/01/2017", 2,
4, "6/01/2017", 2,
5, "7/01/2017", 30,
6, "8/01/2017", 2,
7, "1/02/2017", 9,
8, "2/02/2017", 5,
9, "3/02/2017", 65,
10, "4/02/2017", 3,
11, "5/02/2017", 65
)
library(tidyverse)
library(magrittr)
library(psy)
df %<>% mutate(lagsales = lag(sales))
df2 <- rowwise(df) %>% mutate(z = cronbach(cbind(sales,lagsales))$alpha) %>% ungroup
df2
It creates the following output:
df2
seq date sales lagsales z
1 1 3/01/2017 40 NA -1.232498
2 2 4/01/2017 2 40 -1.232498
3 3 5/01/2017 2 2 -1.232498
4 4 6/01/2017 2 2 -1.232498
5 5 7/01/2017 30 2 -1.232498
6 6 8/01/2017 2 30 -1.232498
7 7 1/02/2017 9 2 -1.232498
8 8 2/02/2017 5 9 -1.232498
9 9 3/02/2017 65 5 -1.232498
10 10 4/02/2017 3 65 -1.232498
11 11 5/02/2017 65 3 -1.232498
Question:
I am looking to get the Alpha for overlap for every 2nd line
Can I use this formula to calc Chronbachs Alpha for each item?;
Reliability = N / ( N - 1)x(Total Variance - Sum of Variance for Each number)/Total Variance
So I would not have – 1.232498 for every item.Only probably for item 1and 2 together.but 2 and 3 would have another alpha and 3 and 4 together would also have another alpha .etc.et. it has to look at row level and taking 2 rows rolling into consideration.
What would the R code look like?