## Interpreting Logistic Coefficients

Create the Confounded Data Set and Save.

```{r,eval=FALSE} 
# eval=FALSE so the data is not over-written on re-running the script

df <- read.csv("~/teach/550/www/lab.csv")
df$LabTest <- as.integer(as.character(df$LabTest))
df <- df[!is.na(df$LabTest),]
labTest <- df[!duplicated(df$ID),"LabTest"]
lab1 <- sample(labTest,200,replace=TRUE)
lab2 <- sample(labTest,200,prob=labTest,replace=TRUE)
l1 <- 2 - lab1/8
l2 <- 5 - lab2/8
p1 <- 1/(1+exp(-l1))
p2 <- 1/(1+exp(-l2))
ys <- runif(400) < c(p1,p2)
gp <- rep(1:2,rep(200,2))
df <- data.frame(dvt=yes.no(ys),Trt=factor(gp,labels=c("Long","Short")), Test=c(lab1,lab2))
save(df,file="DVT.covar.rda")
```

```{r,echo=FALSE,message=FALSE,results='markup',fig.height=4, fig.width=5,fig.show="asis"}
load("DVT.covar.rda")
source("~/tmp/rbfuns.R")
attach(df)
compare.ps(Trt,dvt)
boxplot(split(Test,Trt),main="Unbalanced Distribution")
ttest(split(Test,Trt))
lgfit <- glm( dvt ~ Trt + Test, family=binomial)
summary(lgfit)
fits <- fitted(lgfit)
plot(Test,fits,main="Fitted Probabilities",ylab="Probability",
   xlab="Initial Lab Test")
print(coefTable(lgfit,trans=exp),digits=5)

```
