如何在SPSS中创建相关图(相关矩阵热图)?

时间:2017-03-06 14:27:02

标签: matrix heatmap correlation spss

相关矩阵热图( correlogram )只是我所知道的最棒的可视化工具之一。但是,在SPSS中,没有内置的可能性来使用相关矩阵输出。 enter image description here

Andrew Wheeler写了一篇很棒的SPSS-syntax和博客文章来解决这个问题,但不知何故我不能使用它(没有编码背景)。

在实现变量名称和内容之后,出现错误消息:

The specified variable Var2 does not exist.

(事实并非如此)

这是我的语法:

dataset declare corr_matrix.
OMS
/SELECT TABLES
/IF SUBTYPES = 'Correlations'
/DESTINATION FORMAT = SAV OUTFILE = 'corr_matrix'.


CORRELATIONS
  /VARIABLES=age sport school a_rank_stndrdzd b_rank_stndrdzd time_played_day rage_all toxic_all TIPI_E TIPI_A TIPI_C TIPI_ES TIPI_O POGQ_total

  /PRINT=TWOTAIL NOSIG
  /MISSING=PAIRWISE.

OMSEND.

*cleaning up the file.

dataset activate corr_matrix.

select if Var2 <> "Sig. (2-tailed)" and Var2 <> "N".

match files file = *
/drop Command_ Subtype_ Label_ Var2.
execute.


*now to reshape the data.

varstocases
/make Corr from age to POGQ_total
/INDEX Var2 (Corr).


******************************************************.
*Now to make my graphs.

*I make categories to map to colors.

if Corr < -.6 Corr_Dis = -2.
if Corr >= -.6 and Corr < -.2 Corr_Dis = -1.
if Corr >= -.2 and Corr < .2 Corr_Dis = 0.
if Corr >= .2 and Corr < .6 Corr_Dis = 1.
if Corr > .6 Corr_Dis = 2.
execute.

recode Corr (-1 thru -0.6 = -2)(-0.6 thru -0.2 = -1)(-0.2 thru 0.2 = 0)(0.2 thru 0.6 = 1)(0.6 thru 1 = 2) into Corr_Dis.
execute.

value labels Corr_Dis
-2 '-1 to -0.61'
-1 '-6 to -.21'
0 '-.2 to .19'
1 '.2 to .59'
2 '.6 to 1'
.

*Colors taken from ColorBrewer.

*Heat Map.

formats Corr (F3.2).

DATASET ACTIVATE corr_matrix.
* Chart Builder.
GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=Var2 Var1 Corr_Dis Corr MISSING=LISTWISE 
    REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  PAGE: begin(scale(1200px,800px))
  SOURCE: s=userSource(id("graphdataset"))
  DATA: Var2=col(source(s), name("Var2"), unit.category())
  DATA: Var1=col(source(s), name("Var1"), unit.category())
  DATA: Corr_Dis=col(source(s), name("Corr_Dis"), unit.category())
  DATA: Corr=col(source(s), name("Corr"))
  GUIDE: axis(dim(1), label(" "))
  GUIDE: axis(dim(2), label(" "))
  GUIDE: legend(aesthetic(aesthetic.color.interior), label("Correlation"))
  SCALE: cat(aesthetic(aesthetic.color.interior), map(("-2", color."0571B0"), ("-1", color."92C5DE"),("0", color."F7F7F7"),("1", color."F4A582"), ("2", color."CA0020")))
  SCALE: cat(dim(1), sort.natural(), reverse())
  SCALE: cat(dim(2), sort.natural())
  ELEMENT: polygon(position(Var2*Var1)), color.exterior(color_white), color.interior(Corr_Dis), label(Corr))
  PAGE: end()
END GPL.

compute corr_abs = ABS(corr).
execute.

0 个答案:

没有答案