R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

New file: heart failure

heart_failure <- read_csv(file = “C:/Users/Arene Butto/Documents/MSCR/MSCR 598 - B2K/clinical_heart-failure.csv”) view(heart_failure)

head(heart_failure) tail(heart_failure) dim(heart_failure)

summary(heart_failure)

library(skimr) skim(heart_failure)

library(gtsummary)

tbl_summary(heart_failure, by = smoking) %>% add_p()

Linear regression

fit_lm <- lm(serum_creatinine ~ age + anaemia + creatinine_phosphokinase + diabetes + ejection_fraction + high_blood_pressure + platelets + serum_sodium + sex, data = heart_failure) summary(fit_lm)

Age, and serum_sodium are associated with serum_creatinine (p = 0.01, p=0.001, respectively), but only higher age is associated with increased serum creatinine. Higher serum sodium is associated with lower creatinine.

c <- 0 point <- tribble(~age, ~anaemia, ~creatinine_phosphokinase, ~diabetes, ~ejection_fraction, ~high_blood_pressure, ~platelets, ~serum_sodium, ~sex, ~smoking, ~death, 70, c, c, 1, c, 1, c, 130, c, c, c) point predict(fit_lm, point)

Logistic regression

fit_glm <- glm(death ~ age + anaemia + creatinine_phosphokinase + diabetes + ejection_fraction + high_blood_pressure + platelets + serum_sodium + sex, data = heart_failure, family = “binomial”) summary(fit_glm) ## Predictors for death are age, ejection fraction, and serum sodium

tidy(fit_glm, exponentiate = TRUE) augment(fit_glm, type.predict = “response”)

Creating an ROC curve

library(yardstick) roc_glm <- augment(fit_glm, type.predict = “response”)

roc_curve(roc_glm, TRUTH = death, .fitted, event_level = “second”) %>% autoplot()

rlang::last_error()