|
|
|
 | :: Testing Population Proportion - Critical Value - Free Statistics Software (Calculator) :: | |
|
All rights reserved. The non-commercial (academic) use of this software is free of charge. The only thing that is asked in return is to cite this software when results are used in publications.
This free online software (calculator) computes the critical values for one- and two-sided hypothesis tests about the population proportion. This computation assumes that the number of successes and sample measurements is large enough (normal approximation is used).
In addition the Agresti-Coull approach is used to compute better intervals.
One advantage of this procedure is that its worth does not strongly depend upon the value of n and/or p, and indeed was recommended by Agresti and Coull for virtually all combinations of n and p. Another advantage is that the lower limit cannot be negative.
source: NIST/SEMATECH e-Handbook of Statistical Methods, http://www.itl.nist.gov/div898/handbook/, 2006-11-16.
Finally, the confidence intervals are computed with the Exact (binomial distribution) and the method of Wilson as implemented in the Hmisc package of R.
Click here to edit the underlying code of this R Module.Click here to edit the underlying code of this R Module.
| Source code of R module | | 1 | par1 <- as.numeric(par1) | | 2 | par2 <- as.numeric(par2) | | 3 | par3 <- as.numeric(par3) | | 4 | par4 <- as.numeric(par4) | | 5 | if (par2 < par3) | | 6 | { | | 7 | ucv <- qnorm(par4) | | 8 | } else { | | 9 | ucv <- -qnorm(par4) | | 10 | } | | 11 | cv1 <- par3 + ucv * sqrt(par3 * (1-par3) / par1) | | 12 | cv2low <- par2 - abs(qnorm(par4/2)) * sqrt(par3 * (1-par3) / par1) | | 13 | cv2upp <- par2 + abs(qnorm(par4/2)) * sqrt(par3 * (1-par3) / par1) | | 14 | z21 <- qnorm(par4/2)^2 / par1 | | 15 | z2 <- qnorm(par4/2)^2 / (2*par1) | | 16 | z24 <- qnorm(par4/2)^2 / (4*par1^2) | | 17 | cv2lowexact <- (par2 + z2 - abs(qnorm(par4/2)) * sqrt(par3 * (1-par3) / par1 + z24)) / (1 + z21) | | 18 | cv2uppexact <- (par2 + z2 + abs(qnorm(par4/2)) * sqrt(par3 * (1-par3) / par1 + z24)) / (1 + z21) | | 19 | z11 <- qnorm(par4)^2 / par1 | | 20 | z1 <- qnorm(par4)^2 / (2*par1) | | 21 | z14 <- qnorm(par4)^2 / (4*par1^2) | | 22 | cv1lowexact <- (par2 + z1 - abs(qnorm(par4)) * sqrt(par3 * (1-par3) / par1 + z14)) / (1 + z11) | | 23 | cv1uppexact <- (par2 + z1 + abs(qnorm(par4)) * sqrt(par3 * (1-par3) / par1 + z14)) / (1 + z11) | | 24 | load(file="createtable") | | 25 | a<-table.start() | | 26 | a<-table.row.start(a) | | 27 | a<-table.element(a,"Testing Population Proportion (normal approximation)",2,TRUE) | | 28 | a<-table.row.end(a) | | 29 | a<-table.row.start(a) | | 30 | a<-table.element(a,"Sample size",header=TRUE) | | 31 | a<-table.element(a,par1) | | 32 | a<-table.row.end(a) | | 33 | a<-table.row.start(a) | | 34 | a<-table.element(a,"Sample Proportion",header=TRUE) | | 35 | a<-table.element(a,par2) | | 36 | a<-table.row.end(a) | | 37 | a<-table.row.start(a) | | 38 | a<-table.element(a,"Null hypothesis",header=TRUE) | | 39 | a<-table.element(a,par3) | | 40 | a<-table.row.end(a) | | 41 | a<-table.row.start(a) | | 42 | a<-table.element(a,"Type I error (alpha)",header=TRUE) | | 43 | a<-table.element(a,par4) | | 44 | a<-table.row.end(a) | | 45 | a<-table.row.start(a) | | 46 | a<-table.element(a,"1-sided critical value",header=TRUE) | | 47 | a<-table.element(a,cv1) | | 48 | a<-table.row.end(a) | | 49 | a<-table.row.start(a) | | 50 | a<-table.element(a,"1-sided test",header=TRUE) | | 51 | if (par2 < par3) | | 52 | { | | 53 | if (par2 < cv1) | | 54 | { | | 55 | a<-table.element(a,"Reject the Null Hypothesis") | | 56 | } else { | | 57 | a<-table.element(a,"Do not reject the Null Hypothesis") | | 58 | } | | 59 | } else { | | 60 | if (par2 > cv1) | | 61 | { | | 62 | a<-table.element(a,"Reject the Null Hypothesis") | | 63 | } else { | | 64 | a<-table.element(a,"Do not reject the Null Hypothesis") | | 65 | } | | 66 | } | | 67 | a<-table.row.end(a) | | 68 | a<-table.row.start(a) | | 69 | a<-table.element(a,"2-sided Confidence Interval (sample proportion)",header=TRUE) | | 70 | dum <- paste("[",cv2low) | | 71 | dum <- paste(dum,",") | | 72 | dum <- paste(dum,cv2upp) | | 73 | dum <- paste(dum,"]") | | 74 | a<-table.element(a,dum) | | 75 | a<-table.row.end(a) | | 76 | a<-table.row.start(a) | | 77 | a<-table.element(a,"2-sided test",header=TRUE) | | 78 | if ((par3 < cv2low) | (par3 > cv2upp)) | | 79 | { | | 80 | a<-table.element(a,"Reject the Null Hypothesis") | | 81 | } else { | | 82 | a<-table.element(a,"Do not reject the Null Hypothesis") | | 83 | } | | 84 | a<-table.row.end(a) | | 85 | a<-table.end(a) | | 86 | table.save(a,file="mytable.tab") | | 87 | a<-table.start() | | 88 | a<-table.row.start(a) | | 89 | a<-table.element(a,"Testing Population Proportion (Agresti-Coull method)",2,TRUE) | | 90 | a<-table.row.end(a) | | 91 | a<-table.row.start(a) | | 92 | a<-table.element(a,"Sample size",header=TRUE) | | 93 | a<-table.element(a,par1) | | 94 | a<-table.row.end(a) | | 95 | a<-table.row.start(a) | | 96 | a<-table.element(a,"Sample Proportion",header=TRUE) | | 97 | a<-table.element(a,par2) | | 98 | a<-table.row.end(a) | | 99 | a<-table.row.start(a) | | 100 | a<-table.element(a,"Null hypothesis",header=TRUE) | | 101 | a<-table.element(a,par3) | | 102 | a<-table.row.end(a) | | 103 | a<-table.row.start(a) | | 104 | a<-table.element(a,"Type I error (alpha)",header=TRUE) | | 105 | a<-table.element(a,par4) | | 106 | a<-table.row.end(a) | | 107 | a<-table.row.start(a) | | 108 | a<-table.element(a,"Left 1-sided confidence interval",header=TRUE) | | 109 | dum <- paste("[",cv1lowexact) | | 110 | dum <- paste(dum,", 1 ]") | | 111 | a<-table.element(a,dum) | | 112 | a<-table.row.end(a) | | 113 | a<-table.row.start(a) | | 114 | a<-table.element(a,"Right 1-sided confidence interval",header=TRUE) | | 115 | dum <- paste("[ 0 ,",cv1uppexact) | | 116 | dum <- paste(dum," ]") | | 117 | a<-table.element(a,dum) | | 118 | a<-table.row.end(a) | | 119 | a<-table.row.start(a) | | 120 | a<-table.element(a,"2-sided Confidence Interval (sample proportion)",header=TRUE) | | 121 | dum <- paste("[",cv2lowexact) | | 122 | dum <- paste(dum,",") | | 123 | dum <- paste(dum,cv2uppexact) | | 124 | dum <- paste(dum,"]") | | 125 | a<-table.element(a,dum) | | 126 | a<-table.row.end(a) | | 127 | a<-table.end(a) | | 128 | table.save(a,file="mytable.tab") | | 129 | library(Hmisc) | | 130 | re <- binconf(par2*par1,par1,par4,method="exact") | | 131 | re1 <- binconf(par2*par1,par1,par4*2,method="exact") | | 132 | rw <- binconf(par2*par1,par1,par4,method="wilson") | | 133 | rw1 <- binconf(par2*par1,par1,par4*2,method="wilson") | | 134 | a<-table.start() | | 135 | a<-table.row.start(a) | | 136 | a<-table.element(a,"Testing Population Proportion (Exact and Wilson method)",2,TRUE) | | 137 | a<-table.row.end(a) | | 138 | a<-table.row.start(a) | | 139 | a<-table.element(a,"Sample size",header=TRUE) | | 140 | a<-table.element(a,par1) | | 141 | a<-table.row.end(a) | | 142 | a<-table.row.start(a) | | 143 | a<-table.element(a,"Sample Proportion",header=TRUE) | | 144 | a<-table.element(a,par2) | | 145 | a<-table.row.end(a) | | 146 | a<-table.row.start(a) | | 147 | a<-table.element(a,"Null hypothesis",header=TRUE) | | 148 | a<-table.element(a,par3) | | 149 | a<-table.row.end(a) | | 150 | a<-table.row.start(a) | | 151 | a<-table.element(a,"Type I error (alpha)",header=TRUE) | | 152 | a<-table.element(a,par4) | | 153 | a<-table.row.end(a) | | 154 | a<-table.row.start(a) | | 155 | a<-table.element(a,"Left 1-sided confidence interval (Exact method)",header=TRUE) | | 156 | dum <- paste("[",re1[2]) | | 157 | dum <- paste(dum,", 1 ]") | | 158 | a<-table.element(a,dum) | | 159 | a<-table.row.end(a) | | 160 | a<-table.row.start(a) | | 161 | a<-table.element(a,"Right 1-sided confidence interval (Exact method)",header=TRUE) | | 162 | dum <- paste("[ 0 ,",re1[3]) | | 163 | dum <- paste(dum," ]") | | 164 | a<-table.element(a,dum) | | 165 | a<-table.row.end(a) | | 166 | a<-table.row.start(a) | | 167 | a<-table.element(a,"2-sided Confidence Interval (Exact method)",header=TRUE) | | 168 | dum <- paste("[",re[2]) | | 169 | dum <- paste(dum,",") | | 170 | dum <- paste(dum,re[3]) | | 171 | dum <- paste(dum,"]") | | 172 | a<-table.element(a,dum) | | 173 | a<-table.row.end(a) | | 174 | a<-table.row.start(a) | | 175 | a<-table.element(a,"Left 1-sided confidence interval (Wilson method)",header=TRUE) | | 176 | dum <- paste("[",rw1[2]) | | 177 | dum <- paste(dum,", 1 ]") | | 178 | a<-table.element(a,dum) | | 179 | a<-table.row.end(a) | | 180 | a<-table.row.start(a) | | 181 | a<-table.element(a,"Right 1-sided confidence interval (Wilson method)",header=TRUE) | | 182 | dum <- paste("[ 0 ,",rw1[3]) | | 183 | dum <- paste(dum," ]") | | 184 | a<-table.element(a,dum) | | 185 | a<-table.row.end(a) | | 186 | a<-table.row.start(a) | | 187 | a<-table.element(a,"2-sided Confidence Interval (Wilson method)",header=TRUE) | | 188 | dum <- paste("[",rw[2]) | | 189 | dum <- paste(dum,",") | | 190 | dum <- paste(dum,rw[3]) | | 191 | dum <- paste(dum,"]") | | 192 | a<-table.element(a,dum) | | 193 | a<-table.row.end(a) | | 194 | a<-table.end(a) | | 195 | table.save(a,file="mytable.tab") |
|
| Cite this software as: | | Wessa P., (2008), Testing Population Proportion (Critical values) (v1.0.3) in Free Statistics Software (v1.1.23-r3), Office for Research Development and Education, URL http://www.wessa.net/rwasp_hypothesisprop1.wasp/ | | | The R code is based on : | | | Xycoon, Statistics - Econometrics - Forecasting, Office for Research Development and Education, http://www.xycoon.com/ht_pop_proportion.htm#ex1 | | | NIST/SEMATECH e-Handbook of Statistical Methods, http://www.itl.nist.gov/div898/handbook/, 2006-11-16 | | | A. Agresti and B.A. Coull, Approximate is better than exact for interval estimation of binomial proportions, American Statistician, 52:119-126, 1998. | | | R.G. Newcombe, Logit confidence intervals and the inverse sinh transformation, American Statistician, 55:200-202, 2001. | | | L.D. Brown, T.T. Cai and A. DasGupta, Interval estimation for a binomial proportion (with discussion), Statistical Science, 16:101-133, 2001. | Frank E Harrell Jr and with contributions from many other users. (2006). Hmisc: Harrell Miscellaneous. R package version 3.1-1.
http://biostat.mc.vanderbilt.edu/s/Hmisc,
http://biostat.mc.vanderbilt.edu/twiki/pub/Main/RS/sintro.pdf,
http://biostat.mc.vanderbilt.edu/twiki/pub/Main/StatReport/summary.pdf | | | | |
|
To cite Wessa.net in publications use: Wessa, P. (2009), Free Statistics Software, Office for Research Development and Education, version 1.1.23-r3, URL http://www.wessa.net/
© Resa
R&D, and the 'Office for Research, Development, and Education' - All rights reserved. Academic license for non-commercial use only.
This website is an intellectual
and physical property of Resa R&D. This includes: html content,
graphical illustrations (gif files), computer software, online or electronic
documentation, associated media, and printed materials. The free use of the scientific content, services, and applications in this website is
granted for non commercial use only. In any case,
the source (url) should always be clearly displayed. Under no circumstances are
you allowed to reproduce, copy or redistribute the design, layout, or any
content of this website (for commercial use) including any materials contained
herein without the express written permission of Resa R&D or the Office for Research, Development, and Education.
Information provided
on this web site is provided "AS IS" without warranty of any kind, either
express or implied, including, without limitation, warranties of
merchantability, fitness for a particular purpose, and noninfringement. We use reasonable efforts to include accurate and timely information
and periodically update the information, and software without notice. However, Resa
R&D makes no warranties or representations
as to the accuracy or completeness of such information (or software), and it assumes no
liability or responsibility for errors or omissions in the content of this web
site, or any software bugs in online applications. Your use of this web site is AT YOUR OWN RISK. Under no circumstances and
under no legal theory shall Resa R&D be liable to you or any other
person for any direct, indirect, special, incidental, exemplary, or
consequential damages arising from your access to, or use of, this web site.
Software Version : 1.1.23-r3 Algorithms & Software : Prof. dr. P. Wessa Facilities : Resa R&D - Office for Research, Development, and Education Server : www.wessa.net
Comments, Feedback & Errors | Privacy Policy | Statistics Resources | Wessa.net Home
|
|
|
|
|
|
|
|