srs.1prop=function(data,x,n,N){ data=as.name(data); x=x; n=n; N=N; fpc=(1-n/N) phat=x/n; qhat=1-phat cl.perc=sprintf("%.0f%%",.95*100) vhat.phat=((phat*qhat)/(n-1))*fpc bound=2*sqrt(vhat.phat) lower=phat-bound; upper=phat+bound lowerpct=sprintf("%.2f%%",lower*100); upperpct=sprintf("%.2f%%",upper*100) cat(" ","\n","Results from SRS Data: ",data,"\n","Approximate Level of Confidence =",cl.perc, "\n","Point Estimate of p =",phat,"\n","Estimated variance of phat =",vhat.phat,"\n", "Bound =",bound,"\n","Lower Bound =",lower,"Upper Bound =",upper,"\n","Lower Bound (%) =", lowerpct,"Upper Bound (%) =",upperpct,"\n","","\n") results=list(data=data,n=n,N=N,fpc=fpc,phat=phat,bound=bound,lower=lower,upper=upper, lowerpct=lowerpct,upperpct=upperpct) } # to use the function with its call: # srs.1prop(data,x,n,N) # data: name of dataset, in quotes # x: vector (data) of successes # n: sample size # N: population size