## ----setup, include = FALSE--------------------------------------------------- knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) ## ----install, eval = FALSE---------------------------------------------------- # # from a local source: # install.packages("smartcor", repos = NULL, type = "source") # # # or use devtools from the package directory: # devtools::install("path/to/smartcor") ## ----library------------------------------------------------------------------ library(smartcor) ## ----pairwise----------------------------------------------------------------- # continuous + continuous → Pearson smart_cor(mtcars$mpg, mtcars$wt) ## ----pairwise-binary---------------------------------------------------------- # continuous + binary → point-biserial (= Pearson) smart_cor(mtcars$mpg, mtcars$vs) ## ----ordinal------------------------------------------------------------------ # numeric variables with ≤10 unique values are treated as ordinal by default; # assume_latent_normal controls whether polychoric or Kendall is used smart_cor(mtcars$gear, mtcars$carb, assume_latent_normal = FALSE) ## ----categorical-------------------------------------------------------------- # some categorical data colour = factor(sample(c("red", "blue", "green"), 100, replace = TRUE)) shape = factor(sample(c("circle", "square", "triangle"), 100, replace = TRUE)) smart_cor(colour, shape) ## ----override----------------------------------------------------------------- # force cyl to be treated as continuous smart_cor(mtcars$mpg, mtcars$cyl, y_type = "continuous") ## ----force-method------------------------------------------------------------- smart_cor(mtcars$mpg, mtcars$wt, method = "spearman") ## ----cormat------------------------------------------------------------------- mat = smart_cormat( mtcars[, c("mpg", "cyl", "vs", "gear")], assume_latent_normal = FALSE ) mat ## ----tidy--------------------------------------------------------------------- res = smart_cor(mtcars$mpg, mtcars$wt, verbose = FALSE) tidy(res) ## ----tidy-mat----------------------------------------------------------------- tidy(mat) ## ----available---------------------------------------------------------------- available_methods("ordinal", "ordinal") available_methods("continuous", "binary") available_methods("categorical", "categorical") ## ----auto, eval = FALSE------------------------------------------------------- # # runs the LR test and picks polychoric or Kendall accordingly: # smart_cor(mtcars$gear, mtcars$carb)