library(MASS) # the complete dataset for trypanosome prevalence is included in the file "Isaac_et_al_additional_file_1_complete_trypanosome_prevalence_dataset.txt" # the following procedure assumes that the file "Isaac_et_al_additional_file_1_complete_trypanosome_prevalence_dataset.txt" is located on the C drive (file location "C:/Isaac_et_al_additional_file_1_complete_trypanosome_prevalence_dataset.txt" as indicated below) #load complete dataset: Dataset <- read.table("C:/Isaac_et_al_additional_file_1_complete_trypanosome_prevalence_dataset.txt", header=TRUE, sep="\t", na.strings="NA", dec=".", strip.white=TRUE) Dataset <- within(Dataset, {Fly_sex <- as.factor(Fly_sex)}) #convert numberic variable (Fly_sex) into factor Dataset <- within(Dataset, {Collection_site <- as.factor(Collection_site)}) #convert numberic variable (Collection_site) into factor Dataset <- within(Dataset, {tsetse_species <- as.factor(tsetse_species)}) #convert numberic variable (tsetse_species) into factor #logistic regressions on the complete data set: GLM.1 <- glm(All_trypanosomes ~ Collection_site+Fly_sex+(Collection_site*Fly_sex), family=binomial(logit), data=Dataset) # logistic regression for all trypanosome tsetse_species stepGLM.Alltryps <- stepAIC(GLM.1, direction="backward", steps=2) # stepwise model selection based on AIC stepGLM.Alltryps$anova # display results of model selection GLM.1.1 <- glm(All_trypanosomes ~ Fly_sex, family=binomial(logit), data=Dataset) # selected Model: All_trypanosomes ~ Collection_site summary(GLM.1.1) # output results for selected model exp(coef(GLM.1.1)) # compute the odd ratios for selected model GLM.2 <- glm(T.congolense_subspp. ~ Collection_site+Fly_sex+(Collection_site*Fly_sex), family=binomial(logit), data=Dataset) # logistic regression for T.congolense_subspp. stepGLM.T.congolense_subspp. <- stepAIC(GLM.2, direction="backward", steps=2) # stepwise model selection based on AIC stepGLM.T.congolense_subspp.$anova # display results of model selection GLM.2.1 <- glm(T.congolense_subspp. ~ Collection_site, family=binomial(logit), data=Dataset) # selected Model: T.congolense_subspp. ~ Collection_site summary(GLM.2.1) # output results for selected model exp(coef(GLM.2.1)) # compute the odd ratios for selected model GLM.3 <- glm(T.congolense_Savannah ~ Collection_site+Fly_sex+(Collection_site*Fly_sex), family=binomial(logit), data=Dataset) # logistic regression for T.congolense_Savannah stepGLM.T.congolense_Savannah <- stepAIC(GLM.3, direction="backward", steps=2) # stepwise model selection based on AIC stepGLM.T.congolense_Savannah$anova # display results of model selection (selected Model: T.congolense_Savannah ~ Collection_site + Fly_sex + Fly_sex*Collection_site) summary(GLM.3) # output results for selected model exp(coef(GLM.3)) # compute the odd ratios for selected model GLM.4 <- glm(T.congolense_Forest ~ Collection_site+Fly_sex+(Collection_site*Fly_sex), family=binomial(logit), data=Dataset) # logistic regression for T.congolense_Forest stepGLM.T.congolense_Forest <- stepAIC(GLM.4, direction="backward", steps=2) # stepwise model selection based on AIC stepGLM.T.congolense_Forest$anova # display results of model selection GLM.4.1 <- glm(T.congolense_Forest ~ Collection_site, family=binomial(logit), data=Dataset) # selected Model: T.congolense_Forest ~ Collection_site summary(GLM.4.1) # output results for selected model exp(coef(GLM.4.1)) # compute the odd ratios for selected model GLM.5 <- glm(T.vivax ~ Collection_site+Fly_sex+(Collection_site*Fly_sex), family=binomial(logit), data=Dataset) # logistic regression for T.vivax stepGLM.T.vivax <- stepAIC(GLM.5, direction="backward", steps=2) # stepwise model selection based on AIC stepGLM.T.vivax$anova # display results of model selection (selected Model: T.vivax ~ Collection_site + Fly_sex + Fly_sex*Collection_site) summary(GLM.5) # output results for selected model exp(coef(GLM.5)) # compute the odd ratios for selected model yankari <- subset(Dataset, subset=Collection_site==2) # create a subset dataset from the complete dataset for the Collection_site Yankari only yankari <- within(yankari, {Fly_sex <- as.factor(Fly_sex)}) #convert numberic variable (Fly_sex) into factor in the new created yankari dataset yankari <- within(yankari, {tsetse_species <- as.factor(tsetse_species)}) #convert numberic variable (tsetse_species) into factor in the new created yankari dataset GLM.6 <- glm(All_trypanosomes ~ tsetse_species+Fly_sex+(tsetse_species*Fly_sex), family=binomial(logit), data=yankari) # logistic regression for all trypanosome tsetse_species in yankari stepGLM.Alltryps_yankari <- stepAIC(GLM.6, direction="backward", steps=2) # stepwise model selection based on AIC stepGLM.Alltryps_yankari$anova # display results of model selection GLM.6.1 <- glm(All_trypanosomes ~ Fly_sex, family=binomial(logit), data=yankari) # selected Model: All_trypanosomes ~ Collection_site summary(GLM.6.1) # output results for selected model exp(coef(GLM.6.1)) # compute the odd ratios for selected model GLM.7 <- glm(T.congolense_subspp. ~ tsetse_species+Fly_sex+(tsetse_species*Fly_sex), family=binomial(logit), data=yankari) # logistic regression for T.congolense_subspp. stepGLM.T.congolense_subspp._yankari <- stepAIC(GLM.7, direction="backward", steps=2) # stepwise model selection based on AIC stepGLM.T.congolense_subspp._yankari$anova # display results of model selection GLM.7.1 <- glm(T.congolense_subspp. ~ Fly_sex, family=binomial(logit), data=yankari) # selected Model: T.congolense_subspp. ~ 1 summary(GLM.7.1) # output results for selected model exp(coef(GLM.7.1)) # compute the odd ratios for selected model GLM.8 <- glm(T.congolense_Savannah ~ tsetse_species+Fly_sex+(tsetse_species*Fly_sex), family=binomial(logit), data=yankari) # logistic regression for T.congolense_Savannah stepGLM.T.congolense_Savannah <- stepAIC(GLM.8, direction="backward", steps=2) # stepwise model selection based on AIC stepGLM.T.congolense_Savannah$anova # display results of model selection GLM.8.1 <- glm(T.congolense_Savannah ~ Fly_sex, family=binomial(logit), data=yankari) # selected Model: T.congolense_Savannah ~ Fly_sex summary(GLM.8.1) # output results for selected model exp(coef(GLM.8.1)) # compute the odd ratios for selected model GLM.9 <- glm(T.congolense_Forest ~ tsetse_species+Fly_sex+(tsetse_species*Fly_sex), family=binomial(logit), data=yankari) # logistic regression for T.congolense_Forest stepGLM.T.congolense_Forest <- stepAIC(GLM.9, direction="backward", steps=2) # stepwise model selection based on AIC stepGLM.T.congolense_Forest$anova # display results of model selection (selected Model: T.congolense_Forest ~ Collection_site) summary(GLM.9) # output results for selected model exp(coef(GLM.9)) # compute the odd ratios for selected model GLM.10 <- glm(T.vivax ~ tsetse_species+Fly_sex+(tsetse_species*Fly_sex), family=binomial(logit), data=yankari) # logistic regression for T.vivax stepGLM.T.vivax <- stepAIC(GLM.10, direction="backward", steps=2) # stepwise model selection based on AIC stepGLM.T.vivax$anova # display results of model selection GLM.10.1 <- glm(T.vivax ~ Fly_sex, family=binomial(logit), data=yankari) # selected Model: T.vivax ~ Fly_sex summary(GLM.10.1) # output results for selected model exp(coef(GLM.10.1)) # compute the odd ratios for selected model