---
title: "supplemental file 1 source code"
output: html_document
---

```{r message = FALSE, warning = FALSE}
library(easyGgplot2)
#ggplot2.multiplot(..., plotlist=NULL, cols=2)
library(easyGgplot2)
library(lme4)
library(merTools)
combinedData <- read.csv("~/Desktop/Temperature study/combined_data.csv")

combinedData$time_HR_imputed <- combinedData$time_HR
combinedData$time_HR_imputed[is.na(combinedData$time_HR_imputed)] <- 12

dataVeterans  <- read.csv('~/Desktop/Temperature study/veterans_processed.csv')
dataNHANES    <- read.csv('~/Desktop/Temperature study/NHANES_processed.csv')
ST_data 	  <- read.csv('~/Desktop/Temperature study/STRIDE_processed.csv')

dataVeterans$race <- factor(as.character(dataVeterans$race),levels = c("white", "black"))
combinedData$race [combinedData$race=="asian"]<- "other"
combinedData$race <- factor(combinedData$race,levels = c("white", "black","other" ))
dataNHANES$race[dataNHANES$race == "unknown"] <- NA
dataNHANES$race <- factor(dataNHANES$race,levels = c("white", "black","other" ))
ST_data$race [ST_data$race=="Asian"]<- "Other"
ST_data$race <- factor(ST_data$race,levels = c("White", "Black","Other"))
ST_data$exam_month<-factor (ST_data$exam_month)

dataVeterans$state_type <- factor(dataVeterans$state_type, levels = c("very cold", "cold","moderately_cold","moderate","warm", "hot"))

dataNHANES$exammonth <-as.factor(dataNHANES$exammonth)
dataVeterans$exammonth <-as.factor(dataVeterans$exammonth)


state_temps <- read.csv("~/Desktop/Temperature study/state_temps.csv")
state_codes <- read.csv("~/Desktop/Temperature study/state_codes.csv")
state_codes$Code <- factor(as.character(state_codes$Code), levels=levels(dataVeterans$state))
state_temps$state_code <- state_codes$Code[match(as.character(state_temps$state),as.character(state_codes$State))]

dataVeterans$ambient_temp <- (state_temps$value[match(paste(dataVeterans$state,(dataVeterans$examyear * 100 + as.numeric(dataVeterans$exammonth))), paste(state_temps$state_code,state_temps$date))] - 32) / 1.8

ST_data$state <- "CA"
  
ST_data$ambient_temp <- (state_temps$value[match(paste(ST_data$state,(ST_data$exam_year * 100 + as.numeric(ST_data$exam_month))), paste(state_temps$state_code,state_temps$date))] - 32) / 1.8


```

Supplementary File 1: Predicted body temperature in individuals with infectious diseases in the UAVCW cohort (1860-1940).
Expected body temperature (and associated 95% confidence interval) for a 30-year old white man with body weight of 70 kg and height 170 cm in the UAVCW cohort.  *, **, *** indicates significance at the 90%, 95%, and 99% level, respectively.


```{r message = FALSE, warning = FALSE}
lmVets_inf <- lm(temp_C ~ age + weightKG+ heightCM + cholera + cystitis + dengue + fever_unspec +gastro + goiter +  hepatitis + influenza + malaria + nephritis + pneumonia + scarlet_fever + sepsis + smallpox  + syphilis+ tb, data=dataVeterans)

summary(lmVets_inf)

lmVets_inf_base=data.frame(age=30, weightKG=70, heightCM = 170, race="white", cholera  = FALSE,cystitis  = FALSE,dengue  = FALSE,fever_unspec  = FALSE,gastro  = FALSE,goiter  = FALSE, hepatitis  = FALSE,influenza  = FALSE,malaria  = FALSE,nephritis  = FALSE,osteomyelitis  = FALSE,plague  = FALSE,pneumonia  = FALSE, rheumatic_fever  = FALSE,scarlet_fever  = FALSE,sepsis  = FALSE,smallpox   = FALSE,syphilis = FALSE,tb = FALSE, typhoid = FALSE, typhus = FALSE)


disease_names <- c("cholera", "cystitis ", "dengue", "fever_unspec", "gastro", "goiter", "hepatitis ", "influenza", "malaria", "nephritis", "pneumonia", "scarlet_fever", "sepsis", "smallpox", "syphilis", "tb")

df <- NULL
for (dn in disease_names) {
  lmVets_inf_dn <- lmVets_inf_base
  lmVets_inf_dn[dn] <- TRUE
  pp <- round(predict(lmVets_inf, lmVets_inf_dn, interval="confidence"),2)
  row <- data.frame(disease=dn,fit=pp[1],lower=pp[2],upper=pp[3])
  if (is.null(df)) {
    df <- row
  } else {
    df <- rbind(df,row)
  }
}
write.csv (df,"~/Desktop/Temperature study/diseases.csv")


```