-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContinuousDistributionModules.R
More file actions
71 lines (62 loc) · 1.69 KB
/
ContinuousDistributionModules.R
File metadata and controls
71 lines (62 loc) · 1.69 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
UNICONTINOUS <- function(lowX,highX,a,b){
if(lowX >= a && highX <= b){
tempFun <- function(x){
return(1/(b-a))
}
integralValue <- adaptIntegrate(tempFun,lowX,highX)$integral
return(integralValue)
}
else if (lowX >= a && highX > b && lowX <= b){
tempFun <- function(x){
return(1/(b-a))
}
integralValue <- adaptIntegrate(tempFun,lowX,b)$integral
return(integralValue)
}
else if (lowX < a && highX <= b && highX >= a){
tempFun <- function(x){
return(1/(b-a))
}
integralValue <- adaptIntegrate(tempFun,a,highX)$integral
return(integralValue)
}
else if (lowX < a && highX > b){
tempFun <- function(x){
return(1/(b-a))
}
integralValue <- adaptIntegrate(tempFun,a,b)$integral
return(integralValue)
}
else if ((lowX < a && highX < a)){
return(0)
}
else if ((lowX > b && highX > b)){
return(0)
}
}
NORMALDIST <- function(lowX,highX,popMean,popVariance){
tempFun <- function(x){
numerator <- exp((-0.5)*(((x - popMean)/popVariance)^2))
denominator <- ((2*pi*popVariance)^(0.5))
return(numerator/denominator)
}
integrateValue <- integrate(tempFun,lowX,highX)$value
return(integrateValue)
}
myGamma <- function(alpha){
tempFun <- function(x){
var <- (x^(alpha-1))*(exp(-x))
return(var)
}
integrateValue <- integrate(tempFun,0,Inf)$value
return(integrateValue)
}
GAMMADIST <- function(lowX,highX,alpha,beta){
tempFun <- function(x){
numerator <- (x^(alpha-1))*(exp(-x/beta))
denominator <- (beta^alpha)*myGamma(alpha)
return(numerator/denominator)
}
integralValue <- adaptIntegrate(tempFun,lowX,highX)$integral
return(integralValue)
}