tag:blogger.com,1999:blog-1275149608391671670.post722574931184401413..comments2023-09-28T06:13:40.704-04:00Comments on SAS and R: Example 10.8: The upper 95% CI is 3.69Ken Kleinmanhttp://www.blogger.com/profile/09525118721291529157noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-1275149608391671670.post-85686372762671715442012-12-11T12:43:52.078-05:002012-12-11T12:43:52.078-05:00Good to have you back.
A few comments:
(1) If th...Good to have you back.<br /><br />A few comments:<br /><br />(1) If the goal was to demonstrate the use of ..., then move on to the next point. Otherwise, note that x=0 for every call to mybt. Thus you can redefine <br /><br />mybt <- function(n) binom.test(x=0, n=n)$conf.int[2]<br /><br />(to get the code to run you'll then need to remove x=0 from the apply call.)<br /><br />(2) I had not seen a speed comparison between sapply and apply. Not an intuitive result.<br /><br />A well written loop is not as pretty, but is comparable to apply for speed:<br /><br />uci <- numeric(length(bin.m))<br />for (i in seq_along(bin.m)) {<br /> uci[i] <- binom.test(x=0, n=bin.m[i])$conf.int[2]<br />}<br /><br />[More about simulation speed at <br />http://pages.stat.wisc.edu/~st471-1/Rnotes/SimSpeed.html#sec-1]<br /><br />(3) As for speed (which I know is only a couple seconds for this graphic) you can improve performance by using equally spaced points. Most of the 1999 points in your simulation are bunched on the right because they are on a linear scale but the graphic is on a logarithmic scale. For example, the following covers the same interval (10 to 10000) with equally spaced (on the graph) points :<br /><br />bin.m <- round(10^seq(1,4,length=100))Chris Andrewshttps://www.blogger.com/profile/08124050587254722665noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-46739188024446060022012-12-11T03:03:06.433-05:002012-12-11T03:03:06.433-05:00Approximation using Poisson distribution (two-side...Approximation using Poisson distribution (two-sided ci):<br /><br />1-dpois(0,<b>3.688893</b>)<br />[1] 0.9750003<br /><br />Approximation using Poisson distribution (one-sided ci):<br /><br />> 1-dpois(0, ,<b>2.995718</b>)<br />[1] 0.9499993<br /><br />I calculated those values by minimizing function: <br />ul_0 <- function(x)(dpois(0,x)-a)^2<br />where a=0.05 for one sided and a=0.025 for two-sided confidence interval.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-70580863137136750722012-12-10T19:10:38.965-05:002012-12-10T19:10:38.965-05:00Based on K.ULM 1990 paper on standardized mortalit...Based on K.ULM 1990 paper on standardized mortality ratio, the upper 95% CI when number of event is 0 is: (R code) qchisq(0.975, 2*(# of event+1))/2 = 3.688879Yangnoreply@blogger.com