September 21, 2014

My first Shiny app

This is an R Markdown presentation for my very first Shiny application. You can find it here: http://skkk1972.shinyapps.io/Shiny_01/.

It helps you to conduct a hypothesis test to determine whether the difference between two proportions is significant. The test procedure, called the two-proportion z-test, is appropriate when the following conditions are met:

  • The sampling method for each population is simple random sampling.
  • The samples are independent.
  • Each sample includes at least 10 successes and 10 failures. (Some texts say that 5 successes and 5 failures are enough.)
  • Each population is at least 10 times as big as its sample.

Hypotheses and an analysis plan

Every hypothesis test requires the analyst to state a null hypothesis and an alternative hypothesis. When the null hypothesis states that there is no difference between the two population proportions (i.e., d = 0), the null and alternative hypothesis for a two-tailed test are often stated in the following form: H0: P1 = P2, Ha: P1 <> P2

The analysis plan describes how to use sample data to accept or reject the null hypothesis. It should specify the following elements.

Significance level. Often, researchers choose significance levels equal to 0.01, 0.05, or 0.10.

Test method. Use the two-proportion z-test to determine whether the hypothesized difference between population proportions differs significantly from the observed sample difference.

CALCULATION

To find the test statistic and its associated P-Value we do next calculations:

Pooled sample proportion. p = (p1 * n1 + p2 * n2) / (n1 + n2) (where p1 is the sample proportion from population 1, p2 is the sample proportion from population 2, n1 and n2 are respective sample sizes).

Standard error. SE = sqrt{ p * ( 1 - p ) * [ (1/n1) + (1/n2) ] }

Test statistic. z = (p1 - p2) / SE

P-value. The P-value is the probability of observing a sample statistic as extreme as the test statistic. Since the test statistic is a z-score, we use the normal distribution to assess the probability associated with the z-score. The analysis described above is a two-proportion z-test.

My Shiny statistical calculator

Using the approuch above app calculates minimum difference in proportions between two samples to be significantly diffferent. For example, we teated a drug on 400 men and 600 women, effectivnes id around 40%. What minimal difference signal difference between these two groups?

PooledSample<-(1/(1/400+1/600))
SigDiff <- qt(1-0.05/2,df=PooledSample-1)*sqrt(0.4*(1-0.4))/sqrt(PooledSample)
SigDiff
## [1] 0.06229

In this case if difference is more than 6.3% we can state difference between two populations with 95% confidence.

THANK YOU!