Commit dad78736 authored by jbleher's avatar jbleher
Browse files

New apps

parent 8eb032bf
Loading
Loading
Loading
Loading
+68 −0
Original line number Diff line number Diff line
############################################################
#                 Bernoulli Distribution - Shiny App
############################################################

library(shiny)

# ------------------- User Interface -------------------
ui <- fluidPage(
  
  # Title
  titlePanel("Bernoulli Distribution"),
  
  sidebarLayout(
    
    sidebarPanel(
      # Auswahl: PMF oder CDF
      selectInput("typ", "Function:",
                  choices = c("Distribution function (CDF)" = 0, 
                              "Probability mass function (PMF)" = 1)),
      
      helpText("The Bernoulli distribution models a single trial with outcome 0 or 1."),
      
      # Parameter p
      sliderInput("p", "Success probability (p):",
                  min = 0, max = 1, value = 0.4, step = 0.01)
    ),
    
    mainPanel(
      plotOutput("bernPlot")
    )
  )
)

# ------------------- Server Logic -------------------
server <- function(input, output) {
  
  output$bernPlot <- renderPlot({
    
    p <- input$p
    x <- 0:1
    
    if (input$typ == 1) {
      # PMF
      pmf <- dbinom(x, size = 1, prob = p)
      plot(x, pmf, type = "h", lwd = 3,
           ylim = c(0, 1),
           main = sprintf("Bernoulli PMF (p = %.2f)", p),
           xlab = "x", ylab = "Probability",
           cex.lab = 1.2, cex.main = 1.2)
      points(x, pmf, pch = 19)
      text(x, pmf + 0.05, labels = round(pmf, 3))
      
    } else {
      # CDF
      cdf <- pbinom(x, size = 1, prob = p)
      plot(x, cdf, type = "s", lwd = 3,
           ylim = c(0, 1),
           main = sprintf("Bernoulli CDF (p = %.2f)", p),
           xlab = "x", ylab = "Cumulative probability",
           cex.lab = 1.2, cex.main = 1.2)
      abline(h = c(0, 1), lty = 2)
      points(x, cdf, pch = 19)
    }
  })
}

# ------------------- Start App -------------------
shinyApp(ui = ui, server = server)

02_code/R/Beta_app.R

0 → 100644
+74 −0
Original line number Diff line number Diff line
############################################################
#                 Beta Distribution - Shiny App
############################################################

library(shiny)

# ------------------- User Interface -------------------
ui <- fluidPage(
  
  # Title
  titlePanel("Beta Distribution"),
  
  sidebarLayout(
    
    sidebarPanel(
      
      # Auswahl: CDF oder PDF
      selectInput("typ", "Function:",
                  choices = c("Distribution function (CDF)" = 0, 
                              "Density function (PDF)" = 1)),
      
      helpText("The Beta distribution is defined on [0,1] with two shape parameters."),
      
      # Parameter alpha (shape1) und beta (shape2)
      sliderInput("alpha", "Shape parameter α (shape1):",
                  min = 0.1, max = 10, value = 2, step = 0.1),
      
      sliderInput("beta", "Shape parameter β (shape2):",
                  min = 0.1, max = 10, value = 3, step = 0.1)
    ),
    
    mainPanel(
      plotOutput("betaPlot")
    )
  )
)

# ------------------- Server Logic -------------------
server <- function(input, output) {
  
  output$betaPlot <- renderPlot({
    
    alpha <- input$alpha
    beta  <- input$beta
    
    # x-Werte im Intervall [0,1]
    x <- seq(0, 1, length.out = 400)
    
    if (input$typ == 1) {
      # PDF
      y <- dbeta(x, shape1 = alpha, shape2 = beta)
      
      plot(x, y, type = "l", lwd = 3,
           main = sprintf("Beta PDF (α = %.2f, β = %.2f)", alpha, beta),
           xlab = "x", ylab = "Density",
           cex.lab = 1.2, cex.main = 1.2)
      abline(h = 0, lwd = 2)
      
    } else {
      # CDF
      y <- pbeta(x, shape1 = alpha, shape2 = beta)
      
      plot(x, y, type = "l", lwd = 3,
           main = sprintf("Beta CDF (α = %.2f, β = %.2f)", alpha, beta),
           xlab = "x", ylab = "Cumulative probability",
           cex.lab = 1.2, cex.main = 1.2,
           ylim = c(0, 1))
      abline(h = c(0, 1), lty = 2)
    }
  })
}

# ------------------- Start App -------------------
shinyApp(ui = ui, server = server)

02_code/R/Cauchy_app.R

0 → 100644
+71 −0
Original line number Diff line number Diff line
############################################################
#                 Cauchy Distribution - Shiny App
############################################################

library(shiny)

# ------------------- User Interface -------------------
ui <- fluidPage(
  
  titlePanel("Cauchy Distribution"),
  
  sidebarLayout(
    
    sidebarPanel(
      
      selectInput("typ", "Function:",
                  choices = c("Distribution function (CDF)" = 0,
                              "Density function (PDF)" = 1)),
      
      helpText("The Cauchy distribution is a heavy-tailed distribution with undefined mean and variance."),
      
      sliderInput("x0", "Location parameter (x0):",
                  min = -10, max = 10, value = 0, step = 0.5),
      
      sliderInput("gamma", "Scale parameter (γ):",
                  min = 0.1, max = 10, value = 1, step = 0.1)
    ),
    
    mainPanel(
      plotOutput("cauchyPlot")
    )
  )
)

# ------------------- Server Logic -------------------
server <- function(input, output) {
  
  output$cauchyPlot <- renderPlot({
    
    x0    <- input$x0
    gamma <- input$gamma
    
    # x-range around x0
    x <- seq(x0 - 10 * gamma, x0 + 10 * gamma, length.out = 400)
    
    if (input$typ == 1) {
      # PDF
      y <- dcauchy(x, location = x0, scale = gamma)
      
      plot(x, y, type = "l", lwd = 3,
           main = sprintf("Cauchy PDF (x0 = %.2f, γ = %.2f)", x0, gamma),
           xlab = "x", ylab = "Density",
           cex.lab = 1.2, cex.main = 1.2)
      abline(h = 0, lwd = 2)
      
    } else {
      # CDF
      y <- pcauchy(x, location = x0, scale = gamma)
      
      plot(x, y, type = "l", lwd = 3,
           main = sprintf("Cauchy CDF (x0 = %.2f, γ = %.2f)", x0, gamma),
           xlab = "x", ylab = "Cumulative probability",
           cex.lab = 1.2, cex.main = 1.2,
           ylim = c(0, 1))
      abline(h = c(0, 1), lty = 2)
    }
  })
}

# ------------------- Start App -------------------
shinyApp(ui = ui, server = server)
+82 −0
Original line number Diff line number Diff line
############################################################
#          Extreme Value (Gumbel) Distribution - Shiny App
############################################################

library(shiny)

# -------- Gumbel PDF and CDF (Type I Extreme Value) --------
dgumbel <- function(x, mu = 0, beta = 1) {
  z <- (x - mu) / beta
  (1 / beta) * exp(-(z + exp(-z)))
}

pgumbel <- function(x, mu = 0, beta = 1) {
  z <- (x - mu) / beta
  exp(-exp(-z))
}

# ------------------- User Interface -------------------
ui <- fluidPage(
  
  titlePanel("Extreme Value (Gumbel) Distribution"),
  
  sidebarLayout(
    
    sidebarPanel(
      
      selectInput("typ", "Function:",
                  choices = c("Distribution function (CDF)" = 0,
                              "Density function (PDF)" = 1)),
      
      helpText("Gumbel distribution (Type I Extreme Value) for maxima."),
      
      sliderInput("mu", "Location parameter (μ):",
                  min = -10, max = 10, value = 0, step = 0.5),
      
      sliderInput("beta", "Scale parameter (β):",
                  min = 0.1, max = 10, value = 1, step = 0.1)
    ),
    
    mainPanel(
      plotOutput("gumbelPlot")
    )
  )
)

# ------------------- Server Logic -------------------
server <- function(input, output) {
  
  output$gumbelPlot <- renderPlot({
    
    mu   <- input$mu
    beta <- input$beta
    
    # x-range around mu
    x <- seq(mu - 10 * beta, mu + 10 * beta, length.out = 400)
    
    if (input$typ == 1) {
      # PDF
      y <- dgumbel(x, mu = mu, beta = beta)
      
      plot(x, y, type = "l", lwd = 3,
           main = sprintf("Gumbel PDF (μ = %.2f, β = %.2f)", mu, beta),
           xlab = "x", ylab = "Density",
           cex.lab = 1.2, cex.main = 1.2)
      abline(h = 0, lwd = 2)
      
    } else {
      # CDF
      y <- pgumbel(x, mu = mu, beta = beta)
      
      plot(x, y, type = "l", lwd = 3,
           main = sprintf("Gumbel CDF (μ = %.2f, β = %.2f)", mu, beta),
           xlab = "x", ylab = "Cumulative probability",
           cex.lab = 1.2, cex.main = 1.2,
           ylim = c(0, 1))
      abline(h = c(0, 1), lty = 2)
    }
  })
}

# ------------------- Start App -------------------
shinyApp(ui = ui, server = server)

02_code/R/Logit_app.R

0 → 100644
+71 −0
Original line number Diff line number Diff line
############################################################
#                 Logistic Distribution - Shiny App
############################################################

library(shiny)

# ------------------- User Interface -------------------
ui <- fluidPage(
  
  titlePanel("Logistic Distribution"),
  
  sidebarLayout(
    
    sidebarPanel(
      
      selectInput("typ", "Function:",
                  choices = c("Distribution function (CDF)" = 0,
                              "Density function (PDF)" = 1)),
      
      helpText("The logistic distribution is similar to the normal distribution but has heavier tails."),
      
      sliderInput("mu", "Location parameter (μ):",
                  min = -10, max = 10, value = 0, step = 0.5),
      
      sliderInput("s", "Scale parameter (s):",
                  min = 0.1, max = 10, value = 1, step = 0.1)
    ),
    
    mainPanel(
      plotOutput("logisPlot")
    )
  )
)

# ------------------- Server Logic -------------------
server <- function(input, output) {
  
  output$logisPlot <- renderPlot({
    
    mu <- input$mu
    s  <- input$s
    
    # x-range around mu
    x <- seq(mu - 10 * s, mu + 10 * s, length.out = 400)
    
    if (input$typ == 1) {
      # PDF
      y <- dlogis(x, location = mu, scale = s)
      
      plot(x, y, type = "l", lwd = 3,
           main = sprintf("Logistic PDF (μ = %.2f, s = %.2f)", mu, s),
           xlab = "x", ylab = "Density",
           cex.lab = 1.2, cex.main = 1.2)
      abline(h = 0, lwd = 2)
      
    } else {
      # CDF
      y <- plogis(x, location = mu, scale = s)
      
      plot(x, y, type = "l", lwd = 3,
           main = sprintf("Logistic CDF (μ = %.2f, s = %.2f)", mu, s),
           xlab = "x", ylab = "Cumulative probability",
           cex.lab = 1.2, cex.main = 1.2,
           ylim = c(0, 1))
      abline(h = c(0, 1), lty = 2)
    }
  })
}

# ------------------- Start App -------------------
shinyApp(ui = ui, server = server)
Loading