Supplementary file 4: R statistical software scripts prepared for analyzing calf morbidity and mortality event data setwd("D:/desk top collected/Umar_data") library(survival) library(ggplot2) library(ggpubr) library(GGally) library(ggpubr) library(foreign) library("ggfortify") library(survminer) library(prevalence) library(epiR) mydata<- read.csv("final_data.csv", header = T,",") class(mydata$morbidity.interval) mydata$morbidity.interval<- as.numeric(mydata$morbidity.interval) class(mydata$mortality.interval) mydata$mortality.interval<- as.numeric(mydata$mortality.interval) class(mydata$mortality.interval) ###incidence rate calculation with its 95%CI nmor<- 15 ## number of mortality during follow up ntmor<- 107.41 ## calf 6 months at risk of mortality tmor<- as.matrix(cbind(nmor,ntmor)) ## combine the two vectors epi.conf(tmor,ctype = "inc.rate",method = "exact",N=1000,design = 1, conf.level = 0.95)*100 ncas<-53 ## number of morbidity in the follow up period ntar<- 97.05 ## calf 6 months at risk of morbidity temp<- as.matrix(cbind(ncas,ntar)) ## combine the two vectors epi.conf(temp,ctype = "inc.rate",method = "exact",N=1000,design = 1, conf.level = 0.95)*100 ndia<- 16 ## no of diarric calf nmatr<- 106.87 ## calf at 6 months at risk dia<- as.matrix(cbind(ndia,nmatr)) ## combine two vectors epi.conf(dia,ctype = "inc.rate",method = "exact",N=1000,design = 1, conf.level = 0.95)*100 npnu<- 10 ## no of pnumonia calf nmatr<- 106.99 ## calf at 6 months at risk pnu<- as.matrix(cbind(npnu,nmatr)) ## combine two vectors epi.conf(pnu,ctype = "inc.rate",method = "exact",N=1000,design = 1, conf.level = 0.95)*100 nsep<- 7 ## no of sept. calf nmatr<- 107.24 ## calf at 6 months at risk sep<- as.matrix(cbind(nsep,nmatr)) ## combine two vectors epi.conf(sep,ctype = "inc.rate",method = "exact",N=1000,design = 1, conf.level = 0.95)*100 nomp<- 3 ## no of omphalities calf nmatr<- 107.18 ## calf at 6 months at risk omp<- as.matrix(cbind(nomp,nmatr)) ## combine two vectors epi.conf(omp,ctype = "inc.rate",method = "exact",N=1000,design = 1, conf.level = 0.95)*100 nskd<- 7 ## no of skin disease calf nmatr<- 107.02 ## calf at 6 months at risk skd<- as.matrix(cbind(nskd,nmatr)) ## combine two vectors epi.conf(skd,ctype = "inc.rate",method = "exact",N=1000,design = 1, conf.level = 0.95)*100 nmis<- 10 ## no of skin disease calf nmatr<- 107 ## calf at 6 months at risk mis<- as.matrix(cbind(nmis,nmatr)) ## combine two vectors epi.conf(mis,ctype = "inc.rate",method = "exact",N=1000,design = 1, conf.level = 0.95)*100 ###estimate of cummulative incidence and 95%CI of calf morbidity source("CumIncidence.R") ### find a function from the working directory fit_morb<-CumIncidence (mydata$morbidity.interval, mydata$Morbidity, cencode = 0, xlab="Days", t=c(0,30,60,90,120,150,180), level = 0.95) ##to estimate the commulative incidence of calf mortality and its 95%CI fit_mort<-CumIncidence (mydata$mortality.interval, mydata$Mortality, cencode = 0, xlab="Days", t=c(0,30,60,90,120,150,180), level = 0.95) cuminc(mydata$morbidity.interval, mydata$Morbidity, cencode = 0,level=0.95) ### calculation of calf Mortality hazard at different time interval nmis<- 6## no of cases at day 30 nmatr<- 237 ## calf at risk mis<- as.matrix(cbind(nmis,nmatr)) ## combine two vectors epi.conf(mis,ctype = "inc.rate",method = "exact",N=1000,design = 1, conf.level = 0.95) nmis<- 5## no of cases at day 60 nmatr<- 211 ## calf at risk at d60 mis<- as.matrix(cbind(nmis,nmatr)) ## combine two vectors epi.conf(mis,ctype = "inc.rate",method = "exact",N=1000,design = 1, conf.level = 0.95) nmis<- 1## no of cases at day 90 nmatr<- 148 ## calf at risk at d90 mis<- as.matrix(cbind(nmis,nmatr)) ## combine two vectors epi.conf(mis,ctype = "inc.rate",method = "exact",N=1000,design = 1, conf.level = 0.95) nmis<- 1## no of cases at day 120 nmatr<- 94 ## calf at risk at d120 mis<- as.matrix(cbind(nmis,nmatr)) ## combine two vectors epi.conf(mis,ctype = "inc.rate",method = "exact",N=1000,design = 1, conf.level = 0.95) nmis<- 2## no of cases at day 150 nmatr<- 52 ## calf at risk at d150 mis<- as.matrix(cbind(nmis,nmatr)) ## combine two vectors epi.conf(mis,ctype = "inc.rate",method = "exact",N=1000,design = 1, conf.level = 0.95) nmis<- 0## no of cases at day 180 nmatr<- 2 ## calf at risk at d180 mis<- as.matrix(cbind(nmis,nmatr)) ## combine two vectors epi.conf(mis,ctype = "inc.rate",method = "exact",N=1000,design = 1, conf.level = 0.95) ### calculation of calf morbidity hazard at different time interval nmis<- 17## no of cases at day 30 nmatr<- 237 ## calf at risk mis<- as.matrix(cbind(nmis,nmatr)) ## combine two vectors epi.conf(mis,ctype = "inc.rate",method = "exact",N=1000,design = 1, conf.level = 0.95) nmis<- 15## no of cases at day 60 nmatr<- 198 ## calf at risk at d60 mis<- as.matrix(cbind(nmis,nmatr)) ## combine two vectors epi.conf(mis,ctype = "inc.rate",method = "exact",N=1000,design = 1, conf.level = 0.95) nmis<- 5## no of cases at day 90 nmatr<- 129 ## calf at risk at d90 mis<- as.matrix(cbind(nmis,nmatr)) ## combine two vectors epi.conf(mis,ctype = "inc.rate",method = "exact",N=1000,design = 1, conf.level = 0.95) nmis<- 13## no of cases at day 120 nmatr<- 82 ## calf at risk at d120 mis<- as.matrix(cbind(nmis,nmatr)) ## combine two vectors epi.conf(mis,ctype = "inc.rate",method = "exact",N=1000,design = 1, conf.level = 0.95) nmis<- 3## no of cases at day 150 nmatr<- 40 ## calf at risk at d150 mis<- as.matrix(cbind(nmis,nmatr)) ## combine two vectors epi.conf(mis,ctype = "inc.rate",method = "exact",N=1000,design = 1, conf.level = 0.95) nmis<- 0## no of cases at day 180 nmatr<- 16 ## calf at risk at d180 mis<- as.matrix(cbind(nmis,nmatr)) ## combine two vectors epi.conf(mis,ctype = "inc.rate",method = "exact",N=1000,design = 1, conf.level = 0.95) ##mydata$Interval<- as.numeric(mydata$Interval) ##mydata210<- subset(mydata, mydata$Interval_conception<=210)## interval below 210 days ### median survival time estimated using the following function mydata$Morbidity<- as.numeric(levels(mydata$Morbidity)) morb<- survfit(Surv(mydata$morbidity.interval,mydata$Morbidity)~1) summary(morb) ### ploting the survival curve for morbidity using ggsu ###fitting survival model to plot the morbidity curve my.KMest<- survfit(Surv(mydata$morbidity.interval,mydata$Morbidity)~1) ### ploting the survival curve for morbidity using ggsurvplot ggsurv <- ggsurvplot(my.KMest, data = mydata, title = "survival curve of calf morbidity", palette = "jco", # jco palette xlim = c(0,180), # present narrower X axis, but not affect ylim = c(0.4,1), # survival estimates. xlab = "Time (days)", # customize X axis label. break.time.by = 30, # break X axis in time intervals by 500. ggtheme = theme_survminer(), ylab = "% surviving,s(t)", legend= "none", risk.table = TRUE) # Add risk table ggsurv ## fitting survival model to mortality my.kmmor<- survfit(Surv(mydata$mortality.interval,mydata$Mortality)~1) ggsurv_morta <- ggsurvplot(my.kmmor, data = mydata, title = "survival curve of calf mortality", palette = "jco", # jco palette xlim = c(0,180), # present narrower X axis, but not affect # survival estimates. ylim = c(0.75,1), xlab = "Time (days)", # customize X axis label. break.time.by = 30, # break X axis in time intervals by 500. ggtheme = theme_survminer(), ylab = "% surviving,s(t)", tables.height = 0.25, legend = "none", risk.table = TRUE) # Add risk table ggsurv_morta ##### log rank test of predictor variables on calf mortality mor<- survfit(Surv(mydata$mortality.interval, mydata$Mortality)~1) summary(mor) #### confidence interval of proportions prop.test(3,15,correct=FALSE)## 95% CI male prop.test(41,53,correct=FALSE)## 95% CI female prop.test(13,53,correct=FALSE)## 95% CI young prop.test(38,53,correct=FALSE)## 95% CI adult ### univariate cox proportional regression for calf morbidity attach(mydata) my.surv<- Surv(mydata$morbidity.interval, mydata$Morbidity) sink(file = "morb_univariate.txt") se<- coxph(my.surv ~ mydata$Sex, mydata) se bree<- coxph(my.surv~mydata$Breed, mydata) bree par<- coxph(my.surv~mydata$parity, mydata) par del_sta<- coxph(my.surv~mydata$Delivery.status, mydata) del_sta post_del<- coxph(my.surv~mydata$Postdelivery.complication, mydata) post_del inc<- coxph(my.surv~mydata$income.source, mydata) inc exp<- coxph(my.surv~mydata$Dairying.experience, mydata) exp man<- coxph(my.surv~mydata$Management, mydata) man Her<- coxph(my.surv~mydata$Herd.size, mydata) Her breeding<- coxph(my.surv~mydata$Breeding.method, mydata) breeding floor<- coxph(my.surv~mydata$Floor.type, mydata) floor calfpen< coxph(my.surv~mydata$Calving.pen, mydata) calfpen vac<- coxph(my.surv~mydata$Dam.vaccination, mydata) vac umb<- coxph(my.surv~mydata$umbilical.disinfection, mydata) umb housing<-coxph(my.surv~mydata$Calf.housing, mydata) housing fre<- coxph(my.surv~mydata$pen.cleaning.frequency, mydata) fre bedding<- coxph(my.surv~mydata$pen.bedding, mydata) bedding colos<- coxph(my.surv~mydata$first.colostrum,mydata) colos method<- coxph(my.surv~mydata$colo.feeding.method, mydata) method amount<- coxph(my.surv~mydata$Amount.of.milk.fed, mydata) amount water<- coxph(my.surv~mydata$Water.provision, mydata) water ### univariate cox proportional regression for calf mortality attach(mydata) my.mor<- Surv(mydata$mortality.interval, mydata$Mortality) sink(file = "mortality_univariate.txt") se_mo<- coxph(my.mor ~ mydata$Sex, mydata) se_mo bree_mo<- coxph(my.mor~mydata$Breed, mydata) bree_mo par_mo<- coxph(my.mor~mydata$parity, mydata) par_mo del_sta_mo<- coxph(my.mor~mydata$Delivery.status, mydata) del_sta_mo post_del_mo<- coxph(my.mor~mydata$Postdelivery.complication, mydata) post_del_mo inc_mo<- coxph(my.mor~mydata$income.source, mydata) inc_mo exp_mo<- coxph(my.mor~mydata$Dairying.experience, mydata) exp_mo man_mo<- coxph(my.mor~mydata$Management, mydata) man_mo Her_mo<- coxph(my.mor~mydata$Herd.size, mydata) Her_mo breeding_mo<- coxph(my.mor~mydata$Breeding.method, mydata) breeding_mo floor_mo<- coxph(my.mor~mydata$Floor.type, mydata) floor_mo calfpen_mo< coxph(my.mor~mydata$Calving.pen, mydata) calfpen_mo vac_mo<- coxph(my.mor~mydata$Dam.vaccination, mydata) vac_mo umb_mo<- coxph(my.mor~mydata$umbilical.disinfection, mydata) umb_mo housing_mo<-coxph(my.mor~mydata$Calf.housing, mydata) housing_mo fre_mo<- coxph(my.mor~mydata$pen.cleaning.frequency, mydata) fre_mo bedding_mo<- coxph(my.mor~mydata$pen.bedding, mydata) bedding_mo colos_mo<- coxph(my.mor~mydata$first.colostrum,mydata) colos_mo method_mo<- coxph(my.mor~mydata$colo.feeding.method, mydata) method_mo amount_mo<- coxph(my.mor~mydata$Amount.of.milk.fed, mydata) amount_mo water_mo<- coxph(my.mor~mydata$Water.provision, mydata) water_mo #### multivariate cox proportional hazard model for calf morbidity final_morbidity<- coxph(my.surv~mydata$Breed + mydata$parity + mydata$Delivery.status + mydata$Postdelivery.complication + mydata$income.source + mydata$Dairying.experience + mydata$Herd.size + mydata$Floor.type + mydata$Calving.pen + mydata$Calf.housing + mydata$pen.cleaning.frequency + mydata$pen.bedding + mydata$first.colostrum + mydata$Amount.of.milk.fed + mydata$Water.provision, control = coxph.control(iter.max = 50), mydata) summary(final_morbidity) #### multivariate cox proportional hazard model for calf mortality final_mortality<- coxph(my.mort~mydata$parity + mydata$Delivery.status + mydata$Postdelivery.complication + mydata$Dairying.experience + mydata$Herd.size + mydata$Floor.type + mydata$Calving.pen + mydata$Calf.housing + mydata$pen.cleaning.frequency + mydata$pen.bedding + mydata$first.colostrum + mydata$colo.feeding.method + mydata$Amount.of.milk.fed, control = coxph.control(iter.max = 50), mydata) summary(final_mortality) #### survival curve for dam parity parity<- survfit(Surv(mydata$morbidity.interval, mydata$Morbidity) ~ mydata$parity, data = mydata) ggsurv_parity <- ggsurvplot(parity, data = mydata, title = "Survival curve of dam parity", linetype = "strata", pval = TRUE, # Add p-value conf.int = TRUE, palette = c("#E7B800", "#2E9FDF"), # custom color palette xlim = c(0,180), # present narrower X axis xlab = "Time (days)", # customize X axis label. break.time.by = 30, # break X axis in time intervals by 500. ggtheme = theme_survminer(aspect.ratio = 1), ylab = "% surviving,s(t)", font.x= c(14,"black"), font.y= c(14,"black"), surv.plot.height= 2, legend = "bottom", legend.title = "Parity", legend.labs = c("Multiparous","Primiparous")) # Add risk table ggsurv_parity #### survival curve for cleaning freq. cleaning_freq<- survfit(Surv(mydata$morbidity.interval, mydata$Morbidity) ~ mydata$pen.cleaning.frequency, data = mydata) ggsurv_freq <- ggsurvplot(cleaning_freq, data = mydata, title = "Survival curve of pen cleaning freq.", linetype = "strata", pval = TRUE, # Add p-value conf.int = TRUE, palette = c("#E7B800", "#2E9FDF"), # custom color palette xlim = c(0,180), # present narrower X axis xlab = "Time (days)", # customize X axis label. break.time.by = 30, # break X axis in time intervals by 500. ggtheme = theme_survminer(), ylab = "% surviving,s(t)", font.x= c(14,"black"), font.y= c(14,"black"), legend = "bottom", legend.title = "cleaning frequency", legend.labs = c("Less frequently","Regularly")) ggsurv_freq #### survival curve for first colostrum colostr<- survfit(Surv(mydata$morbidity.interval, mydata$Morbidity) ~ mydata$first.colostrum, data = mydata) ggsurv_colos <- ggsurvplot(colostr, data = mydata, title = "Survival curve of first colostrum feeding", linetype = "strata", pval = TRUE, # Add p-value conf.int = TRUE, palette = c("#E7B800", "#2E9FDF"), # custom color palette xlim = c(0,180), # present narrower X axis xlab = "Time (days)", # customize X axis label. break.time.by = 30, # break X axis in time intervals by 500. ggtheme = theme_survminer(), ylab = "% surviving,s(t)", font.x= c(14,"black"), font.y= c(14,"black"), legend = "bottom", legend.title = "First Colostrum", legend.labs = c("within 6 hours","After 6 hours")) ggsurv_colos ### survival curve of morbidity with delivery status delivery<- survfit(Surv(mydata$morbidity.interval, mydata$Morbidity) ~ mydata$Delivery.status, data = mydata) ggsurv_delivery <- ggsurvplot(delivery, data = mydata, title = "Survival curve of delivery status", linetype = "strata", pval = TRUE, # Add p-value conf.int = TRUE, palette = c("#E7B800", "#2E9FDF"), # custom color palette xlim = c(0,180), # present narrower X axis xlab = "Time (days)", # customize X axis label. break.time.by = 30, # break X axis in time intervals by 500. ggtheme = theme_survminer(aspect.ratio = 1), ylab = "% surviving,s(t)", font.x= c(14,"black"), font.y= c(14,"black"), surv.plot.height= 2, legend = "bottom", legend.title = "delivery status", legend.labs = c("Normal","Dystocia")) ggsurv_delivery ##survival curves for mortality #### survival curves for multivariate significant variables for mortality #### survival curve for dam parity parity_mor<- survfit(Surv(mydata$mortality.interval, mydata$Mortality) ~ mydata$parity, data = mydata) ggsurv_parity_mor <- ggsurvplot(parity_mor, data = mydata, title = "Survival curve of dam parity", linetype = "strata", pval = TRUE, # Add p-value conf.int = TRUE, palette = c("#E7B800", "#2E9FDF"), # custom color palette xlim = c(0,180), # present narrower X axis xlab = "Time (days)", # customize X axis label. break.time.by = 30, # break X axis in time intervals by 500. ggtheme = theme_survminer(aspect.ratio = 1), ylab = "% surviving,s(t)", font.x= c(14,"black"), font.y= c(14,"black"), surv.plot.height= 2, legend = "bottom", legend.title = "Parity", legend.labs = c("Multiparous","Primiparous")) # Add risk table ggsurv_parity_mor #### survival curve for cleaning frequency cleaning_freq_mor<- survfit(Surv(mydata$mortality.interval, mydata$Mortality) ~ mydata$pen.cleaning.frequency, data = mydata) ggsurv_freq_mor <- ggsurvplot(cleaning_freq_mor, data = mydata, title = "Survival curve of pen cleaning freq.", linetype = "strata", pval = TRUE, # Add p-value conf.int = TRUE, palette = c("#E7B800", "#2E9FDF"), # custom color palette xlim = c(0,180), # present narrower X axis xlab = "Time (days)", # customize X axis label. break.time.by = 30, # break X axis in time intervals by 500. ggtheme = theme_survminer(), ylab = "% surviving,s(t)", font.x= c(14,"black"), font.y= c(14,"black"), legend = "bottom", legend.title = "cleaning frequency", legend.labs = c("Less frequently","Regularly")) ggsurv_freq_mor ### survival curve of mortality with delivery status delivery_mor<- survfit(Surv(mydata$mortality.interval, mydata$Mortality) ~ mydata$Delivery.status, data = mydata) ggsurv_delivery_mor <- ggsurvplot(delivery_mor, data = mydata, title = "Survival curve of delivery status", linetype = "strata", pval = TRUE, # Add p-value conf.int = TRUE, palette = c("#E7B800", "#2E9FDF"), # custom color palette xlim = c(0,180), # present narrower X axis xlab = "Time (days)", # customize X axis label. break.time.by = 30, # break X axis in time intervals by 500. ggtheme = theme_survminer(aspect.ratio = 1), ylab = "% surviving,s(t)", font.x= c(14,"black"), font.y= c(14,"black"), surv.plot.height= 2, legend = "bottom", legend.title = "delivery status", legend.labs = c("Normal","Dystocia")) # Add risk table ggsurv_delivery_mor ##test the proportional hazard assumption for covariates in the final model of calf mortality attach(mydata) my.surv<- Surv(mydata$mortality.interval,mydata$Mortality) my_coxph_mortality<- coxph(my.surv~ parity + pen.cleaning.frequency + Delivery.status, control = coxph.control(iter.max = 50), mydata) test.ph<- cox.zph(my_coxph_mortality) test.ph ggcoxzph(test.ph) #### test the proportional hazard assumptions for covariates in the final model of calf morbidity my.morb<- Surv(mydata$morbidity.interval,mydata$Morbidity) my_coxph_morb<- coxph(my.morb~ parity + pen.cleaning.frequency + first.colostrum, control = coxph.control(iter.max = 50), mydata) test.ph1<- cox.zph(my_coxph_morb) test.ph1 ggcoxzph(test.ph1) ##### box plot of different causes of disease on morbidity box<- read.csv(file= "cause.csv", header = T) attach(box) box1<- subset(box,nchar(as.character(box$morbidity.cause))>=5) box2<- subset(box,nchar(as.character(box$mortality.cause))>=5) #### boxplot of median calf morbidity based on their syndrome theme_set(theme_pubr()) ggplot(data=box1, mapping=aes(x=morbidity.cause, y=interval.morbidity, fill = morbidity.cause))+geom_boxplot() + labs( title = "Median age of calf morbidity days by syndrome", x = "Causes of morbidity", y = "Days at risk") + theme(plot.title = element_text(size = 16, face = "bold", hjust = 0.5), legend.title= element_text(colour="blue", size=10, face="bold")) #### boxplot of median calf mortality based on their syndrome theme_set(theme_pubr()) ggplot(data=box2, mapping=aes(x=mortality.cause, y=interval.mortality, fill = mortality.cause))+geom_boxplot() + labs( title = "Median age of calf mortality days by syndrome", x = "Causes of mortality", scale_y_continuous(breaks=c(0,30,60,90,120,150,180)), y = "Days at risk") + theme(plot.title = element_text(size = 16, face = "bold", hjust = 0.5), legend.title= element_text(colour="blue", size=10, face="bold")) #### median days of morbidity for disease syndrome survfit(Surv(mydata$morbidity.interval,mydata$Morbidity)~mydata$Cause.morbidity) ##### median days of mortality survfit(Surv(mydata$mortality.interval,mydata$Mortality)~mydata$Cause.mortality)