Created
May 6, 2014 01:23
-
-
Save palday/3bc889a55d6c99457f27 to your computer and use it in GitHub Desktop.
Beta Error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
library(ggplot2) | |
library(gridExtra) | |
library(scales) | |
library(reshape2) | |
library(zoo) | |
shinyServer(function(input, output) { | |
output$distribution <- renderPlot({ | |
SD <- input$SD | |
mean.pop <- 0 | |
mean.sample <- mean.pop + input$diff.mean | |
max.x <- input$max | |
min.x <- input$min | |
alpha <- input$alphaValue | |
beta <- qnorm(alpha,mean=mean.pop,sd=SD,lower.tail=FALSE)#input$betaValue | |
pts <- 100 | |
x <- seq(min.x,max.x,length.out=pts) | |
pop <- dnorm(x,mean=mean.pop,sd=SD) | |
smp <- dnorm(x,mean=mean.sample,sd=SD) | |
ndata <- data.frame(x,pop,smp) | |
nplot <- ggplot(data=ndata,aes(x=x)) + ylab("P(x)") + geom_line(aes(y=pop)) + geom_line(aes(y=smp)) | |
alphazone <- subset(ndata, pnorm(x,mean=mean.pop,sd=SD,lower.tail=FALSE) <= alpha) | |
betazone <- subset(ndata, x <= min(alphazone$x)) | |
if (length(row.names(alphazone))){ | |
nplot <- nplot + geom_ribbon(aes(x=x,ymin=0,ymax=pop), data=alphazone, fill="blue",alpha=0.5) | |
} | |
if (length(row.names(betazone))){ | |
nplot <- nplot +geom_ribbon(aes(x=x,ymin=0,ymax=smp), data=betazone, fill="red",alpha=0.5) | |
} | |
print(nplot) | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
# Define UI for application that draws a histogram | |
shinyUI(fluidPage( | |
titlePanel("The relationship of significance level (alpha) to beta error"), | |
sidebarLayout( | |
sidebarPanel(h2("Experimental Parameters") | |
, sliderInput("alphaValue" | |
,"Significance / Sensitivity Threshold" | |
,min = 0.01 | |
,max = 1.0 | |
,value = 0.05) | |
, numericInput("max" | |
,"Max x to plot" | |
,value = 10) | |
, numericInput("min" | |
,"min x to plot" | |
,value = -10) | |
, numericInput("SD" | |
,"standard deviation" | |
,value = 1) | |
, numericInput("diff.mean" | |
,"True difference in means" | |
,value = 1) | |
) | |
,mainPanel(h2("Hits and misses at a given significance level.") | |
,plotOutput("distribution") | |
,p("Blue is correctly detected, red is incorrectly dismissed.") | |
) | |
) | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment