Appendix S1. Statistical models of analysis A. Repeatability mixed linear model for the analysis of immune traits, and weekly health and lactation traits corresponding to the week of the immune measurement: Yijklmno Gi D j YM k LAl Wm An eijklmno Yijklmno = Animal record µ = Overall mean Gi = Fixed effect of ith genetic line (i=1, 2) Dj = Fixed effect of jth diet group (j=1, 2) YMk = Fixed effect of kth year by month of calving interaction (k=1, 25) LAl = Fixed effect of lth lactation number (l=1, 3) by age at calving interaction Wm = Fixed effect of mth week of lactation when the record was taken (m=1, 44) An = Random effect of nth individual cow (mean=0, variance=Va) eijklmno = Random residual effect (mean=0, variance=Ve) B. Fixed linear model for the analysis of number of health episodes and reproductive traits: Yijklmo Gi D j YM k LAl Wm eijklmo Yijklmo = Animal record µ = Overall mean Gi = Fixed effect of ith genetic line (i=1, 2) Dj = Fixed effect of jth diet group (j=1, 2) YMk = Fixed effect of kth year by month of calving interaction (k=1, 25) LAl = Fixed effect of lth lactation number (l=1, 3) by age at calving interaction Wm = Fixed effect of mth week of lactation when the record was taken (m=1, 44) eijklmo = Random residual effect (mean=0, variance=Ve) C. Random regression model for repeated measures analysis of lactation traits across the entire lactation: 2 2 p 0 p 0 Yijkqlmnpo Gi D j YM k YMR q LAl b p PpWm Apn PpWm eijkqlmnpo Yijkqlmnpo = Animal record µ = Overall mean Gi = Fixed effect of ith genetic line (i=1, 2) Dj = Fixed effect of jth diet group (j=1, 2) YMk = Fixed effect of kth year by month of calving interaction (k=1, 25) YMRq = Fixed effect of qth year by month of record interaction (q=1, 28) LAl = Fixed effect of lth lactation number (l=1, 3) by age at calving interaction Wm = Fixed effect of mth week of lactation when the record was taken (m=1, 44) bp = Fixed regression coefficient on week of lactation Pp = pth orthogonal polynomial of week of lactation (p=order of polynomial), Apn = Random regression coefficient on week of lactation associated with the random effect of the nth individual cow eijqklmnpo = Random residual effect (mean=0, variance=Ve)