Skip to content

Commit 3735e16

Browse files
add shiny app 04e_gomptertz
1 parent e51d619 commit 3735e16

File tree

3 files changed

+169
-1
lines changed

3 files changed

+169
-1
lines changed

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# BioDataScience2 News
22

3-
## Changes in version 2019.7.0
3+
## Changes in version 2019.8.0
44

55
- shiny app 04c 04d
66

inst/shiny/04e_gompertz/server.R

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#
2+
# This is the server logic of a Shiny web application. You can run the
3+
# application by clicking 'Run App' above.
4+
#
5+
# Find out more about building applications with Shiny here:
6+
#
7+
# http://shiny.rstudio.com/
8+
#
9+
10+
library(shiny)
11+
SciViews::R()
12+
13+
# Define server logic required to draw a histogram
14+
shinyServer(function(input, output) {
15+
16+
output$gomp_plot <- renderPlot({
17+
18+
set.seed(42)
19+
20+
gomp_data <- tibble(
21+
t = seq(0, 10, by = 0.1),
22+
y = SSgompertz(t, Asym = 1, b2 = 5, b3 = 0.5) + rnorm(
23+
n = length(t), sd = 0.05),
24+
y_predit = SSgompertz(x = t, Asym = input$asym_ui, b2 = input$b2_ui,
25+
b3 = input$b3_ui)
26+
)
27+
28+
chart(data = gomp_data, y ~ t) +
29+
geom_point() +
30+
geom_line(f_aes(y_predit ~ t), color = "red") +
31+
xlab("Temps") +
32+
ylab("Population")
33+
34+
})
35+
36+
output$gomp_model <- renderUI({
37+
withMathJax(
38+
sprintf(
39+
"Ton modèle :
40+
$$%.02f \\times e^{- %.02f \\times %.02f^{Temps}}$$",
41+
input$asym_ui, input$b2_ui, input$b3_ui))
42+
})
43+
44+
45+
output$gomp_resid <- renderUI({
46+
47+
set.seed(42)
48+
49+
50+
set.seed(42)
51+
52+
gomp_data <- tibble(
53+
t = seq(0, 10, by = 0.1),
54+
y = SSgompertz(t, Asym = 0.95, b2 = 5, b3 = 0.5) + rnorm(
55+
n = length(t), sd = 0.05),
56+
y_predit = SSgompertz(x = t, Asym = input$asym_ui, b2 = input$b2_ui,
57+
b3 = input$b3_ui),
58+
distance2 = (y_predit - y)^2
59+
)
60+
61+
value <- sum(gomp_data$distance2)
62+
63+
withMathJax(
64+
sprintf("La valeur de la somme des résidus au carré de ton modèle : $$%.05f$$",
65+
value))
66+
})
67+
68+
69+
output$gomp_theo <- renderPlot({
70+
71+
gomp_data <- tibble(
72+
t = seq(0, 10, by = 0.1),
73+
y = SSgompertz(t, Asym = 1, b2 = 5, b3 = 0.5)
74+
)
75+
76+
chart(data = gomp_data, y ~ t) +
77+
geom_line() +
78+
geom_vline(xintercept = 0, col = "darkgray") +
79+
geom_hline(yintercept = c(0, 0.95/exp(1), 0.95), col = "gray",
80+
linetype = "dashed") +
81+
geom_vline(xintercept = 2.3, col = "gray", linetype = "dashed") +
82+
annotate("text", label = "Asym", x = -0.4, y = 0.95) +
83+
annotate("text", label = "Asym/e", x = -0.5, y = 0.95/exp(1)) +
84+
annotate("text", label = "point d'inflexion", x = 3.5, y = 0.32) +
85+
labs( x = "x")
86+
})
87+
88+
})

inst/shiny/04e_gompertz/ui.R

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
library(shiny)
2+
3+
titlePanel_h4 <- function(title, windowTitle = title) {
4+
tagList(tags$head(tags$title(windowTitle)), h4(title))
5+
}
6+
7+
# Define UI for application that draws a histogram
8+
shinyUI(
9+
navbarPage(
10+
title = titlePanel_h4("Modèle de Gompertz"),
11+
tabPanel(
12+
"Un peu de théorie",
13+
sidebarLayout(
14+
sidebarPanel(
15+
withMathJax(),
16+
h4("Le Contexte"),
17+
p("Gompertz a observé de manière empirique que le taux de survie
18+
décroît souvent de manière proportionnelle au logarithme du
19+
nombre d’animaux qui survivent. Ce modèle décrit est utilisé pour
20+
décrire des courbes de survie et des données de croissance."),
21+
h4("L'équation mathématique :"),
22+
p("$$Asym \\times e^{- b_{2} \\times b_{3}^x}$$"),
23+
h4("Eléments importants :"),
24+
p("- une asymptotes horizontales"),
25+
p("- un point d'inflection asymétrique"),
26+
hr(),
27+
h4("La fonction dans R : "),
28+
p("$$SSgompertz(x, Asym, b2, b3)$$"),
29+
h5("Arguments de la fonction : "),
30+
p("x : est un vecteur de nombre représentant le temps."),
31+
p("Asym : est la valeur de y représenté par un asymptote
32+
horizontale."),
33+
p("b2 : TODO."),
34+
p("b3 : TODO."),
35+
width = 5
36+
),
37+
mainPanel(
38+
p("Le graphique ci-dessous représente le modèle de Gompertz avec
39+
Asym = 0.95, b2 = 5, b3 = 0.5"),
40+
plotOutput("gomp_theo"),
41+
width = 7
42+
)
43+
)
44+
),
45+
tabPanel(
46+
title = "A toi de jouer !",
47+
sidebarLayout(
48+
sidebarPanel(
49+
withMathJax(),
50+
p("Le modèle de Gompertz est employé pour décrire des courbes de
51+
survie et des données de croissance avec un asymptote
52+
horizontale et un point d'inflection asymétrique."),
53+
p("L'équation mathématique de la fonction est la
54+
suivante: $$y = Asym \\times e^{- b_{2} \\times b_{3}^x}$$"),
55+
numericInput(inputId = "asym_ui", label = "Valeur de Asym (asymptote horizontale)",
56+
value = 0.50, min = 0.250, max = 10.00, step = 0.25),
57+
p("Valeur par défaut : 0.50"),
58+
numericInput(inputId = "b2_ui", label = "Valeur de b2",
59+
value = 1.00, min = 0.25, max = 10.00, step = 0.25),
60+
p("Valeur par défaut : 1"),
61+
numericInput(inputId = "b3_ui", label = "Valeur de b3",
62+
value = 1.00, min = 0.25, max = 10.00, step = 0.25),
63+
p("Valeur par défaut : 1")
64+
),
65+
mainPanel(
66+
h4("Ajustez le meilleur modèle de Gompertz"),
67+
p("Vous devez ajuster votre modèle en faisant varier les
68+
paramètres du modèle."),
69+
plotOutput("gomp_plot"),
70+
hr(),
71+
withMathJax(),
72+
uiOutput("gomp_model"),
73+
hr(),
74+
uiOutput("gomp_resid"),
75+
hr()
76+
)
77+
)
78+
)
79+
)
80+
)

0 commit comments

Comments
 (0)