O'Reilly logo

R Statistical Application Development by Example Beginner's Guide by Prabhanjan Narayanachar Tattar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – confidence intervals

We create functions that will enable us to obtain confidence intervals of the desired size:

  1. Create a function for obtaining the confidence intervals of the proportion from a binomial distribution with the following function:
    binom_CI = function(x, n, alpha)  {
      phat = x/n
      ll=phat-qnorm(alpha/2,lower.tail=FALSE)*sqrt(phat*(1-phat)/n)
      ul=phat+qnorm(alpha/2,lower.tail=FALSE)*sqrt(phat*(1-phat)/n)
      return(paste("The ", 100*(1-alpha),"% Confidence Interval for Binomial Proportion is (", round(ll,4),",", round(ul,4),")", sep=''))
                }
    The arguments of the functions are x, n, and alpha. That is, the user of the function needs to specify the x number of success out of the n Bernoulli trials, and the significance level

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required