[R] Confidence Interval for p1-p2 and plot the CI with bar chart
Jim Lemon
drj|m|emon @end|ng |rom gm@||@com
Sun Nov 14 02:47:37 CET 2021
Hi Abou,
Perhaps this will be helpful. Be aware that you will cop some flak for
putting error bars on a bar plot.
aadat<-data.frame(group=c(rep("Exp",50),rep("Con",50)),
v1=sample(0:1,100,TRUE),
v2=sample(0:1,100,TRUE),
v3=sample(0:1,100,TRUE),
v4=sample(0:1,100,TRUE),
v5=sample(0:1,100,TRUE))
ggps<-function(x,group) {
gns<-as.vector(table(group))
return(by(x,group,sum)/gns)
}
testggps<-data.frame(
group=c("A","A","A","B","B","B","B","C","C","C","C","C"),
x=c(1,0,1,1,0,1,0,1,1,0,0,0))
aaprop<-sapply(aadat[,2:6],ggps,aadat[,1])
library(plotrix)
barpos<-barp(aaprop,ylim=c(0,0.65),col=c(2,3),names.arg=colnames(aaprop))
legend(2.5,0.65,c("Con","Exp"),fill=c(2,3))
dispersion(barpos$x,barpos$y,ulim=aaprop/10)
Jim
On Sun, Nov 14, 2021 at 11:01 AM AbouEl-Makarim Aboueissa
<abouelmakarim1962 using gmail.com> wrote:
>
> Dear All:
>
>
>
> I do have a binary data set with multiple variables, event = 1 in all
> variables. As an example, I attached a data set with 6 variables. The first
> column is the grouping variable. Then the next 5 columns are the binary
> data for 5 variables.
>
>
>
> - Can we compute the confidence interval for the difference between the two
> proportions of the event = 1 in both groups (say: G1 – G2) for the 5
> variables in one shut.
>
>
>
> - I also need to create the Bar plot of individual proportions (both groups
> side-by-side) and add the confidence intervals bar for the 5 variables in
> one graph.
>
>
>
>
>
> Example.Data <- read.table(file="F/Example_Data_for_R.csv", header=T,
> sep=",")
>
> Example.Data
>
> attach(Example.Data)
>
>
>
>
>
>
>
> #### For example, this is how I use the prop.test() function to get the CI
> for p1-p2
>
>
>
> x12 <- c(x1, x2)
>
> n12 <- c(n1, n2)
>
> prop.test(x12, n12, conf.level = 0.95)$conf.int
>
>
>
> But, I am not sure how to use it for raw data, and for multiple pairs of
> data in one shut if possible.
>
>
>
> With many thanks in advance
>
> Abou
> ______________________
>
>
> *AbouEl-Makarim Aboueissa, PhD*
>
> *Professor, Statistics and Data Science*
> *Graduate Coordinator*
>
> *Department of Mathematics and Statistics*
> *University of Southern Maine*
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list