For binary and independent variables you should use a chi-square test if the Central Limit Theorem's assumptions are not violated or Fisher's exact test if they are.
Here is a piece of code that tests the CLT assumptions and runs the relevant test depending on the outcome.
I've used a rule of thumb value of 5. Feel free to change my number "5" with something a higher value for more conservative or less if you want to be less conservative:
# Generate some random binary outcomes for Series 1 and 2
set.seed(1241535)
Series1 <- rbinom(150, 1, 0.5)
Series2 <- rbinom(200, 1, 0.6)
# All tests need to be confirmed
pooled_p <- (sum(Series1) + sum(Series2))/(length(Series1) + length(Series2))
test1 <- (length(Series1) * pooled_p) >= 5
test2 <- (length(Series2) * pooled_p) >= 5
test3 <- (length(Series1) * (1 - pooled_p)) >= 5
test4 <- (length(Series2) * (1 - pooled_p)) >= 5
final_test <- all(test1, test2, test3, test4)
# Chi-square or Fisher's exact test
x <- c(sum(Series1), sum(Series2))
n <- c(length(Series1), length(Series2))
mash <- rbind(c(sum(Series1), length(Series1) - sum(Series1)),
c(sum(Series2), length(Series2) - sum(Series2)))
if(final_test == T){
## With Yate's continuity correction
prop.test(x,n)
#Exactly the same as:
chisq.test(mash)
}else{
# Fisher's exact test
fisher.test(mash)
}
If your variables are not independent e.g: if series 1 and 2 are measurements of the same individual before and after an intervention, then a McNemar's test is more appropriate:
set.seed(1241535)
Series1 <- rbinom(200, 1, 0.5)
Series2 <- rbinom(200, 1, 0.6)
tab <-
matrix(c(sum(Series1 == 1 & Series2 == 1),
sum(Series1 == 0 & Series2 == 1),
sum(Series1 == 1 & Series2 == 0),
sum(Series1 == 0 & Series2 == 0)
),
nrow = 2,
dimnames = list("Series1" = c("1", "0"),
"Series2" = c("1", "0")))
tab
mcnemar.test(tab)
The latter might be the relevant one for your case as I've noticed that you specify paired = TRUE
in your code.