Last active
December 15, 2016 09:53
-
-
Save n8thangreen/08d81e3a95d434dc5edd to your computer and use it in GitHub Desktop.
plot confidence interval plots of Natsal-3 variables against testing proportions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library("plotrix", lib.loc="C:/Program Files/R/R-3.1.0/library") | |
library(Hmisc) | |
NATSAL.dat <<- read.csv("~/Chlamydia/data/NATSAL/Natsal-3_extract_2April2014.csv") | |
plotCInatsal <- function(varname, save=TRUE){ | |
tab <- table(NATSAL.dat$cttestly=="yes", NATSAL.dat[,varname]) | |
tab.df <- data.frame(addmargins(tab)) | |
# data.frame(prop.table(tab,2)) | |
bin.dat <- binconf(x=tab.df[tab.df$Var1=="TRUE","Freq"], n=tab.df[tab.df$Var1=="Sum","Freq"]) | |
x <- as.character(unique(tab.df$Var2)) | |
cttestly <- bin.dat[,"PointEst"] | |
L <- bin.dat[,"Lower"] | |
U <- bin.dat[,"Upper"] | |
if(save){postscript(file=paste("C:/Users/nathan.green/Documents/chlamydia/classifier/plots/sim_logisticKNN_regn/plotCInatsal_",varname,".eps",sep=""))} | |
par(mar=c(20,4,4,2)) | |
plotCI(x=seq_along(x), cttestly, ui=U, li=L, ,axes = FALSE, xlab="", main=varname) | |
# points(1:5, c(0.1,0.1,0.1,0.1,0.1), pch=4, col="red") | |
axis(at=seq_along(x), side=1, labels=x, las=2) | |
axis(1, at=seq_along(x), labels=FALSE) | |
axis(2) | |
# text(seq_along(x)-0.5, par("usr")[3]-0.01, labels = x, srt = 60, adj=c(1,1))#, pos = 1, xpd = TRUE, cex=0.6) ##TODO## | |
if(save){dev.off()} | |
} | |
plotCInatsal("rsex") | |
plotCInatsal("ethnicgrp") | |
plotCInatsal("ethnic") | |
plotCInatsal("income") | |
plotCInatsal("smokenow") | |
plotCInatsal("rsex") | |
plotCInatsal("dage") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment