Skip to content

Commit 5e9fafc

Browse files
committed
added lognormal vs gamma vs zaga
1 parent 496361d commit 5e9fafc

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

lnorm_vs_gamma_vs_zaga/README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
## A comparison of lognormal, gamma and zaga distributions.

lnorm_vs_gamma_vs_zaga/server.R

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
3+
library(shiny)
4+
library(gamlss)
5+
6+
# Define server logic required to draw a histogram
7+
shinyServer(function(input, output) {
8+
9+
output$distPlot <- renderPlot({
10+
# input to objects
11+
mu <- input$mu
12+
sigma <- input$sigma
13+
nu <- input$nu
14+
15+
# transform parameters
16+
meanlog = log(mu^2 / sqrt(sigma^2 + mu^2))
17+
sdlog = sqrt(log((sigma^2 / mu^2) + 1))
18+
19+
shape = 1 / sigma^2
20+
scale = mu / shape
21+
22+
# plot density
23+
curve(dlnorm(x, meanlog = meanlog, sdlog = sdlog) , 0, 4)
24+
curve(dgamma(x, scale = scale, shape = shape), 0, 4,
25+
col = 'red', add = TRUE)
26+
curve(dZAGA(x, mu = mu, sigma = sigma, nu = nu), 0, 4,
27+
col = 'blue', add = TRUE)
28+
29+
})
30+
31+
})

lnorm_vs_gamma_vs_zaga/ui.R

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
library(shiny)
3+
4+
shinyUI(fluidPage(
5+
6+
# Application title
7+
titlePanel("Lognormal vs Gamma vs ZAGA"),
8+
9+
# Sidebar with a slider input for number of bins
10+
sidebarLayout(
11+
sidebarPanel(
12+
sliderInput("mu",
13+
"mu:",
14+
min = 0.5,
15+
max = 2,
16+
value = 2,
17+
step = 0.1),
18+
sliderInput("sigma",
19+
"sigma:",
20+
min = 0,
21+
max = 1,
22+
value = 0.5,
23+
step = 0.1),
24+
sliderInput("nu",
25+
"nu:",
26+
min = 0,
27+
max = 1,
28+
value = 0,
29+
step = 0.1)
30+
),
31+
32+
# Show a plot of the density functions
33+
mainPanel(
34+
plotOutput("distPlot")
35+
)
36+
)
37+
))

0 commit comments

Comments
 (0)