strs.1prop=function(data,xi,ni,Ni){ data=as.name(data); xi=xi; ni=ni; Ni=Ni n=sum(ni); N=sum(Ni) fpci=(1-ni/Ni); phati=xi/ni; qhati=1-phati cl.perc=sprintf("%.0f%%",.95*100) phatst=(1/N)*sum(Ni*phati) vhat.phati=fpci*(phati*qhati/(ni-1)) vhat.phatst=(1/N^2)*sum(Ni^2*vhat.phati) bound=2*sqrt(vhat.phatst) lower=phatst-bound; upper=phatst+bound lowerpct=sprintf("%.2f%%",lower*100); upperpct=sprintf("%.2f%%",upper*100) cat(" ","\n","Results from StRS Data: ",data,"\n","Approximate Level of Confidence =", cl.perc,"\n","Point Estimate of p =",phatst,"\n","Estimated variance of phat =", vhat.phatst,"\n","Bound =",bound,"\n","Lower Bound =",lower,"Upper Bound =", upper,"\n","Lower Bound (%) =",lowerpct,"Upper Bound (%) =",upperpct,"\n","","\n") results=list(data=data,ni=ni,Ni=Ni,fpci=fpci,phatst=phatst,bound=bound,lower=lower, upper=upper,lowerpct=lowerpct,upperpct=upperpct) } # to use the function with its call: # strs.1prop(data,yi,ni,Ni) # data: name of dataset, in quotes # yi: vector (data) of successes # ni: vector (data) of sample sizes # Ni: vector (data) of population sizes