# Return to Minitab macro index

# How to save this page as a macro

# CORR.MAC 
# This macro computes correlations with P-values.
# P-values use the t-statistic t= R sqrt(n-2) / sqrt(1-r^2), with df n-2. 
# 
#  AUTHOR:  Darryl K. Nester
#           Bluffton College 
#           Bluffton, OH  45817
#           (419)358 - 3483  
#
MACRO 
CORR dat.1-dat.n

MCOLUMN dat.1-dat.N r.1-r.N p.1-p.N t.1-t.N temp
MMATRIX Rmat
MCONSTANT N X Y OBS tval DF M
MTITLE 'Correlations'

#NOTE 
#NOTE  Neither Minitab Inc. nor the author of this MACRO makes any claim 
#NOTE  or offers any warranty whatsoever with regard to the accuracy of 
#NOTE  this MACRO or its suitability for use, and Minitab Inc. and the 
#NOTE  author of this MACRO each disclaims any liability with respect thereto.   
#NOTE   

BRIEF 0
# first put correlations into worksheet columns r.1-r.N
corr dat.1-dat.N Rmat
copy Rmat r.1-r.N

let M = N-1
# now erase upper triangle of matrix (which is the same as the lower triangle)
if M>1
 do X=2:M
  do Y=2:X
   let r.X(Y) = '*'
  enddo
 enddo
endif
delete 1 r.1-r.N

let OBS = N(dat.1)
let DF = OBS-2
do X=1:M
 let t.X = r.X * SQRT( DF / (1 - r.X**2) )
 let temp = -ABSOLUTE(t.X)
 CDF temp temp;
  T DF.
 let p.X= 2*temp
enddo

BRIEF 2
NOTITLE

corr dat.1-dat.N
BRIEF 1
if M=1
  print r.1 t.1 p.1;
   format ('    Correlation: ',F10.7,'; t=',F10.5,'; P-value=',F8.6,'.').
else
  print r.1-r.M
  print t.1-t.M
  print p.1-p.M
endif

BRIEF 2

ENDMACRO