-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoisson.R
133 lines (108 loc) · 3.02 KB
/
poisson.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
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
server <- function(input,output){
#######################################
# These are the reactive calculations # These do not get displayed
#######################################
rand_samp <- reactive({
rpois(input$obs, input$lambda)
})
# THIS WILL NEED TO GET CHANGED FOR POISSON
# calculate some stuff needed to define the quantiles
min_quant <- reactive({
min(rand_samp()) # set the minimum of the quantiles
})
max_quant <- reactive({
max(rand_samp()) # set the maximum of the quantiles
})
quantiles <- reactive({
seq(min_quant(), max_quant(), 1)
})
# probability density
prob_dens <- reactive({
dpois(quantiles(), input$lambda)
})
# cumulative probability
cuml_prob <- reactive({
ppois(quantiles(), input$lambda)
})
# quantiles plot
quant_plot <- reactive({
qpois(seq(0,1,0.01), input$lambda)
})
##################################
# These are the reactive outputs # These get displayed
##################################
# Plot the random sample
output$Plot_sample <-renderPlot({
hist(rand_samp(),main="",xlab="Quantiles",col="grey")
},
width=400,height=400
)
# Mean
output$summary <- renderPrint({
summary(rand_samp())
})
# Standard deviation
output$stdev <- renderPrint({
sd(rand_samp())
})
# Plot the probability density
output$Plot_prob_dens <-renderPlot({
plot(quantiles(), prob_dens(), ylab="Probability density", xlab="Quantiles")
},
width=400,height=400
)
# Plot the cumulative probability
output$Plot_cuml_prob <-renderPlot({
plot(quantiles(), cuml_prob(), ylab="Cumulative Probability", xlab="Quantiles")
},
width=400,height=400
)
# Plot the quantiles
output$Plot_quantiles <-renderPlot({
plot(seq(0,1,0.01), quant_plot(),ylab="Quantiles", xlab="Probability")
},
width=400,height=400
)
}
ui <- shinyUI(pageWithSidebar(
# Title
headerPanel(""),
sidebarPanel(
sliderInput("obs",
label = "Number of observations:",
min = 1,
max = 1000,
value = 500,
step=1),
sliderInput("lambda",
"Lambda:",
min=0.1,
max=15,
value=3,
step=0.1)
),
# GGPLOT
mainPanel(
tabsetPanel(
tabPanel("Random Sample",
plotOutput("Plot_sample"),
h6("Summary:"),
verbatimTextOutput("summary"),
h6("Standard deviation:"),
verbatimTextOutput("stdev")
),
tabPanel("Probability Density",
plotOutput("Plot_prob_dens"),
h6("dpois(quantiles, lambda)")
),
tabPanel("Cumulative Probability",
plotOutput("Plot_cuml_prob"),
h6("ppois(quantiles, lambda)")
),
tabPanel("Quantile Plot",
plotOutput("Plot_quantiles"),
h6("qpois(seq(0,1,0.01), lambda)")
)
)
)
))