-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEffects.R
More file actions
63 lines (46 loc) · 1.77 KB
/
Copy pathEffects.R
File metadata and controls
63 lines (46 loc) · 1.77 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
library(shiny)
ui <- fluidPage(
withMathJax(),
titlePanel("Effect, Sample Size and p-value"),
p("Use the sliders to adjust the effect and sample size and observe the
p-value."),
p("The plot shows the distributions of sample means under the null
hypothesis as well as the alternative hypothesis."),
sidebarPanel(
sliderInput("effect", "Effect Size", 0, 1.2, .2, .01),
sliderInput("N", "Sample Size", 5, 100, 50),
checkboxInput("bothSides", "Two sided hypothesis", FALSE),
verbatimTextOutput("pval")
),
mainPanel(
wellPanel(plotOutput("plot"))
)
)
server <- function(input, output) {
output$plot <- renderPlot({
curve(dnorm(x, sd = (1/sqrt(input$N))), xlim = c(-1, 1.5), ylab =
"", xlab = "Effect")
polygon(c(input$effect, seq(input$effect, 1.5, length.out = 101),
1.5), c(0, dnorm(seq(input$effect, 1.5, length.out = 101), sd =
(1/sqrt(input$N))), 0), col = "lightblue")
if (input$bothSides) {
polygon(c(-1, seq(-1, -input$effect, length.out = 101),
-input$effect), c(0, dnorm(seq(-1, -input$effect, length.out
= 101), sd = (1/sqrt(input$N))), 0),
col = "lightblue")
}
curve(dnorm(x, sd = (1/sqrt(input$N)), mean = input$effect), add =
TRUE, col = "blue")
abline(v = 0)
abline(v = input$effect, col = "blue")
mtext("H0", 1, 2, at = 0)
mtext("H1", 1, 2, at = input$effect, col = "blue")
})
output$pval <- renderPrint({
pval <- pnorm(input$effect*sqrt(input$N), lower.tail = FALSE)
if(input$bothSides)
pval <- pval*2
cat(paste("p-value: ", pval))
})
}
shinyApp(ui, server)