Newer
Older
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
###########################################################################
## power Shiny/R app ui.R ##
## ##
## Author Eugen Pircalabelu https://perso.uclouvain.be/eugen.pircalabelu ##
## For RShiny@UCLouvain http://sites.uclouvain.be/RShiny ##
## ##
## Licences : CC-BY for http://sites.uclouvain.be/RShiny ##
## GPL for source code on ##
## https://forge.uclouvain.be/rshiny_uclouvain/power ##
###########################################################################
library(shiny)
library(shinyjs)
shinyUI(pageWithSidebar(
headerPanel("La fonction de puissance"),
sidebarPanel(
tags$head(
tags$style(type="text/css", "label { display: inline; }"),
tags$style(type="text/css", '.checkbox input[type="checkbox"],.radio input[type="radio"] { float: none; }')
),
HTML(" μ<sub>0</sub> : moyenne sous H<sub>0</sub> : prend la valeur 1 <br>" ),#Label put outside of sliderInput because HTML is not rendered inside sliderInput label
# sliderInput("mu0", "" ,min = 1,max = 1,value = 1, step=0,dragRange=F),
HTML(" μ<sub>1</sub> : moyenne sous H<sub>1</sub> : prend des valeurs entre 0 et 2 <br>"),
HTML(" H<sub>1</sub> est vrai H<sub>0</sub> est faux <br>"),
# sliderInput("mu","",min = 0,max = 2,value = 0, step=0,dragRange=F),
HTML(" <br>"),
HTML(" σ : écart-type de la population d'origine "),
sliderInput("sigma","",min = 0.5,max = 2,value = 0.5, step=0.1,animate = TRUE),
HTML(" n : nombre d'individus par échantillon "),
sliderInput("n"," ",min = 5,max = 150,value = 5, step=5,animate = TRUE),
p(HTML("<A HREF=\"javascript:history.go(0)\">Cliquez ici pour relancer l'expérience</A>")),
HTML('<hr style="border:1px solid #ccc;"/>'),
HTML('<a rel="license" href="http://creativecommons.org/licenses/by/2.0/be/"><img alt="Licence Creative Commons" style="border-width:0"
src="http://i.creativecommons.org/l/by/2.0/be/80x15.png" /></a> Ce(tte) oeuvre de <span xmlns:cc="http://creativecommons.org/ns#"
property="cc:attributionName"> <font face="Courier"> RShiny@UCLouvain </font> </span> est mise à disposition selon les termes de la <a rel="license"
href="http://creativecommons.org/licenses/by/2.0/be/">licence Creative Commons Attribution 2.0 Belgique</a>.'),
HTML('<p>Détails sur l\'utilisation de cette ressource sur <a href="http://sites.uclouvain.be/RShiny"
target="_blank"><font face="Courier"> RShiny@UCLouvain </font></a><br/>
Code source disponible sur <a href="https://forge.uclouvain.be/rshiny_uclouvain/power" target="_blank">GitLab</a></p>')
),
mainPanel(
plotOutput("Plot")
)
))
# Define a server for the Shiny app
function(input, output) {
# Fill in the spot we created for a plot
output$Plot <- renderPlot({
# mu=seq(0,1,length=100)
# mypow1=ifelse(mu==input$mu0,input$myalpha1,
# 1-pnorm((sqrt(input$n)/input$sigma)*(input$mu0-mu)+qnorm(1-input$myalpha1)))
# plot(mu,mypow1,type="l",lwd=2,ylim=c(0,1),cex.lab=2.2,xlab=expression(mu-mu[0]),
# main="",ylab=expression(pi[n](mu)),cex=1.4, cex.axis=2,bty="n",
# xlim=c(0,1),col="black")
disable("mu")
myalpha1=0.01
mu0=1
sigma=input$sigma
n=input$n
mu=seq(0,2,length=100)
mypow1=ifelse(mu==mu0,myalpha1,1-pnorm((sqrt(n)/sigma)*(mu0-mu)+qnorm(1-myalpha1)))
par(mar=c(4,5.5, 0.5, 0.5))
plot(mu-mu0,mypow1,type="l",lwd=2,ylim=c(0,1),cex.lab=2.2,xlab=expression(mu*-~mu[0]),
main="",ylab=expression(pi[n](mu)),cex=1.4, cex.axis=2,bty="n",
xlim=c(-1,1),col="black",xaxt="n")
axis(1, c(-1,0,1),labels=c(-1,0,1),cex.axis=2, tck=-.02)
myalpha2=0.05
mypow2=ifelse(mu==mu0,myalpha2,1-pnorm((sqrt(n)/sigma)*(mu0-mu)+qnorm(1-myalpha2)))
lines(mu-mu0,mypow2,cex.lab=2.2,xlab="",ylab="",col=c("red"),cex=1.4,
yaxt="n", xaxt="n",bty="n",type="l",lty=2,lwd=2)
myalpha3=0.1
mypow3=ifelse(mu==mu0,myalpha3,1-pnorm((sqrt(n)/sigma)*(mu0-mu)+qnorm(1-myalpha3)))
lines(mu-mu0,mypow3,cex.lab=2.2,xlab="",ylab="",col=c("blue"),cex=1.4,
yaxt="n", xaxt="n",bty="n",type="l",lty=3,lwd=3)
legend("topleft",lty=c(NA,1,2,3),col=c("black","black","red","blue"),bty="n",
cex=2,lwd=3,legend=c(
as.expression(bquote(n*"="*.(n))),
as.expression(bquote(alpha*"="*.(format(myalpha1, digits = 2)))),
as.expression(bquote(alpha*"="*.(format(myalpha2, digits = 2)))),
as.expression(bquote(alpha*"="*.(format(myalpha3, digits = 2))))))
})
}