-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSGR test.Rmd
More file actions
146 lines (104 loc) · 5.09 KB
/
Copy pathSGR test.Rmd
File metadata and controls
146 lines (104 loc) · 5.09 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
---
title: "Shale Gouge Ratio using Monte Carlo Simulation"
author: "AmrMoslim"
date: "April 15, 2019"
output:
html_notebook:
code_folding: none
runtime: shiny
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(
echo = FALSE,
message = FALSE,
warning = FALSE
)
```
This R Markdown document is made interactive using Shiny. Unlike the more traditional workflow of creating static reports, you can now create documents that allow your readers to change the assumptions underlying your analysis and see the results immediately.
To learn more, see [Interactive Documents](http://rmarkdown.rstudio.com/authoring_shiny.html).
## Inputs and Outputs
You can embed Shiny inputs and outputs in your document. Outputs are automatically updated whenever inputs change. This demonstrates how a standard R plot can be made interactive by wrapping it in the Shiny `renderPlot` function. The `selectInput` and `sliderInput` functions create the input widgets used to drive the plot.
```{r Ft, echo=FALSE, message=FALSE, warning=FALSE}
inputPanel(
helpText( h5("Enter the Estimated Fault throw in meters below: ")),
textInput("Ft90", label = h4("P90",tags$h6("(is small)")), value = "100"),
textInput("Ft10", label = h4("P10",tags$h6("(is large)")), value = "500"),
selectInput("FtDist",
label = "Distribution Type:",
choices = c("Normal Distribution", "Lognormal Distribution"),
selected = "Normal Distribution")
)
inputPanel(
helpText( h5("Enter the Estimated Layer Thickness in meters below: ")),
textInput("Ft90", label = h4("P90",tags$h6("(is small)")), value = "100"),
textInput("Ft10", label = h4("P10",tags$h6("(is large)")), value = "500"),
selectInput("FtDist",
label = "Distribution Type:",
choices = c("Normal Distribution", "Lognormal Distribution"),
selected = "Normal Distribution")
)
inputPanel(
helpText( h5("Enter the Net to Gross ratio below: ")),
sliderInput("nG", "Net to Gross :",
min = 1, max = 100, value = c(49, 51 )),
selectInput("NgDist",
label = "Distribution Type:",
choices = c("Normal Distribution", "Lognormal Distribution"),
selected = "Normal Distribution"),
sliderInput("Simu", "Numbers of Simulations:",
min = 0, max = 100000, value = 10000)
)
```
```{r SGrCalc, echo=FALSE, message=TRUE, warning=TRUE}
library(mc2d)
###################### Inputs #####################################################
seed = 999
Ftp90 <- reactive({as.numeric(input$Ft90)})
Ftp10 <- reactive({as.numeric(input$Ft10)})
Ltp90 <- reactive({as.numeric(input$Lt90)})
Ltp10 <- reactive({as.numeric(input$Lt10)})
Ngp90 <- reactive({input$nG[1]})
Ngp10 <- reactive({input$nG[2]})
n = reactive({input$Simu})
###################### Calculate the SD ###########################################
Ftsd <- reactive({sd(Ftp90():Ftp10())})
Ltsd <- reactive({sd(Ltp90():Ltp10())})
ngsd <- reactive({sd(Ngp90():Ngp10())})
###################### Calculate the Mean ##########################################
Ftmean <- reactive({mean(Ftp90():Ftp10())})
Ltmean <- reactive({mean(Ltp90():Ltp10())})
ngmean <- reactive({mean(Ngp90():Ngp10())})
###################### Generate the Distributions of the aspects ###################
#Fault throw thaickness Distribution
Ft = reactive({if (input$FtDist =="Normal Distribution" )
{
mcstoc(rnorm, mean=Ftmean(), sd=Ftsd(), rtrunc=TRUE, linf=Ftp90(), lsup=Ftp10(), seed = seed, nsv= n() )}
else if (input$FtDist == "Lognormal Distribution")
{
mcstoc(rlnorm, mean=Ftmean(), sd=Ftsd(), rtrunc=TRUE, linf=Ftp90(), lsup=Ftp10(), seed = seed, nsv= n())}
})
#Layer thaickness Distribution
Lt = reactive({if (input$LtDist =="Normal Distribution" )
{
mcstoc(rnorm, mean=Ltmean(), sd=Ltsd(), rtrunc=TRUE, linf=Ltp90(), lsup=Ltp10(), seed = seed, nsv= n() )}
else if (input$LtDist == "Lognormal Distribution")
{
mcstoc(rlnorm, mean=Ltmean(), sd=Ltsd(), rtrunc=TRUE, linf=Ltp90(), lsup=Ltp10(), seed = seed, nsv= n())}
})
#NG Distribution
#
NG = reactive({if (input$NgDist =="Normal Distribution" ) {
mcstoc(rnorm, mean=ngmean(), sd=ngsd(), rtrunc=TRUE, linf=Ngp90(), lsup=Ngp10(), seed = seed, nsv= n())}
else if (input$NgDist == "Lognormal Distribution") {
mcstoc(rlnorm, mean=ngmean(), sd=ngsd(), rtrunc=TRUE, linf=Ngp90(), lsup=Ngp10(), seed = seed, nsv= n())}
})
###########################################################################################
SGR = reactive({
(((100-NG())*Lt())/Ft())
})
### SGR panel----
renderPlot({
hist(SGR(), xlab="SGR (%)", breaks=100, col="seagreen1")
})
renderPrint({ summary(SGR(), probs = c(0.01,0.1,0.50,0.9,0.99)) })
```