Load libraries
## load packages
## run everytime
## rio needed for import code
library(rio)
## dplyr needed for mutate or recode
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
## janitor needed for crosstable
library(janitor)
##
## Attaching package: 'janitor'
## The following objects are masked from 'package:stats':
##
## chisq.test, fisher.test
## survival needed for clogit
library(survival)
Import Dataset
library(readxl)
df <- read_excel("/home/rstudio/PHW253_2023/PHW253_Wk6_CaseControlStudy_redacted_notxt.xlsx")
## look at the dataset
names(df)
## [1] "CDCID" "CASE" "MLVAPATTERN" "CONTROLLETTER"
## [5] "CDCCASEID" "INTDATE" "AGEYRS" "SEX"
## [9] "RESPONDENT" "ONSETDATE" "SPECIMENDATE" "STRAWBERRY"
## [13] "STRAWHOME" "STRAWCONTAIN" "STRAWLOOSE" "STRAWAWAY"
## [17] "STRAWBOTH" "STRAWWHEREUNK" "STRAWINHOME" "APPLES"
## [21] "APPLEHOME" "APPLESLICED" "APPLESLICEBRAND" "APPLEVARIETY"
## [25] "APPLEAWAY" "APPLEAWAYWHERE" "APPLEBOTH" "APPLEWHEREUNK"
## [29] "APPLEINHOME" "RAWCD" "RAWCDFLAVOR" "RAWCDBREAK"
## [33] "RAWCDLOG" "RAWCDFZN" "RAWCDOTHER" "RAWCDOTHSPEC"
## [37] "RAWCDNOTSHOP" "RAWCDINHOME" "ROLLUP" "ROLLUPFLAVOR"
## [41] "ROLLUPINHOME" "GB" "GBHOME" "GBPINK"
## [45] "GBAWAY" "GBBOTH" "GBWHEREUNK" "GBINHOME"
## [49] "UNDERCOOK" "CDADD" "CDLEFT" "HANDLEGB"
## [53] "MILK" "NOCDFZNDES" "NOCDFLAVOR1" "NOCDFLAVOR2"
## [57] "SMOOTHIE" "SHOPSMOOTHIE" "CCHIP" "CCHIPWITH"
## [61] "CARROT" "CUCUMBER" "RASPBERRY" "WATERMELON"
## [65] "CANTALOUPE" "MANDARIN" "GRAPES" "BOLOGNA"
## [69] "HOTDOG" "BACON"
dim(df) #90 rows, 70 variables
## [1] 90 70
df <- df %>% janitor::clean_names()
names(df)
## [1] "cdcid" "case" "mlvapattern" "controlletter"
## [5] "cdccaseid" "intdate" "ageyrs" "sex"
## [9] "respondent" "onsetdate" "specimendate" "strawberry"
## [13] "strawhome" "strawcontain" "strawloose" "strawaway"
## [17] "strawboth" "strawwhereunk" "strawinhome" "apples"
## [21] "applehome" "applesliced" "appleslicebrand" "applevariety"
## [25] "appleaway" "appleawaywhere" "appleboth" "applewhereunk"
## [29] "appleinhome" "rawcd" "rawcdflavor" "rawcdbreak"
## [33] "rawcdlog" "rawcdfzn" "rawcdother" "rawcdothspec"
## [37] "rawcdnotshop" "rawcdinhome" "rollup" "rollupflavor"
## [41] "rollupinhome" "gb" "gbhome" "gbpink"
## [45] "gbaway" "gbboth" "gbwhereunk" "gbinhome"
## [49] "undercook" "cdadd" "cdleft" "handlegb"
## [53] "milk" "nocdfzndes" "nocdflavor1" "nocdflavor2"
## [57] "smoothie" "shopsmoothie" "cchip" "cchipwith"
## [61] "carrot" "cucumber" "raspberry" "watermelon"
## [65] "cantaloupe" "mandarin" "grapes" "bologna"
## [69] "hotdog" "bacon"
Subset data
## Select only cases that have matched controls
ecoli2 <- df %>%
filter(cdcid !="CDC001" & cdcid !="CDC006" & cdcid !="CDC009" & cdcid !="CDC012" &
cdcid !="CDC015" & cdcid !="CDC022" & cdcid !="CDC023" & cdcid !="CDC024" &
cdcid !="CDC037" & cdcid !="CDC043" & cdcid !="CDC045" & cdcid !="CDC046" &
cdcid !="CDC048" & cdcid !="CDC049" & cdcid !="CDC067" & cdcid !="CDC068")
table(ecoli2$cdcid, exclude = NULL)
##
## CDC005 CDC007 CDC008 CDC010 CDC013 CDC014 CDC017 CDC018 CDC019 CDC020 CDC025
## 2 2 2 2 2 2 2 2 2 2 2
## CDC026 CDC029 CDC030 CDC031 CDC032 CDC033 CDC034 CDC035 CDC038 CDC040 CDC042
## 2 2 2 2 2 2 2 2 2 2 2
## CDC047 CDC052 CDC053 CDC054 CDC055 CDC056 CDC057 CDC058 CDC059 CDC062 CDC063
## 3 2 2 2 2 2 2 2 2 2 2
## CDC064 CDC066 CDC072
## 2 2 2
dim(ecoli2) # now 73 rows
## [1] 73 70
## Some cases have multiple controls
ecoli2 %>% filter(cdcid == "CDC047") %>% tabyl(case)
## Warning: Using one column matrices in `filter()` was deprecated in dplyr 1.1.0.
## ℹ Please use one dimensional logical vectors instead.
## ℹ The deprecated feature was likely used in the janitor package.
## Please report the issue at <https://github.com/sfirke/janitor/issues>.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## case n percent
## 0 2 0.6666667
## 1 1 0.3333333
## Only keep control letter=A for cdcid=="CDC047"
x<-which(ecoli2$cdcid =="CDC047" & ecoli2$controlletter=="B")
ecoli3 <-ecoli2[-x, ]
dim(ecoli3) #now 72 rows
## [1] 72 70
Tabulate number of total cases and total controls in cleaned dataset
#total cases from cleaned dataset (ecoli3)
table(ecoli3$case) #cases = 36, controls = 36
##
## 0 1
## 36 36
Create a numeric variable that identifies each pair (all code is provided) (this is called strata in the regression code)
#create strata variable
#first, select last two characters of the CDCID string/character variable (new variable stratachar)
ecoli3$stratachar<-substr(ecoli3$cdcid,start=5,stop=6)
ecoli3 %>% tabyl(stratachar)
## stratachar n percent
## 05 2 0.02777778
## 07 2 0.02777778
## 08 2 0.02777778
## 10 2 0.02777778
## 13 2 0.02777778
## 14 2 0.02777778
## 17 2 0.02777778
## 18 2 0.02777778
## 19 2 0.02777778
## 20 2 0.02777778
## 25 2 0.02777778
## 26 2 0.02777778
## 29 2 0.02777778
## 30 2 0.02777778
## 31 2 0.02777778
## 32 2 0.02777778
## 33 2 0.02777778
## 34 2 0.02777778
## 35 2 0.02777778
## 38 2 0.02777778
## 40 2 0.02777778
## 42 2 0.02777778
## 47 2 0.02777778
## 52 2 0.02777778
## 53 2 0.02777778
## 54 2 0.02777778
## 55 2 0.02777778
## 56 2 0.02777778
## 57 2 0.02777778
## 58 2 0.02777778
## 59 2 0.02777778
## 62 2 0.02777778
## 63 2 0.02777778
## 64 2 0.02777778
## 66 2 0.02777778
## 72 2 0.02777778
#then, convert to a numeric format (new variable stratanum)
ecoli3$stratanum<-as.numeric(ecoli3$stratachar)
ecoli3 %>% tabyl(stratachar,stratanum)
## stratachar 10 13 14 17 18 19 20 25 26 29 30 31 32 33 34 35 38 40 42 47 5 52 53
## 05 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0
## 07 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## 08 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## 10 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## 13 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## 14 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## 17 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## 18 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## 19 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## 20 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## 25 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## 26 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## 29 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0
## 30 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0
## 31 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0
## 32 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0
## 33 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0
## 34 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0
## 35 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0
## 38 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0
## 40 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0
## 42 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0
## 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0
## 52 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0
## 53 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2
## 54 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## 55 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## 56 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## 57 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## 58 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## 59 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## 62 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## 63 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## 64 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## 66 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## 72 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## 54 55 56 57 58 59 62 63 64 66 7 72 8
## 0 0 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 2 0 0
## 0 0 0 0 0 0 0 0 0 0 0 0 2
## 0 0 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0 0 0
## 2 0 0 0 0 0 0 0 0 0 0 0 0
## 0 2 0 0 0 0 0 0 0 0 0 0 0
## 0 0 2 0 0 0 0 0 0 0 0 0 0
## 0 0 0 2 0 0 0 0 0 0 0 0 0
## 0 0 0 0 2 0 0 0 0 0 0 0 0
## 0 0 0 0 0 2 0 0 0 0 0 0 0
## 0 0 0 0 0 0 2 0 0 0 0 0 0
## 0 0 0 0 0 0 0 2 0 0 0 0 0
## 0 0 0 0 0 0 0 0 2 0 0 0 0
## 0 0 0 0 0 0 0 0 0 2 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0 2 0
Strawberries
ecoli3$strawberry <-as.numeric(ecoli3$strawberry)
table(ecoli3$strawberry)
##
## 0 1 3 99
## 33 32 1 5
#recode strawberry variable
ecoli3$strawberry[ecoli3$strawberry=="3"] <-NA
ecoli3$strawberry[ecoli3$strawberry=="99"] <-NA
ecoli3$strawberry[ecoli3$strawberry=="1"] <- 1
ecoli3$strawberry[ecoli3$strawberry=="0"] <- 0
# 7 NAs - missing data on strawberry
# Look at the two-by-two table
table(ecoli3$strawberry, ecoli3$case, exclude=NULL)
##
## 0 1
## 0 21 12
## 1 14 18
## <NA> 1 6
#check work
df1 <- ecoli3 %>% select(cdcid, case, strawberry)
#percent exposed to among all cases.
#strawberry yes & case yes = 18/36 50%
#percent exposed among all controls.
#strawberry yes & case no = 14/36 39%
#conditional logistic regression for strawberry
s <- clogit(case ~ strawberry + strata(stratanum), data=ecoli3)
summary(s) #to find the 95% CI
## Call:
## coxph(formula = Surv(rep(1, 72L), case) ~ strawberry + strata(stratanum),
## data = ecoli3, method = "exact")
##
## n= 65, number of events= 30
## (7 observations deleted due to missingness)
##
## coef exp(coef) se(coef) z Pr(>|z|)
## strawberry 0.7885 2.2000 0.5394 1.462 0.144
##
## exp(coef) exp(-coef) lower .95 upper .95
## strawberry 2.2 0.4545 0.7644 6.332
##
## Concordance= 0.603 (se = 0.094 )
## Likelihood ratio test= 2.31 on 1 df, p=0.1
## Wald test = 2.14 on 1 df, p=0.1
## Score (logrank) test = 2.25 on 1 df, p=0.1
Ground Beef
ecoli3$gb <-as.numeric(ecoli3$gb)
table(ecoli3$gb)
##
## 0 1 99
## 13 53 3
#recode gb variable
ecoli3$gb[ecoli3$gb=="99"] <-NA
ecoli3$gb[ecoli3$gb=="1"] <- 1
ecoli3$gb[ecoli3$gb=="0"] <- 0
# 6 NAs - missing data on ground beef
# Look at the two-by-two table
table(ecoli3$gb, ecoli3$case, exclude=NULL)
##
## 0 1
## 0 9 4
## 1 26 27
## <NA> 1 5
#check work
df1 <- ecoli3 %>% select(cdcid, case, gb)
#percent exposed to among all cases.
#ground beef yes & case yes = 27/36 75%
#percent exposed among all controls.
#ground beef yes & case no = 26/36 72%
#conditional logistic regression for gb
g <- clogit(case ~ gb + strata(stratanum), data=ecoli3)
summary(g) #to find the 95% CI
## Call:
## coxph(formula = Surv(rep(1, 72L), case) ~ gb + strata(stratanum),
## data = ecoli3, method = "exact")
##
## n= 66, number of events= 31
## (6 observations deleted due to missingness)
##
## coef exp(coef) se(coef) z Pr(>|z|)
## gb 1.2528 3.5000 0.8018 1.562 0.118
##
## exp(coef) exp(-coef) lower .95 upper .95
## gb 3.5 0.2857 0.7271 16.85
##
## Concordance= 0.583 (se = 0.067 )
## Likelihood ratio test= 2.94 on 1 df, p=0.09
## Wald test = 2.44 on 1 df, p=0.1
## Score (logrank) test = 2.78 on 1 df, p=0.1
Raw cookie dough
str(ecoli3$rawcd) #numeric
## num [1:72] 0 0 1 0 1 0 1 0 3 0 ...
table(ecoli3$rawcd, exclude = FALSE)
##
## 0 1 3
## 34 37 1
#recode rawcd variable
ecoli3$rawcd[ecoli3$rawcd=="3"] <-NA
ecoli3$rawcd[ecoli3$rawcd=="1"] <- 1
ecoli3$rawcd[ecoli3$rawcd=="0"] <- 0
# 6 NAs - missing data on ground beef
# Look at the two-by-two table
table(ecoli3$rawcd, ecoli3$case, exclude=NULL)
##
## 0 1
## 0 32 2
## 1 4 33
## <NA> 0 1
#check work
df1 <- ecoli3 %>% select(cdcid, case, rawcd)
#percent exposed to among all cases.
#rawcd yes & case yes = 33/36 92%
#percent exposed among all controls.
#rawcd yes & case no = 4/36 11%
#conditional logistic regression for rawcd
cd <- clogit(case ~ rawcd + strata(stratanum), method="approximate", data=ecoli3)
## Warning in coxph.fit(X, Y, istrat, offset, init, control, weights = weights, :
## Ran out of iterations and did not converge
summary(cd)
## Call:
## coxph(formula = Surv(rep(1, 72L), case) ~ rawcd + strata(stratanum),
## data = ecoli3, method = "breslow")
##
## n= 71, number of events= 35
## (1 observation deleted due to missingness)
##
## coef exp(coef) se(coef) z Pr(>|z|)
## rawcd 2.120e+01 1.615e+09 7.464e+03 0.003 0.998
##
## exp(coef) exp(-coef) lower .95 upper .95
## rawcd 1.615e+09 6.19e-10 0 Inf
##
## Concordance= 0.914 (se = 0.045 )
## Likelihood ratio test= 40.2 on 1 df, p=2e-10
## Wald test = 0 on 1 df, p=1
## Score (logrank) test = 29 on 1 df, p=7e-08
Ice cream/frozen desserts not containing cookie dough
str(ecoli3$nocdfzndes) #numeric
## num [1:72] NA 1 NA 1 99 1 NA 0 1 1 ...
table(ecoli3$nocdfzndes, exclude = FALSE) #five 99 missing & 18 NA = 23 NA
##
## 0 1 99 <NA>
## 12 37 5 18
#recode nocdfzndes variable
ecoli3$nocdfzndes[ecoli3$nocdfzndes=="99"] <-NA
ecoli3$nocdfzndes[ecoli3$nocdfzndes=="1"] <- 1
ecoli3$nocdfzndes[ecoli3$nocdfzndes=="0"] <- 0
# Look at the two-by-two table
table(ecoli3$nocdfzndes, ecoli3$case, exclude=NULL)
##
## 0 1
## 0 7 5
## 1 26 11
## <NA> 3 20
#check work
df1 <- ecoli3 %>% select(cdcid, case, nocdfzndes)
#percent exposed among all cases.
#nocdfzndes yes & case yes = 11/36 31%
#percent exposed among all controls.
#nocdfzndes yes & case no = 26/36 72%
#conditional logistic regression for nocdfzndes
nocd <- clogit(case ~ nocdfzndes+ strata(stratanum), data=ecoli3)
summary(nocd)
## Call:
## coxph(formula = Surv(rep(1, 72L), case) ~ nocdfzndes + strata(stratanum),
## data = ecoli3, method = "exact")
##
## n= 49, number of events= 16
## (23 observations deleted due to missingness)
##
## coef exp(coef) se(coef) z Pr(>|z|)
## nocdfzndes -1.386 0.250 1.118 -1.24 0.215
##
## exp(coef) exp(-coef) lower .95 upper .95
## nocdfzndes 0.25 4 0.02794 2.237
##
## Concordance= 0.607 (se = 0.105 )
## Likelihood ratio test= 1.93 on 1 df, p=0.2
## Wald test = 1.54 on 1 df, p=0.2
## Score (logrank) test = 1.8 on 1 df, p=0.2
Hot dogs
str(ecoli3$hotdog) #numeric
## num [1:72] NA 0 NA 0 1 0 NA 0 1 1 ...
table(ecoli3$hotdog, exclude = FALSE) #ten 99 missing & 16 NA = 26 NA missing data
##
## 0 1 99 <NA>
## 24 22 10 16
#recode hotdog variable
ecoli3$hotdog[ecoli3$hotdog=="99"] <-NA
ecoli3$hotdog[ecoli3$hotdog=="1"] <- 1
ecoli3$hotdog[ecoli3$hotdog=="0"] <- 0
# Look at the two-by-two table
table(ecoli3$hotdog, ecoli3$case, exclude=NULL)
##
## 0 1
## 0 15 9
## 1 15 7
## <NA> 6 20
#check work
df1 <- ecoli3 %>% select(cdcid, case, hotdog)
#percent exposed among all cases.
#hotdog yes & case yes = 7/36 19%
#percent exposed among all controls.
#hotdog yes & case no = 15/36 42%
#conditional logistic regression for hotdog
hd <- clogit(case ~ hotdog + strata(stratanum), data=ecoli3)
summary(hd)
## Call:
## coxph(formula = Surv(rep(1, 72L), case) ~ hotdog + strata(stratanum),
## data = ecoli3, method = "exact")
##
## n= 46, number of events= 16
## (26 observations deleted due to missingness)
##
## coef exp(coef) se(coef) z Pr(>|z|)
## hotdog -0.6931 0.5000 0.7071 -0.98 0.327
##
## exp(coef) exp(-coef) lower .95 upper .95
## hotdog 0.5 2 0.125 1.999
##
## Concordance= 0.625 (se = 0.169 )
## Likelihood ratio test= 1.02 on 1 df, p=0.3
## Wald test = 0.96 on 1 df, p=0.3
## Score (logrank) test = 1 on 1 df, p=0.3
Smoothies
str(ecoli3$smoothie) #numeric
## num [1:72] NA 0 NA 0 0 0 NA 1 0 1 ...
table(ecoli3$smoothie, exclude = FALSE) #one 99 missing & 16 NA = 17 NA missing data
##
## 0 1 99 <NA>
## 48 7 1 16
#recode smoothie variable
ecoli3$smoothie[ecoli3$smoothie=="99"] <-NA
ecoli3$smoothie[ecoli3$smoothie=="1"] <- 1
ecoli3$smoothie[ecoli3$smoothie=="0"] <- 0
# Look at the two-by-two table
table(ecoli3$smoothie, ecoli3$case, exclude=NULL)
##
## 0 1
## 0 31 17
## 1 5 2
## <NA> 0 17
#check work
df1 <- ecoli3 %>% select(cdcid, case, smoothie)
#percent exposed among all cases.
#smoothie yes & case yes = 2/36 6%
#percent exposed among all controls.
#smoothie yes & case no = 5/36 14%
#conditional logistic regression for smoothie
smoo <- clogit(case ~ smoothie+ strata(stratanum), data=ecoli3)
summary(smoo)
## Call:
## coxph(formula = Surv(rep(1, 72L), case) ~ smoothie + strata(stratanum),
## data = ecoli3, method = "exact")
##
## n= 55, number of events= 19
## (17 observations deleted due to missingness)
##
## coef exp(coef) se(coef) z Pr(>|z|)
## smoothie -0.6931 0.5000 0.8660 -0.8 0.423
##
## exp(coef) exp(-coef) lower .95 upper .95
## smoothie 0.5 2 0.09158 2.73
##
## Concordance= 0.553 (se = 0.09 )
## Likelihood ratio test= 0.68 on 1 df, p=0.4
## Wald test = 0.64 on 1 df, p=0.4
## Score (logrank) test = 0.67 on 1 df, p=0.4
Bologna
str(ecoli3$bologna) #numeric
## num [1:72] NA 0 NA 0 0 0 NA 0 1 0 ...
table(ecoli3$bologna, exclude = FALSE) #three 99 missing & 17 NA = 20 NA missing data
##
## 0 1 99 <NA>
## 42 10 3 17
#recode bologna variable
ecoli3$bologna[ecoli3$bologna=="99"] <-NA
ecoli3$bologna[ecoli3$bologna=="1"] <- 1
ecoli3$bologna[ecoli3$bologna=="0"] <- 0
#check work
df1 <- ecoli3 %>% select(cdcid, case, bologna)
# Look at the two-by-two table
table(ecoli3$bologna, ecoli3$case, exclude=NULL)
##
## 0 1
## 0 27 15
## 1 7 3
## <NA> 2 18
#percent exposed among all cases.
#bologna yes & case yes = 3/36 8%
#percent exposed among all controls.
#bologna yes & case no = 7/36 19%
#conditional logistic regression for bologna
bol <- clogit(case ~ bologna + strata(stratanum), data=ecoli3)
summary(bol)
## Call:
## coxph(formula = Surv(rep(1, 72L), case) ~ bologna + strata(stratanum),
## data = ecoli3, method = "exact")
##
## n= 52, number of events= 18
## (20 observations deleted due to missingness)
##
## coef exp(coef) se(coef) z Pr(>|z|)
## bologna -0.6931 0.5000 0.8660 -0.8 0.423
##
## exp(coef) exp(-coef) lower .95 upper .95
## bologna 0.5 2 0.09158 2.73
##
## Concordance= 0.562 (se = 0.106 )
## Likelihood ratio test= 0.68 on 1 df, p=0.4
## Wald test = 0.64 on 1 df, p=0.4
## Score (logrank) test = 0.67 on 1 df, p=0.4
Mandarin Oranges
str(ecoli3$mandarin) #numeric
## num [1:72] NA 0 NA 0 99 0 NA 0 0 0 ...
table(ecoli3$mandarin, exclude = FALSE) # 19 NA missing data
##
## 0 1 99 <NA>
## 45 8 3 16
#recode mandarin variable
ecoli3$mandarin[ecoli3$mandarin=="99"] <- NA
ecoli3$mandarin[ecoli3$mandarin=="1"] <- 1
ecoli3$mandarin[ecoli3$mandarin=="0"] <- 0
#check work
df1 <- ecoli3 %>% select(cdcid, case, mandarin)
# Look at the two-by-two table
table(ecoli3$mandarin, ecoli3$case, exclude=NULL)
##
## 0 1
## 0 29 16
## 1 6 2
## <NA> 1 18
#percent exposed among all cases.
#mandarin yes & case yes = 2/36 6%
#percent exposed among all controls.
#mandarin yes & case no = 6/36 17%
#conditional logistic regression for mandarin
mand <- clogit(case ~ mandarin + strata(stratanum), data=ecoli3)
summary(mand)
## Call:
## coxph(formula = Surv(rep(1, 72L), case) ~ mandarin + strata(stratanum),
## data = ecoli3, method = "exact")
##
## n= 53, number of events= 18
## (19 observations deleted due to missingness)
##
## coef exp(coef) se(coef) z Pr(>|z|)
## mandarin -0.6931 0.5000 0.8660 -0.8 0.423
##
## exp(coef) exp(-coef) lower .95 upper .95
## mandarin 0.5 2 0.09158 2.73
##
## Concordance= 0.559 (se = 0.1 )
## Likelihood ratio test= 0.68 on 1 df, p=0.4
## Wald test = 0.64 on 1 df, p=0.4
## Score (logrank) test = 0.67 on 1 df, p=0.4
Bacon
str(ecoli3$bacon) #numeric
## num [1:72] NA 0 NA 0 0 0 NA 0 1 1 ...
table(ecoli3$bacon, exclude = FALSE) #four 99 missing & 16 NA = 20 NA missing data
##
## 0 1 99 <NA>
## 32 20 4 16
#recode bacon variable
ecoli3$bacon[ecoli3$bacon=="99"] <-NA
ecoli3$bacon[ecoli3$bacon=="1"] <- 1
ecoli3$bacon[ecoli3$bacon=="0"] <- 0
#check work
df1 <- ecoli3 %>% select(cdcid, case, bacon)
# Look at the two-by-two table
table(ecoli3$bacon, ecoli3$case, exclude=NULL)
##
## 0 1
## 0 24 8
## 1 10 10
## <NA> 2 18
#percent exposed among all cases.
#bacon yes & case yes = 10/36 28%
#percent exposed among all controls.
#bacon yes & case no = 10/36 28%
#conditional logistic regression for bacon
bac <- clogit(case ~ bacon + strata(stratanum), data=ecoli3)
summary(bac)
## Call:
## coxph(formula = Surv(rep(1, 72L), case) ~ bacon + strata(stratanum),
## data = ecoli3, method = "exact")
##
## n= 52, number of events= 18
## (20 observations deleted due to missingness)
##
## coef exp(coef) se(coef) z Pr(>|z|)
## bacon 0.5108 1.6667 0.7303 0.699 0.484
##
## exp(coef) exp(-coef) lower .95 upper .95
## bacon 1.667 0.6 0.3983 6.974
##
## Concordance= 0.562 (se = 0.123 )
## Likelihood ratio test= 0.51 on 1 df, p=0.5
## Wald test = 0.49 on 1 df, p=0.5
## Score (logrank) test = 0.5 on 1 df, p=0.5
Raw Carrots
str(ecoli3$carrot) #numeric
## num [1:72] NA 1 NA 1 1 0 NA 1 0 0 ...
table(ecoli3$carrot, exclude = FALSE) #three 99 missing & 15 NA = 18 NA missing data
##
## 0 1 99 <NA>
## 28 26 3 15
#recode carrot variable
ecoli3$carrot[ecoli3$carrot=="99"] <-NA
ecoli3$carrot[ecoli3$carrot=="1"] <- 1
ecoli3$carrot[ecoli3$carrot=="0"] <- 0
#check work
df1 <- ecoli3 %>% select(cdcid, case, carrot)
# Look at the two-by-two table
table(ecoli3$carrot, ecoli3$case, exclude=NULL)
##
## 0 1
## 0 18 10
## 1 17 9
## <NA> 1 17
#percent exposed among all cases.
#carrot yes & case yes = 9/36 25%
#percent exposed among all controls.
#carrot yes & case no = 17/36 47%
#conditional logistic regression for carrot
carr <- clogit(case ~ carrot + strata(stratanum), data=ecoli3)
summary(carr)
## Call:
## coxph(formula = Surv(rep(1, 72L), case) ~ carrot + strata(stratanum),
## data = ecoli3, method = "exact")
##
## n= 54, number of events= 19
## (18 observations deleted due to missingness)
##
## coef exp(coef) se(coef) z Pr(>|z|)
## carrot -0.4055 0.6667 0.6455 -0.628 0.53
##
## exp(coef) exp(-coef) lower .95 upper .95
## carrot 0.6667 1.5 0.1881 2.362
##
## Concordance= 0.556 (se = 0.123 )
## Likelihood ratio test= 0.4 on 1 df, p=0.5
## Wald test = 0.39 on 1 df, p=0.5
## Score (logrank) test = 0.4 on 1 df, p=0.5
Fruit rollups
str(ecoli3$rollup) #numeric
## num [1:72] 0 0 1 0 0 0 0 0 0 0 ...
table(ecoli3$rollup, exclude = FALSE) #one 99 missing, one 3 missing, & 1 NA = 2 NA missing data
##
## 0 1 3 99 <NA>
## 54 15 1 1 1
#recode rollup variable
ecoli3$rollup[ecoli3$rollup=="3"] <-NA
ecoli3$rollup[ecoli3$rollup=="99"] <-NA
ecoli3$rollup[ecoli3$rollup=="1"] <- 1
ecoli3$rollup[ecoli3$rollup=="0"] <- 0
#check work
df1 <- ecoli3 %>% select(cdcid, case, rollup)
# Look at the two-by-two table
table(ecoli3$rollup, ecoli3$case, exclude=NULL)
##
## 0 1
## 0 28 26
## 1 6 9
## <NA> 2 1
#percent exposed among all cases.
#rollup yes & case yes = 9/36 25%
#percent exposed among all controls.
#rollup yes & case no = 6/36 17%
#conditional logistic regression for rollup
roll <- clogit(case ~ rollup + strata(stratanum), data=ecoli3)
summary(roll)
## Call:
## coxph(formula = Surv(rep(1, 72L), case) ~ rollup + strata(stratanum),
## data = ecoli3, method = "exact")
##
## n= 69, number of events= 35
## (3 observations deleted due to missingness)
##
## coef exp(coef) se(coef) z Pr(>|z|)
## rollup 0.4055 1.5000 0.6455 0.628 0.53
##
## exp(coef) exp(-coef) lower .95 upper .95
## rollup 1.5 0.6667 0.4233 5.315
##
## Concordance= 0.53 (se = 0.067 )
## Likelihood ratio test= 0.4 on 1 df, p=0.5
## Wald test = 0.39 on 1 df, p=0.5
## Score (logrank) test = 0.4 on 1 df, p=0.5
Apples
str(ecoli3$apples) #numeric
## num [1:72] NA 1 1 1 1 0 1 1 3 0 ...
table(ecoli3$apples, exclude = FALSE) #six 99 missing, two 3 missing, & 4 NA = 12 NA missing data
##
## 0 1 3 99 <NA>
## 23 37 2 6 4
#recode apples variable
ecoli3$apples[ecoli3$apples=="3"] <-NA
ecoli3$apples[ecoli3$apples=="99"] <-NA
ecoli3$apples[ecoli3$apples=="1"] <- 1
ecoli3$apples[ecoli3$apples=="0"] <- 0
#check work
df1 <- ecoli3 %>% select(cdcid, case, apples)
# Look at the two-by-two table
table(ecoli3$apples, ecoli3$case, exclude=NULL)
##
## 0 1
## 0 14 9
## 1 19 18
## <NA> 3 9
#percent exposed among all cases.
#apples yes & case yes = 18/36 50%
#percent exposed among all controls.
#apples yes & case no = 19/36 53%
#conditional logistic regression for apples
app <- clogit(case ~ apples + strata(stratanum), data=ecoli3)
summary(app)
## Call:
## coxph(formula = Surv(rep(1, 72L), case) ~ apples + strata(stratanum),
## data = ecoli3, method = "exact")
##
## n= 60, number of events= 27
## (12 observations deleted due to missingness)
##
## coef exp(coef) se(coef) z Pr(>|z|)
## apples 0.3365 1.4000 0.5855 0.575 0.566
##
## exp(coef) exp(-coef) lower .95 upper .95
## apples 1.4 0.7143 0.4443 4.411
##
## Concordance= 0.54 (se = 0.097 )
## Likelihood ratio test= 0.33 on 1 df, p=0.6
## Wald test = 0.33 on 1 df, p=0.6
## Score (logrank) test = 0.33 on 1 df, p=0.6
Chocolate Chips
str(ecoli3$cchip) #numeric
## num [1:72] NA 1 NA 1 1 0 NA 0 1 0 ...
table(ecoli3$cchip, exclude = FALSE) #two 99 missing & 15 NA = 17 NA missing data
##
## 0 1 99 <NA>
## 33 22 2 15
#recode cchip variable
ecoli3$cchip[ecoli3$cchip=="99"] <-NA
ecoli3$cchip[ecoli3$cchip=="1"] <- 1
ecoli3$cchip[ecoli3$cchip=="0"] <- 0
#check work
df1 <- ecoli3 %>% select(cdcid, case, cchip)
# Look at the two-by-two table
table(ecoli3$cchip, ecoli3$case, exclude=NULL)
##
## 0 1
## 0 23 10
## 1 12 10
## <NA> 1 16
#percent exposed among all cases.
#cchip yes & case yes = 10/36 28%
#percent exposed among all controls.
#cchip yes & case no = 12/36 33%
#conditional logistic regression for cchip
cc <- clogit(case ~ cchip + strata(stratanum), data=ecoli3)
summary(cc)
## Call:
## coxph(formula = Surv(rep(1, 72L), case) ~ cchip + strata(stratanum),
## data = ecoli3, method = "exact")
##
## n= 55, number of events= 20
## (17 observations deleted due to missingness)
##
## coef exp(coef) se(coef) z Pr(>|z|)
## cchip 0.6931 2.0000 0.7071 0.98 0.327
##
## exp(coef) exp(-coef) lower .95 upper .95
## cchip 2 0.5 0.5002 7.997
##
## Concordance= 0.579 (se = 0.109 )
## Likelihood ratio test= 1.02 on 1 df, p=0.3
## Wald test = 0.96 on 1 df, p=0.3
## Score (logrank) test = 1 on 1 df, p=0.3
Cucumbers
str(ecoli3$cucumber) #numeric
## num [1:72] NA 1 NA 0 99 0 NA 1 1 0 ...
table(ecoli3$cucumber, exclude = FALSE) #two 99 missing & 16 NA = 18 NA missing data
##
## 0 1 99 <NA>
## 34 20 2 16
#recode cucumber variable
ecoli3$cucumber[ecoli3$cucumber=="99"] <-NA
ecoli3$cucumber[ecoli3$cucumber=="1"] <- 1
ecoli3$cucumber[ecoli3$cucumber=="0"] <- 0
#check work
df1 <- ecoli3 %>% select(cdcid, case, cucumber)
# Look at the two-by-two table
table(ecoli3$cucumber, ecoli3$case, exclude=NULL)
##
## 0 1
## 0 21 13
## 1 13 7
## <NA> 2 16
#percent exposed among all cases.
#cucumber yes & case yes = 7/36 19%
#percent exposed among all controls.
#cucumber yes & case no = 13/36 36%
#conditional logistic regression for cucumber
cu <- clogit(case ~ cucumber + strata(stratanum), data=ecoli3)
summary(cu)
## Call:
## coxph(formula = Surv(rep(1, 72L), case) ~ cucumber + strata(stratanum),
## data = ecoli3, method = "exact")
##
## n= 54, number of events= 20
## (18 observations deleted due to missingness)
##
## coef exp(coef) se(coef) z Pr(>|z|)
## cucumber -0.2877 0.7500 0.7638 -0.377 0.706
##
## exp(coef) exp(-coef) lower .95 upper .95
## cucumber 0.75 1.333 0.1679 3.351
##
## Concordance= 0.528 (se = 0.104 )
## Likelihood ratio test= 0.14 on 1 df, p=0.7
## Wald test = 0.14 on 1 df, p=0.7
## Score (logrank) test = 0.14 on 1 df, p=0.7
Grapes
str(ecoli3$grapes) #numeric
## num [1:72] NA 1 NA 1 99 0 NA 0 0 1 ...
table(ecoli3$grapes, exclude = FALSE) #two 99 missing & 16 NA = 18 NA missing data
##
## 0 1 99 <NA>
## 25 29 2 16
#recode grapes variable
ecoli3$grapes[ecoli3$grapes=="99"] <-NA
ecoli3$grapes[ecoli3$grapes=="1"] <- 1
ecoli3$grapes[ecoli3$grapes=="0"] <- 0
#check work
df1 <- ecoli3 %>% select(cdcid, case, grapes)
# Look at the two-by-two table
table(ecoli3$grapes, ecoli3$case, exclude=NULL)
##
## 0 1
## 0 17 8
## 1 17 12
## <NA> 2 16
#percent exposed among all cases.
#grapes yes & case yes = 12/36 33%
#percent exposed among all controls.
#grapes yes & case no = 17/36 47%
#conditional logistic regression for grapes
gr <- clogit(case ~ grapes + strata(stratanum), data=ecoli3)
summary(gr)
## Call:
## coxph(formula = Surv(rep(1, 72L), case) ~ grapes + strata(stratanum),
## data = ecoli3, method = "exact")
##
## n= 54, number of events= 20
## (18 observations deleted due to missingness)
##
## coef exp(coef) se(coef) z Pr(>|z|)
## grapes 0.0000 1.0000 0.5774 0 1
##
## exp(coef) exp(-coef) lower .95 upper .95
## grapes 1 1 0.3225 3.101
##
## Concordance= 0.5 (se = 0 )
## Likelihood ratio test= 0 on 1 df, p=1
## Wald test = 0 on 1 df, p=1
## Score (logrank) test = 0 on 1 df, p=1
Raspberries
str(ecoli3$raspberry) #numeric
## num [1:72] NA 1 NA 0 99 0 NA 0 0 0 ...
table(ecoli3$raspberry, exclude = FALSE) #one 99 missing & 15 NA = 16 NA missing data
##
## 0 1 99 <NA>
## 48 8 1 15
#recode raspberry variable
ecoli3$raspberry[ecoli3$raspberry=="99"] <-NA
ecoli3$raspberry[ecoli3$raspberry=="1"] <- 1
ecoli3$raspberry[ecoli3$raspberry=="0"] <- 0
#check work
df1 <- ecoli3 %>% select(cdcid, case, raspberry)
# Look at the two-by-two table
table(ecoli3$raspberry, ecoli3$case, exclude=NULL)
##
## 0 1
## 0 30 18
## 1 5 3
## <NA> 1 15
#percent exposed among all cases.
#raspberry yes & case yes = 3/36 8%
#percent exposed among all controls.
#raspberry yes & case no = 5/36 14%
#conditional logistic regression for raspberry
rasp <- clogit(case ~ raspberry + strata(stratanum), data=ecoli3)
summary(rasp)
## Call:
## coxph(formula = Surv(rep(1, 72L), case) ~ raspberry + strata(stratanum),
## data = ecoli3, method = "exact")
##
## n= 56, number of events= 21
## (16 observations deleted due to missingness)
##
## coef exp(coef) se(coef) z Pr(>|z|)
## raspberry 0 1 1 0 1
##
## exp(coef) exp(-coef) lower .95 upper .95
## raspberry 1 1 0.1409 7.099
##
## Concordance= 0.5 (se = 0 )
## Likelihood ratio test= 0 on 1 df, p=1
## Wald test = 0 on 1 df, p=1
## Score (logrank) test = 0 on 1 df, p=1
Smoothes from smoothie shop
str(ecoli3$shopsmoothie) #numeric
## num [1:72] NA 0 NA 0 0 0 NA 0 0 1 ...
table(ecoli3$shopsmoothie, exclude = FALSE) #one 99 missing & 17 NA = 18 NA missing data
##
## 0 1 99 <NA>
## 50 4 1 17
#recode shopsmoothie variable
ecoli3$shopsmoothie[ecoli3$shopsmoothie=="99"] <-NA
ecoli3$shopsmoothie[ecoli3$shopsmoothie=="1"] <- 1
ecoli3$shopsmoothie[ecoli3$shopsmoothie=="0"] <- 0
#check work
df1 <- ecoli3 %>% select(cdcid, case, shopsmoothie)
# Look at the two-by-two table
table(ecoli3$shopsmoothie, ecoli3$case, exclude=NULL)
##
## 0 1
## 0 33 17
## 1 2 2
## <NA> 1 17
#percent exposed among all cases.
#shopsmoothie yes & case yes = 2/36 6%
#percent exposed among all controls.
#shopsmoothie yes & case no = 2/36 6%
#conditional logistic regression for shopsmoothie
ssmoo <- clogit(case ~ shopsmoothie + strata(stratanum), data=ecoli3)
summary(ssmoo)
## Call:
## coxph(formula = Surv(rep(1, 72L), case) ~ shopsmoothie + strata(stratanum),
## data = ecoli3, method = "exact")
##
## n= 54, number of events= 19
## (18 observations deleted due to missingness)
##
## coef exp(coef) se(coef) z Pr(>|z|)
## shopsmoothie 0 1 1 0 1
##
## exp(coef) exp(-coef) lower .95 upper .95
## shopsmoothie 1 1 0.1409 7.099
##
## Concordance= 0.5 (se = 0 )
## Likelihood ratio test= 0 on 1 df, p=1
## Wald test = 0 on 1 df, p=1
## Score (logrank) test = 0 on 1 df, p=1
Cantaloupe
str(ecoli3$cantaloupe) #numeric
## num [1:72] NA 0 NA 0 99 0 NA 0 0 0 ...
table(ecoli3$cantaloupe, exclude = FALSE) #two 99 missing & 16 NA = 18 NA missing data
##
## 0 1 99 <NA>
## 43 11 2 16
#recode cantaloupe variable
ecoli3$cantaloupe[ecoli3$cantaloupe=="99"] <-NA
ecoli3$cantaloupe[ecoli3$cantaloupe=="1"] <- 1
ecoli3$cantaloupe[ecoli3$cantaloupe=="0"] <- 0
#check work
df1 <- ecoli3 %>% select(cdcid, case, cantaloupe)
# Look at the two-by-two table
table(ecoli3$cantaloupe, ecoli3$case, exclude=NULL)
##
## 0 1
## 0 29 14
## 1 6 5
## <NA> 1 17
#percent exposed among all cases.
#cantaloupe yes & case yes = 5/36 14%
#percent exposed among all controls.
#cantaloupe yes & case no = 6/36 17%
#conditional logistic regression for cantaloupe
canta <- clogit(case ~ cantaloupe + strata(stratanum), data=ecoli3)
summary(canta)
## Call:
## coxph(formula = Surv(rep(1, 72L), case) ~ cantaloupe + strata(stratanum),
## data = ecoli3, method = "exact")
##
## n= 54, number of events= 19
## (18 observations deleted due to missingness)
##
## coef exp(coef) se(coef) z Pr(>|z|)
## cantaloupe 0.2877 1.3333 0.7638 0.377 0.706
##
## exp(coef) exp(-coef) lower .95 upper .95
## cantaloupe 1.333 0.75 0.2984 5.957
##
## Concordance= 0.528 (se = 0.104 )
## Likelihood ratio test= 0.14 on 1 df, p=0.7
## Wald test = 0.14 on 1 df, p=0.7
## Score (logrank) test = 0.14 on 1 df, p=0.7
Watermelon
str(ecoli3$watermelon) #numeric
## num [1:72] NA 0 NA 0 99 0 NA 1 0 0 ...
table(ecoli3$watermelon, exclude = FALSE) #two 99 missing & 16 NA = 18 NA missing data
##
## 0 1 99 <NA>
## 43 11 2 16
#recode watermelon variable
ecoli3$watermelon[ecoli3$watermelon=="99"] <-NA
ecoli3$watermelon[ecoli3$watermelon=="1"] <- 1
ecoli3$watermelon[ecoli3$watermelon=="0"] <- 0
#check work
df1 <- ecoli3 %>% select(cdcid, case, watermelon)
# Look at the two-by-two table
table(ecoli3$watermelon, ecoli3$case, exclude=NULL)
##
## 0 1
## 0 28 15
## 1 6 5
## <NA> 2 16
#percent exposed among all cases.
#watermelon yes & case yes = 5/36 14%
#percent exposed among all controls.
#watermelon yes & case no = 6/36 17%
#conditional logistic regression for watermelon
wa <- clogit(case ~ watermelon + strata(stratanum), data=ecoli3)
summary(wa)
## Call:
## coxph(formula = Surv(rep(1, 72L), case) ~ watermelon + strata(stratanum),
## data = ecoli3, method = "exact")
##
## n= 54, number of events= 20
## (18 observations deleted due to missingness)
##
## coef exp(coef) se(coef) z Pr(>|z|)
## watermelon 0.4055 1.5000 0.9129 0.444 0.657
##
## exp(coef) exp(-coef) lower .95 upper .95
## watermelon 1.5 0.6667 0.2506 8.977
##
## Concordance= 0.528 (se = 0.087 )
## Likelihood ratio test= 0.2 on 1 df, p=0.7
## Wald test = 0.2 on 1 df, p=0.7
## Score (logrank) test = 0.2 on 1 df, p=0.7
Milk
str(ecoli3$milk) #numeric
## num [1:72] NA 0 NA 1 1 1 NA 0 1 0 ...
table(ecoli3$milk, exclude = FALSE) #NA = 14
##
## 0 1 <NA>
## 9 49 14
#recode milk variable
ecoli3$milk[ecoli3$milk=="NA"] <-NA
ecoli3$milk[ecoli3$milk=="1"] <- 1
ecoli3$milk[ecoli3$milk=="0"] <- 0
#check work
df1 <- ecoli3 %>% select(cdcid, case, milk)
# Look at the two-by-two table
table(ecoli3$milk, ecoli3$case, exclude=NULL)
##
## 0 1
## 0 7 2
## 1 29 20
## <NA> 0 14
#percent exposed among all cases.
#milk yes & case yes = 20/36 56%
#percent exposed among all controls.
#milk yes & case no = 29/36 80%
#conditional logistic regression for milk
mi <- clogit(case ~ milk + strata(stratanum), data=ecoli3)
summary(mi)
## Call:
## coxph(formula = Surv(rep(1, 72L), case) ~ milk + strata(stratanum),
## data = ecoli3, method = "exact")
##
## n= 58, number of events= 22
## (14 observations deleted due to missingness)
##
## coef exp(coef) se(coef) z Pr(>|z|)
## milk 0.6931 2.0000 1.2247 0.566 0.571
##
## exp(coef) exp(-coef) lower .95 upper .95
## milk 2 0.5 0.1814 22.06
##
## Concordance= 0.523 (se = 0.055 )
## Likelihood ratio test= 0.34 on 1 df, p=0.6
## Wald test = 0.32 on 1 df, p=0.6
## Score (logrank) test = 0.33 on 1 df, p=0.6