Hypothesis Testing for Two Populations

Code : https://github.com/sahuvaibhav/Stats.git
App : https://sahuvaibhav.shinyapps.io/Stats/

Added a new functionality to my stats app - Hypothesis testing for comparing two population means.

There are various techniques to compare means of two populations based on the type available sample data and the assumptions on population variance.
- Comparing two independent populations' means using Z-test. This test is applied when sample sizes are large or population variances are known.
This can be performed using "Hypothesis Testing" tab  in the app.
-  Comparing two independent populations' means using t-test. t-test is applied to compare two independent populations means when sample sizes are small or population variances are not known.
Based on assumptions on population variances two techniques are available.
- Pooled Variance Test - When population variances are unknown and are assumed equal, pooled variance test is applied. Pooled Variance and degree of freedom for test is
                      df = n1+n2-2
           s = sqrt(((s1^2*(n1-1) + s2^2*(n2-1))/(n1+n2-2))*(1/n1+1/n2))
- Unpooled Variance Test - When population Variances are unknown and are assumed not equal.
  Unpooled Variance and degree of freedom are
          df = (s1^2/n1+s2^2/n2)/((s1^2/n1)^2/(n1-1) + (s2^2/n2)^2/(n2-1) ) 
          s = sqrt(s1^2/n1 + s2^2/n2)
Both these tests can be performed at "independent sample" tab in the app.
- Paired Sample Test -  When same sample is tested two times to observe the difference paired sample test is performed (Like before and after cases).
"Paired Sample" tab in the app
- Comparing two population Proportions: Two populations can be compared when sample proportions are available.
"Proportions" tab in the app




Shiny R provides a number of functionality to create such applications.
Feedback and comments are welcome!!!





0

Add a comment




  1.                                                     Hypothesis Testing for Two Populations

    Code : https://github.com/sahuvaibhav/Stats.git
    App : https://sahuvaibhav.shinyapps.io/Stats/

    Added a new functionality to my stats app - Hypothesis testing for comparing two population means.

    There are various techniques to compare means of two populations based on the type available sample data and the assumptions on population variance.
    - Comparing two independent populations' means using Z-test. This test is applied when sample sizes are large or population variances are known.
    This can be performed using "Hypothesis Testing" tab  in the app.
    -  Comparing two independent populations' means using t-test. t-test is applied to compare two independent populations means when sample sizes are small or population variances are not known.
    Based on assumptions on population variances two techniques are available.
    - Pooled Variance Test - When population variances are unknown and are assumed equal, pooled variance test is applied. Pooled Variance and degree of freedom for test is
                          df = n1+n2-2
               s = sqrt(((s1^2*(n1-1) + s2^2*(n2-1))/(n1+n2-2))*(1/n1+1/n2))
    - Unpooled Variance Test - When population Variances are unknown and are assumed not equal.
      Unpooled Variance and degree of freedom are
              df = (s1^2/n1+s2^2/n2)/((s1^2/n1)^2/(n1-1) + (s2^2/n2)^2/(n2-1) ) 
              s = sqrt(s1^2/n1 + s2^2/n2)
    Both these tests can be performed at "independent sample" tab in the app.
    - Paired Sample Test -  When same sample is tested two times to observe the difference paired sample test is performed (Like before and after cases).
    "Paired Sample" tab in the app
    - Comparing two population Proportions: Two populations can be compared when sample proportions are available.
    "Proportions" tab in the app




    Shiny R provides a number of functionality to create such applications.
    Feedback and comments are welcome!!!





    0

    Add a comment



  2.                                                                      Hypothesis Testing



    My another effort!

    Added a new page for hypothesis testing. A new address though (https://sahuvaibhav.shinyapps.io/Stats).

    This simple page perform two tail, left tail, right tail hypothesis testing - either z- test or t-test based on the population or sample standard deviation available.



    The simple dynamic normal chart annotates rejection regions as per selected alpha threshold (type - I error margin).and type of test. Test results provide p-value and critical values. However, plot gives a visual understanding to anyone not very close to stats.

    The script is Shiny R only and deploying procedure same as my previous post.





    0

    Add a comment



  3. View Confidence Interval Dynamically


    This is a simple effort for dynamic view of confidence interval in a normal distribution. The  link provides a interactive interface which helps users to understand normal distribution and confidence interval.



    Its a simple application that takes the mean, standard deviation, upper bound and lower bound, and marks the confidence interval in the normal distribution. 


    Application is created by Shiny App. Shiny App is a very simple R tool to create interactive apps on browser. Which can be hosted online. 

    Shiny app tutorials are available here.
    Below is the code for the above app.
    ui.R
    shinyUI(fluidPage(
      titlePanel("Confidence Interval",windowTitle = "Normal Distribution Confidence Interval"),
      sidebarLayout(
        sidebarPanel(
          p("Provide the mean, Standard Deviation, 
            Upper Bound and Lower Bound to plot confidence Interval on Normal Plot"),
          numericInput("mean", label = h4("Mean"), value = 0),
          numericInput("sd", label = h4("Standard Deviation(not Variance)"), value = 1),
          numericInput("lb", label = h4("Lower Bound"), value = -1),
          numericInput("ub", label = h4("Upper Bound"), value = 1)
     
          ),
        mainPanel(plotOutput("map"))
            )
        )
      )
     
    server.R
    normal = function(mean, sd, lb,ub){
      x <- seq(-4,4,length=100)*sd + mean
      hx <- dnorm(x,mean,sd)
     
      plot(x, hx, type="n", ylab="",
           main="Normal Distribution", axes=FALSE)
     
      i <- x >= lb & x <= ub
      lines(x, hx)
      polygon(c(lb,x[i],ub), c(0,hx[i],0), col="red")
     
      area <- pnorm(ub, mean, sd) - pnorm(lb, mean, sd)
      result <- paste("P(",lb,"< IQ <",ub,") =",
                      signif(area, digits=3))
      mtext(result,3)
      axis(1, at=seq(mean-4*sd, mean+4*sd, sd), pos=0) 
    }
     
    shinyServer(function(input, output){
       output$map = renderPlot({normal(input$mean,input$sd,input$lb,input$ub)
     
       })      
     
    }
     
      )
    To host an app online follow the below steps:
    1- sign up here using your google account.
    2 - It will ask to create a "shinyapps.io" account (eg . "myshinyapps.io"). once you create your shinyapp.io account, it will give a token.
    3- Install packages "shiny" and "shinyApps". (to install "shinyApp" follow the instruction here.
    4- Create your shiny app and test locally.
    5- Once done, go to your shinyapp.io account, and deploy your app using below R command


    deployApp("<direcory where app code is present>", appName = "name of your app",


              account = "shinyapps.io account name", upload = TRUE)

    this will upload your ui.R and server.R files and your shiney app is hosted online.


    find my app at 
    https://sahuvaibhav.shinyapps.io/Stats/











    1

    View comments

My Blog List
My Blog List
Blog Archive
About Me
About Me
Loading
Dynamic Views theme. Powered by Blogger. Report Abuse.