My shiny application is a simple way to prove Central Limit Theorem. You can observe as many as you want samples generated by R algorithm that will prove CLT.
7/15/2020
My shiny application is a simple way to prove Central Limit Theorem. You can observe as many as you want samples generated by R algorithm that will prove CLT.
library(shiny)
shinyUI(fluidPage(
# Application title
titlePanel("Central Limit Theorem Test"),
# Sidebar with a slider input for number of obs
sidebarLayout(
sidebarPanel(
sliderInput("observations",
"Enter the number of observation",
min = 1,
max = 500,
value = 10),
sliderInput("mean",
"Enter the mean.",
min = 1,
max = 500,
value = 10),
textOutput("Theoremstatement"),
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot"),
textOutput("statement")
)
)
))
library(shiny)
# Define server logic required to draw a histogram
shinyServer(function(input, output) {
dd <- reactive({rnorm(input$observations, input$mean)})
actualmean <-reactive({ mean(dd())})
output$distPlot <- renderPlot({
#dd <- rnorm(input$observations, input$mean)
#actualmean <- mean(dd)
aa <- dd()
hist(aa)
abline(v = actualmean(), col = "blue")
abline(v = input$mean, col = "red")
})
output$Theoremstatement <- renderText(" The CLT states that the more observations the closer the actual mean gets to theoretical mean ")
output$statement <- reactive({
paste("The theoretical mean is ", input$mean," and the actual mean is", actualmean()," and the difference is ", abs(input$mean - actualmean()))
})
})
All you have to do is just to choose the number of observation and the theorethical mean value. After that a graph will be presented with 2 vertical lines. The Blue like represents actual mean and the red line represents theoretical mean.