Skip to content
Snippets Groups Projects
Commit 138ce99c authored by Clare's avatar Clare
Browse files

Chnage to L_plus_R so that it will return zero rather than NA when n<2 in choose(n,2)

parent 09a03dcf
Branches
No related tags found
No related merge requests found
......@@ -66,11 +66,8 @@ L_plus_R <- function(pos, ws, X = NULL) {
## get L, R and L_plus_R
noL <- length(pos[pos>=currentPos-ws/2 & pos < currentPos]) ## Number of SNPs to the left of the current SNP
noR <- length(pos[pos<=currentPos+ws/2 & pos > currentPos]) ## Number of SNPs to the right of the current SNP
if(noL < 2 || noR < 2){ #Must be at least 2 to calculate n choose 2
outputList$L_plus_R[i]<-NA
} else {
## if n < 2 then choose function will return 0
outputList$L_plus_R[i]<-choose(noL,2)+choose(noR,2)
}
}
return(outputList)
}
......@@ -12,7 +12,7 @@ test_that("L_plus_R calculates L_plus_R statistic correctly", {
expect_equal(L_plus_R(pos = df$POS, ws = 3000, X = NULL),
list(
position=c(100,200,300,400,500,600,700,800,900,1000,1100,1200,1300,1400,1500),
L_plus_R=c(NA,NA,67,58,51,46,43,42,43,46,51,58,67,NA,NA)
L_plus_R=c(91,78,67,58,51,46,43,42,43,46,51,58,67,78,91)
))
})
......@@ -23,7 +23,7 @@ test_that("L_plus_R calculates L_plus_R statistic correctly with a different win
expect_equal(L_plus_R(pos = df$POS, ws = 1100, X = NULL),
list(
position=c(100,200,300,400,500,600,700,800,900,1000,1100,1200,1300,1400,1500),
L_plus_R=c(NA,NA,11,13,16,20,20,20,20,20,16,13,11,NA,NA)
L_plus_R=c(10,10,11,13,16,20,20,20,20,20,16,13,11,10,10)
))
})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment