I want to implement binary logistic regression using binomial data as discussed here. Additionally, I want to add a variable that identifies each binary data point coming from de-aggregation of the same binomial data point, so that I can properly account for their correlation in the analysis.
Below I present the outcome of my attempts so far. It successfully replicates the rows with respective covariates, but does not generate the binary variable yet. Any help would be much appreciated.
#Structure of input binomial data#
DT<-tibble::tibble(Successes = c(2,3,3), Trials=c(3,4,5), X1=c("Yes", "No", "Yes"), X2=c(10.7, 11.3, 9.9))
# A tibble: 3 x 4
Successes Trials X1 X2
<dbl> <dbl> <chr> <dbl>
2 3 Yes 10.7
3 4 No 11.3
3 5 Yes 9.9
#My attempts so far#
DT.expanded <- DT[rep(seq(nrow(DT)), DT$Trials), ]
DT.expanded
# A tibble: 12 x 4
Successes Trials X1 X2
<dbl> <dbl> <chr> <dbl>
2 3 Yes 10.7
2 3 Yes 10.7
2 3 Yes 10.7
3 4 No 11.3
3 4 No 11.3
3 4 No 11.3
3 4 No 11.3
3 5 Yes 9.9
3 5 Yes 9.9
3 5 Yes 9.9
3 5 Yes 9.9
3 5 Yes 9.9
#Expected structure of output binary data#
# A tibble: 12 x 4
Success X1 X2
<chr> <chr> <dbl>
1 Yes 10.7
1 Yes 10.7
0 Yes 10.7
1 No 11.3
1 No 11.3
1 No 11.3
0 No 11.3
1 Yes 9.9
1 Yes 9.9
1 Yes 9.9
0 Yes 9.9
0 Yes 9.9
Thanks in advance for any help.