Download all datasets HERE




library(knitr)
#Windows
knitr::opts_knit$set(root.dir = "C:/Users/rowe0122/Dropbox/R backup/Lockout - R/LOCKOUT")

knitr::opts_chunk$set(echo=TRUE, warning=FALSE, message=FALSE)

#Mac
#knitr::opts_knit$set(root.dir = "~/Dropbox/R backup/Lockout - R/LOCKOUT")



Evaluate Data



Show first 10 rows of dataset



load(file="lockqtrdat.Rdata")
library(dplyr)
lockqtr = lockqtr %>%
  mutate(Tx = recode(lockqtr$Tx,
                     "0" = "Orbeseal", "1" = "Lockout"))
Desc1 <- lockqtr %>% subset(select=c(FARMID,Cow,QTR,Tx,Age,Parity,IMIDO,SCCDO,MYDO,DIMDO,CM1,PeakSCC,DPlength,PCSampDIM,IMIPC,Cure,NewIMI))
head(lockqtr, n=10)



Inspect Data

library(summarytools)

#opts_chunk$set(comment = NA, prompt = FALSE, cache = FALSE, results = 'asis')
print(summarytools::dfSummary(lockqtr, valid.col=FALSE,graph.magnif=1,varnumbers=F,style="grid",graph.col = F))
## Data Frame Summary  
##   
## Dimensions: 3175 x 24  
## Duplicates: 0  
## 
## +-------------+---------------------------------+---------------------+----------+
## | Variable    | Stats / Values                  | Freqs (% of Valid)  | Missing  |
## +=============+=================================+=====================+==========+
## | Cow         | Mean (sd) : 9.4 (1.3)           | 811 distinct values | 0        |
## | [numeric]   | min < med < max:                |                     | (0%)     |
## |             | 6.3 < 10.1 < 11.2               |                     |          |
## |             | IQR (CV) : 2.1 (0.1)            |                     |          |
## +-------------+---------------------------------+---------------------+----------+
## | QTR         | 1. LF                           | 785 (24.7%)         | 0        |
## | [factor]    | 2. LR                           | 798 (25.1%)         | (0%)     |
## |             | 3. RF                           | 796 (25.1%)         |          |
## |             | 4. RR                           | 796 (25.1%)         |          |
## +-------------+---------------------------------+---------------------+----------+
## | FARMID      | Mean (sd) : 3 (1.3)             | 1 :  695 (21.9%)    | 0        |
## | [numeric]   | min < med < max:                | 2 :  298 ( 9.4%)    | (0%)     |
## |             | 1 < 3 < 5                       | 3 : 1125 (35.4%)    |          |
## |             | IQR (CV) : 2 (0.5)              | 4 :  551 (17.3%)    |          |
## |             |                                 | 5 :  506 (15.9%)    |          |
## +-------------+---------------------------------+---------------------+----------+
## | Enrolldate  | min : 2018-06-26                | 17 distinct values  | 0        |
## | [Date]      | med : 2018-07-31                |                     | (0%)     |
## |             | max : 2018-08-22                |                     |          |
## |             | range : 1m 27d                  |                     |          |
## +-------------+---------------------------------+---------------------+----------+
## | Tx          | 1. Orbeseal                     | 1580 (49.8%)        | 0        |
## | [factor]    | 2. Lockout                      | 1595 (50.2%)        | (0%)     |
## +-------------+---------------------------------+---------------------+----------+
## | Age         | Mean (sd) : 46 (15.4)           | 561 distinct values | 0        |
## | [numeric]   | min < med < max:                |                     | (0%)     |
## |             | 17 < 43.9 < 117                 |                     |          |
## |             | IQR (CV) : 23.1 (0.3)           |                     |          |
## +-------------+---------------------------------+---------------------+----------+
## | Parity      | 1. 1                            | 1348 (42.5%)        | 0        |
## | [factor]    | 2. 2                            |  927 (29.2%)        | (0%)     |
## |             | 3. 3                            |  584 (18.4%)        |          |
## |             | 4. 4                            |  316 (10.0%)        |          |
## +-------------+---------------------------------+---------------------+----------+
## | Calv1Date   | min : 2016-02-08                | 208 distinct values | 0        |
## | [Date]      | med : 2017-09-19                |                     | (0%)     |
## |             | max : 2017-12-01                |                     |          |
## |             | range : 1y 9m 23d               |                     |          |
## +-------------+---------------------------------+---------------------+----------+
## | MYDO        | Mean (sd) : 25.4 (9)            | 92 distinct values  | 0        |
## | [numeric]   | min < med < max:                |                     | (0%)     |
## |             | 1.8 < 25.9 < 49                 |                     |          |
## |             | IQR (CV) : 14.1 (0.4)           |                     |          |
## +-------------+---------------------------------+---------------------+----------+
## | DIMDO       | Mean (sd) : 330 (65.5)          | 195 distinct values | 0        |
## | [numeric]   | min < med < max:                |                     | (0%)     |
## |             | 256 < 307 < 869                 |                     |          |
## |             | IQR (CV) : 62 (0.2)             |                     |          |
## +-------------+---------------------------------+---------------------+----------+
## | SCCDO       | Mean (sd) : 4.6 (1.2)           | 330 distinct values | 0        |
## | [numeric]   | min < med < max:                |                     | (0%)     |
## |             | 0 < 4.6 < 8.9                   |                     |          |
## |             | IQR (CV) : 1.5 (0.3)            |                     |          |
## +-------------+---------------------------------+---------------------+----------+
## | PeakSCC     | Mean (sd) : 5.7 (1.2)           | 536 distinct values | 0        |
## | [numeric]   | min < med < max:                |                     | (0%)     |
## |             | 3 < 5.6 < 9.2                   |                     |          |
## |             | IQR (CV) : 1.6 (0.2)            |                     |          |
## +-------------+---------------------------------+---------------------+----------+
## | CM1         | 1. 0                            | 2384 (75.1%)        | 0        |
## | [factor]    | 2. 1                            |  791 (24.9%)        | (0%)     |
## +-------------+---------------------------------+---------------------+----------+
## | Calv2Date   | min : 2018-07-27                | 91 distinct values  | 0        |
## | [Date]      | med : 2018-09-24                |                     | (0%)     |
## |             | max : 2018-11-01                |                     |          |
## |             | range : 3m 5d                   |                     |          |
## +-------------+---------------------------------+---------------------+----------+
## | DPlength    | Mean (sd) : 54.9 (8.7)          | 50 distinct values  | 0        |
## | [numeric]   | min < med < max:                |                     | (0%)     |
## |             | 30 < 55 < 85                    |                     |          |
## |             | IQR (CV) : 13 (0.2)             |                     |          |
## +-------------+---------------------------------+---------------------+----------+
## | DOCult1     | 1. No Growth                    | 2347 (78.0%)        | 165      |
## | [character] | 2. Staphylococcus chromogene    |  317 (10.5%)        | (5.2%)   |
## |             | 3. Staphylococcus sp.           |   82 ( 2.7%)        |          |
## |             | 4. Bacillus sp.                 |   56 ( 1.9%)        |          |
## |             | 5. Staphylococcus haemolytic    |   34 ( 1.1%)        |          |
## |             | 6. Corynebacterium sp.          |   26 ( 0.9%)        |          |
## |             | 7. Streptococcus uberis         |   22 ( 0.7%)        |          |
## |             | 8. Streptococcus sp.            |   14 ( 0.5%)        |          |
## |             | 9. Lactococcus garvieae         |   13 ( 0.4%)        |          |
## |             | 10. Staphylococcus simulans     |   13 ( 0.4%)        |          |
## |             | [ 22 others ]                   |   86 ( 2.9%)        |          |
## +-------------+---------------------------------+---------------------+----------+
## | DOCult2     | 1. Bacillus sp.                 | 8 (21.1%)           | 3137     |
## | [character] | 2. Staphylococcus chromogene    | 8 (21.1%)           | (98.8%)  |
## |             | 3. Staphylococcus sp.           | 8 (21.1%)           |          |
## |             | 4. Streptococcus uberis         | 4 (10.5%)           |          |
## |             | 5. Staphylococcus haemolytic    | 2 ( 5.3%)           |          |
## |             | 6. Staphylococcus sciuri        | 2 ( 5.3%)           |          |
## |             | 7. Corynebacterium sp.          | 1 ( 2.6%)           |          |
## |             | 8. Micrococcus sp.              | 1 ( 2.6%)           |          |
## |             | 9. Staphylococcus xylosus/sa    | 1 ( 2.6%)           |          |
## |             | 10. Streptococcus dysgalactia   | 1 ( 2.6%)           |          |
## |             | [ 2 others ]                    | 2 ( 5.3%)           |          |
## +-------------+---------------------------------+---------------------+----------+
## | PCCult1     | 1. No Growth                    | 2449 (87.2%)        | 368      |
## | [character] | 2. Staphylococcus chromogene    |  100 ( 3.6%)        | (11.59%) |
## |             | 3. Staphylococcus sp.           |   59 ( 2.1%)        |          |
## |             | 4. Bacillus sp.                 |   56 ( 2.0%)        |          |
## |             | 5. Staphylococcus sciuri        |   52 ( 1.9%)        |          |
## |             | 6. Corynebacterium sp.          |   14 ( 0.5%)        |          |
## |             | 7. Escherichia coli             |    8 ( 0.3%)        |          |
## |             | 8. Gram negative organism       |    8 ( 0.3%)        |          |
## |             | 9. Acinetobacter sp.            |    6 ( 0.2%)        |          |
## |             | 10. Gram positive coccus        |    6 ( 0.2%)        |          |
## |             | [ 19 others ]                   |   49 ( 1.8%)        |          |
## +-------------+---------------------------------+---------------------+----------+
## | PCCult2     | 1. Bacillus sp.                 | 5 (27.8%)           | 3157     |
## | [character] | 2. Gram negative organism       | 1 ( 5.6%)           | (99.43%) |
## |             | 3. Staphylococcus chromogene    | 7 (38.9%)           |          |
## |             | 4. Staphylococcus haemolytic    | 2 (11.1%)           |          |
## |             | 5. Staphylococcus sciuri        | 1 ( 5.6%)           |          |
## |             | 6. Staphylococcus sp.           | 1 ( 5.6%)           |          |
## |             | 7. Streptococcus uberis         | 1 ( 5.6%)           |          |
## +-------------+---------------------------------+---------------------+----------+
## | PCSampDIM   | min : 0                         | 14 distinct values  | 158      |
## | [difftime]  | med : 5                         |                     | (4.98%)  |
## |             | max : 13                        |                     |          |
## |             | units : days                    |                     |          |
## +-------------+---------------------------------+---------------------+----------+
## | IMIDO       | Min  : 0                        | 0 : 2347 (78.0%)    | 165      |
## | [numeric]   | Mean : 0.2                      | 1 :  663 (22.0%)    | (5.2%)   |
## |             | Max  : 1                        |                     |          |
## +-------------+---------------------------------+---------------------+----------+
## | IMIPC       | Min  : 0                        | 0 : 2449 (87.2%)    | 368      |
## | [numeric]   | Mean : 0.1                      | 1 :  358 (12.8%)    | (11.59%) |
## |             | Max  : 1                        |                     |          |
## +-------------+---------------------------------+---------------------+----------+
## | Cure        | Min  : 0                        | 0 :  40 ( 7.1%)     | 2613     |
## | [numeric]   | Mean : 0.9                      | 1 : 522 (92.9%)     | (82.3%)  |
## |             | Max  : 1                        |                     |          |
## +-------------+---------------------------------+---------------------+----------+
## | NewIMI      | Min  : 0                        | 0 : 2371 (89.0%)    | 511      |
## | [numeric]   | Mean : 0.1                      | 1 :  293 (11.0%)    | (16.09%) |
## |             | Max  : 1                        |                     |          |
## +-------------+---------------------------------+---------------------+----------+
?summarytools::dfSummary



Compare treatment groups

table1::table1(~ factor(FARMID) + Age + Parity + factor(IMIDO) + SCCDO + MYDO + as.numeric(DIMDO) + CM1 + PeakSCC + as.numeric(DPlength) + as.numeric(PCSampDIM) | Tx, data=lockqtr)
Orbeseal
(n=1580)
Lockout
(n=1595)
Overall
(n=3175)
factor(FARMID)
1 343 (21.7%) 352 (22.1%) 695 (21.9%)
2 144 (9.1%) 154 (9.7%) 298 (9.4%)
3 560 (35.4%) 565 (35.4%) 1125 (35.4%)
4 272 (17.2%) 279 (17.5%) 551 (17.4%)
5 261 (16.5%) 245 (15.4%) 506 (15.9%)
Age
Mean (SD) 46.7 (16.2) 45.3 (14.6) 46.0 (15.4)
Median [Min, Max] 44.0 [18.0, 117] 43.9 [17.0, 113] 43.9 [17.0, 117]
Parity
1 661 (41.8%) 687 (43.1%) 1348 (42.5%)
2 452 (28.6%) 475 (29.8%) 927 (29.2%)
3 288 (18.2%) 296 (18.6%) 584 (18.4%)
4 179 (11.3%) 137 (8.6%) 316 (10.0%)
factor(IMIDO)
0 1184 (74.9%) 1163 (72.9%) 2347 (73.9%)
1 317 (20.1%) 346 (21.7%) 663 (20.9%)
Missing 79 (5.0%) 86 (5.4%) 165 (5.2%)
SCCDO
Mean (SD) 4.54 (1.21) 4.57 (1.22) 4.55 (1.21)
Median [Min, Max] 4.60 [0.00, 8.92] 4.53 [0.00, 8.85] 4.55 [0.00, 8.92]
MYDO
Mean (SD) 25.4 (8.82) 25.4 (9.18) 25.4 (9.00)
Median [Min, Max] 26.3 [2.72, 48.5] 25.4 [1.81, 49.0] 25.9 [1.81, 49.0]
as.numeric(DIMDO)
Mean (SD) 330 (63.2) 330 (67.8) 330 (65.5)
Median [Min, Max] 308 [256, 817] 307 [260, 869] 307 [256, 869]
CM1
0 1170 (74.1%) 1214 (76.1%) 2384 (75.1%)
1 410 (25.9%) 381 (23.9%) 791 (24.9%)
PeakSCC
Mean (SD) 5.69 (1.16) 5.80 (1.33) 5.75 (1.25)
Median [Min, Max] 5.55 [3.00, 9.21] 5.58 [3.09, 9.21] 5.56 [3.00, 9.21]
as.numeric(DPlength)
Mean (SD) 54.9 (8.83) 54.9 (8.64) 54.9 (8.73)
Median [Min, Max] 55.0 [30.0, 84.0] 55.0 [30.0, 85.0] 55.0 [30.0, 85.0]
as.numeric(PCSampDIM)
Mean (SD) 5.17 (2.48) 5.15 (2.39) 5.16 (2.44)
Median [Min, Max] 5.00 [0.00, 13.0] 5.00 [0.00, 13.0] 5.00 [0.00, 13.0]
Missing 81 (5.1%) 77 (4.8%) 158 (5.0%)




Compare herds

table1::table1(~ Age + Parity + SCCDO + MYDO + CM1 + PeakSCC + as.numeric(DPlength) + as.numeric(PCSampDIM) + factor(IMIDO) + factor(IMIPC) + factor(Cure) + factor(NewIMI) | factor(FARMID), data=lockqtr)
1
(n=695)
2
(n=298)
3
(n=1125)
4
(n=551)
5
(n=506)
Overall
(n=3175)
Age
Mean (SD) 43.2 (13.3) 41.1 (9.93) 46.9 (14.6) 49.3 (17.6) 47.2 (18.6) 46.0 (15.4)
Median [Min, Max] 42.3 [28.6, 90.4] 37.6 [29.6, 65.2] 44.9 [30.1, 103] 46.2 [17.4, 113] 44.5 [17.0, 117] 43.9 [17.0, 117]
Parity
1 314 (45.2%) 157 (52.7%) 443 (39.4%) 226 (41.0%) 208 (41.1%) 1348 (42.5%)
2 252 (36.3%) 89 (29.9%) 305 (27.1%) 140 (25.4%) 141 (27.9%) 927 (29.2%)
3 75 (10.8%) 52 (17.4%) 282 (25.1%) 104 (18.9%) 71 (14.0%) 584 (18.4%)
4 54 (7.8%) 0 (0%) 95 (8.4%) 81 (14.7%) 86 (17.0%) 316 (10.0%)
SCCDO
Mean (SD) 4.17 (1.32) 4.45 (1.14) 4.63 (1.02) 4.55 (1.24) 4.98 (1.32) 4.55 (1.21)
Median [Min, Max] 4.16 [0.00, 7.88] 4.41 [2.64, 7.38] 4.57 [2.56, 8.92] 4.66 [0.00, 8.63] 4.89 [0.00, 8.85] 4.55 [0.00, 8.92]
MYDO
Mean (SD) 15.7 (5.35) 26.2 (4.85) 30.4 (7.90) 29.5 (7.50) 23.0 (6.79) 25.4 (9.00)
Median [Min, Max] 15.9 [2.72, 30.8] 26.8 [13.6, 36.3] 31.8 [13.2, 48.5] 29.9 [13.6, 49.0] 23.6 [1.81, 47.2] 25.9 [1.81, 49.0]
CM1
0 592 (85.2%) 263 (88.3%) 694 (61.7%) 452 (82.0%) 383 (75.7%) 2384 (75.1%)
1 103 (14.8%) 35 (11.7%) 431 (38.3%) 99 (18.0%) 123 (24.3%) 791 (24.9%)
PeakSCC
Mean (SD) 5.62 (1.16) 5.17 (1.08) 5.73 (1.33) 5.88 (1.16) 6.16 (1.20) 5.75 (1.25)
Median [Min, Max] 5.54 [3.47, 8.78] 5.03 [3.18, 7.79] 5.44 [3.00, 9.21] 5.69 [3.40, 8.95] 6.12 [3.09, 8.85] 5.56 [3.00, 9.21]
as.numeric(DPlength)
Mean (SD) 54.9 (9.57) 55.2 (7.79) 54.1 (9.93) 57.8 (5.36) 53.5 (7.38) 54.9 (8.73)
Median [Min, Max] 54.0 [30.0, 79.0] 56.0 [36.0, 79.0] 52.0 [30.0, 85.0] 58.0 [35.0, 73.0] 53.0 [30.0, 72.0] 55.0 [30.0, 85.0]
as.numeric(PCSampDIM)
Mean (SD) 3.66 (2.61) 3.91 (2.36) 5.77 (1.92) 5.68 (2.44) 5.89 (2.13) 5.16 (2.44)
Median [Min, Max] 3.00 [0.00, 12.0] 4.00 [0.00, 9.00] 6.00 [2.00, 9.00] 5.00 [0.00, 13.0] 6.00 [3.00, 12.0] 5.00 [0.00, 13.0]
Missing 50 (7.2%) 31 (10.4%) 38 (3.4%) 27 (4.9%) 12 (2.4%) 158 (5.0%)
factor(IMIDO)
0 419 (60.3%) 235 (78.9%) 1002 (89.1%) 320 (58.1%) 371 (73.3%) 2347 (73.9%)
1 184 (26.5%) 53 (17.8%) 112 (10.0%) 198 (35.9%) 116 (22.9%) 663 (20.9%)
Missing 92 (13.2%) 10 (3.4%) 11 (1.0%) 33 (6.0%) 19 (3.8%) 165 (5.2%)
factor(IMIPC)
0 530 (76.3%) 203 (68.1%) 1002 (89.1%) 324 (58.8%) 390 (77.1%) 2449 (77.1%)
1 55 (7.9%) 29 (9.7%) 40 (3.6%) 157 (28.5%) 77 (15.2%) 358 (11.3%)
Missing 110 (15.8%) 66 (22.1%) 83 (7.4%) 70 (12.7%) 39 (7.7%) 368 (11.6%)
factor(Cure)
0 2 (0.3%) 3 (1.0%) 3 (0.3%) 25 (4.5%) 7 (1.4%) 40 (1.3%)
1 146 (21.0%) 35 (11.7%) 99 (8.8%) 143 (26.0%) 99 (19.6%) 522 (16.4%)
Missing 547 (78.7%) 260 (87.2%) 1023 (90.9%) 383 (69.5%) 400 (79.1%) 2613 (82.3%)
factor(NewIMI)
0 466 (67.1%) 198 (66.4%) 995 (88.4%) 331 (60.1%) 381 (75.3%) 2371 (74.7%)
1 44 (6.3%) 26 (8.7%) 37 (3.3%) 119 (21.6%) 67 (13.2%) 293 (9.2%)
Missing 185 (26.6%) 74 (24.8%) 93 (8.3%) 101 (18.3%) 58 (11.5%) 511 (16.1%)



Outcome 1: Cure

library(gmodels)
CrossTable(lockqtr$Tx,lockqtr$Cure,prop.c=FALSE,prop.t=FALSE,prop.chisq = FALSE)
## 
##  
##    Cell Contents
## |-------------------------|
## |                       N |
## |           N / Row Total |
## |-------------------------|
## 
##  
## Total Observations in Table:  562 
## 
##  
##              | lockqtr$Cure 
##   lockqtr$Tx |         0 |         1 | Row Total | 
## -------------|-----------|-----------|-----------|
##     Orbeseal |        22 |       240 |       262 | 
##              |     0.084 |     0.916 |     0.466 | 
## -------------|-----------|-----------|-----------|
##      Lockout |        18 |       282 |       300 | 
##              |     0.060 |     0.940 |     0.534 | 
## -------------|-----------|-----------|-----------|
## Column Total |        40 |       522 |       562 | 
## -------------|-----------|-----------|-----------|
## 
## 



Logistic regression model for dry period cure

Model building plan

Model type: Logistic regression with mixed effects (generalized linear mixed model with binomial family / logit link).

Step 1: Identify potential confouders using a directed acyclic graph (DAG)

Step 2: Identify correlated variables using pearson and kendalls correlation coefficients

Step 3: Create model with all potential confounders

Step 4: Investigate potential effect measure modification

Step 5: Remove unneccesary covariates in backwards stepwise fashion using 10% rule (i.e. if odds ratio for algorithm or culture changes by >10% after removing the covariate, the covariate is retained in the model)

Step 6: Report final model



Step 1: DAG

This is used to identify variables that could be confounders if they are not balanced between treatment groups.

library(DiagrammeR)
mermaid("graph LR
        T(Treatment)-->U(Cure)
        A(Age)-->T
        P(Parity)-->T
        M(Yield at dry-off)-->T
        S(SCC during prev lactation)-->T
        C(CM in prev lact)-->T
        D(DIM at dry off) --> T
        K(DIM at post calving sample) --> T
        D-->M
        D-->S
        D-->U
        K-->U
        A-->U
        P-->U
        M-->U
        S-->U
        C-->U
        C-->M
        P-->C
        P-->S
        P-->M
        A-->P
        A-->C
        A-->S
        A-->M
        M-->S
        C-->S
style D fill:#FFFFFF, stroke-width:0px
style K fill:#FFFFFF, stroke-width:0px
style A fill:#FFFFFF, stroke-width:0px
        style T fill:#FFFFFF, stroke-width:2px
        style P fill:#FFFFFF, stroke-width:0px
        style M fill:#FFFFFF, stroke-width:0px
        style S fill:#FFFFFF, stroke-width:0px
        style C fill:#FFFFFF, stroke-width:0px
        style I fill:#FFFFFF, stroke-width:0px
        style U fill:#FFFFFF, stroke-width:2px
        ")

According to this DAG, I may need to control for the following variables.

Parity [“Parity”] or Age [“Age”] <- likely to correlated

Yield at most recent test before dry off [“DOMY”]

Somatic cell count during previous lactation [“SCCDO” and “PeakSCC”]

Clinical mastitis in previous lactation [“CM1”]

Days in milk at dry-off [“DODIM”]

Days in milk at post-calving sample [“PCSampDIM”]





Step 2: Identify correlated covariates

Pearson correlation matrix among potential predictors

library(psych)
cor <- Desc1[, c(5,6,8,9,10,12,13)]
cor$Parity <- as.numeric(cor$Parity)
cor <- cor(cor, use = "complete.obs")
corPlot(cor,numbers=TRUE)

cor <- Desc1[, c(5,6,8,9,10,12,13)]
cor$Parity <- as.numeric(cor$Parity)
cor <- cor(cor, use = "complete.obs", method="kendal")
corPlot(cor,numbers=TRUE)

Age and Parity highly correlated as expected. Will only offer parity.





Steps 3 to 6 done in Stata. Log file pasted below.

. *Step 3: Create full model with all potential covariates
. meglm Cure i.Tx i.Parity SCCDO PeakSCC MYDO i.CM1 DIMDO PCSampDIM || FARMID: || Cow:, family(binomial) link(logit) nolog nocnsreport nopvalues 

Mixed-effects GLM                               Number of obs     =        561
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5         38      112.2        168
            Cow |        367          1        1.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(10)     =      11.82
Log likelihood = -130.24057                     Prob > chi2       =     0.2975
--------------------------------------------------------------
        Cure |      Coef.   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |    .512229    .355489     -.1845167    1.208975
             |
      Parity |
          2  |  -.2742185   .4422871     -1.141085    .5926484
          3  |   .7200151    .628142     -.5111205    1.951151
          4  |  -.5752739   .5804639     -1.712962    .5624144
             |
       SCCDO |    .117288   .1475205     -.1718469    .4064229
     PeakSCC |   -.287137   .1722732     -.6247862    .0505123
        MYDO |  -.0097148   .0285632     -.0656976     .046268
             |
         CM1 |
          1  |   .9204964   .4926131     -.0450075       1.886
       DIMDO |  -.0028965   .0027986     -.0083817    .0025887
   PCSampDIM |   .0369436   .0781341     -.1161965    .1900836
       _cons |   4.726348   1.790483      1.217066    8.235631
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .6741527    .606448      .1156225    3.930739
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   8.86e-34   1.11e-17             .           .
--------------------------------------------------------------
LR test vs. logistic model: chibar2(01) = 9.93        Prob >= chibar2 = 0.0008

. 
. *Step 4: Effect measure modification
. *Will test Tx:Farm, Tx:Parity, Tx:PrevCM
. 
. *Step 4a: Tx:Farm
. meglm Cure i.Tx##i.FARMID i.Parity SCCDO PeakSCC MYDO i.CM1 DIMDO PCSampDIM || FARMID: || Cow:, family(binomial) link(logit) nolog nocnsreport nopvalues 

Mixed-effects GLM                               Number of obs     =        561
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5         38      112.2        168
            Cow |        367          1        1.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(18)     =      31.39
Log likelihood = -123.77899                     Prob > chi2       =     0.0259
--------------------------------------------------------------
        Cure |      Coef.   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |   .0366577   1.438829     -2.783395    2.856711
             |
      FARMID |
          2  |  -2.195981   1.515395     -5.166101    .7741389
          3  |  -1.503598   1.361501     -4.172092    1.164895
          4  |  -3.242125   1.176727     -5.548467   -.9357832
          5  |   -2.02928   1.185866     -4.353535    .2949742
             |
   Tx#FARMID |
        1#2  |  -.0872561   1.930424     -3.870818    3.696306
        1#3  |   .5758022   1.922322      -3.19188    4.343484
        1#4  |   .6237609   1.512506     -2.340695    3.588217
        1#5  |   .5327658   1.654455     -2.709906    3.775437
             |
      Parity |
          2  |  -.2087316   .4532388     -1.097063    .6796001
          3  |   .8060823   .6386669     -.4456818    2.057846
          4  |  -.5422512   .5993706     -1.716996    .6324935
             |
       SCCDO |   .1534688   .1532957     -.1469852    .4539229
     PeakSCC |  -.2917319   .1775356     -.6396953    .0562315
        MYDO |   .0063618   .0294397     -.0513391    .0640626
             |
         CM1 |
          1  |   .9046163   .4963608     -.0682329    1.877465
       DIMDO |  -.0026624   .0030389     -.0086187    .0032938
   PCSampDIM |   .0551309   .0810745     -.1037722    .2140339
       _cons |   5.897307   1.953007      2.069485     9.72513
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   3.26e-35   2.69e-18             .           .
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   9.88e-33   1.11e-16             .           .
--------------------------------------------------------------
LR test vs. logistic model: chi2(0) = 0.00                Prob > chi2 =      .

Note: LR test is conservative and provided only for reference.

. testparm Tx#FARMID

 ( 1)  [Cure]2.Tx#2.FARMID = 0
 ( 2)  [Cure]2.Tx#3.FARMID = 0
 ( 3)  [Cure]2.Tx#4.FARMID = 0
 ( 4)  [Cure]2.Tx#5.FARMID = 0

           chi2(  4) =    0.40
         Prob > chi2 =    0.9825

. 
. *P > 0.05. Will not investigate further
. 
. *Step 4b: Tx: Parity
. meglm Cure i.Tx##i.Parity SCCDO PeakSCC MYDO i.CM1 DIMDO PCSampDIM || FARMID: || Cow:, family(binomial) link(logit) nolog nocnsreport nopvalues 

Mixed-effects GLM                               Number of obs     =        561
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5         38      112.2        168
            Cow |        367          1        1.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(13)     =      15.83
Log likelihood =  -128.2291                     Prob > chi2       =     0.2586
--------------------------------------------------------------
        Cure |      Coef.   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |    .121818   .5428949     -.9422365    1.185872
             |
      Parity |
          2  |  -.8349406      .5673     -1.946828     .276947
          3  |   .6940131   .8862026     -1.042912    2.430938
          4  |  -.4143782   .7796615     -1.942487     1.11373
             |
   Tx#Parity |
        1#2  |   1.507879   .9083797     -.2725126     3.28827
        1#3  |   .0656075   1.179987     -2.247125     2.37834
        1#4  |  -.4157975   1.078838     -2.530281    1.698686
             |
       SCCDO |   .1093517   .1476322     -.1800021    .3987055
     PeakSCC |   -.260975   .1736674     -.6013569    .0794069
        MYDO |   .0012534   .0301762     -.0578907    .0603976
             |
         CM1 |
          1  |   .9140898   .4953901     -.0568569    1.885037
       DIMDO |  -.0033123    .002864     -.0089256     .002301
   PCSampDIM |   .0497226   .0801312     -.1073316    .2067769
       _cons |   4.605594   1.863781      .9526506    8.258538
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .8009463   .7191471      .1378268    4.654502
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   9.66e-34   1.70e-17             .           .
--------------------------------------------------------------
LR test vs. logistic model: chibar2(01) = 10.29       Prob >= chibar2 = 0.0007

. testparm Tx#Parity

 ( 1)  [Cure]2.Tx#2.Parity = 0
 ( 2)  [Cure]2.Tx#3.Parity = 0
 ( 3)  [Cure]2.Tx#4.Parity = 0

           chi2(  3) =    3.68
         Prob > chi2 =    0.2979

. *P > 0.05. Will not investigate further
. 
. 
. *Step 4c: Tx:PrevCM
. meglm Cure i.Tx##i.CM1 i.Parity SCCDO PeakSCC MYDO DIMDO PCSampDIM || FARMID: || Cow:, family(binomial) link(logit) nolog nocnsreport nopvalues 

Mixed-effects GLM                               Number of obs     =        561
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5         38      112.2        168
            Cow |        367          1        1.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(11)     =      11.55
Log likelihood = -129.36034                     Prob > chi2       =     0.3981
--------------------------------------------------------------
        Cure |      Coef.   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |   .3018214   .3904861     -.4635173     1.06716
             |
         CM1 |
          1  |   .4580864   .5812234     -.6810906    1.597263
             |
      Tx#CM1 |
        1#1  |    1.45075   1.200273     -.9017428    3.803243
             |
      Parity |
          2  |  -.2794865   .4427814     -1.147322     .588349
          3  |   .7441237   .6302965     -.4912348    1.979482
          4  |  -.6002023   .5812827     -1.739495    .5390908
             |
       SCCDO |    .108524   .1496034     -.1846933    .4017413
     PeakSCC |  -.2789173    .170748     -.6135773    .0557427
        MYDO |  -.0099424   .0284513     -.0657058    .0458211
       DIMDO |  -.0030744   .0028495     -.0086594    .0025107
   PCSampDIM |   .0163779   .0802518     -.1409128    .1736686
       _cons |   4.978886   1.819937      1.411875    8.545896
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .6404598    .582882      .1076004    3.812149
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   7.73e-33   4.84e-17             .           .
--------------------------------------------------------------
LR test vs. logistic model: chibar2(01) = 9.32        Prob >= chibar2 = 0.0011

. testparm Tx#CM1

 ( 1)  [Cure]2.Tx#2.CM1 = 0

           chi2(  1) =    1.46
         Prob > chi2 =    0.2268

. *P > 0.05. Will not investigate further
. 
. 
. *Step 5: Removing unnecessary covariates using 10% rule. Will do so in this order:
. 
. *DOMY DODIM PCSampDIM PrevCM DOSCC Parity
. *Step 5a: full model
. meglm Cure i.Tx i.Parity SCCDO PeakSCC MYDO i.CM1 DIMDO PCSampDIM || FARMID: || Cow:, family(binomial) link(logit) or nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =        561
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5         38      112.2        168
            Cow |        367          1        1.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(10)     =      11.82
Log likelihood = -130.24057                     Prob > chi2       =     0.2975
--------------------------------------------------------------
        Cure | Odds Ratio   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |   1.669007   .5933137      .8315061    3.350048
             |
      Parity |
          2  |    .760166   .3362116      .3194721    1.808772
          3  |   2.054464   1.290495      .5998231     7.03678
          4  |   .5625507   .3265404      .1803308    1.754904
             |
       SCCDO |   1.124443   .1658784      .8421081    1.501437
     PeakSCC |    .750409   .1292753      .5353759     1.05181
        MYDO |   .9903322    .028287       .936414    1.047355
             |
         CM1 |
          1  |   2.510536   1.236723      .9559903    6.592947
       DIMDO |   .9971077   .0027905      .9916534    1.002592
   PCSampDIM |   1.037634   .0810746      .8903003    1.209351
       _cons |   112.8826   202.1144      3.377263    3773.019
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .6741527    .606448      .1156225    3.930739
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   8.86e-34   1.11e-17             .           .
--------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline odds (conditional on zero random effects).
LR test vs. logistic model: chibar2(01) = 9.93        Prob >= chibar2 = 0.0008

. 
. *Step 5b: remove DOMY
. meglm Cure i.Tx i.Parity SCCDO PeakSCC i.CM1 DIMDO PCSampDIM || FARMID: || Cow:, family(binomial) link(logit) or nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =        561
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5         38      112.2        168
            Cow |        367          1        1.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(9)      =      11.72
Log likelihood =  -130.2983                     Prob > chi2       =     0.2296
--------------------------------------------------------------
        Cure | Odds Ratio   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |   1.661797     .59031      .8283443    3.333843
             |
      Parity |
          2  |   .7946263   .3359804      .3469459     1.81997
          3  |   2.146118    1.32451      .6402079    7.194258
          4  |   .5791328   .3325894      .1879069    1.784899
             |
       SCCDO |   1.130234   .1652456      .8486305    1.505283
     PeakSCC |   .7538218   .1294788      .5383487    1.055538
             |
         CM1 |
          1  |    2.45861   1.199915      .9446354    6.399044
       DIMDO |   .9973368   .0027519      .9919578    1.002745
   PCSampDIM |   1.036155   .0811755      .8886666     1.20812
       _cons |   77.72179   111.1998      4.706443    1283.491
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .7416456   .6210632      .1436778    3.828275
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   1.50e-33   2.35e-17             .           .
--------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline odds (conditional on zero random effects).
LR test vs. logistic model: chibar2(01) = 16.10       Prob >= chibar2 = 0.0000

. *Changed by <10%. DOMY stays out
. 
. *Step 5c: remove DODIM
. meglm Cure i.Tx i.Parity SCCDO PeakSCC i.CM1 PCSampDIM || FARMID: || Cow:, family(binomial) link(logit) or nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =        561
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5         38      112.2        168
            Cow |        367          1        1.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(8)      =      10.91
Log likelihood =  -130.7209                     Prob > chi2       =     0.2070
--------------------------------------------------------------
        Cure | Odds Ratio   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |   1.699229   .6017471      .8488215    3.401633
             |
      Parity |
          2  |   .7412139   .3074409      .3287623     1.67111
          3  |   2.141099   1.324396      .6369695    7.197057
          4  |    .574293   .3289759      .1868678    1.764951
             |
       SCCDO |   1.133209   .1635074      .8540687    1.503583
     PeakSCC |   .7436705   .1259901      .5335473    1.036545
             |
         CM1 |
          1  |   2.498938   1.216688      .9623231    6.489185
   PCSampDIM |   1.031659   .0804094       .885507    1.201934
       _cons |   35.04308   40.46316      3.645409    336.8669
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .7260559   .6081756      .1405941    3.749497
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   2.33e-29   2.33e-14             .           .
--------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline odds (conditional on zero random effects).
LR test vs. logistic model: chibar2(01) = 15.89       Prob >= chibar2 = 0.0000

. *Changed by <10%. DODIM stays out
. 
. *Step 5d: remove PCSampDIM
. meglm Cure i.Tx i.Parity SCCDO PeakSCC i.CM1 || FARMID: || Cow:, family(binomial) link(logit) or nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =        562
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5         38      112.4        168
            Cow |        368          1        1.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(7)      =      10.82
Log likelihood = -130.82493                     Prob > chi2       =     0.1469
--------------------------------------------------------------
        Cure | Odds Ratio   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |   1.665129   .5812004      .8401227    3.300299
             |
      Parity |
          2  |   .7382078   .3059527      .3276388    1.663267
          3  |   2.129951    1.31803      .6333435     7.16308
          4  |   .5675259   .3249434      .1847654    1.743214
             |
       SCCDO |   1.124764   .1614888      .8488865    1.490299
     PeakSCC |   .7453258   .1265213      .5343824    1.039537
             |
         CM1 |
          1  |   2.492523   1.210663      .9620446    6.457777
       _cons |   42.28299   44.83497       5.29164    337.8634
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .6982026   .5837121       .135631    3.594214
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   5.01e-32   2.76e-16             .           .
--------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline odds (conditional on zero random effects).
LR test vs. logistic model: chibar2(01) = 16.37       Prob >= chibar2 = 0.0000

. *Changed by <10%. PCSampDIM stays out
. 
. *Step 5e: remove PrevCM
. meglm Cure i.Tx i.Parity SCCDO PeakSCC || FARMID: || Cow:, family(binomial) link(logit) or nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =        562
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5         38      112.4        168
            Cow |        368          1        1.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(6)      =       7.50
Log likelihood = -132.85253                     Prob > chi2       =     0.2769
--------------------------------------------------------------
        Cure | Odds Ratio   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |   1.604854   .5616123      .8082786    3.186473
             |
      Parity |
          2  |    .739246    .309952      .3250096    1.681442
          3  |   2.384718   1.468877      .7130762    7.975137
          4  |   .6354926   .3706968       .202575    1.993587
             |
       SCCDO |   1.087728   .1578423      .8184663    1.445572
     PeakSCC |   .8043482   .1344563      .5796364    1.116176
       _cons |   38.94173   42.98071      4.476395    338.7679
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .7303932   .6097908      .1422019    3.751527
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   .0687491   .7564114      2.96e-11    1.59e+08
--------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline odds (conditional on zero random effects).
LR test vs. logistic model: chi2(2) = 17.09               Prob > chi2 = 0.0002

Note: LR test is conservative and provided only for reference.

. *Changed by <10%. PrevCM stays out
. 
. *Step 5f: remove DOSCC
. meglm Cure i.Tx i.Parity PeakSCC || FARMID: || Cow:, family(binomial) link(logit) or nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =        562
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5         38      112.4        168
            Cow |        368          1        1.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(5)      =       7.12
Log likelihood = -133.01662                     Prob > chi2       =     0.2118
--------------------------------------------------------------
        Cure | Odds Ratio   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |   1.594086   .5576207      .8030752    3.164223
             |
      Parity |
          2  |   .7536823   .3141544      .3329549    1.706048
          3  |   2.473306   1.518896      .7422355    8.241646
          4  |    .681603   .3871933      .2238698    2.075236
             |
     PeakSCC |   .8333465   .1308334      .6126169    1.133606
       _cons |    46.2046   49.73164      5.604111    380.9461
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .7314725   .6073575      .1436901    3.723653
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   .0666384   .7613338      1.26e-11    3.54e+08
--------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline odds (conditional on zero random effects).
LR test vs. logistic model: chi2(2) = 17.52               Prob > chi2 = 0.0002

Note: LR test is conservative and provided only for reference.

. *Changed by <10%. DOSCC stays out
. 
. *Step 5g: remove PeakSCC
. meglm Cure i.Tx i.Parity || FARMID: || Cow:, family(binomial) link(logit) or nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =        562
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5         38      112.4        168
            Cow |        368          1        1.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(4)      =       5.86
Log likelihood = -133.67981                     Prob > chi2       =     0.2100
--------------------------------------------------------------
        Cure | Odds Ratio   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |   1.531611   .5389857      .7684296    3.052761
             |
      Parity |
          2  |   .6875063   .2854363      .3047038    1.551227
          3  |   2.057424   1.222176      .6422179    6.591207
          4  |   .5587272   .3077471      .1898269     1.64453
             |
       _cons |   17.28676    10.3898      5.322541     56.1446
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .7240803   .6045697       .140954    3.719599
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|    .164989    .800493      .0000122      2224.9
--------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline odds (conditional on zero random effects).
LR test vs. logistic model: chi2(2) = 17.19               Prob > chi2 = 0.0002

Note: LR test is conservative and provided only for reference.

. *Changed by <10%. Stays out.
. 
. *Step 5h: remove Parity
. meglm Cure i.Tx || FARMID: || Cow:, family(binomial) link(logit) or nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =        562
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5         38      112.4        168
            Cow |        368          1        1.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(1)      =       1.54
Log likelihood =  -135.8617                     Prob > chi2       =     0.2150
--------------------------------------------------------------
        Cure | Odds Ratio   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |   1.586101    .590095      .7649776    3.288614
       _cons |   18.88079    11.3833      5.791989    61.54783
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .7069282   .6079811       .131013    3.814487
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   .6684589   .9850049      .0372212    12.00492
--------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline odds (conditional on zero random effects).
LR test vs. logistic model: chi2(2) = 15.56               Prob > chi2 = 0.0004

Note: LR test is conservative and provided only for reference.

. *Changed by <10%. Parity stays out
. 




Final model: IMI Cure

. 
. **************************
. *Step 6: Report final model
. meglm Cure i.Tx || FARMID: || Cow:, family(binomial) link(logit) nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =        562
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5         38      112.4        168
            Cow |        368          1        1.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(1)      =       1.54
Log likelihood =  -135.8617                     Prob > chi2       =     0.2150
--------------------------------------------------------------
        Cure |      Coef.   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |   .4612787   .3720413     -.2679087    1.190466
       _cons |   2.938145   .6029036      1.756476    4.119815
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .7069282   .6079811       .131013    3.814487
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   .6684589   .9850049      .0372212    12.00492
--------------------------------------------------------------
LR test vs. logistic model: chi2(2) = 15.56               Prob > chi2 = 0.0004

Note: LR test is conservative and provided only for reference.

. meglm Cure i.Tx || FARMID: || Cow:, family(binomial) link(logit) or nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =        562
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5         38      112.4        168
            Cow |        368          1        1.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(1)      =       1.54
Log likelihood =  -135.8617                     Prob > chi2       =     0.2150
--------------------------------------------------------------
        Cure | Odds Ratio   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |   1.586101    .590095      .7649776    3.288614
       _cons |   18.88079    11.3833      5.791989    61.54783
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .7069282   .6079811       .131013    3.814487
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   .6684589   .9850049      .0372212    12.00492
--------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline odds (conditional on zero random effects).
LR test vs. logistic model: chi2(2) = 15.56               Prob > chi2 = 0.0004

Note: LR test is conservative and provided only for reference.

. 
. margins Tx

Adjusted predictions                            Number of obs     =        562
Model VCE    : OIM

Expression   : Marginal predicted mean, predict()

------------------------------------------------------------------------------
             |            Delta-method
             |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
          Tx |
          0  |   .9182151   .0326631    28.11   0.000     .8541967    .9822336
          1  |    .944484   .0241041    39.18   0.000     .8972408    .9917272
------------------------------------------------------------------------------

. margins, dydx(Tx)

Conditional marginal effects                    Number of obs     =        562
Model VCE    : OIM

Expression   : Marginal predicted mean, predict()
dy/dx w.r.t. : 2.Tx

------------------------------------------------------------------------------
             |            Delta-method
             |      dy/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
          Tx |
          1  |   .0262689   .0225771     1.16   0.245    -.0179815    .0705192
------------------------------------------------------------------------------
Note: dy/dx for factor levels is the discrete change from the base level.

. 
. *Report ICC
. meglm Cure || FARMID: || Cow:, family(binomial) link(logit) notable nolog nocnsreport nopvalues noheader
LR test vs. logistic model: chi2(2) = 15.21               Prob > chi2 = 0.0005

Note: LR test is conservative and provided only for reference.

. estat icc

Intraclass correlation

------------------------------------------------------------------------------
                       Level |        ICC   Std. Err.     [95% Conf. Interval]
-----------------------------+------------------------------------------------
                      FARMID |   .1469917   .1063801       .031637    .4761412
                  Cow|FARMID |   .3039145   .1912284       .069112    .7196969
------------------------------------------------------------------------------



Outcome 2: IMI at Calving

CrossTable(lockqtr$Tx,lockqtr$IMIPC,prop.c=FALSE,prop.t=FALSE,prop.chisq = FALSE)
## 
##  
##    Cell Contents
## |-------------------------|
## |                       N |
## |           N / Row Total |
## |-------------------------|
## 
##  
## Total Observations in Table:  2807 
## 
##  
##              | lockqtr$IMIPC 
##   lockqtr$Tx |         0 |         1 | Row Total | 
## -------------|-----------|-----------|-----------|
##     Orbeseal |      1195 |       187 |      1382 | 
##              |     0.865 |     0.135 |     0.492 | 
## -------------|-----------|-----------|-----------|
##      Lockout |      1254 |       171 |      1425 | 
##              |     0.880 |     0.120 |     0.508 | 
## -------------|-----------|-----------|-----------|
## Column Total |      2449 |       358 |      2807 | 
## -------------|-----------|-----------|-----------|
## 
## 



Logistic regression model for IMI at calving

Model building plan

Model type: Logistic regression with mixed effects (generalized linear mixed model with binomial family / logit link).

Step 1: Identify potential confouders using a directed acyclic graph (DAG)

Step 2: Create model with all potential confounders

Step 3: Investigate potential effect measure modification

Step 4: Remove unneccesary covariates in backwards stepwise fashion using 10% rule (i.e. if odds ratio for algorithm or culture changes by >10% after removing the covariate, the covariate is retained in the model)

Step 5: Report final model



Step 1: DAG

This is used to identify variables that could be confounders if they are not balanced between treatment groups.

library(DiagrammeR)
mermaid("graph LR
        T(Treatment)-->U(IMI at calving)
        A(Age)-->T
        P(Parity)-->T
        M(Yield at dry-off)-->T
        S(SCC during prev lactation)-->T
        C(CM in prev lact)-->T
        D(DIM at dry off) --> M
        I(IMI at dry off) --> T
        K(DIM at post calving sample) --> T
        I-->U
        P-->I
        A-->I
        C-->I
        I-->S
        I-->M
        D-->S
        D-->U
        K-->U
        A-->U
        P-->U
        M-->U
        S-->U
        C-->U
        C-->M
        P-->C
        P-->S
        P-->M
        A-->P
        A-->C
        A-->S
        A-->M
        M-->S
        C-->S
style D fill:#FFFFFF, stroke-width:0px
style K fill:#FFFFFF, stroke-width:0px
style A fill:#FFFFFF, stroke-width:0px
        style T fill:#FFFFFF, stroke-width:2px
        style P fill:#FFFFFF, stroke-width:0px
        style M fill:#FFFFFF, stroke-width:0px
        style S fill:#FFFFFF, stroke-width:0px
        style C fill:#FFFFFF, stroke-width:0px
        style I fill:#FFFFFF, stroke-width:0px
        style U fill:#FFFFFF, stroke-width:2px
        ")

According to this DAG, I may need to control for the following variables.

Parity [“Parity”] or Age [“Age”] <- will use Parity

Yield at most recent test before dry off [“MYDO”]

Somatic cell count during previous lactation [“SCCDO” and “PeakSCC”]

Clinical mastitis in previous lactation [“CM1”]

IMI at dry-off [“IMIDO”]

Days in milk at dry-off [“DODIM”]

Days in milk at post-calving sample [“PCSampDIM”]





Steps 2 to 5 done in Stata. Log file pasted below.

. *Step 2: Create full model with all potential confounders
. meglm IMIPC i.Tx i.Parity SCCDO PeakSCC MYDO i.CM1 DIMDO IMIDO PCSampDIM || FARMID: || Cow:, family(binomial) link(logit) or nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =      2,657
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5        222      531.4      1,032
            Cow |        766          1        3.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(11)     =      19.16
Log likelihood = -883.49805                     Prob > chi2       =     0.0583
--------------------------------------------------------------
       IMIPC | Odds Ratio   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |   .8526211   .1240094      .6411404    1.133859
             |
      Parity |
          2  |   1.054916   .1905421      .7404084    1.503019
          3  |   .8605353   .1885691      .5600734    1.322186
          4  |   1.297922   .3221896       .797904    2.111283
             |
       SCCDO |   1.105053   .0774154      .9632774    1.267695
     PeakSCC |   1.092998   .0807955      .9455783      1.2634
        MYDO |   1.019457   .0117154      .9967515    1.042679
             |
         CM1 |
          1  |   1.330063   .2432873      .9293416     1.90357
       DIMDO |   1.000524   .0013234      .9979334    1.003121
       IMIDO |   1.071764   .1666775      .7901741    1.453702
   PCSampDIM |   1.044958   .0331687      .9819294    1.112032
       _cons |   .0180352   .0152849      .0034255    .0949554
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .7410145   .4875065      .2040935    2.690445
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   .5605919   .2191698      .2605313     1.20624
--------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline odds (conditional on zero random effects).
LR test vs. logistic model: chi2(2) = 184.01              Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.

. 
. *Step 3: Explore effect measure modification
. *Will test Tx:Farm, Tx:Parity, Tx:IMIDO
. 
. *Tx: Farm
. meglm IMIPC i.Tx##i.FARMID i.Parity SCCDO PeakSCC MYDO i.CM1 DIMDO IMIDO PCSampDIM || FARMID: || Cow:, family(binomial) link(logit) or nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =      2,657
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5        222      531.4      1,032
            Cow |        766          1        3.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(19)     =     159.56
Log likelihood = -871.81805                     Prob > chi2       =     0.0000
--------------------------------------------------------------
       IMIPC | Odds Ratio   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |   1.096767   .3836544      .5525354    2.177052
             |
      FARMID |
          2  |   2.002762   .8357318      .8839582    4.537607
          3  |   .2711118   .1080903      .1241025    .5922651
          4  |   4.170508   1.477817       2.08241    8.352408
          5  |     1.5492   .5378318      .7845089    3.059264
             |
   Tx#FARMID |
        1#2  |   .4811907   .2798198      .1539325    1.504194
        1#3  |   .8044829   .3950387       .307282    2.106185
        1#4  |   .7207913   .3122362      .3083767    1.684758
        1#5  |   .8559021   .3943238      .3469492    2.111457
             |
      Parity |
          2  |   1.060631   .1913592      .7447158    1.510561
          3  |   .8494198   .1860658      .5529252    1.304904
          4  |   1.287494   .3205117      .7903963    2.097226
             |
       SCCDO |   1.107777   .0779656      .9650383    1.271628
     PeakSCC |   1.094783   .0808678       .947224    1.265329
        MYDO |   1.020067   .0118425       .997118    1.043544
             |
         CM1 |
          1  |     1.3615   .2483881      .9521974    1.946742
       DIMDO |   1.000524   .0013237      .9979331    1.003122
       IMIDO |   1.059593   .1645737      .7815065    1.436634
   PCSampDIM |   1.047616   .0333123      .9843181    1.114984
       _cons |   .0137039   .0098903      .0033305    .0563859
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   5.76e-34   6.42e-18             .           .
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   .5335491   .2157549      .2415285    1.178638
--------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline odds (conditional on zero random effects).
LR test vs. logistic model: chibar2(01) = 9.15        Prob >= chibar2 = 0.0012

. testparm Tx#FARMID

 ( 1)  [IMIPC]2.Tx#2.FARMID = 0
 ( 2)  [IMIPC]2.Tx#3.FARMID = 0
 ( 3)  [IMIPC]2.Tx#4.FARMID = 0
 ( 4)  [IMIPC]2.Tx#5.FARMID = 0

           chi2(  4) =    1.79
         Prob > chi2 =    0.7742

. 
. *P > 0.05. Will not investigate further. 
. 
. *Tx:Parity
. meglm IMIPC i.Tx##i.Parity SCCDO PeakSCC MYDO i.CM1 DIMDO IMIDO PCSampDIM || FARMID: || Cow:, family(binomial) link(logit) or nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =      2,657
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5        222      531.4      1,032
            Cow |        766          1        3.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(14)     =      23.95
Log likelihood = -881.15384                     Prob > chi2       =     0.0465
--------------------------------------------------------------
       IMIPC | Odds Ratio   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |   1.224073   .2734098      .7901005     1.89641
             |
      Parity |
          2  |   1.425634   .3538197      .8765034    2.318797
          3  |   1.134152    .339253      .6310382    2.038388
          4  |   1.846228   .5790093      .9984667    3.413791
             |
   Tx#Parity |
        1#2  |    .548477   .1923125      .2758681    1.090474
        1#3  |   .5797691   .2413201       .256422    1.310856
        1#4  |   .4556812   .2165122      .1795649     1.15638
             |
       SCCDO |   1.108314   .0773078      .9666947    1.270681
     PeakSCC |   1.091295   .0802556      .9448073    1.260494
        MYDO |   1.018514   .0116553      .9959247    1.041617
             |
         CM1 |
          1  |   1.324941   .2402947      .9285822    1.890482
       DIMDO |    1.00052   .0013194      .9979377     1.00311
       IMIDO |   1.066585   .1653005      .7871824    1.445159
   PCSampDIM |   1.047096   .0329797      .9844112    1.113772
       _cons |   .0152921   .0129669       .002902    .0805824
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .7225974   .4754845        .19897     2.62425
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   .5107268   .2144791      .2242474    1.163187
--------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline odds (conditional on zero random effects).
LR test vs. logistic model: chi2(2) = 178.74              Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.

. testparm Tx#Parity

 ( 1)  [IMIPC]2.Tx#2.Parity = 0
 ( 2)  [IMIPC]2.Tx#3.Parity = 0
 ( 3)  [IMIPC]2.Tx#4.Parity = 0

           chi2(  3) =    4.71
         Prob > chi2 =    0.1945

. 
. *P > 0.05. Will not investigate further. 
. 
. *Tx:DOIMI
. meglm IMIPC i.Tx##i.IMIDO i.Parity SCCDO PeakSCC MYDO i.CM1 DIMDO PCSampDIM || FARMID: || Cow:, family(binomial) link(logit) or nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =      2,657
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5        222      531.4      1,032
            Cow |        766          1        3.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(12)     =      19.63
Log likelihood = -883.25034                     Prob > chi2       =     0.0745
--------------------------------------------------------------
       IMIPC | Odds Ratio   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |   .9028598   .1504021      .6513639     1.25146
     1.IMIDO |   1.191804   .2569769      .7810322    1.818616
             |
    Tx#IMIDO |
        1#1  |   .8082563   .2445578      .4466807    1.462517
             |
      Parity |
          2  |    1.05328   .1903505      .7391175    1.500979
          3  |   .8584737   .1882909      .5585103    1.319541
          4  |   1.296293    .322016      .7966249     2.10937
             |
       SCCDO |   1.104353   .0773994      .9626108    1.266966
     PeakSCC |   1.094044   .0808679      .9464923    1.264599
        MYDO |   1.019737   .0117355      .9969934       1.043
             |
         CM1 |
          1  |   1.329352   .2433142      .9286302    1.902993
       DIMDO |   1.000494    .001328      .9978949    1.003101
   PCSampDIM |   1.044254   .0331819      .9812023    1.111357
       _cons |   .0176302   .0149819      .0033336    .0932388
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .7439755   .4894462      .2049135    2.701137
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   .5625323   .2192438      .2620574    1.207532
--------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline odds (conditional on zero random effects).
LR test vs. logistic model: chi2(2) = 184.43              Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.

. testparm Tx#IMIDO

 ( 1)  [IMIPC]2.Tx#1.IMIDO = 0

           chi2(  1) =    0.49
         Prob > chi2 =    0.4817

. 
. *P > 0.05. Will not investigate further. 
. 
. 
. *Step 4: Remove unnecessary covariates from the model using 10% rule
. 
. 
. 
. *I will remove in this order: DODIM DOMY PCSampDIM Parity PrevCM DOSCC PeakSCC IMIDO
. 
. *Step 4a: Full model
. meglm IMIPC i.Tx i.Parity SCCDO PeakSCC MYDO i.CM1 DIMDO i.IMIDO PCSampDIM || FARMID: || Cow:, family(binomial) link(logit) or nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =      2,657
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5        222      531.4      1,032
            Cow |        766          1        3.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(11)     =      19.16
Log likelihood = -883.49805                     Prob > chi2       =     0.0583
--------------------------------------------------------------
       IMIPC | Odds Ratio   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |   .8526211   .1240094      .6411404    1.133859
             |
      Parity |
          2  |   1.054916   .1905421      .7404084    1.503019
          3  |   .8605353   .1885691      .5600734    1.322186
          4  |   1.297922   .3221896       .797904    2.111283
             |
       SCCDO |   1.105053   .0774154      .9632774    1.267695
     PeakSCC |   1.092998   .0807955      .9455783      1.2634
        MYDO |   1.019457   .0117154      .9967515    1.042679
             |
         CM1 |
          1  |   1.330063   .2432873      .9293416     1.90357
       DIMDO |   1.000524   .0013234      .9979334    1.003121
     1.IMIDO |   1.071764   .1666775      .7901741    1.453702
   PCSampDIM |   1.044958   .0331687      .9819294    1.112032
       _cons |   .0180352   .0152849      .0034255    .0949554
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .7410145   .4875065      .2040935    2.690445
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   .5605919   .2191698      .2605313     1.20624
--------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline odds (conditional on zero random effects).
LR test vs. logistic model: chi2(2) = 184.01              Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.

. 
. 
. *Step 4b: remove DODIM
. meglm IMIPC i.Tx i.Parity SCCDO PeakSCC MYDO i.CM1 i.IMIDO PCSampDIM || FARMID: || Cow:, family(binomial) link(logit) or nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =      2,657
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5        222      531.4      1,032
            Cow |        766          1        3.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(10)     =      19.02
Log likelihood = -883.57533                     Prob > chi2       =     0.0399
--------------------------------------------------------------
       IMIPC | Odds Ratio   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |   .8518846   .1239063      .6405807     1.13289
             |
      Parity |
          2  |   1.059826   .1910461      .7443816    1.508946
          3  |   .8645008   .1892811      .5628545    1.327806
          4  |   1.299683   .3225645      .7990611    2.113949
             |
       SCCDO |   1.104537   .0773133      .9629408    1.266955
     PeakSCC |   1.093653   .0808304      .9461683    1.264127
        MYDO |   1.018363   .0113743      .9963123    1.040902
             |
         CM1 |
          1  |   1.332399   .2436823      .9310183    1.906824
     1.IMIDO |   1.074175   .1669434      .7921098    1.456683
   PCSampDIM |   1.045792   .0331286      .9828354     1.11278
       _cons |   .0218065   .0151888       .005568    .0854022
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .7387983   .4860104      .2035037    2.682128
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   .5612556   .2190401      .2611945    1.206028
--------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline odds (conditional on zero random effects).
LR test vs. logistic model: chi2(2) = 183.86              Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.

. *Changed by <10%. DODIM stays out
. 
. *Step 4c: remove DOMY
. meglm IMIPC i.Tx i.Parity SCCDO PeakSCC i.CM1 DIMDO i.IMIDO PCSampDIM || FARMID: || Cow:, family(binomial) link(logit) or nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =      2,657
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5        222      531.4      1,032
            Cow |        766          1        3.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(10)     =      16.38
Log likelihood = -884.90464                     Prob > chi2       =     0.0892
--------------------------------------------------------------
       IMIPC | Odds Ratio   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |   .8592784   .1254167      .6454997    1.143857
             |
      Parity |
          2  |   1.014747   .1826062      .7131517    1.443888
          3  |   .8243104   .1806085      .5365256    1.266459
          4  |   1.252307    .310417      .7704034    2.035651
             |
       SCCDO |   1.083721   .0746636       .946833    1.240399
     PeakSCC |   1.081847   .0798498      .9361379    1.250236
             |
         CM1 |
          1  |   1.348252   .2475241      .9408061    1.932156
       DIMDO |   .9999856   .0013109      .9974196    1.002558
     1.IMIDO |   1.082805   .1685537       .798085    1.469101
   PCSampDIM |   1.047183    .033323      .9838659    1.114574
       _cons |    .040304   .0281569      .0102492    .1584924
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .7401815   .4864727      .2041265    2.683967
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   .5841656   .2218798      .2774787    1.229822
--------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline odds (conditional on zero random effects).
LR test vs. logistic model: chi2(2) = 184.56              Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.

. *Changed by <10%. DOMY stays out
. 
. *Step 4d: remove PCSampDIM
. meglm IMIPC i.Tx i.Parity SCCDO PeakSCC i.CM1 DIMDO i.IMIDO || FARMID: || Cow:, family(binomial) link(logit) or nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =      2,664
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5        224      532.8      1,032
            Cow |        769          1        3.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(9)      =      14.24
Log likelihood = -889.13484                     Prob > chi2       =     0.1141
--------------------------------------------------------------
       IMIPC | Odds Ratio   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |    .857747   .1250242      .6445982    1.141377
             |
      Parity |
          2  |   .9966681   .1779262       .702414    1.414191
          3  |   .8178438   .1791563      .5323616    1.256418
          4  |   1.226873   .3036687      .7552926    1.992895
             |
       SCCDO |   1.072833   .0734531      .9381092    1.226905
     PeakSCC |   1.091261   .0801763      .9449088    1.260282
             |
         CM1 |
          1  |    1.35156   .2483127      .9428659    1.937406
       DIMDO |   1.000041   .0013024      .9974911    1.002597
     1.IMIDO |   1.069302   .1662611      .7884079    1.450274
       _cons |   .0502771   .0342101      .0132491    .1907896
-------------+------------------------------------------------
FARMID       |
   var(_cons)|     .74412   .4886677      .2054254    2.695452
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   .5904299   .2217945      .2827583    1.232882
--------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline odds (conditional on zero random effects).
LR test vs. logistic model: chi2(2) = 186.86              Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.

. 
. *Changed by <10%. PCSampdim stays out
. 
. *Step 4e: remove Parity
. meglm IMIPC i.Tx SCCDO PeakSCC i.CM1 i.IMIDO || FARMID: || Cow:, family(binomial) link(logit) or nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =      2,664
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5        224      532.8      1,032
            Cow |        769          1        3.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(5)      =      11.96
Log likelihood =  -890.2503                     Prob > chi2       =     0.0353
--------------------------------------------------------------
       IMIPC | Odds Ratio   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |   .8528697   .1241489       .641175    1.134459
       SCCDO |   1.074486    .072636      .9411505    1.226712
     PeakSCC |   1.088803   .0793807      .9438245    1.256051
             |
         CM1 |
          1  |   1.360952   .2496945      .9498884    1.949904
     1.IMIDO |   1.066383   .1657357      .7863586    1.446125
       _cons |   .0504162   .0280844      .0169203    .1502217
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .7573574   .4970865      .2092283    2.741456
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   .6043032   .2235542      .2926603    1.247803
--------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline odds (conditional on zero random effects).
LR test vs. logistic model: chi2(2) = 191.48              Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.

. 
. *Changed by <10%. Parity stays out. 
. 
. *Step 4f: remove PrevCM
. meglm IMIPC i.Tx SCCDO PeakSCC i.IMIDO || FARMID: || Cow:, family(binomial) link(logit) or nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =      2,664
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5        224      532.8      1,032
            Cow |        769          1        3.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(4)      =       9.16
Log likelihood = -891.65389                     Prob > chi2       =     0.0573
--------------------------------------------------------------
       IMIPC | Odds Ratio   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |    .845582     .12293      .6359292    1.124353
       SCCDO |   1.074486   .0724133       .941533    1.226214
     PeakSCC |   1.127303   .0790526       .982539    1.293396
     1.IMIDO |    1.07916   .1672113      .7965179    1.462096
       _cons |   .0444787   .0242799      .0152581    .1296594
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .7126244   .4676333      .1969207    2.578874
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   .6042837   .2243598      .2918803    1.251056
--------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline odds (conditional on zero random effects).
LR test vs. logistic model: chi2(2) = 190.35              Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.

. 
. *Changed by <10%. PrevCM stays out
. 
. *Step 4g: DOSCC
. meglm IMIPC i.Tx PeakSCC  i.IMIDO || FARMID: || Cow:, family(binomial) link(logit) or nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =      2,664
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5        224      532.8      1,032
            Cow |        769          1        3.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(3)      =       8.02
Log likelihood = -892.22827                     Prob > chi2       =     0.0455
--------------------------------------------------------------
       IMIPC | Odds Ratio   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |   .8439212   .1230008      .6342201    1.122959
     PeakSCC |   1.168549   .0716712      1.036191    1.317813
     1.IMIDO |   1.083526   .1681793      .7993191    1.468786
       _cons |   .0500799   .0267405      .0175857    .1426159
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .7161972   .4700647      .1978609     2.59242
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   .6179893   .2251595      .3025885    1.262146
--------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline odds (conditional on zero random effects).
LR test vs. logistic model: chi2(2) = 190.31              Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.

. 
. *Changed by <10%. DOSCC stays out
. 
. *Step 4h: PeakSCC
. meglm IMIPC i.Tx i.IMIDO || FARMID: || Cow:, family(binomial) link(logit) or nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =      2,664
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5        224      532.8      1,032
            Cow |        769          1        3.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(2)      =       1.64
Log likelihood = -895.45112                     Prob > chi2       =     0.4413
--------------------------------------------------------------
       IMIPC | Odds Ratio   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |   .8591458   .1253886       .645413    1.143658
     1.IMIDO |   1.129384   .1746726      .8340524    1.529291
       _cons |   .1196973   .0481548      .0544053    .2633462
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .7257508   .4760928      .2006314    2.625282
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   .6387133   .2293791      .3159488    1.291205
--------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline odds (conditional on zero random effects).
LR test vs. logistic model: chi2(2) = 193.16              Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.

. 
. *Changed by <10%. Stays out. 
. *Step 4i: IMIDO
. meglm IMIPC i.Tx || FARMID: || Cow:, family(binomial) link(logit) or nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =      2,807
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5        232      561.4      1,042
            Cow |        776          1        3.6          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(1)      =       1.49
Log likelihood = -953.29006                     Prob > chi2       =     0.2223
--------------------------------------------------------------
       IMIPC | Odds Ratio   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |   .8373414   .1217953      .6296385    1.113561
       _cons |   .1220898   .0506964      .0541038    .2755062
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .7872649   .5146736      .2185994     2.83526
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   .7504504    .229786      .4117999    1.367596
--------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline odds (conditional on zero random effects).
LR test vs. logistic model: chi2(2) = 234.69              Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.

. 
. *Changed by <10%. IMIDO stays out
. 



Final Model: IMI at calving

. 
. *******************
. *Report final model
. meglm IMIPC i.Tx || FARMID: || Cow:, family(binomial) link(logit) nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =      2,807
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5        232      561.4      1,042
            Cow |        776          1        3.6          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(1)      =       1.49
Log likelihood = -953.29006                     Prob > chi2       =     0.2223
--------------------------------------------------------------
       IMIPC |      Coef.   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |  -.1775235   .1454547     -.4626095    .1075626
       _cons |  -2.102998   .4152387     -2.916851   -1.289145
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .7872649   .5146736      .2185994     2.83526
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   .7504504    .229786      .4117999    1.367596
--------------------------------------------------------------
LR test vs. logistic model: chi2(2) = 234.69              Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.

. margins Tx

Adjusted predictions                            Number of obs     =      2,807
Model VCE    : OIM

Expression   : Marginal predicted mean, predict()

------------------------------------------------------------------------------
             |            Delta-method
             |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
          Tx |
          0  |   .1598742   .0478097     3.34   0.001      .066169    .2535794
          1  |   .1409829   .0439408     3.21   0.001     .0548605    .2271053
------------------------------------------------------------------------------

. margins, dydx(Tx)

Conditional marginal effects                    Number of obs     =      2,807
Model VCE    : OIM

Expression   : Marginal predicted mean, predict()
dy/dx w.r.t. : 2.Tx

------------------------------------------------------------------------------
             |            Delta-method
             |      dy/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
          Tx |
          1  |  -.0188913   .0159574    -1.18   0.236    -.0501673    .0123846
------------------------------------------------------------------------------
Note: dy/dx for factor levels is the discrete change from the base level.

. 
. *Report ICC
. meglm IMIPC || FARMID: || Cow:, family(binomial) link(logit) notable nolog nocnsreport nopvalues noheader
LR test vs. logistic model: chi2(2) = 234.68              Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.

. estat icc

Intraclass correlation

------------------------------------------------------------------------------
                       Level |        ICC   Std. Err.     [95% Conf. Interval]
-----------------------------+------------------------------------------------
                      FARMID |   .1627225   .0887857      .0513998    .4107503
                  Cow|FARMID |   .3197727   .0816909      .1837868    .4953167
------------------------------------------------------------------------------



Outcome 3: New IMI

CrossTable(lockqtr$Tx,lockqtr$NewIMI,prop.c=FALSE,prop.t=FALSE,prop.chisq = FALSE)
## 
##  
##    Cell Contents
## |-------------------------|
## |                       N |
## |           N / Row Total |
## |-------------------------|
## 
##  
## Total Observations in Table:  2664 
## 
##  
##              | lockqtr$NewIMI 
##   lockqtr$Tx |         0 |         1 | Row Total | 
## -------------|-----------|-----------|-----------|
##     Orbeseal |      1162 |       152 |      1314 | 
##              |     0.884 |     0.116 |     0.493 | 
## -------------|-----------|-----------|-----------|
##      Lockout |      1209 |       141 |      1350 | 
##              |     0.896 |     0.104 |     0.507 | 
## -------------|-----------|-----------|-----------|
## Column Total |      2371 |       293 |      2664 | 
## -------------|-----------|-----------|-----------|
## 
## 



Logistic regression model for new IMI

Model building plan

Model type: Logistic regression with mixed effects (generalized linear mixed model with binomial family / logit link).

Step 1: Identify potential confouders using a directed acyclic graph (DAG)

Step 2: Create model with all potential confounders

Step 3: Investigate potential effect measure modification

Step 4: Remove unneccesary covariates in backwards stepwise fashion using 10% rule (i.e. if odds ratio for algorithm or culture changes by >10% after removing the covariate, the covariate is retained in the model)

Step 5: Report final model



Step 1: DAG

This is used to identify variables that could be confounders if they are not balanced between treatment groups.

library(DiagrammeR)
mermaid("graph LR
        T(Treatment)-->U(New IMI)
        A(Age)-->T
        P(Parity)-->T
        M(Yield at dry-off)-->T
        S(SCC during prev lactation)-->T
        C(CM in prev lact)-->T
        D(DIM at dry off) --> T
        I(IMI at dry off) --> T
        K(DIM at post calving sample) --> T
        I-->U
        P-->I
        A-->I
        C-->I
        I-->S
        I-->M
        D-->S
        D-->M        
        D-->U
        K-->U
        A-->U
        P-->U
        M-->U
        S-->U
        C-->U
        C-->M
        P-->C
        P-->S
        P-->M
        A-->P
        A-->C
        A-->S
        A-->M
        M-->S
        C-->S
style D fill:#FFFFFF, stroke-width:0px
style K fill:#FFFFFF, stroke-width:0px
style A fill:#FFFFFF, stroke-width:0px
        style T fill:#FFFFFF, stroke-width:2px
        style P fill:#FFFFFF, stroke-width:0px
        style M fill:#FFFFFF, stroke-width:0px
        style S fill:#FFFFFF, stroke-width:0px
        style C fill:#FFFFFF, stroke-width:0px
        style I fill:#FFFFFF, stroke-width:0px
        style U fill:#FFFFFF, stroke-width:2px
        ")

According to this DAG, I may need to control for the following variables.

Parity [“Parity”] or Age [“Age”] <- will use Parity

Yield at most recent test before dry off [“MYDO”]

Somatic cell count during previous lactation [“SCCDO” and “PeakSCC”]

Clinical mastitis in previous lactation [“CM1”]

IMI at dry-off [“IMIDO”]

Days in milk at dry-off [“DODIM”]

Days in milk at post-calving sample [“PCSampDIM”]





Steps 2 to 5 done in Stata. Log file pasted below.

 *Outcome 3: New IMI
. *Step 2: Full model with possible covariates
. meglm NewIMI i.Tx i.Parity SCCDO PeakSCC MYDO i.CM1 DIMDO PCSampDIM i.IMIDO || FARMID: || Cow:, family(binomial) link(logit) or nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =      2,657
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5        222      531.4      1,032
            Cow |        766          1        3.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(11)     =      29.12
Log likelihood = -824.66806                     Prob > chi2       =     0.0022
--------------------------------------------------------------
      NewIMI | Odds Ratio   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |   .8823876   .1330734      .6565824     1.18585
             |
      Parity |
          2  |   .9955547   .1871672      .6887106    1.439108
          3  |   .9461034   .2120247      .6097919    1.467897
          4  |   1.221864   .3148114      .7374149    2.024574
             |
       SCCDO |   1.150886   .0856709      .9946482    1.331665
     PeakSCC |    1.04425   .0811007      .8968025    1.215941
        MYDO |   1.020653   .0121526      .9971105    1.044752
             |
         CM1 |
          1  |    1.52801   .2880962      1.055936    2.211131
       DIMDO |   .9998069   .0014144      .9970386    1.002583
   PCSampDIM |   1.052698   .0344933      .9872172    1.122521
     1.IMIDO |   .5517464    .098117      .3893771    .7818233
       _cons |   .0220487   .0194278      .0039207    .1239946
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .7522128   .4965783      .2062597    2.743261
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   .5642543   .2322081      .2518715    1.264069
--------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline odds (conditional on zero random effects).
LR test vs. logistic model: chi2(2) = 168.53              Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.

. 
. *Step 3: Check for effect measure modification
. *I will investigate: Tx:FARM Tx:Parity Tx:IMIDO
. 
. *Tx:FARMD
. meglm NewIMI i.Tx##i.FARMID i.Parity SCCDO PeakSCC MYDO i.CM1 DIMDO PCSampDIM i.IMIDO || FARMID: || Cow:, family(binomial) link(logit) or nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =      2,657
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5        222      531.4      1,032
            Cow |        766          1        3.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(19)     =     142.67
Log likelihood = -812.81068                     Prob > chi2       =     0.0000
--------------------------------------------------------------
      NewIMI | Odds Ratio   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |   1.151037   .4113481      .5713386    2.318914
             |
      FARMID |
          2  |   1.713704   .7310513      .7427126    3.954131
          3  |   .2120549   .0876135      .0943544    .4765785
          4  |    3.31937   1.210456      1.624249    6.783574
          5  |   1.297225   .4648709      .6426585    2.618485
             |
   Tx#FARMID |
        1#2  |   .4163804   .2517536      .1273014    1.361907
        1#3  |   .7937819   .4004553      .2953101    2.133655
        1#4  |   .7121408   .3183826      .2964915    1.710486
        1#5  |   .8719572   .4127536      .3447995    2.205077
             |
      Parity |
          2  |   1.001579   .1879038      .6934153    1.446695
          3  |   .9326265   .2087292      .6014536     1.44615
          4  |   1.210038   .3124146      .7295094    2.007091
             |
       SCCDO |   1.156331   .0864341      .9987482    1.338777
     PeakSCC |   1.045769   .0811464      .8982285    1.217544
        MYDO |    1.02188   .0122967      .9980605    1.046267
             |
         CM1 |
          1  |   1.571115   .2953242      1.086943    2.270959
       DIMDO |   .9998162   .0014146      .9970475    1.002593
   PCSampDIM |   1.056168    .034659       .990376    1.126331
     1.IMIDO |   .5439701   .0965875      .3840922    .7703971
       _cons |   .0192131   .0144903      .0043816    .0842492
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   3.77e-34   3.50e-18             .           .
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   .5320089   .2282998      .2294271    1.233653
--------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline odds (conditional on zero random effects).
LR test vs. logistic model: chibar2(01) = 7.96        Prob >= chibar2 = 0.0024

. testparm Tx#FARMID

 ( 1)  [NewIMI]2.Tx#2.FARMID = 0
 ( 2)  [NewIMI]2.Tx#3.FARMID = 0
 ( 3)  [NewIMI]2.Tx#4.FARMID = 0
 ( 4)  [NewIMI]2.Tx#5.FARMID = 0

           chi2(  4) =    2.38
         Prob > chi2 =    0.6661

. 
. *P > 0.05. Will not investigate further
. 
. *Tx:Parity
. meglm NewIMI i.Tx##i.Parity SCCDO PeakSCC MYDO i.CM1 DIMDO PCSampDIM i.IMIDO || FARMID: || Cow:, family(binomial) link(logit) or nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =      2,657
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5        222      531.4      1,032
            Cow |        766          1        3.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(14)     =      33.97
Log likelihood = -822.32128                     Prob > chi2       =     0.0021
--------------------------------------------------------------
      NewIMI | Odds Ratio   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |     1.2467   .2895292      .7908279    1.965359
             |
      Parity |
          2  |   1.242759   .3237966      .7457779    2.070926
          3  |   1.306335   .3979602      .7190274    2.373359
          4  |   1.812376   .5846508      .9630764    3.410638
             |
   Tx#Parity |
        1#2  |    .653044   .2384996      .3192077    1.336016
        1#3  |    .524748   .2237301       .227528    1.210227
        1#4  |   .3988503   .1995183      .1496271    1.063187
             |
       SCCDO |   1.151672   .0854406      .9958174     1.33192
     PeakSCC |    1.04439    .080777      .8974859     1.21534
        MYDO |   1.019804   .0120988      .9963645    1.043795
             |
         CM1 |
          1  |   1.536405     .28746      1.064747    2.216995
       DIMDO |   .9997299   .0014125      .9969652    1.002502
   PCSampDIM |   1.055431   .0343283      .9902481    1.124904
     1.IMIDO |   .5472463    .097121      .3864721    .7749033
       _cons |   .0191822   .0169158      .0034062    .1080264
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .7383036   .4873611      .2024645    2.692285
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   .5128879   .2266224      .2157318    1.219356
--------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline odds (conditional on zero random effects).
LR test vs. logistic model: chi2(2) = 164.82              Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.

. testparm Tx#Parity

 ( 1)  [NewIMI]2.Tx#2.Parity = 0
 ( 2)  [NewIMI]2.Tx#3.Parity = 0
 ( 3)  [NewIMI]2.Tx#4.Parity = 0

           chi2(  3) =    4.68
         Prob > chi2 =    0.1964

. 
. *P<0.05. Will investigate further.
. margins Tx#Parity

Predictive margins                              Number of obs     =      2,657
Model VCE    : OIM

Expression   : Marginal predicted mean, predict()

------------------------------------------------------------------------------
             |            Delta-method
             |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
   Tx#Parity |
        0#1  |   .1287193    .042599     3.02   0.003     .0452267    .2122118
        0#2  |   .1507968   .0483652     3.12   0.002     .0560027    .2455909
        0#3  |    .156239   .0524243     2.98   0.003     .0534891    .2589888
        0#4  |    .195489   .0622394     3.14   0.002     .0735021     .317476
        1#1  |   .1511379    .046859     3.23   0.001     .0592961    .2429798
        1#2  |   .1298435   .0443053     2.93   0.003     .0430066    .2166804
        1#3  |   .1143677   .0429259     2.66   0.008     .0302344     .198501
        1#4  |   .1190691   .0495025     2.41   0.016     .0220459    .2160922
------------------------------------------------------------------------------

. 
. *P > 0.05. Will not investigate further.
. 
. *Tx:IMIDO
. meglm NewIMI i.Tx##i.IMIDO i.Parity SCCDO PeakSCC MYDO i.CM1 DIMDO PCSampDIM || FARMID: || Cow:, family(binomial) link(logit) or nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =      2,657
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5        222      531.4      1,032
            Cow |        766          1        3.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(12)     =      29.12
Log likelihood = -824.61215                     Prob > chi2       =     0.0038
--------------------------------------------------------------
      NewIMI | Odds Ratio   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |   .9035005   .1504823      .6518636    1.252276
     1.IMIDO |   .5848235   .1448055       .359967    .9501384
             |
    Tx#IMIDO |
        1#1  |    .890981   .3075693      .4529301    1.752692
             |
      Parity |
          2  |   .9946082   .1870647      .6879535    1.437954
          3  |   .9446493   .2118569      .6086551    1.466121
          4  |   1.220569   .3146216      .7364634    2.022895
             |
       SCCDO |   1.150454   .0856912      .9941864    1.331284
     PeakSCC |   1.044736   .0811597      .8971835    1.216554
        MYDO |   1.020794   .0121692      .9972192    1.044926
             |
         CM1 |
          1  |   1.528364    .288288      1.056012    2.211999
       DIMDO |   .9997892   .0014174       .997015    1.002571
   PCSampDIM |   1.052467   .0345073      .9869614    1.122321
       _cons |   .0218619   .0192902      .0038781    .1232417
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .7535387   .4974648      .2066173    2.748176
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   .5658199    .232346      .2530138    1.265354
--------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline odds (conditional on zero random effects).
LR test vs. logistic model: chi2(2) = 168.64              Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.

. testparm Tx#IMIDO

 ( 1)  [NewIMI]2.Tx#1.IMIDO = 0

           chi2(  1) =    0.11
         Prob > chi2 =    0.7381

. *P > 0.05. Will not investigate further.
. 
. *Step 4: remove unnecessary covariates using 10% rule. I will remove in the following order: DODIM DOMY Parity DOSCC PCSampDIM PrevCM IMIDO
. 
. *Step 4a: Full model
. meglm NewIMI i.Tx i.Parity SCCDO PeakSCC MYDO i.CM1 DIMDO PCSampDIM i.IMIDO || FARMID: || Cow:, family(binomial) link(logit) or nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =      2,657
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5        222      531.4      1,032
            Cow |        766          1        3.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(11)     =      29.12
Log likelihood = -824.66806                     Prob > chi2       =     0.0022
--------------------------------------------------------------
      NewIMI | Odds Ratio   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |   .8823876   .1330734      .6565824     1.18585
             |
      Parity |
          2  |   .9955547   .1871672      .6887106    1.439108
          3  |   .9461034   .2120247      .6097919    1.467897
          4  |   1.221864   .3148114      .7374149    2.024574
             |
       SCCDO |   1.150886   .0856709      .9946482    1.331665
     PeakSCC |    1.04425   .0811007      .8968025    1.215941
        MYDO |   1.020653   .0121526      .9971105    1.044752
             |
         CM1 |
          1  |    1.52801   .2880962      1.055936    2.211131
       DIMDO |   .9998069   .0014144      .9970386    1.002583
   PCSampDIM |   1.052698   .0344933      .9872172    1.122521
     1.IMIDO |   .5517464    .098117      .3893771    .7818233
       _cons |   .0220487   .0194278      .0039207    .1239946
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .7522128   .4965783      .2062597    2.743261
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   .5642543   .2322081      .2518715    1.264069
--------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline odds (conditional on zero random effects).
LR test vs. logistic model: chi2(2) = 168.53              Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.

. 
. 
. *Step 4b: Removed DODIM
. meglm NewIMI i.Tx i.Parity SCCDO PeakSCC MYDO i.CM1 PCSampDIM i.IMIDO || FARMID: || Cow:, family(binomial) link(logit) or nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =      2,657
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5        222      531.4      1,032
            Cow |        766          1        3.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(10)     =      29.10
Log likelihood = -824.67743                     Prob > chi2       =     0.0012
--------------------------------------------------------------
      NewIMI | Odds Ratio   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |   .8825776   .1331118      .6567095    1.186131
             |
      Parity |
          2  |   .9940796   .1866003      .6880828    1.436156
          3  |   .9445171   .2113517      .6091708     1.46447
          4  |   1.221263   .3147016      .7369991    2.023724
             |
       SCCDO |   1.150922   .0857067      .9946239    1.331782
     PeakSCC |   1.044178   .0811042      .8967251    1.215877
        MYDO |   1.021046   .0118133      .9981531    1.044464
             |
         CM1 |
          1  |   1.526821   .2877842      1.055234    2.209162
   PCSampDIM |   1.052377   .0344089      .9870519    1.122025
     1.IMIDO |   .5513717   .0980169       .389159    .7811994
       _cons |   .0205555   .0147361      .0050432    .0837816
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .7533713   .4972699      .2066166    2.746963
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   .5649549   .2322797       .252374    1.264687
--------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline odds (conditional on zero random effects).
LR test vs. logistic model: chi2(2) = 169.06              Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.

. *Changed by <10%. DODIM stays out
. 
. 
. *Step 4c: Removed DOMY
. meglm NewIMI i.Tx i.Parity SCCDO PeakSCC i.CM1 PCSampDIM i.IMIDO || FARMID: || Cow:, family(binomial) link(logit) or nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =      2,657
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5        222      531.4      1,032
            Cow |        766          1        3.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(9)      =      25.97
Log likelihood = -826.30059                     Prob > chi2       =     0.0021
--------------------------------------------------------------
      NewIMI | Odds Ratio   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |   .8901232   .1349192      .6613485    1.198036
             |
      Parity |
          2  |   .9506386   .1779071      .6587452    1.371871
          3  |   .8961212   .2005454      .5779284    1.389503
          4  |   1.172613   .3022598      .7075283    1.943415
             |
       SCCDO |   1.124251   .0823199      .9739498    1.297747
     PeakSCC |   1.031972    .080122      .8863006    1.201586
             |
         CM1 |
          1  |   1.543373   .2926722      1.064281    2.238131
   PCSampDIM |   1.053966   .0346075       .988273    1.124026
     1.IMIDO |    .557347   .0992448      .3931472    .7901255
       _cons |    .041337   .0245808      .0128877    .1325871
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .7346272   .4844321      .2017264    2.675292
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|    .598346   .2360968      .2761107    1.296646
--------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline odds (conditional on zero random effects).
LR test vs. logistic model: chi2(2) = 167.12              Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.

. 
. *Changed by <10%. DOMY stays out
. 
. 
. *Step 4d: Removed Parity
. meglm NewIMI i.Tx SCCDO PeakSCC i.CM1 PCSampDIM i.IMIDO || FARMID: || Cow:, family(binomial) link(logit) or nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =      2,657
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5        222      531.4      1,032
            Cow |        766          1        3.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(6)      =      24.98
Log likelihood =  -826.7996                     Prob > chi2       =     0.0003
--------------------------------------------------------------
      NewIMI | Odds Ratio   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |   .8856087   .1338138      .6586079    1.190849
       SCCDO |   1.125731   .0813045      .9771422    1.296916
     PeakSCC |   1.032318    .079505      .8876819    1.200521
             |
         CM1 |
          1  |   1.552579    .293357      1.072064    2.248468
   PCSampDIM |    1.05374   .0344471       .988342    1.123465
     1.IMIDO |   .5561222   .0989328      .3924132    .7881283
       _cons |   .0403506   .0239251      .0126225    .1289895
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .7442489   .4904555      .2045416    2.708039
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   .6020971   .2374896      .2779207    1.304404
--------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline odds (conditional on zero random effects).
LR test vs. logistic model: chi2(2) = 170.88              Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.

. 
. *Changed by <10%. Parity stays out
. 
. *Step 4e: Removed DOSCC
. meglm NewIMI i.Tx PeakSCC i.CM1 PCSampDIM i.IMIDO || FARMID: || Cow:, family(binomial) link(logit) or nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =      2,657
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5        222      531.4      1,032
            Cow |        766          1        3.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(5)      =      22.24
Log likelihood = -828.17187                     Prob > chi2       =     0.0005
--------------------------------------------------------------
      NewIMI | Odds Ratio   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |   .8818227   .1339351      .6547825    1.187587
     PeakSCC |   1.096166   .0738278      .9606098    1.250851
             |
         CM1 |
          1  |   1.559795   .2970607      1.073885    2.265571
   PCSampDIM |   1.049809   .0344033      .9844992    1.119451
     1.IMIDO |   .5581793   .0996566      .3933701    .7920382
       _cons |   .0497063     .02878      .0159795    .1546175
-------------+------------------------------------------------
FARMID       |
   var(_cons)|    .749555   .4941241      .2059072    2.728572
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   .6319215   .2397648      .3003991    1.329314
--------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline odds (conditional on zero random effects).
LR test vs. logistic model: chi2(2) = 170.97              Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.

. 
. 
. *Changed by <10%. DOSCC stays out
. 
. *Step 4f: Removed PCSampDIM
. meglm NewIMI i.Tx PeakSCC i.CM1 i.IMIDO || FARMID: || Cow:, family(binomial) link(logit) or nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =      2,664
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5        224      532.8      1,032
            Cow |        769          1        3.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(4)      =      20.34
Log likelihood = -832.29595                     Prob > chi2       =     0.0004
--------------------------------------------------------------
      NewIMI | Odds Ratio   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |   .8835279   .1339003      .6564764    1.189108
     PeakSCC |   1.099794   .0738815      .9641166    1.254564
             |
         CM1 |
          1  |    1.56217   .2973392      1.075754    2.268526
     1.IMIDO |   .5523014   .0984613      .3894292    .7832921
       _cons |   .0623561   .0345454      .0210529    .1846913
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .7519559   .4953053      .2067831    2.734448
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   .6340916   .2391797      .3027459    1.328084
--------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline odds (conditional on zero random effects).
LR test vs. logistic model: chi2(2) = 172.25              Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.

. 
. *Changed by <10%. PCSampDIM stays out
. 
. *Step 4g: Removed PeakSCC
. meglm NewIMI i.Tx i.CM1 i.IMIDO || FARMID: || Cow:, family(binomial) link(logit) or nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =      2,664
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5        224      532.8      1,032
            Cow |        769          1        3.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(3)      =      18.35
Log likelihood = -833.29586                     Prob > chi2       =     0.0004
--------------------------------------------------------------
      NewIMI | Odds Ratio   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |   .8945491    .135549      .6646967    1.203885
             |
         CM1 |
          1  |   1.707501   .3080109       1.19899    2.431681
     1.IMIDO |   .5614905   .1000692      .3959503    .7962402
       _cons |   .1040656   .0434544      .0459064    .2359071
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .7683075   .5055526      .2115619    2.790182
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|    .644518   .2410856      .3096266    1.341627
--------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline odds (conditional on zero random effects).
LR test vs. logistic model: chi2(2) = 178.20              Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.

. 
. *Step 4g: Removed PrevCM
. meglm NewIMI i.Tx i.IMIDO || FARMID: || Cow:, family(binomial) link(logit) or nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =      2,664
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5        224      532.8      1,032
            Cow |        769          1        3.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(2)      =       9.84
Log likelihood = -837.64384                     Prob > chi2       =     0.0073
--------------------------------------------------------------
      NewIMI | Odds Ratio   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |   .8876924   .1348038      .6591742    1.195432
     1.IMIDO |   .5873966   .1039058      .4152988    .8308109
       _cons |    .116967   .0463651      .0537838    .2543753
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .6955475   .4582592      .1912121    2.530103
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   .6673437   .2457953      .3242171    1.373609
--------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline odds (conditional on zero random effects).
LR test vs. logistic model: chi2(2) = 169.76              Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.

. 
. *Changed by <10%. PrevCM stays out
. 
. 
. *Step 4h: Removed IMIDO
. meglm NewIMI i.Tx || FARMID: || Cow:, family(binomial) link(logit) or nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =      2,664
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5        224      532.8      1,032
            Cow |        769          1        3.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(1)      =       0.82
Log likelihood = -842.42692                     Prob > chi2       =     0.3652
--------------------------------------------------------------
      NewIMI | Odds Ratio   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |   .8713214   .1325574      .6466687    1.174018
       _cons |   .1048718   .0398007       .049844    .2206504
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .6326601   .4180353      .1732735    2.309983
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   .6926578   .2469965      .3443394    1.393319
--------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline odds (conditional on zero random effects).
LR test vs. logistic model: chi2(2) = 160.35              Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.



Final model: New IMI

. *Step 5: Report final model
. meglm NewIMI i.Tx || FARMID: || Cow:, family(binomial) link(logit) nolog nocnsreport nopvalues

Mixed-effects GLM                               Number of obs     =      2,664
Family:                binomial
Link:                     logit

-------------------------------------------------------------
                |     No. of       Observations per Group
 Group Variable |     Groups    Minimum    Average    Maximum
----------------+--------------------------------------------
         FARMID |          5        224      532.8      1,032
            Cow |        769          1        3.5          4
-------------------------------------------------------------

Integration method: mvaghermite                 Integration pts.  =          7

                                                Wald chi2(1)      =       0.82
Log likelihood = -842.42692                     Prob > chi2       =     0.3652
--------------------------------------------------------------
      NewIMI |      Coef.   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
          Tx |
          1  |  -.1377444   .1521338     -.4359212    .1604324
       _cons |  -2.255017   .3795177     -2.998858   -1.511176
-------------+------------------------------------------------
FARMID       |
   var(_cons)|   .6326601   .4180353      .1732735    2.309983
-------------+------------------------------------------------
FARMID>Cow   |
   var(_cons)|   .6926578   .2469965      .3443394    1.393319
--------------------------------------------------------------
LR test vs. logistic model: chi2(2) = 160.35              Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.

. margins Tx

Adjusted predictions                            Number of obs     =      2,664
Model VCE    : OIM

Expression   : Marginal predicted mean, predict()

------------------------------------------------------------------------------
             |            Delta-method
             |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
          Tx |
          0  |   .1376321   .0396795     3.47   0.001     .0598617    .2154025
          1  |   .1241345   .0368807     3.37   0.001     .0518496    .1964194
------------------------------------------------------------------------------

. margins, dydx(Tx)

Conditional marginal effects                    Number of obs     =      2,664
Model VCE    : OIM

Expression   : Marginal predicted mean, predict()
dy/dx w.r.t. : 2.Tx

------------------------------------------------------------------------------
             |            Delta-method
             |      dy/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
          Tx |
          1  |  -.0134976   .0151591    -0.89   0.373     -.043209    .0162137
------------------------------------------------------------------------------
Note: dy/dx for factor levels is the discrete change from the base level.

. 
. *Report ICC
. meglm NewIMI || FARMID: || Cow:, family(binomial) link(logit) notable nolog nocnsreport nopvalues noheader
LR test vs. logistic model: chi2(2) = 160.39              Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.

. estat icc

Intraclass correlation

------------------------------------------------------------------------------
                       Level |        ICC   Std. Err.     [95% Conf. Interval]
-----------------------------+------------------------------------------------
                      FARMID |    .137017   .0778794      .0418387    .3660068
                  Cow|FARMID |   .2876195   .0775701      .1612458    .4588534
------------------------------------------------------------------------------