# NOT RUN {
library(dplyr)
# connect DBMS
con_sqlite <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
# copy heartfailure to the DBMS with a table named TB_HEARTFAILURE
copy_to(con_sqlite, heartfailure, name = "TB_HEARTFAILURE", overwrite = TRUE)
# Using pipes ---------------------------------
# Normality test of all numerical variables
con_sqlite %>%
tbl("TB_HEARTFAILURE") %>%
normality()
# Positive values select variables, and In-memory mode and collect size is 200
con_sqlite %>%
tbl("TB_HEARTFAILURE") %>%
normality(platelets, sodium, collect_size = 200)
# Positions values select variables
con_sqlite %>%
tbl("TB_HEARTFAILURE") %>%
normality(1)
# Using pipes & dplyr -------------------------
# Test all numerical variables by 'smoking' and 'death_event',
# and extract only those with 'smoking' variable level is "Yes".
con_sqlite %>%
tbl("TB_HEARTFAILURE") %>%
group_by(smoking, death_event) %>%
normality() %>%
filter(smoking == "Yes")
# extract only those with 'sex' variable level is "Male",
# and test 'sodium' by 'smoking' and 'death_event'
con_sqlite %>%
tbl("TB_HEARTFAILURE") %>%
filter(sex == "Male") %>%
group_by(smoking, death_event) %>%
normality(sodium)
# Test log(sodium) variables by 'smoking' and 'death_event',
# and extract only p.value greater than 0.01.
# SQLite extension functions for log
RSQLite::initExtension(con_sqlite)
con_sqlite %>%
tbl("TB_HEARTFAILURE") %>%
mutate(log_sodium = log(sodium)) %>%
group_by(smoking, death_event) %>%
normality(log_sodium) %>%
filter(p_value > 0.01)
# Disconnect DBMS
DBI::dbDisconnect(con_sqlite)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab