<?xml version="1.0" encoding="utf-8"?><!DOCTYPE article  PUBLIC '-//OASIS//DTD DocBook XML V4.4//EN'  'http://www.docbook.org/xml/4.4/docbookx.dtd'><article><articleinfo><title>FAQ/BinomialCofidence/2gpp/Rcode</title><revhistory><revision><revnumber>2</revnumber><date>2013-03-08 10:17:27</date><authorinitials>localhost</authorinitials><revremark>converted to 1.6 markup</revremark></revision><revision><revnumber>1</revnumber><date>2010-08-27 09:24:32</date><authorinitials>PeterWatson</authorinitials></revision></revhistory></articleinfo><section><title>R code for running Agresti-Min CI for difference in paired proportions</title><!--rule (<hr>) is not applicable to DocBook--><para>citation to Agresti and Min</para><!--rule (<hr>) is not applicable to DocBook--><para> Agresti, A. and Min, Y. (2005). Simple improved confidence intervals for comparing matched proportions. Statistics in Medicine 24, 729-740. </para><para>--- a portion of a Google cached U.Fla web site, probably by Agresti</para><!--rule (<hr>) is not applicable to DocBook--><para>R code for the adjustment of the Wald confidence interval for a difference  of proportions, with matched pairs. This is the interval called Wald+2 in  Agresti and Min, Statistics in Medicine, 2004, which adds 0.5 to each cell  before constructing the Wald CI. The CI is truncated when it overshoots the  boundary. </para><screen><![CDATA[diffpropci <- function(b,c,n,conflev)
{
 z  <- qnorm(1-(1-conflev)/2)
 diff <- (c-b)/(n+2)
 sd <- sqrt((b+c+1)-(c-b)^2/(n+2))/(n+2)
 ll <- diff - z*sd
 ul <- diff + z*sd
 if(ll < -1) ll = -1
 if(ul > 1) ul = 1 
 c(ll, ul)
}
# Adjusted Wald interval for difference of proportions with matched pairs
# "conflev"=confidence coefficient, n=sample size, b,c = off-diag counts]]></screen><!--rule (<hr>) is not applicable to DocBook--><para>end extract from Agresti's site</para><!--rule (<hr>) is not applicable to DocBook--></section></article>