R program code \226 Muistio

8 downloads 0 Views 21KB Size Report
Department of Mathematics & Statistics, Williams College,Williamtown, MA, USA,. 31.8.2012. For the code to work, each row has to contain y1, n1, y2 and n2, ...
R program code R program code for the computation of the Miettinen-Nurminen confidence limits for stratified 2x2 data by Bernhard Klingenberg, Department of Mathematics & Statistics, Williams College,Williamtown, MA, USA, 31.8.2012. For the code to work, each row has to contain y1, n1, y2 and n2, in that order, where y1 is the binomial response out of n1 trials for the treatment group and y2 is the binomial response out of n2 trials for the control group. Each row presents a stratum. The procedure then computes the CI for the common difference in the proportions of the treated group minus the control group. Below are the necessary functions, the very last one is the main function that you call to get the CI. E.g., if we had three strata dataset = matrix(c(23, 50, 32, 53, 25, 51, 35, 49, 25, 53, 31, 48), ncol=4,byrow=TRUE) e.g., > dataset [,1] [,2] [,3] [,4] [1,]

23

50

32

53

[2,]

25

51

35

49

[3,]

25

53

31

48

then calling > scoreint.strat.MN(dataset) [1] -0.28792414 -0.06811103 shows the 95% CI for the common difference to be [-0.29, -0.07]. One can choose different weights through e.g., > scoreint.strat.MN(dataset, weight="Cochran") [1] -0.28788500 -0.06810079 One can also use the bias correction to be applied to the weights, i.e., the weights are now unbiased estimators under the null of no differences of the variance of the difference of proportion. > scoreint.strat.MN(dataset, bias.correct=TRUE) [1] -0.28792061 -0.06810695

resMLE.MN =0,1,-1)*sqrt(L2^2/(3*L3)^2 - L1/(3*L3)) a=(pi+acos(c/b^3))/3 p2=2*b*cos(a)-L2/(3*L3) #p1=p2+delta #z=(y[1]/n[1]-y[2]/n[2]-delta)/sqrt(p1*(1-p1)/n[1] + p2*(1-p2)/n[2]) #Mee #z2=(y[1]/n[1]-y[2]/n[2]-delta)^2 / ((p1*(1-p1)/n[1] + p2*(1-p2)/n[2])*N/(N-1)) #Miettinen and Nurminen return(c(p2+delta,p2)) #return(z2-qchisq(conflev,1)) } MN.weights