-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProbabilityAnalysisModules.R
45 lines (37 loc) · 1.23 KB
/
ProbabilityAnalysisModules.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
PERMUTATION <- function(n,r){
#Assumptions : Works well with valid inputs.
#Valid Inputs : n can take positive value greater than or equal to 1.
# r can takes value less than or equal to n.
#Returns nPr
numerator <- FACTORIAL(n)
denominator <- FACTORIAL(n-r)
nPr <- numerator/denominator
return(nPr)
}
COMBINATION <- function(n,r){
#Assumptions : Works well with valid inputs.
#Valid Inputs : n can take positive value greater than or equal to 1.
# r can takes value less than or equal to n.
#Returns nCr
numerator <- FACTORIAL(n)
denominator <- FACTORIAL(r)*FACTORIAL(n-r)
nCr <- numerator/denominator
return(nCr)
}
BASICPROBABILITY <- function(favorable,total){
#Assumptions : Works well for valid input i.e, favorable <= total and both positive.
probability <- favorable/total
return(probability)
}
BAYESTHEOREM <- function(pofAi, pofBAi, i) {
len <- length(pofAi)
numerator <- as.numeric(pofAi[i])*as.numeric(pofBAi[i])
denominator <- 0
for(j in 1:len){
product <- as.numeric(pofAi[j])*as.numeric(pofBAi[j])
denominator <- denominator + product
}
result <- (numerator/denominator)
pofAiB <- formatC(result, digits = 6, format = "f")
return(pofAiB)
}