Correlation and Regression

Before You Start

Questions to open with.

Basic Procedure

Answering the questions.

Report Results

How does the literature report the results?

Summary and Practice

Syntax

Explain and comment the code.

The examples use the scored version of the simulated dataset described in Example Data.

Correlation table

This code runs when the site is built, so the table below it is its output.

library(sjPlot)
mydata <- read.csv("data/mydata_scored.csv")
data_cor <- mydata[, c("C_total", "B_s1", "B_s2", "B_s3", "A_s1", "A_s2", "A_s3", "B_total", "A_total")]
tab_corr(data_cor,
         corr.method = "spearman",
         title = "Correlation",
         triangle = "lower",
         show.p = TRUE)
Correlation
  C_total B_s1 B_s2 B_s3 A_s1 A_s2 A_s3 B_total A_total
C_total                  
B_s1 0.125**                
B_s2 0.222*** 0.436***              
B_s3 0.214*** 0.424*** 0.381***            
A_s1 0.161*** 0.237*** 0.261*** 0.330***          
A_s2 0.201*** 0.266*** 0.305*** 0.296*** 0.440***        
A_s3 0.155*** 0.276*** 0.272*** 0.306*** 0.441*** 0.426***      
B_total 0.240*** 0.758*** 0.819*** 0.731*** 0.353*** 0.370*** 0.355***    
A_total 0.221*** 0.320*** 0.352*** 0.397*** 0.792*** 0.782*** 0.776*** 0.454***  
Computed correlation used spearman-method with listwise-deletion.

Correlation heatmap

The same correlations as a heatmap. This code runs in your browser when the page loads; the first visit downloads the packages, so the plot takes a moment to appear. Change the options (for example type = "full" or lab = FALSE) and run it again.

Resources & References

References.

Further Study