Correlation Matrix

# FALLBACK
library(dplyr)
Warning: package 'dplyr' was built under R version 4.4.3

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
if(!exists("raw_data")) {
   raw_data <- data.frame(
    age = rnorm(50, 20, 2),
    anxiety = rnorm(50, 10, 3),
    depression = rnorm(50, 10, 3)
  )
}

# 1. Select Numeric Vars
numeric_vars <- raw_data %>% 
  select(where(is.numeric)) 

# 2. Compute Correlation
cor_mat <- cor(numeric_vars, use = "complete.obs")

# 3. Simple Visualization (Round to 2 decimals)
round(cor_mat, 2) %>% 
  knitr::kable(caption = "Pearson Correlations")
Table 1: Correlation Matrix
Pearson Correlations
age anxiety depression
age 1.00 0.04 0.16
anxiety 0.04 1.00 -0.08
depression 0.16 -0.08 1.00

Contact Request

If your default mail client did not open, you can copy my direct email details below: